From 636f38d83a7e0e6ca076ae65e086c800337fb3a3 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Fri, 22 Jan 2016 12:30:08 -0700 Subject: test/py: move U-Boot respawn trigger to the test core Prior to this change, U-Boot was lazilly (re-)spawned if/when a test attempted to interact with it, and no active connection existed. This approach was simple, yet had the disadvantage that U-Boot might be spawned in the middle of a test function, e.g. after the test had already performed actions such as creating data files, etc. In that case, this could cause the log to contain the sequence (1) some test logs, (2) U-Boot's boot process, (3) the rest of that test's logs. This isn't optimally readable. This issue will affect the upcoming DFU and enhanced UMS tests. This change converts u_boot_console to be a function-scoped fixture, so that pytest attempts to re-create the object for each test invocation. This allows the fixture factory function to ensure that U-Boot is spawned prior to every test. In practice, the same object is returned each time so there is essentially no additional overhead due to this change. This allows us to remove: - The explicit ensure_spawned() call from test_sleep, since the core now ensures that the spawn happens before the test code is executed. - The laxy calls to ensure_spawned() in the u_boot_console_* implementations. The one downside is that test_env's "state_ttest_env" fixture must be converted to a function-scoped fixture too, since a module-scoped fixture cannot use a function-scoped fixture. To avoid overhead, we use the same trick of returning the same object each time. Signed-off-by: Stephen Warren Acked-by: Simon Glass --- test/py/u_boot_console_sandbox.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test/py/u_boot_console_sandbox.py') diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index 88b137e8c3a..eb84150a1e4 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -51,7 +51,6 @@ class ConsoleSandbox(ConsoleBase): Nothing. ''' - self.ensure_spawned() self.log.action('kill %d' % sig) self.p.kill(sig) -- cgit v1.2.3 From e8debf394fbba594fcfc267c61f8c6bbca395b06 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Tue, 26 Jan 2016 13:41:30 -0700 Subject: test/py: use " for docstrings Python's coding style docs indicate to use " not ' for docstrings. test/py has other violations of the coding style docs, since the docs specify a stranger style than I would expect, but nobody has complained about those yet:-) Signed-off-by: Stephen Warren Reviewed-by: Simon Glass --- test/py/u_boot_console_sandbox.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/py/u_boot_console_sandbox.py') diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index eb84150a1e4..267f8b06508 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -10,11 +10,11 @@ from u_boot_spawn import Spawn from u_boot_console_base import ConsoleBase class ConsoleSandbox(ConsoleBase): - '''Represents a connection to a sandbox U-Boot console, executed as a sub- - process.''' + """Represents a connection to a sandbox U-Boot console, executed as a sub- + process.""" def __init__(self, log, config): - '''Initialize a U-Boot console connection. + """Initialize a U-Boot console connection. Args: log: A multiplexed_log.Logfile instance. @@ -22,12 +22,12 @@ class ConsoleSandbox(ConsoleBase): Returns: Nothing. - ''' + """ super(ConsoleSandbox, self).__init__(log, config, max_fifo_fill=1024) def get_spawn(self): - '''Connect to a fresh U-Boot instance. + """Connect to a fresh U-Boot instance. A new sandbox process is created, so that U-Boot begins running from scratch. @@ -37,25 +37,25 @@ class ConsoleSandbox(ConsoleBase): Returns: A u_boot_spawn.Spawn object that is attached to U-Boot. - ''' + """ return Spawn([self.config.build_dir + '/u-boot']) def kill(self, sig): - '''Send a specific Unix signal to the sandbox process. + """Send a specific Unix signal to the sandbox process. Args: sig: The Unix signal to send to the process. Returns: Nothing. - ''' + """ self.log.action('kill %d' % sig) self.p.kill(sig) def validate_exited(self): - '''Determine whether the sandbox process has exited. + """Determine whether the sandbox process has exited. If required, this function waits a reasonable time for the process to exit. @@ -65,7 +65,7 @@ class ConsoleSandbox(ConsoleBase): Returns: Boolean indicating whether the process has exited. - ''' + """ p = self.p self.p = None -- cgit v1.2.3 From 77bcb22d77d1b1975c166755b012e0c0c1abb50a Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Wed, 27 Jan 2016 23:57:52 -0700 Subject: test/py: pass test DTB to sandbox This is required for at least "ut dm" to operate correctly. Signed-off-by: Stephen Warren Acked-by: Simon Glass --- test/py/u_boot_console_sandbox.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/py/u_boot_console_sandbox.py') diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index 267f8b06508..bbf41e788ba 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -39,7 +39,12 @@ class ConsoleSandbox(ConsoleBase): A u_boot_spawn.Spawn object that is attached to U-Boot. """ - return Spawn([self.config.build_dir + '/u-boot']) + cmd = [ + self.config.build_dir + '/u-boot', + '-d', + self.config.build_dir + '/arch/sandbox/dts/test.dtb' + ] + return Spawn(cmd) def kill(self, sig): """Send a specific Unix signal to the sandbox process. -- cgit v1.2.3 From d27f2fc1e19c70d529932cf5725259dded19d5fd Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Wed, 27 Jan 2016 23:57:53 -0700 Subject: test/py: run sandbox in source directory Some unit tests expect the cwd of the sandbox process to be the root of the source tree. Ensure that requirement is met. Signed-off-by: Stephen Warren Acked-by: Simon Glass --- test/py/u_boot_console_sandbox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/py/u_boot_console_sandbox.py') diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index bbf41e788ba..a7263f30b8c 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -44,7 +44,7 @@ class ConsoleSandbox(ConsoleBase): '-d', self.config.build_dir + '/arch/sandbox/dts/test.dtb' ] - return Spawn(cmd) + return Spawn(cmd, cwd=self.config.source_dir) def kill(self, sig): """Send a specific Unix signal to the sandbox process. -- cgit v1.2.3