From 971e90ba0cac0baea6829202b225a07bd61618d4 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 17 Dec 2019 09:58:48 -0500 Subject: [PATCH] Fix #294: Use alternate setup function for Tests Implements a more layered architecture for test code. Rather than having each test provide OS_Application_Startup() directly, now the UT assert library provides OS_Application_Startup() in common code. This also introduces a new function OS_Application_Run() to implement the test routine. This replaces UtTest_Run. The actual test setup is now done by a function called UtTest_Setup(). This allows for better layering where UT-Assert provides the notion of an "OSAL application". This is a step toward simplifying the BSP architecture, eventually combining the normal application and unit test BSP code into a single BSP. --- CMakeLists.txt | 6 ++-- src/bsp/genppc-vxworks6.4/ut-src/bsp_ut.c | 13 +++---- src/bsp/pc-linux/ut-src/bsp_ut.c | 10 +++--- src/bsp/pc-rtems/ut-src/bsp_ut.c | 11 +++--- src/os/inc/osapi-os-core.h | 7 +++- .../bin-sem-flush-test/bin-sem-flush-test.c | 2 +- src/tests/bin-sem-test/bin-sem-test.c | 2 +- .../bin-sem-timeout-test.c | 2 +- src/tests/count-sem-test/count-sem-test.c | 2 +- src/tests/file-api-test/file-api-test.c | 2 +- src/tests/mutex-test/mutex-test.c | 2 +- src/tests/osal-core-test/osal-core-test.c | 2 +- .../queue-timeout-test/queue-timeout-test.c | 2 +- src/tests/sem-speed-test/sem-speed-test.c | 2 +- src/tests/symbol-api-test/symbol-api-test.c | 2 +- src/tests/timer-test/timer-test.c | 2 +- .../portable/coveragetest-posixfile.c | 4 +-- .../portable/coveragetest-posixgettime.c | 4 +-- .../portable/coveragetest-posixio.c | 4 +-- .../posix/src/coveragetest-osapi.c | 4 +-- .../shared/src/coveragetest-binsem.c | 2 +- .../shared/src/coveragetest-clock.c | 2 +- .../shared/src/coveragetest-common.c | 2 +- .../shared/src/coveragetest-countsem.c | 2 +- .../shared/src/coveragetest-dir.c | 2 +- .../shared/src/coveragetest-errors.c | 2 +- .../shared/src/coveragetest-file.c | 2 +- .../shared/src/coveragetest-filesys.c | 2 +- .../shared/src/coveragetest-fpu.c | 2 +- .../shared/src/coveragetest-heap.c | 2 +- .../shared/src/coveragetest-idmap.c | 2 +- .../shared/src/coveragetest-interrupts.c | 2 +- .../shared/src/coveragetest-module.c | 2 +- .../shared/src/coveragetest-mutex.c | 2 +- .../shared/src/coveragetest-network.c | 2 +- .../shared/src/coveragetest-printf.c | 2 +- .../shared/src/coveragetest-queue.c | 2 +- .../shared/src/coveragetest-select.c | 2 +- .../shared/src/coveragetest-sockets.c | 2 +- .../shared/src/coveragetest-task.c | 2 +- .../shared/src/coveragetest-time.c | 2 +- .../shared/src/coveragetest-timebase.c | 2 +- .../vxworks/src/coveragetest-osapi.c | 4 +-- .../vxworks/src/coveragetest-osfileapi.c | 4 +-- .../vxworks/src/coveragetest-osfilesys.c | 4 +-- .../vxworks/src/coveragetest-osloader.c | 4 +-- .../vxworks/src/coveragetest-ostimer.c | 4 +-- .../vxworks/src/coveragetest-printf.c | 4 +-- src/unit-tests/oscore-test/ut_oscore_test.c | 2 +- src/unit-tests/osfile-test/ut_osfile_test.c | 2 +- .../osfilesys-test/ut_osfilesys_test.c | 2 +- .../osloader-test/ut_osloader_test.c | 2 +- .../osnetwork-test/ut_osnetwork_test.c | 2 +- src/unit-tests/ostimer-test/ut_ostimer_test.c | 2 +- ut_assert/inc/utbsp.h | 4 +-- ut_assert/inc/uttest.h | 10 +++--- ut_assert/src/uttest.c | 36 +++++++++++++++++-- 57 files changed, 119 insertions(+), 96 deletions(-) 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/genppc-vxworks6.4/ut-src/bsp_ut.c b/src/bsp/genppc-vxworks6.4/ut-src/bsp_ut.c index 8f3b30ede..1b1890418 100644 --- a/src/bsp/genppc-vxworks6.4/ut-src/bsp_ut.c +++ b/src/bsp/genppc-vxworks6.4/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 61ce966b5..4f7b9272d 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/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 4e828af77..eee7c2ba0 100644 --- a/src/tests/sem-speed-test/sem-speed-test.c +++ b/src/tests/sem-speed-test/sem-speed-test.c @@ -119,7 +119,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 20e000d01..a51252fb4 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixfile.c +++ b/src/unit-test-coverage/portable/coveragetest-posixfile.c @@ -187,12 +187,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 525191ba7..834e4be98 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixgettime.c +++ b/src/unit-test-coverage/portable/coveragetest-posixgettime.c @@ -87,12 +87,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 7f4424c0b..6419f2933 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixio.c +++ b/src/unit-test-coverage/portable/coveragetest-posixio.c @@ -159,12 +159,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 eaa5e7610..294eb5d1e 100644 --- a/src/unit-test-coverage/posix/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/posix/src/coveragetest-osapi.c @@ -521,12 +521,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 b26fd66a7..ae5d0a38a 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -207,7 +207,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 5873d530c..2bbfb2dba 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -276,7 +276,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 a1f272b75..63df65004 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -194,7 +194,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 a7b76a13a..b307d1412 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 ae09ddf24..0ea44efa3 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -472,7 +472,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 39aba02f3..46eaf7527 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -605,7 +605,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 82fc67216..8215514cf 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -660,7 +660,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 61a0f1a22..f4877a410 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -268,7 +268,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 ca2fe9aa5..d0c88408a 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -179,7 +179,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 d7079c2c7..c1604f253 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -112,7 +112,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 2dffbd41a..7d4e2a820 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -207,7 +207,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 d38068017..5d774da93 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-select.c +++ b/src/unit-test-coverage/shared/src/coveragetest-select.c @@ -133,7 +133,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 658d05a4c..395725023 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -470,7 +470,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 d4dbb8dfe..6ce52090b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -312,7 +312,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 4e354bbfe..c4ec7d68b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -333,7 +333,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 2fd7dfdb1..c63d6c27b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -330,7 +330,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 1fc3bf12d..08ba55cac 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c @@ -723,12 +723,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 1ce265e25..a29d7c8af 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c @@ -162,12 +162,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 84dcb8af6..5c1491dde 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c @@ -175,12 +175,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 220f772d0..f6c0231b7 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c @@ -143,12 +143,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 c729379ca..ee7ca998f 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c @@ -225,12 +225,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 58dba58f4..0646408c2 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-printf.c @@ -109,12 +109,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 6961a7930..fbab83627 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -171,7 +171,7 @@ void UT_os_init_task_get_info_test() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_setup(UT_OS_LOG_FILENAME); diff --git a/src/unit-tests/osfile-test/ut_osfile_test.c b/src/unit-tests/osfile-test/ut_osfile_test.c index 2e4c9278a..684b02465 100644 --- a/src/unit-tests/osfile-test/ut_osfile_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_test.c @@ -109,7 +109,7 @@ void UT_os_init_file_misc() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_setup(UT_OS_LOG_FILENAME); diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c index e95e8336a..2dd4f3906 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -108,7 +108,7 @@ void UT_os_init_checkfs_test() ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_setup(UT_OS_LOG_FILENAME); diff --git a/src/unit-tests/osloader-test/ut_osloader_test.c b/src/unit-tests/osloader-test/ut_osloader_test.c index eca277a0f..77edcf071 100644 --- a/src/unit-tests/osloader-test/ut_osloader_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_test.c @@ -40,7 +40,7 @@ extern UT_OsLogInfo_t g_logInfo; ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_setup(UT_OS_LOG_FILENAME); diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_test.c index 45fc36ba1..e37ffdbe0 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_test.c +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_test.c @@ -40,7 +40,7 @@ extern UT_OsLogInfo_t g_logInfo; ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_setup(UT_OS_LOG_FILENAME); diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.c b/src/unit-tests/ostimer-test/ut_ostimer_test.c index 709f56c9b..5144fd4e9 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.c @@ -220,7 +220,7 @@ void UT_timertest_task(void) ** Main **--------------------------------------------------------------------------------*/ -void OS_Application_Startup(void) +void UtTest_Setup(void) { UT_os_setup(UT_OS_LOG_FILENAME); 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(); +} + +