@@ -472,13 +472,22 @@ static int start_test(struct test_suite *test, int i, int subi, struct child_tes
472
472
for (j = 0, k = 0; j < ARRAY_SIZE(tests); j++, k = 0) \
473
473
while ((t = tests[j][k++]) != NULL)
474
474
475
+ /* State outside of __cmd_test for the sake of the signal handler. */
476
+
477
+ static size_t num_tests ;
478
+ static struct child_test * * child_tests ;
479
+ static jmp_buf cmd_test_jmp_buf ;
480
+
481
+ static void cmd_test_sig_handler (int sig )
482
+ {
483
+ siglongjmp (cmd_test_jmp_buf , sig );
484
+ }
485
+
475
486
static int __cmd_test (int argc , const char * argv [], struct intlist * skiplist )
476
487
{
477
488
struct test_suite * t ;
478
- int width = 0 ;
489
+ static int width = 0 ;
479
490
unsigned int j , k ;
480
- size_t num_tests = 0 ;
481
- struct child_test * * child_tests ;
482
491
int err = 0 ;
483
492
484
493
for_each_test (j , k , t ) {
@@ -502,6 +511,26 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
502
511
if (!child_tests )
503
512
return - ENOMEM ;
504
513
514
+ err = sigsetjmp (cmd_test_jmp_buf , 1 );
515
+ if (err ) {
516
+ pr_err ("\nSignal (%d) while running tests.\nTerminating tests with the same signal\n" ,
517
+ err );
518
+ for (size_t x = 0 ; x < num_tests ; x ++ ) {
519
+ struct child_test * child_test = child_tests [x ];
520
+
521
+ if (!child_test )
522
+ continue ;
523
+
524
+ pr_debug3 ("Killing %d pid %d\n" ,
525
+ child_test -> test_num + 1 ,
526
+ child_test -> process .pid );
527
+ kill (child_test -> process .pid , err );
528
+ }
529
+ goto err_out ;
530
+ }
531
+ signal (SIGINT , cmd_test_sig_handler );
532
+ signal (SIGTERM , cmd_test_sig_handler );
533
+
505
534
/*
506
535
* In parallel mode pass 1 runs non-exclusive tests in parallel, pass 2
507
536
* runs the exclusive tests sequentially. In other modes all tests are
@@ -562,6 +591,8 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
562
591
}
563
592
}
564
593
err_out :
594
+ signal (SIGINT , SIG_DFL );
595
+ signal (SIGTERM , SIG_DFL );
565
596
if (err ) {
566
597
pr_err ("Internal test harness failure. Completing any started tests:\n:" );
567
598
for (size_t x = 0 ; x < num_tests ; x ++ )
0 commit comments