follow-up for f4ll_c changes
This commit is contained in:
parent
b9114f049a
commit
f62880b4fa
6 changed files with 261 additions and 32 deletions
|
@ -56,8 +56,8 @@ void MainLoop()
|
|||
|
||||
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx) {
|
||||
struct initdata_t const *id = &initdata[idx];
|
||||
Pku_Init(&g_uartStatuses[idx], id->uart, id->dma, id->stream_rx, id->stream_tx, &g_crcStatus, NULL, NULL);
|
||||
memcpy(Pku_GetTxBuffer(&g_uartStatuses[idx]), text2Send, sizeof(text2Send) -1);
|
||||
Pu_Init(&g_uartStatuses[idx], id->uart, id->dma, id->stream_rx, id->stream_tx, &g_crcStatus, NULL, NULL);
|
||||
memcpy(Pu_GetTxBuffer(&g_uartStatuses[idx]), text2Send, sizeof(text2Send) -1);
|
||||
}
|
||||
|
||||
Dma_Init(&g_ConsoleTxDmaInfo, CONSOLE_DMA_ENGINE, CONSOLE_TX_DMA_STREAM);
|
||||
|
@ -68,7 +68,7 @@ void MainLoop()
|
|||
lastStatsTick = HAL_GetTick();
|
||||
|
||||
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx)
|
||||
Pku_SetupReceive(&g_uartStatuses[idx]);
|
||||
Pu_SetupReceive(&g_uartStatuses[idx]);
|
||||
|
||||
for(;;) {
|
||||
uint32_t tick = HAL_GetTick();
|
||||
|
@ -80,14 +80,14 @@ void MainLoop()
|
|||
if(!g_uartStatuses[idx].txBuffer.busy && send) {
|
||||
uint16_t len = sizeof(text2Send) - 1 - (rand() & randmask);
|
||||
DIAG_ENTER_BUSY();
|
||||
Mcd_Copy(Pku_GetTxBuffer(&g_uartStatuses[idx]), text2Send, len);
|
||||
Pku_Post(&g_uartStatuses[idx], NULL, len, &g_crcStatus, 1);
|
||||
Mcd_Copy(Pu_GetTxBuffer(&g_uartStatuses[idx]), text2Send, len);
|
||||
Pu_Post(&g_uartStatuses[idx], NULL, len, &g_crcStatus, 1);
|
||||
DIAG_EXIT_BUSY();
|
||||
}
|
||||
for(uint16_t rIdx = 0; rIdx < 2; ++rIdx)
|
||||
if(g_uartStatuses[idx].rxBuffers[rIdx].busy || g_uartStatuses[idx].rxBuffers[rIdx].error) {
|
||||
DIAG_ENTER_BUSY();
|
||||
Pku_ConsumePacket(&g_uartStatuses[idx], rIdx);
|
||||
Pu_ConsumePacket(&g_uartStatuses[idx], rIdx);
|
||||
DIAG_EXIT_BUSY();
|
||||
}
|
||||
}
|
||||
|
|
97
application/platform/mockme.h
Normal file
97
application/platform/mockme.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* mockme.h
|
||||
*
|
||||
* Created on: Nov 25, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_MOCKME_H_
|
||||
#define PLATFORM_MOCKME_H_
|
||||
|
||||
//#define TOSTR(x) #x
|
||||
#ifdef __cplusplus
|
||||
#define DECLARE_MOCK(F) \
|
||||
extern decltype(F) F ## __, *test_ ## F
|
||||
#else
|
||||
#define DECLARE_MOCK(F) \
|
||||
extern typeof(F) F ## __, *test_ ## F
|
||||
#endif
|
||||
|
||||
#define MOCKABLE(F) __attribute__((section(\
|
||||
".bss\n\t"\
|
||||
".globl test_" #F "\n\t"\
|
||||
".align 4\n\t"\
|
||||
".type test_" #F ", @object\n\t"\
|
||||
".size test_" #F ", 4\n"\
|
||||
"test_" #F ":\n\t"\
|
||||
".zero 4\n\t"\
|
||||
".text\n\t"\
|
||||
".p2align 4,,15\n\t"\
|
||||
".globl " #F "\n\t"\
|
||||
".type " #F ", @function\n"\
|
||||
#F ":\n\t"\
|
||||
".cfi_startproc\n\t"\
|
||||
"push %edx\n\t"\
|
||||
"push %edx\n\t"\
|
||||
"push %eax\n\t"\
|
||||
"movl test_" #F ", %eax\n\t"\
|
||||
"leal " #F "__, %edx\n\t"\
|
||||
"test %eax, %eax\n\t"\
|
||||
"cmove %edx, %eax\n\t"\
|
||||
"mov %eax, 8(%esp)\n\t"\
|
||||
"pop %eax\n\t"\
|
||||
"pop %edx\n\t"\
|
||||
"ret\n\t"\
|
||||
".cfi_endproc\n\t"\
|
||||
".size " #F ", .-" #F "\n\t"\
|
||||
".section .text"))) F ## __
|
||||
|
||||
#define DEFINE_MOCK_RET(rettype, fn, decor, ...) \
|
||||
static int fn ## _ ## decor ## _callcount; \
|
||||
static rettype fn ## _ ## decor ## _retval; \
|
||||
static rettype fn ## _ ## decor(__VA_ARGS__) { \
|
||||
++fn ## _ ## decor ## _callcount;
|
||||
|
||||
#define DEFINE_MOCK(fn, decor, ...) \
|
||||
static int fn ## _ ## decor ## _callcount; \
|
||||
static void fn ## _ ## decor(__VA_ARGS__) { \
|
||||
++fn ## _ ## decor ## _callcount;
|
||||
|
||||
#define RETURN_MOCK(fn, decor, ret) \
|
||||
fn##_##decor##_retval = ret; \
|
||||
return ret; }
|
||||
|
||||
#define RETURN_MOCK_PREDEF(fn, decor) \
|
||||
return fn##_##decor##_retval; }
|
||||
|
||||
#define LEAVE_MOCK }
|
||||
|
||||
#define DEFINE_MOCK_VAR(type, fn, decor, varname) type fn##_##decor##_##varname
|
||||
|
||||
#define MOCK_STORE(fn, decor, varname, value) fn##_##decor##_##varname = value
|
||||
|
||||
#define MOCK_VAR(fn, decor, varname) fn##_##decor##_##varname
|
||||
#define MOCK_CALLCOUNT(fn, decor) fn ## _ ## decor ## _callcount
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace mockme {
|
||||
template <typename T> class mockguard {
|
||||
T* m_guarded;
|
||||
public:
|
||||
mockguard(T* guarded, T testFunc) : m_guarded(guarded) { *m_guarded = testFunc; }
|
||||
~mockguard() { *m_guarded = nullptr; }
|
||||
};
|
||||
} // namespace mockme
|
||||
|
||||
#define ACTIVATE_MOCK(fn, decor) \
|
||||
fn ## _ ## decor ## _callcount = 0; \
|
||||
mockme::mockguard<decltype(fn)*> fn ## _ ## decor ## _mockguard(&test_ ## fn, fn ## _ ## decor)
|
||||
|
||||
#define ACTIVATE_MOCK_RV(fn, decor, ret) \
|
||||
fn##_##decor##_callcount = 0; \
|
||||
fn##_##decor##_retval = ret; \
|
||||
mockme::mockguard<decltype(fn)*> fn##_##decor##_mockguard(&test_ ## fn, fn##_##decor)
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* PLATFORM_MOCKME_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue