aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2017-03-08 10:36:59 -0500
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2017-03-08 10:41:37 -0500
commitf7c6401ff84ab8ffffc281a29aa0a787f7eb346e (patch)
tree8d90ead71336f264f58014f6b264cfb7f6d485b4 /tools
parent99c014a87979c9244806685f3c3fc7767f79f645 (diff)
ktest: Make sure wait_for_input does honor the timeout
The function wait_for_input takes in a timeout, and even has a default timeout. But if for some reason the STDIN descriptor keeps sending in data, the function will never time out. The timout is to wait for the data from the passed in file descriptor, not for STDIN. Adding a test in the case where there's no data from the passed in file descriptor that checks to see if the timeout passed, will ensure that it will timeout properly even if there's input in STDIN. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/testing/ktest/ktest.pl18
1 files changed, 11 insertions, 7 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 0c006a2f165d..49f7c8b9d9c4 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -1880,6 +1880,7 @@ sub get_grub_index {
1880sub wait_for_input 1880sub wait_for_input
1881{ 1881{
1882 my ($fp, $time) = @_; 1882 my ($fp, $time) = @_;
1883 my $start_time;
1883 my $rin; 1884 my $rin;
1884 my $rout; 1885 my $rout;
1885 my $nr; 1886 my $nr;
@@ -1895,12 +1896,12 @@ sub wait_for_input
1895 vec($rin, fileno($fp), 1) = 1; 1896 vec($rin, fileno($fp), 1) = 1;
1896 vec($rin, fileno(\*STDIN), 1) = 1; 1897 vec($rin, fileno(\*STDIN), 1) = 1;
1897 1898
1899 $start_time = time;
1900
1898 while (1) { 1901 while (1) {
1899 $nr = select($rout=$rin, undef, undef, $time); 1902 $nr = select($rout=$rin, undef, undef, $time);
1900 1903
1901 if ($nr <= 0) { 1904 last if ($nr <= 0);
1902 return undef;
1903 }
1904 1905
1905 # copy data from stdin to the console 1906 # copy data from stdin to the console
1906 if (vec($rout, fileno(\*STDIN), 1) == 1) { 1907 if (vec($rout, fileno(\*STDIN), 1) == 1) {
@@ -1908,7 +1909,11 @@ sub wait_for_input
1908 syswrite($fp, $buf, $nr) if ($nr > 0); 1909 syswrite($fp, $buf, $nr) if ($nr > 0);
1909 } 1910 }
1910 1911
1911 next if (vec($rout, fileno($fp), 1) != 1); 1912 # The timeout is based on time waiting for the fp data
1913 if (vec($rout, fileno($fp), 1) != 1) {
1914 last if (defined($time) && (time - $start_time > $time));
1915 next;
1916 }
1912 1917
1913 $line = ""; 1918 $line = "";
1914 1919
@@ -1918,12 +1923,11 @@ sub wait_for_input
1918 last if ($ch eq "\n"); 1923 last if ($ch eq "\n");
1919 } 1924 }
1920 1925
1921 if (!length($line)) { 1926 last if (!length($line));
1922 return undef;
1923 }
1924 1927
1925 return $line; 1928 return $line;
1926 } 1929 }
1930 return undef;
1927} 1931}
1928 1932
1929sub reboot_to { 1933sub reboot_to {