Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #944, add OS_API_Teardown #948

Merged
merged 2 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/os/inc/osapi-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ void OS_Application_Run(void);
*/
int32 OS_API_Init(void);

/*-------------------------------------------------------------------------------------*/
/**
* @brief Teardown/de-initialization of OSAL API
*
* This is the inverse of OS_API_Init(). It will release all OS resources and
* return the system to a state similar to what it was prior to invoking
* OS_API_Init() initially.
*
* Normally for embedded applications, the OSAL is initialized after boot and will remain
* initialized in memory until the processor is rebooted. However for testing and
* developement purposes, it is potentially useful to reset back to initial conditions.
*
* For testing purposes, this API is designed/intended to be compatible with the
* UtTest_AddTeardown() routine provided by the UT-Assert subsystem.
*
* @note This is a "best-effort" routine and it may not always be possible/guaranteed
* to recover all resources, particularly in the case of off-nominal conditions, or if
* a resource is used outside of OSAL.
*
* For example, while this will attempt to unload all dynamically-loaded modules, doing
* so may not be possible and/or may induce undefined behavior if resources are in use by
* tasks/functions outside of OSAL.
*
* @return None
*/
void OS_API_Teardown(void);

/*-------------------------------------------------------------------------------------*/
/**
* @brief Background thread implementation - waits forever for events to occur.
Expand Down
22 changes: 22 additions & 0 deletions src/os/shared/src/osapi-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ int32 OS_API_Init(void)
return (return_code);
} /* end OS_API_Init */

/*----------------------------------------------------------------
*
* Function: OS_API_Teardown
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
void OS_API_Teardown(void)
{
/*
* This should delete any remaining user-created objects/tasks
*/
OS_DeleteAllObjects();

/*
* This should cause the "internal" objects (e.g. console utility task)
* to exit, and will prevent any new objects from being created.
*/
OS_ApplicationShutdown(true);
}

/*----------------------------------------------------------------
*
* Function: OS_RegisterEventHandler
Expand Down
3 changes: 3 additions & 0 deletions src/tests/bin-sem-flush-test/bin-sem-flush-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/bin-sem-test/bin-sem-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/count-sem-test/count-sem-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/file-api-test/file-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* This test case requires a fixed virtual dir for one test case.
* Just map /test to a dir of the same name, relative to current dir.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/idmap-api-test/idmap-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/mutex-test/mutex-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/network-api-test/network-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/osal-core-test/osal-core-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

UtTest_Add(TestTasks, NULL, NULL, "TASK");
UtTest_Add(TestQueues, NULL, NULL, "MSGQ");
UtTest_Add(TestBinaries, NULL, NULL, "BSEM");
Expand Down
3 changes: 3 additions & 0 deletions src/tests/queue-test/queue-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/select-test/select-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/sem-speed-test/sem-speed-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/shell-test/shell-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/symbol-api-test/symbol-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/time-base-api-test/time-base-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/timer-add-api-test/timer-add-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the test setup and check routines in UT assert
*/
Expand Down
3 changes: 3 additions & 0 deletions src/tests/timer-test/timer-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* Register the timer test setup and check routines in UT assert
*/
Expand Down
13 changes: 13 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ void Test_OS_API_Init(void)
UT_ResetState(UT_KEY(OS_TaskAPI_Init));
}

void Test_OS_API_Teardown(void)
{
/*
* Test Case For:
* void OS_API_Teardown(void);
*/

/* Just need to call the API for coverage; there are no conditionals
* and the internal functions are each tested separately */
OS_API_Teardown();
}

void Test_OS_ApplicationExit(void)
{
/*
Expand Down Expand Up @@ -325,4 +337,5 @@ void UtTest_Setup(void)
ADD_TEST(OS_IdleLoopAndShutdown);
ADD_TEST(OS_ApplicationExit);
ADD_TEST(OS_NotifyEvent);
ADD_TEST(OS_API_Teardown);
}
3 changes: 3 additions & 0 deletions src/unit-tests/oscore-test/ut_oscore_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ void UT_os_init_task_get_info_test()

void UtTest_Setup(void)
{
/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

UtTest_Add(UT_os_apiinit_test, NULL, NULL, "OS_API_Init");

UtTest_Add(UT_os_printf_test, NULL, NULL, "OS_printf");
Expand Down
3 changes: 3 additions & 0 deletions src/unit-tests/osfile-test/ut_osfile_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ void UT_os_init_file_misc()

void UtTest_Setup(void)
{
/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

UT_os_initfs_test();

if (UT_os_setup_fs() == OS_SUCCESS)
Expand Down
3 changes: 3 additions & 0 deletions src/unit-tests/osfilesys-test/ut_osfilesys_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

UT_os_init_fs_misc();

UtTest_Add(UT_os_makefs_test, NULL, NULL, "OS_mkfs");
Expand Down
3 changes: 3 additions & 0 deletions src/unit-tests/osloader-test/ut_osloader_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

/*
* This test needs to load the modules from the filesystem, so
* there must be a virtual path corresponding to the path where
Expand Down
3 changes: 3 additions & 0 deletions src/unit-tests/osnetwork-test/ut_osnetwork_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

UtTest_Add(UT_os_networkgetid_test, NULL, NULL, "OS_NetworkGetID");
UtTest_Add(UT_os_networkgethostname_test, NULL, NULL, "OS_NetworkGetHostName");
}
Expand Down
3 changes: 3 additions & 0 deletions src/unit-tests/ostimer-test/ut_ostimer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ void UtTest_Setup(void)
UtAssert_Abort("OS_API_Init() failed");
}

/* the test should call OS_API_Teardown() before exiting */
UtTest_AddTeardown(OS_API_Teardown, "Cleanup");

UT_os_init_timer_misc();

UtTest_Add(UT_os_timercreate_test, UT_os_setup_timercreate_test, NULL, "OS_TimerCreate");
Expand Down