@@ -76,6 +76,7 @@ void Test_BinSem(void)
7676 osal_id_t task_id [3 ];
7777 char long_name [OS_MAX_API_NAME + 1 ];
7878 OS_bin_sem_prop_t sem_prop ;
79+ OS_task_prop_t task_prop ;
7980 uint32 test_val ;
8081 bool get_info_implemented ;
8182
@@ -174,28 +175,44 @@ void Test_BinSem(void)
174175
175176 /* Start 3 child tasks, give and confirm highest priority task increments, flush and confirm all three */
176177 UtAssert_INT32_EQ (
177- OS_TaskCreate (& task_id [0 ], "Task_0" , Test_BinSem_Task0 , NULL , TASK_STACK_SIZE , OSAL_PRIORITY_C (100 ), 0 ),
178+ OS_TaskCreate (& task_id [0 ], "Task_0" , Test_BinSem_Task0 , NULL , TASK_STACK_SIZE , OSAL_PRIORITY_C (200 ), 0 ),
178179 OS_SUCCESS );
180+ OS_TaskDelay (50 );
179181 UtAssert_INT32_EQ (
180- OS_TaskCreate (& task_id [1 ], "Task_1" , Test_BinSem_Task1 , NULL , TASK_STACK_SIZE , OSAL_PRIORITY_C (200 ), 0 ),
182+ OS_TaskCreate (& task_id [1 ], "Task_1" , Test_BinSem_Task1 , NULL , TASK_STACK_SIZE , OSAL_PRIORITY_C (100 ), 0 ),
181183 OS_SUCCESS );
182184 UtAssert_INT32_EQ (
183185 OS_TaskCreate (& task_id [2 ], "Task_2" , Test_BinSem_Task2 , NULL , TASK_STACK_SIZE , OSAL_PRIORITY_C (250 ), 0 ),
184186 OS_SUCCESS );
185- OS_TaskDelay (100 );
187+ OS_TaskDelay (50 );
186188 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 );
191189 UtAssert_INT32_EQ (OS_BinSemFlush (sem_id [0 ]), OS_SUCCESS );
192190 OS_TaskDelay (100 );
193- UtAssert_UINT32_EQ (task_counter [0 ], 2 );
191+ UtAssert_UINT32_EQ (task_counter [0 ], 1 );
194192 UtAssert_UINT32_EQ (task_counter [1 ], 1 );
195193 UtAssert_UINT32_EQ (task_counter [2 ], 1 );
196194
195+ test_val = 3 ;
196+
197+ /* In permissive mode, priorities are not enforced, and thus there is no
198+ * guarantee of which task will run first. If priorities are enabled then
199+ * it should be guaranteed that Task_1 will get the sem first. By getting the
200+ * task properties we can check if the priority is in effect */
201+ UtAssert_INT32_EQ (OS_TaskGetInfo (task_id [1 ], & task_prop ), OS_SUCCESS );
202+ if (task_prop .priority == OSAL_PRIORITY_C (100 ))
203+ {
204+ UtAssert_INT32_EQ (OS_BinSemGive (sem_id [0 ]), OS_SUCCESS );
205+ OS_TaskDelay (100 );
206+ UtAssert_UINT32_EQ (task_counter [1 ], 2 );
207+ UtAssert_UINT32_EQ (task_counter [2 ] + task_counter [2 ], 2 );
208+ ++ test_val ;
209+ }
210+ else
211+ {
212+ UtPrintf ("Task Priorities not in effect, skipping sem priority test" );
213+ }
214+
197215 /* Give loop for tasks to complete */
198- test_val = 4 ;
199216 while (test_val < 9 )
200217 {
201218 test_val ++ ;
0 commit comments