diff options
author | Tom Rini <trini@konsulko.com> | 2021-10-15 07:50:59 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-10-15 07:50:59 -0400 |
commit | 2d34be0a9e12cf050de39ad95375213f48e685bd (patch) | |
tree | eec9902ce120d15c0868a9024e2c9e4adc947132 /test/py/u_boot_spawn.py | |
parent | 10cd8efe1a7eacd63907ba95bd8442bc2cdce461 (diff) | |
parent | 35b2b5f04c71efb73ec0f1a01535542e4b602e15 (diff) |
Merge branch '2021-10-14-assorted-updates'
- Update to LLVM-13 in CI, assorted PCI fixes and pytest in CI
improvements
Diffstat (limited to 'test/py/u_boot_spawn.py')
-rw-r--r-- | test/py/u_boot_spawn.py | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index 6991b78cca8..e34cb217e84 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -35,6 +35,8 @@ class Spawn(object): """ self.waited = False + self.exit_code = 0 + self.exit_info = '' self.buf = '' self.output = '' self.logfile_read = None @@ -80,25 +82,44 @@ class Spawn(object): os.kill(self.pid, sig) - def isalive(self): + def checkalive(self): """Determine whether the child process is still running. - Args: - None. - Returns: - Boolean indicating whether process is alive. + tuple: + True if process is alive, else False + 0 if process is alive, else exit code of process + string describing what happened ('' or 'status/signal n') """ if self.waited: - return False + return False, self.exit_code, self.exit_info w = os.waitpid(self.pid, os.WNOHANG) if w[0] == 0: - return True - + return True, 0, 'running' + status = w[1] + + if os.WIFEXITED(status): + self.exit_code = os.WEXITSTATUS(status) + self.exit_info = 'status %d' % self.exit_code + elif os.WIFSIGNALED(status): + signum = os.WTERMSIG(status) + self.exit_code = -signum + self.exit_info = 'signal %d (%s)' % (signum, signal.Signals(signum)) self.waited = True - return False + return False, self.exit_code, self.exit_info + + def isalive(self): + """Determine whether the child process is still running. + + Args: + None. + + Returns: + Boolean indicating whether process is alive. + """ + return self.checkalive()[0] def send(self, data): """Send data to the sub-process's stdin. @@ -168,9 +189,20 @@ class Spawn(object): events = self.poll.poll(poll_maxwait) if not events: raise Timeout() - c = os.read(self.fd, 1024).decode(errors='replace') - if not c: - raise EOFError() + try: + c = os.read(self.fd, 1024).decode(errors='replace') + except OSError as err: + # With sandbox, try to detect when U-Boot exits when it + # shouldn't and explain why. This is much more friendly than + # just dying with an I/O error + if err.errno == 5: # Input/output error + alive, exit_code, info = self.checkalive() + if alive: + raise + else: + raise ValueError('U-Boot exited with %s' % info) + else: + raise if self.logfile_read: self.logfile_read.write(c) self.buf += c |