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.

ktest: Run POST_KTEST hooks on failure and cancellation

PRE_KTEST can be useful for setting up the environment and POST_KTEST to
tear it down, however POST_KTEST only runs on the normal end-of-run path.
It is skipped when ktest exits through dodie() or cancel_test(). Final
cleanup hooks are skipped.

Factor the final hook execution into run_post_ktest(), call it from the
normal exit path and from the early exit paths, and guard it so the hook
runs at most once.

Cc: John Hawley <warthog9@eaglescrag.net>
Cc: Andrea Righi <arighi@nvidia.com>
Cc: Marcos Paulo de Souza <mpdesouza@suse.com>
Cc: Matthieu Baerts <matttbe@kernel.org>
Cc: Fernando Fernandez Mancera <fmancera@suse.de>
Cc: Pedro Falcato <pfalcato@suse.de>
Link: https://patch.msgid.link/20260307-ktest-fixes-v1-8-565d412f4925@suse.com
Fixes: 921ed4c7208e ("ktest: Add PRE/POST_KTEST and TEST options")
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Ricardo B. Marlière and committed by
Steven Rostedt
bc6e165a 972816d2

+22 -5
+22 -5
tools/testing/ktest/ktest.pl
··· 100 100 my $build_type; 101 101 my $build_options; 102 102 my $final_post_ktest; 103 + my $post_ktest_done = 0; 103 104 my $pre_ktest; 104 105 my $pre_ktest_die; 105 106 my $post_ktest; ··· 1587 1586 return $name; 1588 1587 } 1589 1588 1589 + sub run_post_ktest { 1590 + my $cmd; 1591 + 1592 + return if ($post_ktest_done); 1593 + 1594 + if (defined($final_post_ktest)) { 1595 + $cmd = $final_post_ktest; 1596 + } elsif (defined($post_ktest)) { 1597 + $cmd = $post_ktest; 1598 + } else { 1599 + return; 1600 + } 1601 + 1602 + my $cp_post_ktest = eval_kernel_version($cmd); 1603 + run_command $cp_post_ktest; 1604 + $post_ktest_done = 1; 1605 + } 1606 + 1590 1607 sub dodie { 1591 1608 # avoid recursion 1592 1609 return if ($in_die); ··· 1664 1645 if (defined($post_test)) { 1665 1646 run_command $post_test; 1666 1647 } 1648 + run_post_ktest; 1667 1649 1668 1650 die @_, "\n"; 1669 1651 } ··· 4334 4314 send_email("KTEST: Your [$name] test was cancelled", 4335 4315 "Your test started at $script_start_time was cancelled: sig int"); 4336 4316 } 4317 + run_post_ktest; 4337 4318 die "\nCaught Sig Int, test interrupted: $!\n" 4338 4319 } 4339 4320 ··· 4700 4679 success $i; 4701 4680 } 4702 4681 4703 - if (defined($final_post_ktest)) { 4704 - 4705 - my $cp_final_post_ktest = eval_kernel_version $final_post_ktest; 4706 - run_command $cp_final_post_ktest; 4707 - } 4682 + run_post_ktest; 4708 4683 4709 4684 if ($opt{"POWEROFF_ON_SUCCESS"}) { 4710 4685 halt;