Skip to content

Commit

Permalink
Fix #1318, adjust timing on condvar tests
Browse files Browse the repository at this point in the history
The order of task wakeup when using OS_CondVarSignal() with multiple
tasks pending may not be guaranteed.  This relaxes the test case so that
a specific order is not assumed/required.  This also adjust certain
sleep times to make sure the test waits long enough for the tasks to do
the expected work.
  • Loading branch information
jphickey committed Oct 25, 2022
1 parent fa9671f commit ca8889d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/tests/condvar-test/condvar-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void condvar_worker(uint32 my_num)
++my_state->run_count;
UtPrintf("Doing Work task %u, mask=0x%x condition was=%x\n", (unsigned int)my_num, (unsigned int)my_state->mask,
(unsigned int)prev_condition);
OS_TaskDelay(50 + (NUM_TASKS * 5));
OS_TaskDelay(25 + (NUM_TASKS * 5));
}
}

Expand Down Expand Up @@ -169,7 +169,6 @@ void CondVarTest_Execute(void)
UtAssert_UINT32_EQ(total_work, num_signals);
UtAssert_UINT32_NEQ(curr_condition, ALL_RUN_CONDITION);
UtAssert_UINT32_NEQ(curr_condition, 0);
UtAssert_UINT32_EQ(task_states[i].run_count, 1);
UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS);

UtAssert_INT32_EQ(OS_CondVarSignal(condvar_id), OS_SUCCESS);
Expand All @@ -180,13 +179,19 @@ void CondVarTest_Execute(void)

/* after a the last signal, all the other tasks should have run */
UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS);
for (i = 0; i < NUM_TASKS; ++i)
{
UtAssert_UINT32_EQ(task_states[i].run_count, 1);
}
UtAssert_UINT32_EQ(total_work, num_signals);
UtAssert_BITMASK_UNSET(curr_condition, ALL_RUN_CONDITION);
curr_condition = ALL_RUN_CONDITION;
UtAssert_INT32_EQ(OS_CondVarBroadcast(condvar_id), OS_SUCCESS);
UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS);

OS_TaskDelay(100);
/* Give sufficient time for all tasks to wake up and do their work */
OS_TaskDelay(100 + (NUM_TASKS * 10));

UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS);
UtAssert_BITMASK_UNSET(curr_condition, ALL_RUN_CONDITION);
for (i = 0; i < NUM_TASKS; ++i)
Expand All @@ -198,7 +203,8 @@ void CondVarTest_Execute(void)
UtAssert_INT32_EQ(OS_CondVarBroadcast(condvar_id), OS_SUCCESS);
UtAssert_INT32_EQ(OS_CondVarUnlock(condvar_id), OS_SUCCESS);

OS_TaskDelay(20);
/* Give sufficient time for all tasks to wake up and do their work */
OS_TaskDelay(100 + (NUM_TASKS * 10));

UtAssert_INT32_EQ(OS_CondVarLock(condvar_id), OS_SUCCESS);
UtAssert_UINT32_EQ(total_work, (NUM_TASKS * 2) + 1);
Expand Down

0 comments on commit ca8889d

Please sign in to comment.