Skip to content

Commit 0a7a4ab

Browse files
rbmarlieregregkh
authored andcommitted
ktest: Run POST_KTEST hooks on failure and cancellation
[ Upstream commit bc6e165 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9b798ad commit 0a7a4ab

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 $post_ktest;
105106
my $pre_test;
@@ -1575,6 +1576,24 @@ ()
15751576
return $name;
15761577
}
15771578

1579+
sub run_post_ktest {
1580+
my $cmd;
1581+
1582+
return if ($post_ktest_done);
1583+
1584+
if (defined($final_post_ktest)) {
1585+
$cmd = $final_post_ktest;
1586+
} elsif (defined($post_ktest)) {
1587+
$cmd = $post_ktest;
1588+
} else {
1589+
return;
1590+
}
1591+
1592+
my $cp_post_ktest = eval_kernel_version($cmd);
1593+
run_command $cp_post_ktest;
1594+
$post_ktest_done = 1;
1595+
}
1596+
15781597
sub dodie {
15791598
# avoid recursion
15801599
return if ($in_die);
@@ -1634,6 +1653,7 @@ sub dodie {
16341653
if (defined($post_test)) {
16351654
run_command $post_test;
16361655
}
1656+
run_post_ktest;
16371657

16381658
die @_, "\n";
16391659
}
@@ -4300,6 +4320,7 @@ sub cancel_test {
43004320
send_email("KTEST: Your [$name] test was cancelled",
43014321
"Your test started at $script_start_time was cancelled: sig int");
43024322
}
4323+
run_post_ktest;
43034324
die "\nCaught Sig Int, test interrupted: $!\n"
43044325
}
43054326

@@ -4661,11 +4682,7 @@ sub die_usage {
46614682
success $i;
46624683
}
46634684

4664-
if (defined($final_post_ktest)) {
4665-
4666-
my $cp_final_post_ktest = eval_kernel_version $final_post_ktest;
4667-
run_command $cp_final_post_ktest;
4668-
}
4685+
run_post_ktest;
46694686

46704687
if ($opt{"POWEROFF_ON_SUCCESS"}) {
46714688
halt;

0 commit comments

Comments
 (0)