]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test/py: handle exceptions in console creation
authorStephen Warren <swarren@nvidia.com>
Wed, 10 Feb 2016 23:54:37 +0000 (16:54 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 15 Feb 2016 20:58:29 +0000 (20:58 +0000)
u_boot_console.exec_attach.get_spawn() performs two steps:
1) Spawn a process to communicate with the serial console.
2) Reset the board so that U-Boot starts running from scratch.

Currently, if an exception happens in step (2), no cleanup is performed on
the process created in step (1). That process stays running and may e.g.
hold serial port locks, or simply continue to read data from the serial
port, thus preventing it from reaching any other process that attempts to
read from the same serial port later. While there is error cleanup code in
u_boot_console_base.ensure_spawned(), this is not triggered since the
exception prevents assignment to self.p there, and hence the exception
handler has no object to operate upon in cleanup_spawn().

Solve this by enhancing u_boot_console.exec_attach.get_spawn() to clean
up any objects it has created.

In theory, u_boot_spawn.Spawn's constructor has a similar issue, so fix
this too.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
test/py/u_boot_console_exec_attach.py
test/py/u_boot_spawn.py

index 1be27c1930794d244f34c1f745653a4bdfd459f9..445b58dda6121f85eb7bc3bb3fbdc6408e8a1fb2 100644 (file)
@@ -58,10 +58,14 @@ class ConsoleExecAttach(ConsoleBase):
         args = [self.config.board_type, self.config.board_identity]
         s = Spawn(['u-boot-test-console'] + args)
 
-        self.log.action('Resetting board')
-        cmd = ['u-boot-test-reset'] + args
-        runner = self.log.get_runner(cmd[0], sys.stdout)
-        runner.run(cmd)
-        runner.close()
+        try:
+            self.log.action('Resetting board')
+            cmd = ['u-boot-test-reset'] + args
+            runner = self.log.get_runner(cmd[0], sys.stdout)
+            runner.run(cmd)
+            runner.close()
+        except:
+            s.close()
+            raise
 
         return s
index 3d9cde5ee0d063dcbd98384ce04a58cf8e1483ee..a5f4a8e91baed1aa8c9f3dce7c0072fc28ca13da 100644 (file)
@@ -56,8 +56,12 @@ class Spawn(object):
             finally:
                 os._exit(255)
 
-        self.poll = select.poll()
-        self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL)
+        try:
+            self.poll = select.poll()
+            self.poll.register(self.fd, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP | select.POLLNVAL)
+        except:
+            self.close()
+            raise
 
     def kill(self, sig):
         """Send unix signal "sig" to the child process.