blob: 3de0fe4a3b6df831239b9825c06dcfd789e676db [file] [log] [blame]
Stephen Warren10e50632016-01-15 11:15:24 -07001# Copyright (c) 2015 Stephen Warren
2# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
3#
4# SPDX-License-Identifier: GPL-2.0
5
6# Logic to interact with the sandbox port of U-Boot, running as a sub-process.
7
8import time
9from u_boot_spawn import Spawn
10from u_boot_console_base import ConsoleBase
11
12class ConsoleSandbox(ConsoleBase):
Stephen Warren75e731e2016-01-26 13:41:30 -070013 """Represents a connection to a sandbox U-Boot console, executed as a sub-
14 process."""
Stephen Warren10e50632016-01-15 11:15:24 -070015
16 def __init__(self, log, config):
Stephen Warren75e731e2016-01-26 13:41:30 -070017 """Initialize a U-Boot console connection.
Stephen Warren10e50632016-01-15 11:15:24 -070018
19 Args:
20 log: A multiplexed_log.Logfile instance.
21 config: A "configuration" object as defined in conftest.py.
22
23 Returns:
24 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070025 """
Stephen Warren10e50632016-01-15 11:15:24 -070026
27 super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024)
28
29 def get_spawn(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070030 """Connect to a fresh U-Boot instance.
Stephen Warren10e50632016-01-15 11:15:24 -070031
32 A new sandbox process is created, so that U-Boot begins running from
33 scratch.
34
35 Args:
36 None.
37
38 Returns:
39 A u_boot_spawn.Spawn object that is attached to U-Boot.
Stephen Warren75e731e2016-01-26 13:41:30 -070040 """
Stephen Warren10e50632016-01-15 11:15:24 -070041
Stephen Warren33db1ee2016-02-04 16:11:50 -070042 cmd = []
43 if self.config.gdbserver:
44 cmd += ['gdbserver', self.config.gdbserver]
45 cmd += [
Stephen Warrenb8936ae2016-01-27 23:57:52 -070046 self.config.build_dir + '/u-boot',
47 '-d',
48 self.config.build_dir + '/arch/sandbox/dts/test.dtb'
49 ]
Stephen Warrena85fce92016-01-27 23:57:53 -070050 return Spawn(cmd, cwd=self.config.source_dir)
Stephen Warren10e50632016-01-15 11:15:24 -070051
52 def kill(self, sig):
Stephen Warren75e731e2016-01-26 13:41:30 -070053 """Send a specific Unix signal to the sandbox process.
Stephen Warren10e50632016-01-15 11:15:24 -070054
55 Args:
56 sig: The Unix signal to send to the process.
57
58 Returns:
59 Nothing.
Stephen Warren75e731e2016-01-26 13:41:30 -070060 """
Stephen Warren10e50632016-01-15 11:15:24 -070061
Stephen Warren10e50632016-01-15 11:15:24 -070062 self.log.action('kill %d' % sig)
63 self.p.kill(sig)
64
65 def validate_exited(self):
Stephen Warren75e731e2016-01-26 13:41:30 -070066 """Determine whether the sandbox process has exited.
Stephen Warren10e50632016-01-15 11:15:24 -070067
68 If required, this function waits a reasonable time for the process to
69 exit.
70
71 Args:
72 None.
73
74 Returns:
75 Boolean indicating whether the process has exited.
Stephen Warren75e731e2016-01-26 13:41:30 -070076 """
Stephen Warren10e50632016-01-15 11:15:24 -070077
78 p = self.p
79 self.p = None
80 for i in xrange(100):
81 ret = not p.isalive()
82 if ret:
83 break
84 time.sleep(0.1)
85 p.close()
86 return ret