Commit 4e7d2a8f authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt (Google)

ktest.pl: Add RUN_TIMEOUT option with default unlimited

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: 6e98d1b4 ("ktest: Add timeout to ssh command")
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 83d29d43
...@@ -178,6 +178,7 @@ my $store_failures; ...@@ -178,6 +178,7 @@ my $store_failures;
my $store_successes; my $store_successes;
my $test_name; my $test_name;
my $timeout; my $timeout;
my $run_timeout;
my $connect_timeout; my $connect_timeout;
my $config_bisect_exec; my $config_bisect_exec;
my $booted_timeout; my $booted_timeout;
...@@ -340,6 +341,7 @@ my %option_map = ( ...@@ -340,6 +341,7 @@ my %option_map = (
"STORE_SUCCESSES" => \$store_successes, "STORE_SUCCESSES" => \$store_successes,
"TEST_NAME" => \$test_name, "TEST_NAME" => \$test_name,
"TIMEOUT" => \$timeout, "TIMEOUT" => \$timeout,
"RUN_TIMEOUT" => \$run_timeout,
"CONNECT_TIMEOUT" => \$connect_timeout, "CONNECT_TIMEOUT" => \$connect_timeout,
"CONFIG_BISECT_EXEC" => \$config_bisect_exec, "CONFIG_BISECT_EXEC" => \$config_bisect_exec,
"BOOTED_TIMEOUT" => \$booted_timeout, "BOOTED_TIMEOUT" => \$booted_timeout,
...@@ -1858,6 +1860,14 @@ sub run_command { ...@@ -1858,6 +1860,14 @@ sub run_command {
$command =~ s/\$SSH_USER/$ssh_user/g; $command =~ s/\$SSH_USER/$ssh_user/g;
$command =~ s/\$MACHINE/$machine/g; $command =~ s/\$MACHINE/$machine/g;
if (!defined($timeout)) {
$timeout = $run_timeout;
}
if (!defined($timeout)) {
$timeout = -1; # tell wait_for_input to wait indefinitely
}
doprint("$command ... "); doprint("$command ... ");
$start_time = time; $start_time = time;
...@@ -1884,13 +1894,10 @@ sub run_command { ...@@ -1884,13 +1894,10 @@ sub run_command {
while (1) { while (1) {
my $fp = \*CMD; my $fp = \*CMD;
if (defined($timeout)) {
doprint "timeout = $timeout\n";
}
my $line = wait_for_input($fp, $timeout); my $line = wait_for_input($fp, $timeout);
if (!defined($line)) { if (!defined($line)) {
my $now = time; my $now = time;
if (defined($timeout) && (($now - $start_time) >= $timeout)) { if ($timeout >= 0 && (($now - $start_time) >= $timeout)) {
doprint "Hit timeout of $timeout, killing process\n"; doprint "Hit timeout of $timeout, killing process\n";
$hit_timeout = 1; $hit_timeout = 1;
kill 9, $pid; kill 9, $pid;
...@@ -2062,6 +2069,11 @@ sub wait_for_input { ...@@ -2062,6 +2069,11 @@ sub wait_for_input {
$time = $timeout; $time = $timeout;
} }
if ($time < 0) {
# Negative number means wait indefinitely
undef $time;
}
$rin = ''; $rin = '';
vec($rin, fileno($fp), 1) = 1; vec($rin, fileno($fp), 1) = 1;
vec($rin, fileno(\*STDIN), 1) = 1; vec($rin, fileno(\*STDIN), 1) = 1;
......
...@@ -817,6 +817,11 @@ ...@@ -817,6 +817,11 @@
# is issued instead of a reboot. # is issued instead of a reboot.
# CONNECT_TIMEOUT = 25 # CONNECT_TIMEOUT = 25
# 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 = 600
# In between tests, a reboot of the box may occur, and this # In between tests, a reboot of the box may occur, and this
# is the time to wait for the console after it stops producing # is the time to wait for the console after it stops producing
# output. Some machines may not produce a large lag on reboot # output. Some machines may not produce a large lag on reboot
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment