Skip to content

Commit bc6e165

Browse files
rbmarliererostedt
authored andcommitted
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: 921ed4c ("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>
1 parent 972816d commit bc6e165

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

tools/testing/ktest/ktest.pl

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
my $build_type;
101101
my $build_options;
102102
my $final_post_ktest;
103+
my $post_ktest_done = 0;
103104
my $pre_ktest;
104105
my $pre_ktest_die;
105106
my $post_ktest;
@@ -1586,6 +1587,24 @@ ()
15861587
return $name;
15871588
}
15881589

1590+
sub run_post_ktest {
1591+
my $cmd;
1592+
1593+
return if ($post_ktest_done);
1594+
1595+
if (defined($final_post_ktest)) {
1596+
$cmd = $final_post_ktest;
1597+
} elsif (defined($post_ktest)) {
1598+
$cmd = $post_ktest;
1599+
} else {
1600+
return;
1601+
}
1602+
1603+
my $cp_post_ktest = eval_kernel_version($cmd);
1604+
run_command $cp_post_ktest;
1605+
$post_ktest_done = 1;
1606+
}
1607+
15891608
sub dodie {
15901609
# avoid recursion
15911610
return if ($in_die);
@@ -1645,6 +1664,7 @@ sub dodie {
16451664
if (defined($post_test)) {
16461665
run_command $post_test;
16471666
}
1667+
run_post_ktest;
16481668

16491669
die @_, "\n";
16501670
}
@@ -4314,6 +4334,7 @@ sub cancel_test {
43144334
send_email("KTEST: Your [$name] test was cancelled",
43154335
"Your test started at $script_start_time was cancelled: sig int");
43164336
}
4337+
run_post_ktest;
43174338
die "\nCaught Sig Int, test interrupted: $!\n"
43184339
}
43194340

@@ -4679,11 +4700,7 @@ sub die_usage {
46794700
success $i;
46804701
}
46814702

4682-
if (defined($final_post_ktest)) {
4683-
4684-
my $cp_final_post_ktest = eval_kernel_version $final_post_ktest;
4685-
run_command $cp_final_post_ktest;
4686-
}
4703+
run_post_ktest;
46874704

46884705
if ($opt{"POWEROFF_ON_SUCCESS"}) {
46894706
halt;

0 commit comments

Comments
 (0)