From e7bba8f0fbec5236aa7b7d4f370fbf72268c2f68 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Mon, 20 Apr 2020 09:05:03 -0400 Subject: [PATCH] Fix #424, Add looping wait for self exiting task --- src/tests/osal-core-test/osal-core-test.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/tests/osal-core-test/osal-core-test.c b/src/tests/osal-core-test/osal-core-test.c index a1d7f5458..a1d0d8ac8 100644 --- a/src/tests/osal-core-test/osal-core-test.c +++ b/src/tests/osal-core-test/osal-core-test.c @@ -9,6 +9,9 @@ #include "uttest.h" #include "utbsp.h" +/* Defines */ +#define UT_EXIT_LOOP_MAX 100 /* Used to limit wait for self-exiting task to exit */ + /* OS Constructs */ void TestTasks (void); @@ -73,6 +76,8 @@ void TestTasks(void) int tasknum; uint32 saved_task0_id; static TestTaskData TaskData[OS_MAX_TASKS + 1]; + OS_task_prop_t taskprop; + int loopcnt; /* OS_TaskRegister(); */ @@ -118,16 +123,20 @@ void TestTasks(void) status = OS_TaskCreate( &TaskData[tasknum].task_id, taskname, task_generic_with_exit, TaskData[tasknum].task_stack, TASK_0_STACK_SIZE, (250 - OS_MAX_TASKS) + tasknum, 0); - /* - * A small delay in this parent task to allow the child task to run. - * It should exit immediately.... - */ - OS_TaskDelay(10); - UtDebug("Create %s Status = %d, Id = %d\n",taskname,(int)status,(int)TaskData[tasknum].task_id); UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate, self exiting task"); + /* Looping delay in parent task to wait for child task to exit */ + loopcnt = 0; + while ((OS_TaskGetInfo(TaskData[tasknum].task_id, &taskprop) == OS_SUCCESS) && (loopcnt < UT_EXIT_LOOP_MAX)) + { + OS_TaskDelay(10); + loopcnt++; + } + UtDebug("Looped %d times waiting for child task Id %d to exit\n", loopcnt, (int)TaskData[tasknum].task_id); + UtAssert_True(loopcnt < UT_EXIT_LOOP_MAX, "Looped %d times without self-exiting task exiting", loopcnt); + /* * Attempting to delete the task that exited itself should always fail */