Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf test: Add a signal handler to kill forked child processes

If the `perf test` process is killed the child tests continue running
and may run indefinitely. Propagate SIGINT (ctrl-C) and SIGTERM (kill)
signals to the running child processes so that they terminate when the
parent is killed.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Link: https://lore.kernel.org/r/20241025192109.132482-10-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
553d5efe 94d1a913

+34 -3
+34 -3
tools/perf/tests/builtin-test.c
··· 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) { ··· 510 501 child_tests = calloc(num_tests, sizeof(*child_tests)); 511 502 if (!child_tests) 512 503 return -ENOMEM; 504 + 505 + err = sigsetjmp(cmd_test_jmp_buf, 1); 506 + if (err) { 507 + pr_err("\nSignal (%d) while running tests.\nTerminating tests with the same signal\n", 508 + err); 509 + for (size_t x = 0; x < num_tests; x++) { 510 + struct child_test *child_test = child_tests[x]; 511 + 512 + if (!child_test) 513 + continue; 514 + 515 + pr_debug3("Killing %d pid %d\n", 516 + child_test->test_num + 1, 517 + child_test->process.pid); 518 + kill(child_test->process.pid, err); 519 + } 520 + goto err_out; 521 + } 522 + signal(SIGINT, cmd_test_sig_handler); 523 + signal(SIGTERM, cmd_test_sig_handler); 513 524 514 525 /* 515 526 * In parallel mode pass 1 runs non-exclusive tests in parallel, pass 2 ··· 591 562 } 592 563 } 593 564 err_out: 565 + signal(SIGINT, SIG_DFL); 566 + signal(SIGTERM, SIG_DFL); 594 567 if (err) { 595 568 pr_err("Internal test harness failure. Completing any started tests:\n:"); 596 569 for (size_t x = 0; x < num_tests; x++)