diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f934e5cc..28ce58a06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,8 @@ function(add_osal_ut_exe TGTNAME) # It is not an issue for UT builds that use OSAL stubs or no OSAL at all. set_target_properties(${TGTNAME} PROPERTIES COMPILE_DEFINITIONS "_UNIT_TEST_") set_target_properties(${TGTNAME} PROPERTIES COMPILE_FLAGS "${UT_C_FLAGS}") - set_target_properties(${TGTNAME} PROPERTIES LINK_FLAGS "${UT_C_FLAGS} -u OS_VolumeTable -u OS_STATIC_SYMBOL_TABLE -u UT_BSP_DoText") - target_link_libraries(${TGTNAME} ut_bsp osal ut_assert ${OSAL_LINK_LIBS}) + set_target_properties(${TGTNAME} PROPERTIES LINK_FLAGS "${UT_C_FLAGS} -u OS_VolumeTable -u OS_Application_Startup") + target_link_libraries(${TGTNAME} ut_assert osal) add_test(${TGTNAME} ${TGTNAME}) foreach(TGT ${INSTALL_TARGET_LIST}) install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) @@ -206,6 +206,7 @@ if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/bsp/${UT_OSAL_BSPTYPE}/ut-src) aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/bsp/${UT_OSAL_BSPTYPE}/ut-src UT_BSPFILES) add_library(ut_bsp STATIC EXCLUDE_FROM_ALL ${UT_BSPFILES}) set_target_properties(ut_bsp PROPERTIES COMPILE_DEFINITIONS "_UNIT_TEST_") + target_link_libraries(ut_assert ut_bsp) endif() if (ENABLE_UNIT_TESTS) @@ -246,7 +247,6 @@ if (ENABLE_UNIT_TESTS) src/ut-stubs/osapi-utstub-timebase.c) add_library(ut_osapi_stubs STATIC ${UT_OSAPI_STUB_SRCFILES}) - target_link_libraries(ut_osapi_stubs ut_assert) add_subdirectory(src/tests tests) add_subdirectory(src/unit-tests unit-tests) diff --git a/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c b/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c index 8f3b30ede..1b1890418 100644 --- a/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c +++ b/src/bsp/mcp750-vxworks/ut-src/bsp_ut.c @@ -162,9 +162,9 @@ void UT_BSP_DoTestSegmentReport(const char *SegmentName, const UtAssert_TestCoun UT_BSP_DoText(UTASSERT_CASETYPE_END, ReportBuffer); } -void UT_BSP_Setup(const char *Name) +void UT_BSP_Setup(void) { - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, Name); + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "VxWorks UNIT TEST"); } @@ -203,20 +203,15 @@ int RunTest(void) if (RetVal == 0) { - UT_BSP_Setup("VxWorks UNIT TEST"); - /* ** Call application specific entry point. */ OS_Application_Startup(); /* - ** In unit test mode, call the UtTest_Run function (part of UT Assert library) + ** The OS_Application_Run function is part of UT Assert library */ - UtTest_Run(); - - UT_BSP_EndTest(UtAssert_GetCounters()); - + OS_Application_Run(); RetVal = (UtAssert_GetCounters()->CaseCount[UTASSERT_CASETYPE_FAILURE] + UtAssert_GetCounters()->CaseCount[UTASSERT_CASETYPE_TSF]); diff --git a/src/bsp/pc-linux/ut-src/bsp_ut.c b/src/bsp/pc-linux/ut-src/bsp_ut.c index df8762437..a9cb1449f 100644 --- a/src/bsp/pc-linux/ut-src/bsp_ut.c +++ b/src/bsp/pc-linux/ut-src/bsp_ut.c @@ -111,7 +111,7 @@ void UT_BSP_ParseCommandLine(int argc, char *argv[]) } } -void UT_BSP_Setup(const char *Name) +void UT_BSP_Setup(void) { int mode; uint32 i; @@ -125,7 +125,7 @@ void UT_BSP_Setup(const char *Name) EnableTermCodes = isatty(STDOUT_FILENO); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, Name); + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "PC-LINUX UNIT TEST"); /* ** Create local directories for "disk" mount points @@ -344,7 +344,6 @@ void UT_BSP_EndTest(const UtAssert_TestCounter_t *TestCounters) int main(int argc, char *argv[]) { - UT_BSP_Setup("PC-LINUX UNIT TEST"); UT_BSP_ParseCommandLine(argc, argv); /* @@ -353,10 +352,9 @@ int main(int argc, char *argv[]) OS_Application_Startup(); /* - ** In unit test mode, call the UtTest_Run function (part of UT Assert library) + ** The OS_Application_Run function is part of UT Assert library */ - UtTest_Run(); - UT_BSP_EndTest(UtAssert_GetCounters()); + OS_Application_Run(); /* Should typically never get here */ return(EXIT_SUCCESS); diff --git a/src/bsp/pc-rtems/ut-src/bsp_ut.c b/src/bsp/pc-rtems/ut-src/bsp_ut.c index c0c94060a..26d82cba2 100644 --- a/src/bsp/pc-rtems/ut-src/bsp_ut.c +++ b/src/bsp/pc-rtems/ut-src/bsp_ut.c @@ -121,7 +121,7 @@ const char * UT_BSP_GetOptionString(int32 OptionNum) } -void UT_BSP_Setup(const char *Name) +void UT_BSP_Setup(void) { int status; int i; @@ -280,7 +280,7 @@ void UT_BSP_Setup(const char *Name) be sent to the console in case of a slow port */ rtems_task_wake_after(50); - UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, Name); + UT_BSP_DoText(UTASSERT_CASETYPE_BEGIN, "PC-RTEMS UNIT TEST"); } @@ -465,8 +465,6 @@ rtems_task Init( rtems_task_argument ignored ) { - UT_BSP_Setup("PC-RTEMS UNIT TEST"); - /* ** Call application specific entry point. ** This is supposed to call OS_API_Init() @@ -474,10 +472,9 @@ rtems_task Init( OS_Application_Startup(); /* - ** In unit test mode, call the UtTest_Run function (part of UT Assert library) + ** The OS_Application_Run function is part of UT Assert library */ - UtTest_Run(); - UT_BSP_EndTest(UtAssert_GetCounters()); + OS_Application_Run(); rtems_shutdown_executive(UtAssert_GetFailCount() != 0); } diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h index 44b9574e6..d7df853d5 100644 --- a/src/os/inc/osapi-os-core.h +++ b/src/os/inc/osapi-os-core.h @@ -142,10 +142,15 @@ typedef void (*OS_ArgCallback_t)(uint32 object_id, void *arg); /* ** Prototype for application startup function. -** This is implemented by the user application +** This is implemented by the BSP or user application */ void OS_Application_Startup(void); +/* +** Prototype for application run function. +** This is implemented by the BSP or user application +*/ +void OS_Application_Run(void); /* ** Exported Functions diff --git a/src/os/posix/ostimer.c b/src/os/posix/ostimer.c index 69dd8bfc7..54ad418fc 100644 --- a/src/os/posix/ostimer.c +++ b/src/os/posix/ostimer.c @@ -325,6 +325,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) int status; int i; struct sigevent evp; + struct timespec ts; OS_impl_timebase_internal_record_t *local; OS_common_record_t *global; OS_U32ValueWrapper_t arg; @@ -403,6 +404,34 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) sigemptyset(&local->sigset); sigaddset(&local->sigset, local->assigned_signal); + /* + * Ensure that the chosen signal is NOT already pending. + * + * Perform a "sigtimedwait" with a zero timeout to poll the + * status of the selected signal. RT signals are also queued, + * so this needs to be called in a loop to until sigtimedwait() + * returns an error. + * + * The max number of signals that can be queued is available + * via sysconf() as the _SC_SIGQUEUE_MAX value. + * + * The output is irrelevant here; the objective is to just ensure + * that the signal is not already pending. + */ + i = sysconf( _SC_SIGQUEUE_MAX); + do + { + ts.tv_sec = 0; + ts.tv_nsec = 0; + if (sigtimedwait(&local->sigset, NULL, &ts) < 0) + { + /* signal is NOT pending */ + break; + } + --i; + } + while(i > 0); + /* ** Initialize the sigevent structures for the handler. */ diff --git a/src/tests/bin-sem-flush-test/bin-sem-flush-test.c b/src/tests/bin-sem-flush-test/bin-sem-flush-test.c index 7fe26538e..0cc0e0ea4 100644 --- a/src/tests/bin-sem-flush-test/bin-sem-flush-test.c +++ b/src/tests/bin-sem-flush-test/bin-sem-flush-test.c @@ -156,7 +156,7 @@ void task_3(void) /* ** Main function */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/bin-sem-test/bin-sem-test.c b/src/tests/bin-sem-test/bin-sem-test.c index 3ac44188d..029437bc7 100644 --- a/src/tests/bin-sem-test/bin-sem-test.c +++ b/src/tests/bin-sem-test/bin-sem-test.c @@ -147,7 +147,7 @@ void BinSemCheck(void) } -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c b/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c index e1a8a8a16..183306e16 100644 --- a/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c +++ b/src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c @@ -153,7 +153,7 @@ void BinSemTimeoutCheck(void) UtAssert_True(task_1_timeouts <= limit, "Task 1 timeouts=%u <= %u", (unsigned int)task_1_timeouts, (unsigned int)limit); } -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/count-sem-test/count-sem-test.c b/src/tests/count-sem-test/count-sem-test.c index 41b53d110..38fc9d411 100644 --- a/src/tests/count-sem-test/count-sem-test.c +++ b/src/tests/count-sem-test/count-sem-test.c @@ -129,7 +129,7 @@ void task_3(void) } } -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/file-api-test/file-api-test.c b/src/tests/file-api-test/file-api-test.c index 206982c8e..c528a88b9 100644 --- a/src/tests/file-api-test/file-api-test.c +++ b/src/tests/file-api-test/file-api-test.c @@ -25,7 +25,7 @@ os_fs_err_name_t errname; /* *************************************** MAIN ************************************** */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { errname[0] = 0; diff --git a/src/tests/mutex-test/mutex-test.c b/src/tests/mutex-test/mutex-test.c index 3cf58663d..fbe772a93 100644 --- a/src/tests/mutex-test/mutex-test.c +++ b/src/tests/mutex-test/mutex-test.c @@ -193,7 +193,7 @@ void task_3(void) } } -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/osal-core-test/osal-core-test.c b/src/tests/osal-core-test/osal-core-test.c index 8dbfea0b9..a1d7f5458 100644 --- a/src/tests/osal-core-test/osal-core-test.c +++ b/src/tests/osal-core-test/osal-core-test.c @@ -22,7 +22,7 @@ void TestMutexes(void); void TestGetInfos(void); /* *************************************** MAIN ************************************** */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/queue-timeout-test/queue-timeout-test.c b/src/tests/queue-timeout-test/queue-timeout-test.c index 73d16b5b1..a024d38e4 100644 --- a/src/tests/queue-timeout-test/queue-timeout-test.c +++ b/src/tests/queue-timeout-test/queue-timeout-test.c @@ -110,7 +110,7 @@ void QueueTimeoutCheck(void) } -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/sem-speed-test/sem-speed-test.c b/src/tests/sem-speed-test/sem-speed-test.c index b94171f3a..fbebc1b02 100644 --- a/src/tests/sem-speed-test/sem-speed-test.c +++ b/src/tests/sem-speed-test/sem-speed-test.c @@ -136,7 +136,7 @@ void task_2(void) } } -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/symbol-api-test/symbol-api-test.c b/src/tests/symbol-api-test/symbol-api-test.c index ab340984b..0af206cd3 100644 --- a/src/tests/symbol-api-test/symbol-api-test.c +++ b/src/tests/symbol-api-test/symbol-api-test.c @@ -66,7 +66,7 @@ void TestSymbolApi(void) } /* end TestSymbolApi */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/tests/timer-test/timer-test.c b/src/tests/timer-test/timer-test.c index f6cf3d683..73bf0c242 100644 --- a/src/tests/timer-test/timer-test.c +++ b/src/tests/timer-test/timer-test.c @@ -47,7 +47,7 @@ void test_func(uint32 timer_id) /* ********************** MAIN **************************** */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) diff --git a/src/unit-test-coverage/portable/coveragetest-posixfile.c b/src/unit-test-coverage/portable/coveragetest-posixfile.c index 5de2a5017..592b12c5e 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixfile.c +++ b/src/unit-test-coverage/portable/coveragetest-posixfile.c @@ -197,12 +197,12 @@ void Osapi_TearDown(void) #define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_FileOpen_Impl); ADD_TEST(OS_FileStat_Impl); diff --git a/src/unit-test-coverage/portable/coveragetest-posixgettime.c b/src/unit-test-coverage/portable/coveragetest-posixgettime.c index bbe3e4f14..f88258cf0 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixgettime.c +++ b/src/unit-test-coverage/portable/coveragetest-posixgettime.c @@ -97,12 +97,12 @@ void Osapi_TearDown(void) #define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_GetLocalTime_Impl); ADD_TEST(OS_SetLocalTime_Impl); diff --git a/src/unit-test-coverage/portable/coveragetest-posixio.c b/src/unit-test-coverage/portable/coveragetest-posixio.c index fc4e4c3cd..eaaf3c164 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixio.c +++ b/src/unit-test-coverage/portable/coveragetest-posixio.c @@ -169,12 +169,12 @@ void Osapi_TearDown(void) #define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_GenericClose_Impl); ADD_TEST(OS_GenericSeek_Impl); diff --git a/src/unit-test-coverage/posix/src/coveragetest-osapi.c b/src/unit-test-coverage/posix/src/coveragetest-osapi.c index d6a4181dc..50e8103e3 100644 --- a/src/unit-test-coverage/posix/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/posix/src/coveragetest-osapi.c @@ -531,12 +531,12 @@ void Osapi_TearDown(void) #define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_Lock_Global_Impl); ADD_TEST(OS_Unlock_Global_Impl); diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index 75238a7e2..41cf226c0 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -217,7 +217,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_BinSemAPI_Init); ADD_TEST(OS_BinSemCreate); diff --git a/src/unit-test-coverage/shared/src/coveragetest-clock.c b/src/unit-test-coverage/shared/src/coveragetest-clock.c index 13cf82cb3..eb8d590a7 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-clock.c +++ b/src/unit-test-coverage/shared/src/coveragetest-clock.c @@ -74,7 +74,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_GetLocalTime); ADD_TEST(OS_SetLocalTime); diff --git a/src/unit-test-coverage/shared/src/coveragetest-common.c b/src/unit-test-coverage/shared/src/coveragetest-common.c index 117b17c65..b6eeb1ad9 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -286,7 +286,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_API_Init); ADD_TEST(OS_DeleteAllObjects); diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 166a61274..8c3a225d4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -204,7 +204,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_CountSemAPI_Init); ADD_TEST(OS_CountSemCreate); diff --git a/src/unit-test-coverage/shared/src/coveragetest-dir.c b/src/unit-test-coverage/shared/src/coveragetest-dir.c index 703e6a3ba..56e88c135 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-dir.c +++ b/src/unit-test-coverage/shared/src/coveragetest-dir.c @@ -205,7 +205,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_DirAPI_Init); ADD_TEST(OS_mkdir); diff --git a/src/unit-test-coverage/shared/src/coveragetest-errors.c b/src/unit-test-coverage/shared/src/coveragetest-errors.c index 197b4c94b..50bff1b66 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-errors.c +++ b/src/unit-test-coverage/shared/src/coveragetest-errors.c @@ -61,7 +61,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_GetErrorName); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index f9184b205..feef86180 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -482,7 +482,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_FileAPI_Init); ADD_TEST(OS_creat); diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 4828f6425..005fa4999 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -619,7 +619,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_FileSysAPI_Init); ADD_TEST(OS_FileSysAddFixedMap); diff --git a/src/unit-test-coverage/shared/src/coveragetest-fpu.c b/src/unit-test-coverage/shared/src/coveragetest-fpu.c index 0fa6ca876..9d7bd13a4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-fpu.c +++ b/src/unit-test-coverage/shared/src/coveragetest-fpu.c @@ -120,7 +120,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_FPUExcAttachHandler); ADD_TEST(OS_FPUExcEnable); diff --git a/src/unit-test-coverage/shared/src/coveragetest-heap.c b/src/unit-test-coverage/shared/src/coveragetest-heap.c index cdc984442..2c581b5a4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-heap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-heap.c @@ -58,7 +58,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_HeapGetInfo); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index cbb3965b8..583a77549 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -670,7 +670,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_ObjectIdInit); ADD_TEST(OS_ObjectIdMapUnmap); diff --git a/src/unit-test-coverage/shared/src/coveragetest-interrupts.c b/src/unit-test-coverage/shared/src/coveragetest-interrupts.c index 29cbf1133..fe608bf76 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-interrupts.c +++ b/src/unit-test-coverage/shared/src/coveragetest-interrupts.c @@ -148,7 +148,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_IntAttachHandler); ADD_TEST(OS_IntLock); diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index 06eccaf65..e12bf3cde 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -278,7 +278,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_ModuleAPI_Init); ADD_TEST(OS_ModuleLoad); diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 8713389ee..8c49b9d87 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -189,7 +189,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_MutexAPI_Init); ADD_TEST(OS_MutSemCreate); diff --git a/src/unit-test-coverage/shared/src/coveragetest-network.c b/src/unit-test-coverage/shared/src/coveragetest-network.c index 85a95247d..d17ad8426 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-network.c +++ b/src/unit-test-coverage/shared/src/coveragetest-network.c @@ -98,7 +98,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_NetworkAPI_Init); ADD_TEST(OS_NetworkGetID); diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index d543a8c70..a609aaefb 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -122,7 +122,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_ConsoleAPI_Init); ADD_TEST(OS_printf); diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index 0385be681..e869e18bc 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -217,7 +217,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_QueueAPI_Init); ADD_TEST(OS_QueueCreate); diff --git a/src/unit-test-coverage/shared/src/coveragetest-select.c b/src/unit-test-coverage/shared/src/coveragetest-select.c index dc5860496..85f65eeaa 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-select.c +++ b/src/unit-test-coverage/shared/src/coveragetest-select.c @@ -143,7 +143,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_SelectFdAddClearOps); ADD_TEST(OS_SelectSingle); diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index fc6c898d2..c7719aa93 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -480,7 +480,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_SocketAPI_Init); ADD_TEST(OS_SocketAddr); diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index 06495f2ac..add2cff87 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -323,7 +323,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_TaskAPI_Init); ADD_TEST(OS_TaskEntryPoint); diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index 3125d0d9a..b35f76998 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -343,7 +343,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_TimerCbAPI_Init); ADD_TEST(OS_TimerAdd); diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index 0fb83b95c..b01eda7da 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -340,7 +340,7 @@ void Osapi_TearDown(void) /* * Register the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_TimeBaseAPI_Init); ADD_TEST(OS_TimeBaseCreate); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c index 855d4694d..d384b47af 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c @@ -733,12 +733,12 @@ void Osapi_TearDown(void) } -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_Lock_Global_Impl); ADD_TEST(OS_Unlock_Global_Impl); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c index 35eab6101..b7deec7b8 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c @@ -172,12 +172,12 @@ void Osapi_TearDown(void) } -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_VxWorks_StreamAPI_Impl_Init); ADD_TEST(OS_VxWorks_DirAPI_Impl_Init); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c index 23d295199..04c1d55c2 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c @@ -183,12 +183,12 @@ void Osapi_TearDown(void) } -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_FileSysStartVolume_Impl); ADD_TEST(OS_FileSysStopVolume_Impl); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c b/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c index fd6158050..3ea20b6e3 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c @@ -153,12 +153,12 @@ void Osapi_TearDown(void) } -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_VxWorks_ModuleAPI_Impl_Init); ADD_TEST(OS_SymTableIterator_Impl); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c index 1572740d8..0067c5035 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c @@ -241,12 +241,12 @@ void Osapi_TearDown(void) } -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_VxWorks_TimeBaseAPI_Impl_Init); ADD_TEST(OS_TimeBaseLock_Impl); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c b/src/unit-test-coverage/vxworks/src/coveragetest-printf.c index 13768da72..3fb17c207 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-printf.c @@ -119,12 +119,12 @@ void Osapi_TearDown(void) #define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) -/* Osapi_AddTestCase_Tasks +/* UtTest_Setup * * Purpose: * Registers the test cases to execute with the unit test tool */ -void OS_Application_Startup(void) +void UtTest_Setup(void) { ADD_TEST(OS_ConsoleCreate_Impl); ADD_TEST(OS_ConsoleOutput_Impl); diff --git a/src/unit-tests/oscore-test/ut_oscore_test.c b/src/unit-tests/oscore-test/ut_oscore_test.c index e9a4aedcd..6b7b75ae7 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -166,7 +166,7 @@ void UT_os_init_task_get_info_test() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UtTest_Add(UT_os_apiinit_test, NULL, NULL, "OS_API_Init"); diff --git a/src/unit-tests/osfile-test/ut_osfile_test.c b/src/unit-tests/osfile-test/ut_osfile_test.c index 584b8de8a..1fd090953 100644 --- a/src/unit-tests/osfile-test/ut_osfile_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_test.c @@ -108,7 +108,7 @@ void UT_os_init_file_misc() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_initfs_test(); diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c index 58a2b7231..c79caa9d1 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -94,7 +94,7 @@ void UT_os_init_fs_misc() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/unit-tests/osloader-test/ut_osloader_test.c b/src/unit-tests/osloader-test/ut_osloader_test.c index d2828cd94..24d12eb51 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_test.c @@ -38,7 +38,7 @@ ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_test.c index c66b39a4d..1d317d68d 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_test.c +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_test.c @@ -38,7 +38,7 @@ ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.c b/src/unit-tests/ostimer-test/ut_ostimer_test.c index 4658e6f66..9564d7e66 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.c @@ -74,10 +74,8 @@ void UT_os_timercallback(uint32 timerId) OS_GetLocalTime(&endTime); - if (endTime.seconds == currTime.seconds) - currIntervalTime = endTime.microsecs - currTime.microsecs; - else - currIntervalTime = endTime.microsecs + (1000000 - currTime.microsecs); + currIntervalTime = 1000000 * (endTime.seconds - currTime.seconds) + + endTime.microsecs - currTime.microsecs; if (currIntervalTime >= prevIntervalTime) deltaTime = currIntervalTime - prevIntervalTime; @@ -88,18 +86,12 @@ void UT_os_timercallback(uint32 timerId) res = -1; loopCnt++; + currTime = endTime; + prevIntervalTime = currIntervalTime; - if (loopCnt < g_cbLoopCntMax) - { - currTime = endTime; - prevIntervalTime = currIntervalTime; - } - else + if (loopCnt == g_cbLoopCntMax) { g_status = (res == 0) ? 1 : -1; - - /* slow the timer down so the main test thread can continue */ - res = OS_TimerSet(g_timerId, 1000, 500000); } } } @@ -176,7 +168,7 @@ void UT_os_setup_timerset_test() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { if (OS_API_Init() != OS_SUCCESS) { diff --git a/ut_assert/inc/utbsp.h b/ut_assert/inc/utbsp.h index 42a650210..95ab9bde5 100644 --- a/ut_assert/inc/utbsp.h +++ b/ut_assert/inc/utbsp.h @@ -67,10 +67,8 @@ const char * UT_BSP_GetOptionString(int32 OptionNum); * Initialize the BSP for unit test. * * This is just a hook for the BSP to be informed of the start-of-test event and may be a no-op. - * - * \param Name Name of application under test */ -void UT_BSP_Setup(const char *Name); +void UT_BSP_Setup(void); /** * Initialize the unit test at the BSP layer. diff --git a/ut_assert/inc/uttest.h b/ut_assert/inc/uttest.h index ba846ff41..ac881eaa1 100644 --- a/ut_assert/inc/uttest.h +++ b/ut_assert/inc/uttest.h @@ -32,11 +32,11 @@ /* Adds a new unit test to the test database. */ void UtTest_Add(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), const char *TestName); -/* Executes all unit tests contained in the test database. Once all tests have finished executing - * a results summary is printed to the console and the test database is deleted. This function also - * returns a boolean status indicating if any of the tests failed. (true = at least one test failure - * has occurred, false = all tests passed) */ -bool UtTest_Run(void); +/* + * Set up function for UT-Assert based test routines + * This should call UtTest_Add() for each test set + */ +void UtTest_Setup(void); #endif diff --git a/ut_assert/src/uttest.c b/ut_assert/src/uttest.c index f431bb2df..f4a2bcb2f 100644 --- a/ut_assert/src/uttest.c +++ b/ut_assert/src/uttest.c @@ -19,10 +19,12 @@ * Includes */ -#include "common_types.h" +#include "osapi.h" #include "utassert.h" #include "utlist.h" #include "utbsp.h" +#include "uttest.h" +#include "utstubs.h" /* * Type Definitions @@ -57,7 +59,7 @@ void UtTest_Add(void (*Test)(void), void (*Setup)(void), void (*Teardown)(void), UtList_Add(&UtTestDataBase, &UtTestDataBaseEntry, sizeof(UtTestDataBaseEntry_t), 0); } -bool UtTest_Run(void) +void OS_Application_Run(void) { uint32 i; UtListNode_t *UtListNode; @@ -87,5 +89,33 @@ bool UtTest_Run(void) UtList_Reset(&UtTestDataBase); - return (UtAssert_GetFailCount() > 0); + UT_BSP_EndTest(UtAssert_GetCounters()); } + +/* + * Entry point from the BSP. + * When linking with UT-Assert, the test framework (this library) serves + * the role of the "application" being executed. + * + * There is a separate entry point (UT_Test_Setup) to configure the test cases. + */ +void OS_Application_Startup(void) +{ + /* + * Reset the test global variables, just in case. + */ + memset(&UtTestDataBase, 0, sizeof(UtTestDataBase)); + UtTestsExecutedCount = 0; + + UT_BSP_Setup(); + + /* + * Wrap the UtTest_Setup() function in a UT segment called "SETUP" + * This allows any assert calls to be used and recorded during setup + */ + UtAssert_BeginTest("SETUP"); + UtTest_Setup(); + UtAssert_EndTest(); +} + +