@@ -218,9 +218,15 @@ static void entry_abort_isr(void *p1, void *p2, void *p3)
218
218
ztest_test_fail ();
219
219
}
220
220
221
+ extern struct k_sem offload_sem ;
222
+
221
223
/**
222
224
* @ingroup kernel_thread_tests
223
- * @brief Show that threads can be aborted from interrupt context
225
+ *
226
+ * @brief Show that threads can be aborted from interrupt context by itself
227
+ *
228
+ * @details Spwan a thread, then enter ISR context in child thread and abort
229
+ * the child thread. Check if ISR completed and target thread was aborted.
224
230
*
225
231
* @see k_thread_abort()
226
232
*/
@@ -231,6 +237,56 @@ void test_abort_from_isr(void)
231
237
NULL , NULL , NULL , 0 , 0 , K_NO_WAIT );
232
238
233
239
240
+ k_thread_join (& tdata , K_FOREVER );
241
+ zassert_true (isr_finished , "ISR did not complete" );
242
+
243
+ /* Notice: Recover back the offload_sem: This is use for releasing
244
+ * offload_sem which might be held when thread aborts itself in ISR
245
+ * context, it will cause irq_offload cannot be used again.
246
+ */
247
+ k_sem_give (& offload_sem );
248
+ }
249
+
250
+ /* use for sync thread start */
251
+ static struct k_sem sem_abort ;
252
+
253
+ static void entry_aborted_thread (void * p1 , void * p2 , void * p3 )
254
+ {
255
+ k_sem_give (& sem_abort );
256
+
257
+ /* wait for being aborted */
258
+ while (1 ) {
259
+ k_sleep (K_MSEC (1 ));
260
+ }
261
+ zassert_unreachable ("should not reach here" );
262
+ }
263
+
264
+ /**
265
+ * @ingroup kernel_thread_tests
266
+ *
267
+ * @brief Show that threads can be aborted from interrupt context
268
+ *
269
+ * @details Spwan a thread, then enter ISR context in main thread and abort
270
+ * the child thread. Check if ISR completed and target thread was aborted.
271
+ *
272
+ * @see k_thread_abort()
273
+ */
274
+ void test_abort_from_isr_not_self (void )
275
+ {
276
+ k_tid_t tid ;
277
+
278
+ isr_finished = false;
279
+ k_sem_init (& sem_abort , 0 , 1 );
280
+
281
+ tid = k_thread_create (& tdata , tstack , STACK_SIZE , entry_aborted_thread ,
282
+ NULL , NULL , NULL , 0 , 0 , K_NO_WAIT );
283
+
284
+ /* wait for thread started */
285
+ k_sem_take (& sem_abort , K_FOREVER );
286
+
287
+ /* Simulate taking an interrupt which kills spwan thread */
288
+ irq_offload (offload_func , (void * )tid );
289
+
234
290
k_thread_join (& tdata , K_FOREVER );
235
291
zassert_true (isr_finished , "ISR did not complete" );
236
292
}
0 commit comments