From nobody Tue Apr 7 04:18:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 089043E0C4E for ; Mon, 16 Mar 2026 18:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773686453; cv=none; b=PfnX1acVVRulp14JcbLI6owxQb7utFuwapPhI1kzC6DYzsbvjjyJc/HQzIOJZvJdsZfU3EFPs7u3V0+1CtQ15rgj0X0q93JXKMsiBNunZC130mcV1M9lRGbmx/yow5kSMDoBq9sBZZMgitCtZVL5/17+oB4O978qg48w/OzyXd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773686453; c=relaxed/simple; bh=6qZkbVnkcbyDKNTFPeLtDr8tCnz30c0+OKblk/GUdNg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=PQKVf6GN5vySERgObbonD0L4liyFVoU/ZNDu5MtSvgdusLmjsalqi60jJN4RE545fnLZEKje+exmeHkqRVKJs6CSO8XNajtzcL3JIU30gLU/fRdut6MbvAYVOytrxMNbsN+zLYehgU2iyI3FiajwiggfaHdoKjXM2pENVE2aWxk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q+H4UE0y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q+H4UE0y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA644C19421; Mon, 16 Mar 2026 18:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773686452; bh=6qZkbVnkcbyDKNTFPeLtDr8tCnz30c0+OKblk/GUdNg=; h=Date:From:To:Cc:Subject:References:From; b=Q+H4UE0yXIjr4xxZQl054mHHAqHCJ2/DUAjpr6UF3Z7XH5mKqjukPTnaAGOKsgf05 4rYExEBkD6UbbLE5kCpRN0E4toJPo/ts+ABSnbXyddHSkUEW6mBVjxGR9wQQ1u/N5+ 1nc0e2C3Coglot0CBYWGlypN2crdi8XOFYCYMoBklqvYOgUQDTHUzBULdS3JdVACAv EfP/w8CjpiLVPFrahITXHKyPXNS4FQqJbRzU+0gV08nu9QyT860XTPVFwJLdiTpCwS UOlvPQjxvO7cg5PQZ98JJDR2cYJIkuCL13sldGREeutfAzlAj8IAc7jFvPZQ/zoICZ U0Hb80W3PWALw== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1w2CsO-0000000855N-466X; Mon, 16 Mar 2026 14:41:16 -0400 Message-ID: <20260316184116.847775505@kernel.org> User-Agent: quilt/0.69 Date: Mon, 16 Mar 2026 14:40:41 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: "John Warthog9 Hawley" , =?UTF-8?q?Ricardo=20B.=20Marli=C3=A8re?= , John Hawley , Andrea Righi , Marcos Paulo de Souza , Matthieu Baerts , Fernando Fernandez Mancera , Pedro Falcato Subject: [for-next][PATCH 8/9] ktest: Run POST_KTEST hooks on failure and cancellation References: <20260316184033.927944169@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: =3D?UTF-8?q?Ricardo=3D20B=3D2E=3D20Marli=3DC3=3DA8re?=3D 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 Cc: Andrea Righi Cc: Marcos Paulo de Souza Cc: Matthieu Baerts Cc: Fernando Fernandez Mancera Cc: Pedro Falcato 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=C3=A8re Signed-off-by: Steven Rostedt --- tools/testing/ktest/ktest.pl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index b018b937e028..8962857ce4a6 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -100,6 +100,7 @@ my $test_type; my $build_type; my $build_options; my $final_post_ktest; +my $post_ktest_done =3D 0; my $pre_ktest; my $pre_ktest_die; my $post_ktest; @@ -1586,6 +1587,24 @@ sub get_test_name() { return $name; } =20 +sub run_post_ktest { + my $cmd; + + return if ($post_ktest_done); + + if (defined($final_post_ktest)) { + $cmd =3D $final_post_ktest; + } elsif (defined($post_ktest)) { + $cmd =3D $post_ktest; + } else { + return; + } + + my $cp_post_ktest =3D eval_kernel_version($cmd); + run_command $cp_post_ktest; + $post_ktest_done =3D 1; +} + sub dodie { # avoid recursion return if ($in_die); @@ -1645,6 +1664,7 @@ sub dodie { if (defined($post_test)) { run_command $post_test; } + run_post_ktest; =20 die @_, "\n"; } @@ -4314,6 +4334,7 @@ sub cancel_test { send_email("KTEST: Your [$name] test was cancelled", "Your test started at $script_start_time was cancelled: sig int"); } + run_post_ktest; die "\nCaught Sig Int, test interrupted: $!\n" } =20 @@ -4679,11 +4700,7 @@ for (my $i =3D 1; $i <=3D $opt{"NUM_TESTS"}; $i++) { success $i; } =20 -if (defined($final_post_ktest)) { - - my $cp_final_post_ktest =3D eval_kernel_version $final_post_ktest; - run_command $cp_final_post_ktest; -} +run_post_ktest; =20 if ($opt{"POWEROFF_ON_SUCCESS"}) { halt; --=20 2.51.0