diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 7075b5bfb..94d8ba43e 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -53,6 +53,7 @@ extern char g_long_task_name[UT_OS_NAME_BUFF_SIZE]; **--------------------------------------------------------------------------------*/ uint32 g_task_result = 0; +bool g_task_handler_called; osal_id_t g_task_sync_sem; osal_id_t g_task_ids[UT_OS_TASK_LIST_LEN]; osal_id_t g_task_get_id_result; @@ -191,15 +192,21 @@ void UT_os_task_create_test() } /*-----------------------------------------------------*/ - /* #9 Nominal */ + /* Nominal, fixed stack */ UT_NOMINAL(OS_TaskCreate(&g_task_ids[9], g_task_names[9], generic_test_task, OSAL_STACKPTR_C(&g_task_stacks[9]), sizeof(g_task_stacks[9]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0)); + /*-----------------------------------------------------*/ + /* Nominal, dynamic stack */ + + UT_NOMINAL(OS_TaskCreate(&g_task_ids[8], g_task_names[8], generic_test_task, NULL, sizeof(g_task_stacks[8]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0)); + /* Delay to let child task run */ OS_TaskDelay(200); /* Reset test environment */ + UT_TEARDOWN(OS_TaskDelete(g_task_ids[8])); UT_TEARDOWN(OS_TaskDelete(g_task_ids[9])); } @@ -242,6 +249,7 @@ void UT_os_task_delete_test() void delete_handler_callback(void) { UtPrintf("Task delete callback...\n"); + g_task_handler_called = true; } /*--------------------------------------------------------------------------------*/ @@ -290,6 +298,8 @@ void UT_os_task_install_delete_handler_test(void) { OS_BinSemTake(g_task_sync_sem); + g_task_handler_called = false; + if (UT_SETUP(OS_TaskCreate(&g_task_ids[2], g_task_names[2], delete_handler_test_task, OSAL_STACKPTR_C(&g_task_stacks[2]), sizeof(g_task_stacks[2]), OSAL_PRIORITY_C(UT_TASK_PRIORITY), 0))) @@ -304,6 +314,7 @@ void UT_os_task_install_delete_handler_test(void) UtAssert_True(g_task_result == OS_SUCCESS, "OS_TaskInstallDeleteHandler() (%d) == OS_SUCCESS", (int)g_task_result); + UtAssert_True(g_task_handler_called, "OS_TaskInstallDeleteHandler() callback invoked"); } UT_TEARDOWN(OS_BinSemDelete(g_task_sync_sem)); @@ -381,10 +392,27 @@ void UT_os_task_exit_test(void) **--------------------------------------------------------------------------------*/ void UT_os_task_delay_test() { - /*-----------------------------------------------------*/ - /* #2 Nominal */ + OS_time_t before_time; + OS_time_t after_time; + int64 elapsed; + /*-----------------------------------------------------*/ + /* Nominal, 100ms delay */ + UT_SETUP(OS_GetLocalTime(&before_time)); UT_NOMINAL(OS_TaskDelay(100)); + UT_SETUP(OS_GetLocalTime(&after_time)); + + elapsed = OS_TimeGetTotalMilliseconds(OS_TimeSubtract(after_time, before_time)); + UtAssert_True(elapsed >= 100, "Elapsed time %ld msec, expected 100", (long)elapsed); + + /*-----------------------------------------------------*/ + /* Nominal, 250ms delay */ + UT_SETUP(OS_GetLocalTime(&before_time)); + UT_NOMINAL(OS_TaskDelay(250)); + UT_SETUP(OS_GetLocalTime(&after_time)); + + elapsed = OS_TimeGetTotalMilliseconds(OS_TimeSubtract(after_time, before_time)); + UtAssert_True(elapsed >= 250, "Elapsed time %ld msec, expected 250", (long)elapsed); } /*--------------------------------------------------------------------------------*