Skip to content

Commit

Permalink
Merge pull request #426 from skliper/fix424-self-exit-task-delay
Browse files Browse the repository at this point in the history
Fix #424, Add looping wait for self exiting task
  • Loading branch information
astrogeco committed Apr 28, 2020
2 parents a138fba + e7bba8f commit 3707b78
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/tests/osal-core-test/osal-core-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(); */

Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 3707b78

Please sign in to comment.