@@ -132,6 +132,57 @@ TEST_CASE("FreeRTOS Event Group Sync", "[freertos]")
132
132
vEventGroupDelete (eg );
133
133
}
134
134
135
+ static TaskHandle_t run_order [2 ];
136
+ static uint32_t run_order_index = 0 ;
137
+
138
+ void task_test_eg_prio (void * arg )
139
+ {
140
+ TaskHandle_t main_task_hdl = (TaskHandle_t )arg ;
141
+
142
+ /* Notify the main task that this task has been created */
143
+ xTaskNotifyGive (main_task_hdl );
144
+
145
+ /* Wait for the event group bits to be set */
146
+ TEST_ASSERT_EQUAL (1 , xEventGroupWaitBits (eg , 1 , pdTRUE , pdTRUE , portMAX_DELAY ));
147
+
148
+ /* Record the task handle in the run order array */
149
+ run_order [run_order_index ++ ] = xTaskGetCurrentTaskHandle ();
150
+
151
+ /* Suspend the task */
152
+ vTaskSuspend (NULL );
153
+ }
154
+
155
+ TEST_CASE ("FreeRTOS Event Groups do not cause priority inversion when higher priority task is unblocked" , "[freertos]" )
156
+ {
157
+ run_order [0 ] = NULL ;
158
+ run_order [1 ] = NULL ;
159
+ run_order_index = 0 ;
160
+
161
+ /* Initialize the event group */
162
+ eg = xEventGroupCreate ();
163
+
164
+ /* Create a task with higher priority than the task that will set the event group bits */
165
+ TaskHandle_t higher_prio_hdl ;
166
+ TEST_ASSERT_EQUAL (pdTRUE , xTaskCreatePinnedToCore (task_test_eg_prio , "task_test_eg_prio" , 2048 , (void * )xTaskGetCurrentTaskHandle (), CONFIG_UNITY_FREERTOS_PRIORITY + 1 , & higher_prio_hdl , CONFIG_UNITY_FREERTOS_CPU ));
167
+
168
+ /* Wait for the task to be created */
169
+ ulTaskNotifyTake (pdTRUE , portMAX_DELAY );
170
+
171
+ /* Set the event group bits */
172
+ xEventGroupSetBits (eg , 1 );
173
+
174
+ /* Record the task handle in the run order array */
175
+ run_order [run_order_index ++ ] = xTaskGetCurrentTaskHandle ();
176
+
177
+ /* Verify that the higher priority task was unblocked and immediately scheduled and the lower priority task was preempted */
178
+ TEST_ASSERT_EQUAL (higher_prio_hdl , run_order [0 ]);
179
+ TEST_ASSERT_EQUAL (xTaskGetCurrentTaskHandle (), run_order [1 ]);
180
+
181
+ /* Clean up */
182
+ vEventGroupDelete (eg );
183
+ vTaskDelete (higher_prio_hdl );
184
+ }
185
+
135
186
/*-----------------Test case for event group trace facilities-----------------*/
136
187
#ifdef CONFIG_FREERTOS_USE_TRACE_FACILITY
137
188
/*
0 commit comments