Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 6e98d1b4415fe ("ktest: Add timeout to ssh command")
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

+21 -4
+16 -4
tools/testing/ktest/ktest.pl
··· 178 178 my $store_successes; 179 179 my $test_name; 180 180 my $timeout; 181 + my $run_timeout; 181 182 my $connect_timeout; 182 183 my $config_bisect_exec; 183 184 my $booted_timeout; ··· 341 340 "STORE_SUCCESSES" => \$store_successes, 342 341 "TEST_NAME" => \$test_name, 343 342 "TIMEOUT" => \$timeout, 343 + "RUN_TIMEOUT" => \$run_timeout, 344 344 "CONNECT_TIMEOUT" => \$connect_timeout, 345 345 "CONFIG_BISECT_EXEC" => \$config_bisect_exec, 346 346 "BOOTED_TIMEOUT" => \$booted_timeout, ··· 1860 1858 $command =~ s/\$SSH_USER/$ssh_user/g; 1861 1859 $command =~ s/\$MACHINE/$machine/g; 1862 1860 1861 + if (!defined($timeout)) { 1862 + $timeout = $run_timeout; 1863 + } 1864 + 1865 + if (!defined($timeout)) { 1866 + $timeout = -1; # tell wait_for_input to wait indefinitely 1867 + } 1868 + 1863 1869 doprint("$command ... "); 1864 1870 $start_time = time; 1865 1871 ··· 1894 1884 1895 1885 while (1) { 1896 1886 my $fp = \*CMD; 1897 - if (defined($timeout)) { 1898 - doprint "timeout = $timeout\n"; 1899 - } 1900 1887 my $line = wait_for_input($fp, $timeout); 1901 1888 if (!defined($line)) { 1902 1889 my $now = time; 1903 - if (defined($timeout) && (($now - $start_time) >= $timeout)) { 1890 + if ($timeout >= 0 && (($now - $start_time) >= $timeout)) { 1904 1891 doprint "Hit timeout of $timeout, killing process\n"; 1905 1892 $hit_timeout = 1; 1906 1893 kill 9, $pid; ··· 2067 2060 2068 2061 if (!defined($time)) { 2069 2062 $time = $timeout; 2063 + } 2064 + 2065 + if ($time < 0) { 2066 + # Negative number means wait indefinitely 2067 + undef $time; 2070 2068 } 2071 2069 2072 2070 $rin = '';
+5
tools/testing/ktest/sample.conf
··· 817 817 # is issued instead of a reboot. 818 818 # CONNECT_TIMEOUT = 25 819 819 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 + 820 825 # In between tests, a reboot of the box may occur, and this 821 826 # is the time to wait for the console after it stops producing 822 827 # output. Some machines may not produce a large lag on reboot