Message ID | 1453328158-23818-1-git-send-email-swarren@wwwdotorg.org |
---|---|
State | Accepted |
Commit | d314e247e1aede35cdfe448ad9262edc0d90a9ba |
Delegated to: | Simon Glass |
Headers | show |
Hi Stephen, > From: Stephen Warren <swarren@nvidia.com> > > Currently, Spawn.expect() imposes its timeout solely upon receipt of > new data, not on its overall operation. In theory, this could cause > the timeout not to fire if U-Boot continually generated output that > did not match the expected patterns. > > Fix the code to additionally impose a timeout on overall operation, > which is the intended mode of operation. > > Signed-off-by: Stephen Warren <swarren@nvidia.com> > --- > test/py/u_boot_spawn.py | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py > index 1baee63df25c..df4c67597cab 100644 > --- a/test/py/u_boot_spawn.py > +++ b/test/py/u_boot_spawn.py > @@ -122,6 +122,7 @@ class Spawn(object): > if type(patterns[pi]) == type(''): > patterns[pi] = re.compile(patterns[pi]) > > + tstart_s = time.time() > try: > while True: > earliest_m = None > @@ -142,7 +143,11 @@ class Spawn(object): > self.after = self.buf[pos:posafter] > self.buf = self.buf[posafter:] > return earliest_pi > - events = self.poll.poll(self.timeout) > + tnow_s = time.time() > + tdelta_ms = (tnow_s - tstart_s) * 1000 > + if tdelta_ms > self.timeout: > + raise Timeout() > + events = self.poll.poll(self.timeout - tdelta_ms) > if not events: > raise Timeout() > c = os.read(self.fd, 1024) Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
On 20 January 2016 at 15:15, Stephen Warren <swarren@wwwdotorg.org> wrote: > From: Stephen Warren <swarren@nvidia.com> > > Currently, Spawn.expect() imposes its timeout solely upon receipt of new > data, not on its overall operation. In theory, this could cause the > timeout not to fire if U-Boot continually generated output that did not > match the expected patterns. > > Fix the code to additionally impose a timeout on overall operation, which > is the intended mode of operation. > > Signed-off-by: Stephen Warren <swarren@nvidia.com> > --- > test/py/u_boot_spawn.py | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) Acked-by: Simon Glass <sjg@chromium.org>
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index 1baee63df25c..df4c67597cab 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -122,6 +122,7 @@ class Spawn(object): if type(patterns[pi]) == type(''): patterns[pi] = re.compile(patterns[pi]) + tstart_s = time.time() try: while True: earliest_m = None @@ -142,7 +143,11 @@ class Spawn(object): self.after = self.buf[pos:posafter] self.buf = self.buf[posafter:] return earliest_pi - events = self.poll.poll(self.timeout) + tnow_s = time.time() + tdelta_ms = (tnow_s - tstart_s) * 1000 + if tdelta_ms > self.timeout: + raise Timeout() + events = self.poll.poll(self.timeout - tdelta_ms) if not events: raise Timeout() c = os.read(self.fd, 1024)