aboutsummaryrefslogtreecommitdiff
path: root/test/py/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/py/tests')
-rw-r--r--test/py/tests/test_button.py36
-rw-r--r--test/py/tests/test_fs/test_ext.py6
-rw-r--r--test/py/tests/test_log.py96
-rw-r--r--test/py/tests/test_ofplatdata.py47
-rw-r--r--test/py/tests/test_pinmux.py36
-rw-r--r--test/py/tests/test_pstore.py77
-rw-r--r--test/py/tests/test_pstore_data_console.hexbin0 -> 4096 bytes
-rw-r--r--test/py/tests/test_pstore_data_panic1.hexbin0 -> 4096 bytes
-rw-r--r--test/py/tests/test_pstore_data_panic2.hexbin0 -> 4096 bytes
-rw-r--r--test/py/tests/test_spl.py34
-rw-r--r--test/py/tests/test_vboot.py46
11 files changed, 203 insertions, 175 deletions
diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py
index 98067a98f2..3b7f148c8f 100644
--- a/test/py/tests/test_button.py
+++ b/test/py/tests/test_button.py
@@ -4,16 +4,34 @@ import pytest
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_button')
-def test_button_exit_statuses(u_boot_console):
- """Test that non-input button commands correctly return the command
- success/failure status."""
+def test_button_list(u_boot_console):
+ """Test listing buttons"""
- expected_response = 'rc:0'
response = u_boot_console.run_command('button list; echo rc:$?')
- assert(expected_response in response)
- response = u_boot_console.run_command('button summer; echo rc:$?')
- assert(expected_response in response)
+ assert('button1' in response)
+ assert('button2' in response)
+ assert('rc:0' in response)
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_button')
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_button_return_code(u_boot_console):
+ """Test correct reporting of the button status
+
+ The sandbox gpio driver reports the last output value as input value.
+ We can use this in our test to emulate different input statuses.
+ """
+
+ u_boot_console.run_command('gpio set a3; gpio input a3');
+ response = u_boot_console.run_command('button button1; echo rc:$?')
+ assert('on' in response)
+ assert('rc:0' in response)
+
+ u_boot_console.run_command('gpio clear a3; gpio input a3');
+ response = u_boot_console.run_command('button button1; echo rc:$?')
+ assert('off' in response)
+ assert('rc:1' in response)
- expected_response = 'rc:1'
response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
- assert(expected_response in response)
+ assert('not found' in response)
+ assert('rc:1' in response)
diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py
index 6b7fc48701..dba874fc59 100644
--- a/test/py/tests/test_fs/test_ext.py
+++ b/test/py/tests/test_fs/test_ext.py
@@ -74,7 +74,7 @@ class TestFsExt(object):
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/none/%s.w3 $filesize'
% (fs_type, ADDR, MIN_FILE)])
- assert('Unable to write "/dir1/none/' in ''.join(output))
+ assert('Unable to write file /dir1/none/' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext4(self, u_boot_console, fs_obj_ext):
@@ -216,7 +216,7 @@ class TestFsExt(object):
output = u_boot_console.run_command(
'%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x'
% (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400))
- assert('Unable to write "/dir1' in output)
+ assert('Unable to write file /dir1' in output)
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext9(self, u_boot_console, fs_obj_ext):
@@ -231,7 +231,7 @@ class TestFsExt(object):
'%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE),
'%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
% (fs_type, ADDR, MIN_FILE)])
- assert('Unable to write "/dir1' in ''.join(output))
+ assert('Unable to write file /dir1' in ''.join(output))
assert_fs_integrity(fs_type, fs_img)
def test_fs_ext10(self, u_boot_console, fs_obj_ext):
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index ddc28f19ee..387b392ce9 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -10,102 +10,6 @@ and checks that the output is correct.
import pytest
-LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6)
-
-@pytest.mark.buildconfigspec('cmd_log')
-def test_log(u_boot_console):
- """Test that U-Boot logging works correctly."""
- def check_log_entries(lines, mask, max_level=LOGL_INFO):
- """Check that the expected log records appear in the output
-
- Args:
- lines: iterator containing lines to check
- mask: bit mask to select which lines to check for:
- bit 0: standard log line
- bit 1: _log line
- max_level: maximum log level to expect in the output
- """
- for i in range(max_level):
- if mask & 1:
- assert 'log_run() log %d' % i == next(lines)
- if mask & 3:
- assert 'func() _log %d' % i == next(lines)
-
- def run_test(testnum):
- """Run a particular test number (the 'log test' command)
-
- Args:
- testnum: Test number to run
- Returns:
- iterator containing the lines output from the command
- """
- output = u_boot_console.run_command('log format fm')
- assert output == ''
- with cons.log.section('basic'):
- output = u_boot_console.run_command('log test %d' % testnum)
- split = output.replace('\r', '').splitlines()
- lines = iter(split)
- assert 'test %d' % testnum == next(lines)
- return lines
-
- def test0():
- lines = run_test(0)
- check_log_entries(lines, 3)
-
- def test1():
- lines = run_test(1)
- check_log_entries(lines, 3)
-
- def test2():
- lines = run_test(2)
-
- def test3():
- lines = run_test(3)
- check_log_entries(lines, 2)
-
- def test4():
- lines = run_test(4)
- assert next(lines, None) == None
-
- def test5():
- lines = run_test(5)
- check_log_entries(lines, 2)
-
- def test6():
- lines = run_test(6)
- check_log_entries(lines, 3)
-
- def test7():
- lines = run_test(7)
- check_log_entries(lines, 3, LOGL_WARNING)
-
- def test8():
- lines = run_test(8)
- check_log_entries(lines, 3)
-
- def test9():
- lines = run_test(9)
- check_log_entries(lines, 3)
-
- def test10():
- lines = run_test(10)
- for i in range(7):
- assert 'log_test() level %d' % i == next(lines)
-
- # TODO(sjg@chromium.org): Consider structuring this as separate tests
- cons = u_boot_console
- test0()
- test1()
- test2()
- test3()
- test4()
- test5()
- test6()
- test7()
- test8()
- test9()
- test10()
-
@pytest.mark.buildconfigspec('cmd_log')
def test_log_format(u_boot_console):
"""Test the 'log format' and 'log rec' commands"""
diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py
index 263334b074..78837a3c00 100644
--- a/test/py/tests/test_ofplatdata.py
+++ b/test/py/tests/test_ofplatdata.py
@@ -4,53 +4,6 @@
import pytest
import u_boot_utils as util
-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 <NULL>
-stringarray "one" "" ""
-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 <NULL>
-stringarray "spl" "" ""
-'''
-
-@pytest.mark.buildconfigspec('spl_of_platdata')
-def test_ofplatdata(u_boot_console):
- """Test that of-platdata can be generated and used in sandbox"""
- cons = u_boot_console
- cons.restart_uboot_with_flags(['--show_of_platdata'])
- output = cons.get_spawn_output().replace('\r', '')
- assert OF_PLATDATA_OUTPUT in output
-
@pytest.mark.buildconfigspec('spl_of_platdata')
def test_spl_devicetree(u_boot_console):
"""Test content of spl device-tree"""
diff --git a/test/py/tests/test_pinmux.py b/test/py/tests/test_pinmux.py
index 4e6df992a4..0cbbae000c 100644
--- a/test/py/tests/test_pinmux.py
+++ b/test/py/tests/test_pinmux.py
@@ -28,15 +28,15 @@ def test_pinmux_status_all(u_boot_console):
assert ('a6 : gpio output .' in output)
assert ('pinctrl:' in output)
- assert ('SCL : I2C SCL.' in output)
- assert ('SDA : I2C SDA.' in output)
- assert ('TX : Uart TX.' in output)
- assert ('RX : Uart RX.' in output)
- assert ('W1 : 1-wire gpio.' in output)
- assert ('GPIO0 : gpio bias-pull-up input-disable.' in output)
- assert ('GPIO1 : gpio drive-open-drain.' in output)
- assert ('GPIO2 : gpio bias-pull-down input-enable.' in output)
- assert ('GPIO3 : gpio bias-disable.' in output)
+ assert ('P0 : UART TX.' in output)
+ assert ('P1 : UART RX.' in output)
+ assert ('P2 : I2S SCK.' in output)
+ assert ('P3 : I2S SD.' in output)
+ assert ('P4 : I2S WS.' in output)
+ assert ('P5 : GPIO0 bias-pull-up input-disable.' in output)
+ assert ('P6 : GPIO1 drive-open-drain.' in output)
+ assert ('P7 : GPIO2 bias-pull-down input-enable.' in output)
+ assert ('P8 : GPIO3 bias-disable.' in output)
@pytest.mark.buildconfigspec('cmd_pinmux')
@pytest.mark.boardspec('sandbox')
@@ -73,12 +73,12 @@ def test_pinmux_status(u_boot_console):
assert (not 'pinctrl-gpio:' in output)
assert (not 'pinctrl:' in output)
- assert ('SCL : I2C SCL.' in output)
- assert ('SDA : I2C SDA.' in output)
- assert ('TX : Uart TX.' in output)
- assert ('RX : Uart RX.' in output)
- assert ('W1 : 1-wire gpio.' in output)
- assert ('GPIO0 : gpio bias-pull-up input-disable.' in output)
- assert ('GPIO1 : gpio drive-open-drain.' in output)
- assert ('GPIO2 : gpio bias-pull-down input-enable.' in output)
- assert ('GPIO3 : gpio bias-disable.' in output)
+ assert ('P0 : UART TX.' in output)
+ assert ('P1 : UART RX.' in output)
+ assert ('P2 : I2S SCK.' in output)
+ assert ('P3 : I2S SD.' in output)
+ assert ('P4 : I2S WS.' in output)
+ assert ('P5 : GPIO0 bias-pull-up input-disable.' in output)
+ assert ('P6 : GPIO1 drive-open-drain.' in output)
+ assert ('P7 : GPIO2 bias-pull-down input-enable.' in output)
+ assert ('P8 : GPIO3 bias-disable.' in output)
diff --git a/test/py/tests/test_pstore.py b/test/py/tests/test_pstore.py
new file mode 100644
index 0000000000..5a35724f60
--- /dev/null
+++ b/test/py/tests/test_pstore.py
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2020, Collabora
+# Author: Frédéric Danis <frederic.danis@collabora.com>
+
+import pytest
+import u_boot_utils
+import os
+import tempfile
+import shutil
+
+PSTORE_ADDR=0x3000000
+PSTORE_LENGTH=0x100000
+PSTORE_PANIC1='test/py/tests/test_pstore_data_panic1.hex'
+PSTORE_PANIC2='test/py/tests/test_pstore_data_panic2.hex'
+PSTORE_CONSOLE='test/py/tests/test_pstore_data_console.hex'
+ADDR=0x01000008
+
+def load_pstore(u_boot_console):
+ """Load PStore records from sample files"""
+
+ output = u_boot_console.run_command_list([
+ 'host load hostfs - 0x%x %s' % (PSTORE_ADDR,
+ os.path.join(u_boot_console.config.source_dir, PSTORE_PANIC1)),
+ 'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 4096,
+ os.path.join(u_boot_console.config.source_dir, PSTORE_PANIC2)),
+ 'host load hostfs - 0x%x %s' % (PSTORE_ADDR + 253 * 4096,
+ os.path.join(u_boot_console.config.source_dir, PSTORE_CONSOLE)),
+ 'pstore set 0x%x 0x%x' % (PSTORE_ADDR, PSTORE_LENGTH)])
+
+def checkfile(u_boot_console, path, filesize, checksum):
+ """Check file against MD5 checksum"""
+
+ output = u_boot_console.run_command_list([
+ 'load hostfs - %x %s' % (ADDR, path),
+ 'printenv filesize'])
+ assert('filesize=%x' % (filesize) in ''.join(output))
+
+ output = u_boot_console.run_command_list([
+ 'md5sum %x $filesize' % ADDR,
+ 'setenv filesize'])
+ assert(checksum in ''.join(output))
+
+@pytest.mark.buildconfigspec('cmd_pstore')
+def test_pstore_display_all_records(u_boot_console):
+ """Test that pstore displays all records."""
+
+ u_boot_console.run_command('')
+ load_pstore(u_boot_console)
+ response = u_boot_console.run_command('pstore display')
+ assert('**** Dump' in response)
+ assert('**** Console' in response)
+
+@pytest.mark.buildconfigspec('cmd_pstore')
+def test_pstore_display_one_record(u_boot_console):
+ """Test that pstore displays only one record."""
+
+ u_boot_console.run_command('')
+ load_pstore(u_boot_console)
+ response = u_boot_console.run_command('pstore display dump 1')
+ assert('Panic#2 Part1' in response)
+ assert('**** Console' not in response)
+
+@pytest.mark.buildconfigspec('cmd_pstore')
+def test_pstore_save_records(u_boot_console):
+ """Test that pstore saves all records."""
+
+ outdir = tempfile.mkdtemp()
+
+ u_boot_console.run_command('')
+ load_pstore(u_boot_console)
+ u_boot_console.run_command('pstore save hostfs - %s' % (outdir))
+
+ checkfile(u_boot_console, '%s/dmesg-ramoops-0' % (outdir), 3798, '8059335ab4cfa62c77324c491659c503')
+ checkfile(u_boot_console, '%s/dmesg-ramoops-1' % (outdir), 4035, '3ff30df3429d81939c75d0070b5187b9')
+ checkfile(u_boot_console, '%s/console-ramoops-0' % (outdir), 4084, 'bb44de4a9b8ebd9b17ae98003287325b')
+
+ shutil.rmtree(outdir)
diff --git a/test/py/tests/test_pstore_data_console.hex b/test/py/tests/test_pstore_data_console.hex
new file mode 100644
index 0000000000..e7f426e892
--- /dev/null
+++ b/test/py/tests/test_pstore_data_console.hex
Binary files differ
diff --git a/test/py/tests/test_pstore_data_panic1.hex b/test/py/tests/test_pstore_data_panic1.hex
new file mode 100644
index 0000000000..988929d12c
--- /dev/null
+++ b/test/py/tests/test_pstore_data_panic1.hex
Binary files differ
diff --git a/test/py/tests/test_pstore_data_panic2.hex b/test/py/tests/test_pstore_data_panic2.hex
new file mode 100644
index 0000000000..8f9d56cbe0
--- /dev/null
+++ b/test/py/tests/test_pstore_data_panic2.hex
Binary files differ
diff --git a/test/py/tests/test_spl.py b/test/py/tests/test_spl.py
new file mode 100644
index 0000000000..bd273dad89
--- /dev/null
+++ b/test/py/tests/test_spl.py
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2020 Google LLC
+# Written by Simon Glass <sjg@chromium.org>
+
+import os.path
+import pytest
+
+def test_spl(u_boot_console, ut_spl_subtest):
+ """Execute a "ut" subtest.
+
+ The subtests are collected in function generate_ut_subtest() from linker
+ generated lists by applying a regular expression to the lines of file
+ spl/u-boot-spl.sym. The list entries are created using the C macro
+ UNIT_TEST().
+
+ Strict naming conventions have to be followed to match the regular
+ expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in
+ test suite foo that can be executed via command 'ut foo bar' and is
+ implemented in C function foo_test_bar().
+
+ Args:
+ u_boot_console (ConsoleBase): U-Boot console
+ ut_subtest (str): SPL test to be executed (e.g. 'dm platdata_phandle')
+ """
+ try:
+ cons = u_boot_console
+ cons.restart_uboot_with_flags(['-u', '-k', ut_spl_subtest.split()[1]])
+ output = cons.get_spawn_output().replace('\r', '')
+ assert 'Failures: 0' in output
+ finally:
+ # Restart afterward in case a non-SPL test is run next. This should not
+ # happen since SPL tests are run in their own invocation of test.py, but
+ # the cost of doing this is not too great at present.
+ u_boot_console.restart_uboot()
diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index 6b998cfd70..e45800d94c 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -126,6 +126,23 @@ def test_vboot(u_boot_console, sha_algo, padding, sign_options, required):
cons.log.action('%s: Sign images' % sha_algo)
util.run_and_log(cons, args)
+ def sign_fit_norequire(sha_algo, options):
+ """Sign the FIT
+
+ Signs the FIT and writes the signature into it. It also writes the
+ public key into the dtb. It does not mark key as 'required' in dtb.
+
+ Args:
+ sha_algo: Either 'sha1' or 'sha256', to select the algorithm to
+ use.
+ options: Options to provide to mkimage.
+ """
+ args = [mkimage, '-F', '-k', tmpdir, '-K', dtb, fit]
+ if options:
+ args += options.split(' ')
+ cons.log.action('%s: Sign images' % sha_algo)
+ util.run_and_log(cons, args)
+
def replace_fit_totalsize(size):
"""Replace FIT header's totalsize with something greater.
@@ -279,15 +296,40 @@ def test_vboot(u_boot_console, sha_algo, padding, sign_options, required):
# Build the FIT with dev key (keys NOT required). This adds the
# signature into sandbox-u-boot.dtb, NOT marked 'required'.
make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
- sign_fit(sha_algo, sign_options)
+ sign_fit_norequire(sha_algo, sign_options)
# So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
# Only the prod key is set as 'required'. But FIT we just built has
- # a dev signature only (sign_fit() overwrites the FIT).
+ # a dev signature only (sign_fit_norequire() overwrites the FIT).
# Try to boot the FIT with dev key. This FIT should not be accepted by
# U-Boot because the prod key is required.
run_bootm(sha_algo, 'required key', '', False)
+ # Build the FIT with dev key (keys required) and sign it. This puts the
+ # signature into sandbox-u-boot.dtb, marked 'required'.
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
+ sign_fit(sha_algo, sign_options)
+
+ # Set the required-mode policy to "any".
+ # So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
+ # Both the dev and prod key are set as 'required'. But FIT we just built has
+ # a dev signature only (sign_fit() overwrites the FIT).
+ # Try to boot the FIT with dev key. This FIT should be accepted by
+ # U-Boot because the dev key is required and policy is "any" required key.
+ util.run_and_log(cons, 'fdtput -t s %s /signature required-mode any' %
+ (dtb))
+ run_bootm(sha_algo, 'multi required key', 'dev+', True)
+
+ # Set the required-mode policy to "all".
+ # So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
+ # Both the dev and prod key are set as 'required'. But FIT we just built has
+ # a dev signature only (sign_fit() overwrites the FIT).
+ # Try to boot the FIT with dev key. This FIT should not be accepted by
+ # U-Boot because the prod key is required and policy is "all" required key
+ util.run_and_log(cons, 'fdtput -t s %s /signature required-mode all' %
+ (dtb))
+ run_bootm(sha_algo, 'multi required key', '', False)
+
cons = u_boot_console
tmpdir = cons.config.result_dir + '/'
datadir = cons.config.source_dir + '/test/py/tests/vboot/'