diff options
author | Josh Poimboeuf <jpoimboe@redhat.com> | 2015-01-28 14:38:39 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2015-02-02 10:43:24 -0500 |
commit | 9d2f7f051b8917305ea20ed79ff08254ea73f26d (patch) | |
tree | 4241225b589643b8d7dc70d412d137712e357770 | |
parent | 9f2cdcbbb90e70e5e8fe6cd30151b8ac1c8745ac (diff) |
ktest: Enable user input to the console
Allow the user to send input to the console by putting the terminal in
cbreak mode (to allow reading stdin one character at a time) and copying
all stdin data to the console's pty.
Link: http://lkml.kernel.org/r/bb1bbe7d202c95a3ce7894cfffdd8c725875978e.1422473610.git.jpoimboe@redhat.com
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 2d3191693567..ef1d99f3859c 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl | |||
@@ -178,7 +178,7 @@ my $checkout; | |||
178 | my $localversion; | 178 | my $localversion; |
179 | my $iteration = 0; | 179 | my $iteration = 0; |
180 | my $successes = 0; | 180 | my $successes = 0; |
181 | my $stty; | 181 | my $stty_orig; |
182 | 182 | ||
183 | my $bisect_good; | 183 | my $bisect_good; |
184 | my $bisect_bad; | 184 | my $bisect_bad; |
@@ -1458,7 +1458,11 @@ sub open_console { | |||
1458 | my $pid; | 1458 | my $pid; |
1459 | 1459 | ||
1460 | # save terminal settings | 1460 | # save terminal settings |
1461 | $stty = `stty -g`; | 1461 | $stty_orig = `stty -g`; |
1462 | |||
1463 | # place terminal in cbreak mode so that stdin can be read one character at | ||
1464 | # a time without having to wait for a newline | ||
1465 | system("stty -icanon -echo -icrnl"); | ||
1462 | 1466 | ||
1463 | create_pty($ptm, $pts); | 1467 | create_pty($ptm, $pts); |
1464 | 1468 | ||
@@ -1487,7 +1491,7 @@ sub close_console { | |||
1487 | close($fp); | 1491 | close($fp); |
1488 | 1492 | ||
1489 | # restore terminal settings | 1493 | # restore terminal settings |
1490 | system("stty $stty"); | 1494 | system("stty $stty_orig"); |
1491 | } | 1495 | } |
1492 | 1496 | ||
1493 | sub start_monitor { | 1497 | sub start_monitor { |
@@ -1827,7 +1831,9 @@ sub wait_for_input | |||
1827 | { | 1831 | { |
1828 | my ($fp, $time) = @_; | 1832 | my ($fp, $time) = @_; |
1829 | my $rin; | 1833 | my $rin; |
1830 | my $ready; | 1834 | my $rout; |
1835 | my $nr; | ||
1836 | my $buf; | ||
1831 | my $line; | 1837 | my $line; |
1832 | my $ch; | 1838 | my $ch; |
1833 | 1839 | ||
@@ -1837,21 +1843,36 @@ sub wait_for_input | |||
1837 | 1843 | ||
1838 | $rin = ''; | 1844 | $rin = ''; |
1839 | vec($rin, fileno($fp), 1) = 1; | 1845 | vec($rin, fileno($fp), 1) = 1; |
1840 | ($ready, $time) = select($rin, undef, undef, $time); | 1846 | vec($rin, fileno(\*STDIN), 1) = 1; |
1841 | 1847 | ||
1842 | $line = ""; | 1848 | while (1) { |
1849 | $nr = select($rout=$rin, undef, undef, $time); | ||
1843 | 1850 | ||
1844 | # try to read one char at a time | 1851 | if ($nr <= 0) { |
1845 | while (sysread $fp, $ch, 1) { | 1852 | return undef; |
1846 | $line .= $ch; | 1853 | } |
1847 | last if ($ch eq "\n"); | ||
1848 | } | ||
1849 | 1854 | ||
1850 | if (!length($line)) { | 1855 | # copy data from stdin to the console |
1851 | return undef; | 1856 | if (vec($rout, fileno(\*STDIN), 1) == 1) { |
1852 | } | 1857 | sysread(\*STDIN, $buf, 1000); |
1858 | syswrite($fp, $buf, 1000); | ||
1859 | next; | ||
1860 | } | ||
1853 | 1861 | ||
1854 | return $line; | 1862 | $line = ""; |
1863 | |||
1864 | # try to read one char at a time | ||
1865 | while (sysread $fp, $ch, 1) { | ||
1866 | $line .= $ch; | ||
1867 | last if ($ch eq "\n"); | ||
1868 | } | ||
1869 | |||
1870 | if (!length($line)) { | ||
1871 | return undef; | ||
1872 | } | ||
1873 | |||
1874 | return $line; | ||
1875 | } | ||
1855 | } | 1876 | } |
1856 | 1877 | ||
1857 | sub reboot_to { | 1878 | sub reboot_to { |