Skip to content

Commit 4e7d2a8

Browse files
committed
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: [email protected] Fixes: 6e98d1b ("ktest: Add timeout to ssh command") Signed-off-by: Steven Rostedt <[email protected]>
1 parent 83d29d4 commit 4e7d2a8

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
my $store_successes;
179179
my $test_name;
180180
my $timeout;
181+
my $run_timeout;
181182
my $connect_timeout;
182183
my $config_bisect_exec;
183184
my $booted_timeout;
@@ -340,6 +341,7 @@
340341
"STORE_SUCCESSES" => \$store_successes,
341342
"TEST_NAME" => \$test_name,
342343
"TIMEOUT" => \$timeout,
344+
"RUN_TIMEOUT" => \$run_timeout,
343345
"CONNECT_TIMEOUT" => \$connect_timeout,
344346
"CONFIG_BISECT_EXEC" => \$config_bisect_exec,
345347
"BOOTED_TIMEOUT" => \$booted_timeout,
@@ -1858,6 +1860,14 @@ sub run_command {
18581860
$command =~ s/\$SSH_USER/$ssh_user/g;
18591861
$command =~ s/\$MACHINE/$machine/g;
18601862

1863+
if (!defined($timeout)) {
1864+
$timeout = $run_timeout;
1865+
}
1866+
1867+
if (!defined($timeout)) {
1868+
$timeout = -1; # tell wait_for_input to wait indefinitely
1869+
}
1870+
18611871
doprint("$command ... ");
18621872
$start_time = time;
18631873

@@ -1884,13 +1894,10 @@ sub run_command {
18841894

18851895
while (1) {
18861896
my $fp = \*CMD;
1887-
if (defined($timeout)) {
1888-
doprint "timeout = $timeout\n";
1889-
}
18901897
my $line = wait_for_input($fp, $timeout);
18911898
if (!defined($line)) {
18921899
my $now = time;
1893-
if (defined($timeout) && (($now - $start_time) >= $timeout)) {
1900+
if ($timeout >= 0 && (($now - $start_time) >= $timeout)) {
18941901
doprint "Hit timeout of $timeout, killing process\n";
18951902
$hit_timeout = 1;
18961903
kill 9, $pid;
@@ -2062,6 +2069,11 @@ sub wait_for_input {
20622069
$time = $timeout;
20632070
}
20642071

2072+
if ($time < 0) {
2073+
# Negative number means wait indefinitely
2074+
undef $time;
2075+
}
2076+
20652077
$rin = '';
20662078
vec($rin, fileno($fp), 1) = 1;
20672079
vec($rin, fileno(\*STDIN), 1) = 1;

tools/testing/ktest/sample.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@
817817
# is issued instead of a reboot.
818818
# CONNECT_TIMEOUT = 25
819819

820+
# The timeout in seconds for how long to wait for any running command
821+
# to timeout. If not defined, it will let it go indefinitely.
822+
# (default undefined)
823+
#RUN_TIMEOUT = 600
824+
820825
# In between tests, a reboot of the box may occur, and this
821826
# is the time to wait for the console after it stops producing
822827
# output. Some machines may not produce a large lag on reboot

0 commit comments

Comments
 (0)