Skip to content

Commit 4a10f96

Browse files
committed
Fix nasa#1445, add conditional around priority sem test
The multi-thread sem tests (count + bin) have a test that relies on the priority taking effect, that the highest priority thread will get the sem first. However when running as non-root and in permissive mode, the priority is not applied and thus this becomes a race condtion. For now, just skip this test if configured for permissive mode.
1 parent a77b5bd commit 4a10f96

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/tests/bin-sem-test/bin-sem-test.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,26 @@ void Test_BinSem(void)
184184
OS_SUCCESS);
185185
OS_TaskDelay(100);
186186
UtAssert_UINT32_EQ(task_counter[0] + task_counter[1] + task_counter[2], 0);
187-
UtAssert_INT32_EQ(OS_BinSemGive(sem_id[0]), OS_SUCCESS);
188-
OS_TaskDelay(100);
189-
UtAssert_UINT32_EQ(task_counter[0], 1);
190-
UtAssert_UINT32_EQ(task_counter[1] + task_counter[2], 0);
191187
UtAssert_INT32_EQ(OS_BinSemFlush(sem_id[0]), OS_SUCCESS);
192188
OS_TaskDelay(100);
193-
UtAssert_UINT32_EQ(task_counter[0], 2);
189+
UtAssert_UINT32_EQ(task_counter[0], 1);
194190
UtAssert_UINT32_EQ(task_counter[1], 1);
195191
UtAssert_UINT32_EQ(task_counter[2], 1);
196192

193+
test_val = 3;
194+
195+
/* In permissive mode, priorities are not enforced, and thus there is no
196+
* guarantee of which task will run first. If priorities are enabled then
197+
* it should be guaranteed that Task_0 will get the sem first. */
198+
#ifndef OSAL_CONFIG_DEBUG_PERMISSIVE_MODE
199+
UtAssert_INT32_EQ(OS_BinSemGive(sem_id[0]), OS_SUCCESS);
200+
OS_TaskDelay(100);
201+
UtAssert_UINT32_EQ(task_counter[0], 2);
202+
UtAssert_UINT32_EQ(task_counter[1] + task_counter[2], 2);
203+
++test_val;
204+
#endif
205+
197206
/* Give loop for tasks to complete */
198-
test_val = 4;
199207
while (test_val < 9)
200208
{
201209
test_val++;

src/tests/count-sem-test/count-sem-test.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,20 @@ void Test_CountSem(void)
186186
OS_SUCCESS);
187187
OS_TaskDelay(100);
188188
UtAssert_UINT32_EQ(task_counter[0] + task_counter[1] + task_counter[2], 0);
189+
test_val = 0;
190+
191+
/* In permissive mode, priorities are not enforced, and thus there is no
192+
* guarantee of which task will run first. If priorities are enabled then
193+
* it should be guaranteed that Task_0 will get the sem first. */
194+
#ifndef OSAL_CONFIG_DEBUG_PERMISSIVE_MODE
189195
UtAssert_INT32_EQ(OS_CountSemGive(sem_id[0]), OS_SUCCESS);
190196
OS_TaskDelay(100);
191197
UtAssert_UINT32_EQ(task_counter[0], 1);
192198
UtAssert_UINT32_EQ(task_counter[1] + task_counter[2], 0);
199+
++test_val;
200+
#endif
193201

194202
/* Give loop for tasks to complete */
195-
test_val = 1;
196203
while (test_val < 9)
197204
{
198205
test_val++;

0 commit comments

Comments
 (0)