From 2fedbaa4aea4f781863c9b11879ae4d43149c447 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 4 Jul 2016 11:58:37 -0600 Subject: test/py: Handle testing with the sandbox_spl board This board can sometimes be used for tests. Handle it the same way as sandbox. Note: I plan to drop the sandbox_spl board at some point and merge its features into sandbox. So this commit may not be necessary. Signed-off-by: Simon Glass --- test/py/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/py') diff --git a/test/py/conftest.py b/test/py/conftest.py index 449f98bee3..050f6e409d 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -192,7 +192,7 @@ def pytest_configure(config): for v in env_vars: os.environ['U_BOOT_' + v.upper()] = getattr(ubconfig, v) - if board_type == 'sandbox': + if board_type.startswith('sandbox'): import u_boot_console_sandbox console = u_boot_console_sandbox.ConsoleSandbox(log, ubconfig) else: -- cgit v1.2.3 From c7f636f59d7d506b89d7fc52aa6509329e9ded1b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 4 Jul 2016 11:58:38 -0600 Subject: test/py: Note which console produced unexpected output At present the SPL and U-Boot consoles both present the same error message when the expected console output does not appear. Add "SPL" to the SPL error message to resolve this ambiguity. Signed-off-by: Simon Glass --- test/py/u_boot_console_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/py') diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py index 815fa64d5f..2dcb2894f9 100644 --- a/test/py/u_boot_console_base.py +++ b/test/py/u_boot_console_base.py @@ -329,7 +329,7 @@ class ConsoleBase(object): m = self.p.expect([pattern_u_boot_spl_signon] + self.bad_patterns) if m != 0: - raise Exception('Bad pattern found on console: ' + + raise Exception('Bad pattern found on SPL console: ' + self.bad_pattern_ids[m - 1]) m = self.p.expect([pattern_u_boot_main_signon] + self.bad_patterns) if m != 0: -- cgit v1.2.3 From ebec58fbcb6da7404b535b9d860546d9baef55c2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 4 Jul 2016 11:58:39 -0600 Subject: test/py: Provide a way to get early console output Some tests want to check the console output from SPL or U-Boot proper. Provide a means to do this. Signed-off-by: Simon Glass --- test/py/u_boot_console_base.py | 10 ++++++++++ test/py/u_boot_spawn.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) (limited to 'test/py') diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py index 2dcb2894f9..3d2ac44875 100644 --- a/test/py/u_boot_console_base.py +++ b/test/py/u_boot_console_base.py @@ -377,6 +377,16 @@ class ConsoleBase(object): pass self.p = None + def get_spawn_output(self): + """Return the start-up output from U-Boot + + Returns: + The output produced by ensure_spawed(), as a string. + """ + if self.p: + return self.p.get_expect_output() + return None + def validate_version_string_in_text(self, text): """Assert that a command's output includes the U-Boot signon message. diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index d15517389e..3a0fbfad90 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -18,6 +18,9 @@ class Timeout(Exception): class Spawn(object): """Represents the stdio of a freshly created sub-process. Commands may be sent to the process, and responses waited for. + + Members: + output: accumulated output from expect() """ def __init__(self, args, cwd=None): @@ -34,6 +37,7 @@ class Spawn(object): self.waited = False self.buf = '' + self.output = '' self.logfile_read = None self.before = '' self.after = '' @@ -154,6 +158,7 @@ class Spawn(object): posafter = earliest_m.end() self.before = self.buf[:pos] self.after = self.buf[pos:posafter] + self.output += self.buf[:posafter] self.buf = self.buf[posafter:] return earliest_pi tnow_s = time.time() @@ -198,3 +203,11 @@ class Spawn(object): if not self.isalive(): break time.sleep(0.1) + + def get_expect_output(self): + """Return the output read by expect() + + Returns: + The output processed by expect(), as a string. + """ + return self.output -- cgit v1.2.3 From a811779b174f8c5c687aaa5574dfdea9f3745f98 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 4 Jul 2016 11:58:40 -0600 Subject: test/py: Start sandbox SPL when enabled When sandbox SPL is enabled we want to start that rather than U-Boot proper, since some tests may rely on running it first. Signed-off-by: Simon Glass --- test/py/u_boot_console_sandbox.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/py') diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index 04654ae8c9..6bf4653083 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -39,11 +39,15 @@ class ConsoleSandbox(ConsoleBase): A u_boot_spawn.Spawn object that is attached to U-Boot. """ + bcfg = self.config.buildconfig + config_spl = bcfg.get('config_spl', 'n') == 'y' + fname = '/spl/u-boot-spl' if config_spl else '/u-boot' + print fname cmd = [] if self.config.gdbserver: cmd += ['gdbserver', self.config.gdbserver] cmd += [ - self.config.build_dir + '/u-boot', + self.config.build_dir + fname, '-v', '-d', self.config.build_dir + '/arch/sandbox/dts/test.dtb' -- cgit v1.2.3 From b979d3d4c55def30cd0eb1e2c82beefb30fc8e87 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 4 Jul 2016 11:58:41 -0600 Subject: dm: Add a test for of-platdata Add a simple test which checks that the of-platdata system is working correctly. The sequence is as follows: - SPL starts up and probes all the UCLASS_MISC drivers - There are 3 of these in sandbox.dts - Therefore there should be 3 U_BOOT_DEVICE() declarations in dt-platdata.c - These should produce 3 sandbox_spl_test devices - Each device prints out its platform data when probed - This test checks for this output and compares it against expectations Signed-off-by: Simon Glass --- test/py/tests/test_ofplatdata.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/py/tests/test_ofplatdata.py (limited to 'test/py') diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py new file mode 100644 index 0000000000..c8b309e3d2 --- /dev/null +++ b/test/py/tests/test_ofplatdata.py @@ -0,0 +1,42 @@ +# Copyright (c) 2016 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ + +import pytest + +OF_PLATDATA_OUTPUT = ''' +of-platdata probe: +bool 1 +byte 05 +bytearray 06 00 00 +int 1 +intarray 2 3 4 0 +longbytearray 09 0a 0b 0c 0d 0e 0f 10 11 +string message +stringarray "multi-word" "message" "" +of-platdata probe: +bool 0 +byte 08 +bytearray 01 23 34 +int 3 +intarray 5 0 0 0 +longbytearray 09 00 00 00 00 00 00 00 00 +string message2 +stringarray "another" "multi-word" "message" +of-platdata probe: +bool 0 +byte 00 +bytearray 00 00 00 +int 0 +intarray 0 0 0 0 +longbytearray 00 00 00 00 00 00 00 00 00 +string +stringarray "one" "" "" +''' + +@pytest.mark.buildconfigspec('spl') +def test_ofplatdata(u_boot_console): + """Test that of-platdata can be generated and used in sandbox""" + cons = u_boot_console + output = cons.get_spawn_output().replace('\r', '') + assert OF_PLATDATA_OUTPUT in output -- cgit v1.2.3