Skip to content

Commit

Permalink
Fix #1021, add additional test cases
Browse files Browse the repository at this point in the history
Call OS_TaskCreate with a NULL stack pointer
Confirm OS_TaskDeleteHandler function was invoked
Confirm OS_TaskDelay interval
  • Loading branch information
jphickey committed May 26, 2021
1 parent 11fe719 commit 1870d32
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/unit-tests/oscore-test/ut_oscore_task_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]));
}

Expand Down Expand Up @@ -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;
}

/*--------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -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)))
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}

/*--------------------------------------------------------------------------------*
Expand Down

0 comments on commit 1870d32

Please sign in to comment.