From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
"John Warthog9 Hawley" <warthog9@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [GIT PULL][PATCH 2/2] ktest: Make sure wait_for_input does honor the timeout
Date: Wed, 08 Mar 2017 10:55:23 -0500 [thread overview]
Message-ID: <20170308155739.848392185@goodmis.org> (raw)
In-Reply-To: <20170308155521.516183603@goodmis.org>
[-- Attachment #1: 0002-ktest-Make-sure-wait_for_input-does-honor-the-timeou.patch --]
[-- Type: text/plain, Size: 1963 bytes --]
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
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>
---
tools/testing/ktest/ktest.pl | 18 +++++++++++-------
1 file 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 {
sub wait_for_input
{
my ($fp, $time) = @_;
+ my $start_time;
my $rin;
my $rout;
my $nr;
@@ -1895,12 +1896,12 @@ sub wait_for_input
vec($rin, fileno($fp), 1) = 1;
vec($rin, fileno(\*STDIN), 1) = 1;
+ $start_time = time;
+
while (1) {
$nr = select($rout=$rin, undef, undef, $time);
- if ($nr <= 0) {
- return undef;
- }
+ last if ($nr <= 0);
# copy data from stdin to the console
if (vec($rout, fileno(\*STDIN), 1) == 1) {
@@ -1908,7 +1909,11 @@ sub wait_for_input
syswrite($fp, $buf, $nr) if ($nr > 0);
}
- next if (vec($rout, fileno($fp), 1) != 1);
+ # The timeout is based on time waiting for the fp data
+ if (vec($rout, fileno($fp), 1) != 1) {
+ last if (defined($time) && (time - $start_time > $time));
+ next;
+ }
$line = "";
@@ -1918,12 +1923,11 @@ sub wait_for_input
last if ($ch eq "\n");
}
- if (!length($line)) {
- return undef;
- }
+ last if (!length($line));
return $line;
}
+ return undef;
}
sub reboot_to {
--
2.10.2
next prev parent reply other threads:[~2017-03-08 15:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 15:55 [GIT PULL][PATCH 0/2] ktest: Fixes for 4.11 Steven Rostedt
2017-03-08 15:55 ` [GIT PULL][PATCH 1/2] ktest: Fix while loop in wait_for_input Steven Rostedt
2017-03-08 15:55 ` Steven Rostedt [this message]
2017-03-08 16:11 ` [GIT PULL][PATCH 0/2] ktest: Fixes for 4.11 Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170308155739.848392185@goodmis.org \
--to=rostedt@goodmis.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=warthog9@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®