From nobody Sun Sep 14 20:41:23 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11E6AC46467 for ; Wed, 18 Jan 2023 22:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230053AbjARWC2 (ORCPT ); Wed, 18 Jan 2023 17:02:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjARWBv (ORCPT ); Wed, 18 Jan 2023 17:01:51 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8638337F01; Wed, 18 Jan 2023 14:01:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 46EFFB81F14; Wed, 18 Jan 2023 22:01:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBF1BC4339E; Wed, 18 Jan 2023 22:01:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pIGV8-002HAL-2V; Wed, 18 Jan 2023 17:01:46 -0500 Message-ID: <20230118220146.639491327@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 18 Jan 2023 16:54:38 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: "John Warthog9 Hawley" , Masami Hiramatsu , stable@vger.kernel.org Subject: [for-linus][PATCH 3/3] ktest.pl: Add RUN_TIMEOUT option with default unlimited References: <20230118215435.016435760@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt There is a disconnect between the run_command function and the wait_for_input. The wait_for_input has a default timeout of 2 minutes. But if that happens, the run_command loop will exit out to the waitpid() of the executing command. This fails in that it no longer monitors the command, and also, the ssh to the test box can hang when its finished, as it's waiting for the pipe it's writing to to flush, but the loop that reads that pipe has already exited, leaving the command stuck, and the test hangs. Instead, make the default "wait_for_input" of the run_command infinite, and allow the user to override it if they want with a default timeout option "RUN_TIMEOUT". But this fixes the hang that happens when the pipe is full and the ssh session never exits. Cc: stable@vger.kernel.org Fixes: 6e98d1b4415fe ("ktest: Add timeout to ssh command") Signed-off-by: Steven Rostedt --- tools/testing/ktest/ktest.pl | 20 ++++++++++++++++---- tools/testing/ktest/sample.conf | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 78249c3a03a5..7c91d753a9f2 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -178,6 +178,7 @@ my $store_failures; my $store_successes; my $test_name; my $timeout; +my $run_timeout; my $connect_timeout; my $config_bisect_exec; my $booted_timeout; @@ -340,6 +341,7 @@ my %option_map =3D ( "STORE_SUCCESSES" =3D> \$store_successes, "TEST_NAME" =3D> \$test_name, "TIMEOUT" =3D> \$timeout, + "RUN_TIMEOUT" =3D> \$run_timeout, "CONNECT_TIMEOUT" =3D> \$connect_timeout, "CONFIG_BISECT_EXEC" =3D> \$config_bisect_exec, "BOOTED_TIMEOUT" =3D> \$booted_timeout, @@ -1862,6 +1864,14 @@ sub run_command { $command =3D~ s/\$SSH_USER/$ssh_user/g; $command =3D~ s/\$MACHINE/$machine/g; =20 + if (!defined($timeout)) { + $timeout =3D $run_timeout; + } + + if (!defined($timeout)) { + $timeout =3D -1; # tell wait_for_input to wait indefinitely + } + doprint("$command ... "); $start_time =3D time; =20 @@ -1888,13 +1898,10 @@ sub run_command { =20 while (1) { my $fp =3D \*CMD; - if (defined($timeout)) { - doprint "timeout =3D $timeout\n"; - } my $line =3D wait_for_input($fp, $timeout); if (!defined($line)) { my $now =3D time; - if (defined($timeout) && (($now - $start_time) >=3D $timeout)) { + if ($timeout >=3D 0 && (($now - $start_time) >=3D $timeout)) { doprint "Hit timeout of $timeout, killing process\n"; $hit_timeout =3D 1; kill 9, $pid; @@ -2066,6 +2073,11 @@ sub wait_for_input { $time =3D $timeout; } =20 + if ($time < 0) { + # Negative number means wait indefinitely + undef $time; + } + $rin =3D ''; vec($rin, fileno($fp), 1) =3D 1; vec($rin, fileno(\*STDIN), 1) =3D 1; diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.c= onf index 2d0fe15a096d..f43477a9b857 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -817,6 +817,11 @@ # is issued instead of a reboot. # CONNECT_TIMEOUT =3D 25 =20 +# The timeout in seconds for how long to wait for any running command +# to timeout. If not defined, it will let it go indefinitely. +# (default undefined) +#RUN_TIMEOUT =3D 600 + # In between tests, a reboot of the box may occur, and this # is the time to wait for the console after it stops producing # output. Some machines may not produce a large lag on reboot --=20 2.39.0