summaryrefslogtreecommitdiff
path: root/test/py/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/py/tests')
-rw-r--r--test/py/tests/test_efi_selftest.py1
-rw-r--r--test/py/tests/test_fit_mkimage_validate.py58
-rw-r--r--test/py/tests/test_help.py1
-rw-r--r--test/py/tests/test_mmc.py30
-rw-r--r--test/py/tests/test_tpm2.py86
5 files changed, 88 insertions, 88 deletions
diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py
index 12cbe5caa9b..58dac72fd40 100644
--- a/test/py/tests/test_efi_selftest.py
+++ b/test/py/tests/test_efi_selftest.py
@@ -179,6 +179,7 @@ def test_efi_selftest_text_input_ex(ubman):
@pytest.mark.buildconfigspec('cmd_bootefi_selftest')
@pytest.mark.buildconfigspec('efi_tcg2_protocol')
+@pytest.mark.notbuildconfigspec('sandbox')
def test_efi_selftest_tcg2(ubman):
"""Test the EFI_TCG2 PROTOCOL
diff --git a/test/py/tests/test_fit_mkimage_validate.py b/test/py/tests/test_fit_mkimage_validate.py
new file mode 100644
index 00000000000..af56f08ca10
--- /dev/null
+++ b/test/py/tests/test_fit_mkimage_validate.py
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2025
+#
+# Test that mkimage validates image references in configurations
+
+import os
+import subprocess
+import pytest
+import fit_util
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.requiredtool('dtc')
+def test_fit_invalid_image_reference(ubman):
+ """Test that mkimage fails when configuration references a missing image"""
+
+ its_fname = fit_util.make_fname(ubman, "invalid.its")
+ itb_fname = fit_util.make_fname(ubman, "invalid.itb")
+ kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel')
+
+ # Write ITS with an invalid reference to a nonexistent image
+ its_text = '''
+/dts-v1/;
+
+/ {
+ images {
+ kernel@1 {
+ description = "Test Kernel";
+ data = /incbin/("kernel.bin");
+ type = "kernel";
+ arch = "sandbox";
+ os = "linux";
+ compression = "none";
+ load = <0x40000>;
+ entry = <0x40000>;
+ };
+ };
+
+ configurations {
+ default = "conf@1";
+ conf@1 {
+ kernel = "kernel@1";
+ fdt = "notexist";
+ };
+ };
+};
+'''
+
+ with open(its_fname, 'w') as f:
+ f.write(its_text)
+
+ mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage')
+ cmd = [mkimage, '-f', its_fname, itb_fname]
+
+ result = subprocess.run(cmd, capture_output=True, text=True)
+
+ assert result.returncode != 0, "mkimage should fail due to missing image reference"
+ assert "references undefined image 'notexist'" in result.stderr
+
diff --git a/test/py/tests/test_help.py b/test/py/tests/test_help.py
index 12cb36b7b98..afb57201ba3 100644
--- a/test/py/tests/test_help.py
+++ b/test/py/tests/test_help.py
@@ -4,6 +4,7 @@
import pytest
+@pytest.mark.buildconfigspec('cmd_help')
def test_help(ubman):
"""Test that the "help" command can be executed."""
diff --git a/test/py/tests/test_mmc.py b/test/py/tests/test_mmc.py
index e751a3bd36a..1f738ef3dcb 100644
--- a/test/py/tests/test_mmc.py
+++ b/test/py/tests/test_mmc.py
@@ -99,7 +99,7 @@ def test_mmc_dev(ubman):
devices[x]['detected'] = 'yes'
for y in mmc_modes:
- output = ubman.run_command('mmc dev %d 0 %d' % x, y)
+ output = ubman.run_command('mmc dev %d 0 %d' % (x, y))
if 'Card did not respond to voltage select' in output:
fail = 1
@@ -122,7 +122,7 @@ def test_mmcinfo(ubman):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
for y in mmc_modes:
- ubman.run_command('mmc dev %d 0 %d' % x, y)
+ ubman.run_command('mmc dev %d 0 %d' % (x, y))
output = ubman.run_command('mmcinfo')
if 'busy timeout' in output:
pytest.skip('No SD/MMC/eMMC device present')
@@ -146,7 +146,7 @@ def test_mmc_info(ubman):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
for y in mmc_modes:
- ubman.run_command('mmc dev %d 0 %d' % x, y)
+ ubman.run_command('mmc dev %d 0 %d' % (x, y))
output = ubman.run_command('mmc info')
assert mmc_modes_name[mmc_modes.index(y)] in output
@@ -172,7 +172,7 @@ def test_mmc_rescan(ubman):
for x in range(0, controllers):
if devices[x]['detected'] == 'yes':
for y in mmc_modes:
- ubman.run_command('mmc dev %d 0 %d' % x, y)
+ ubman.run_command('mmc dev %d 0 %d' % (x, y))
output = ubman.run_command('mmc rescan')
if output:
pytest.fail('mmc rescan has something to check')
@@ -210,7 +210,7 @@ def test_mmc_part(ubman):
elif part_type == '83':
print('ext(2/4) detected')
output = ubman.run_command(
- 'fstype mmc %d:%d' % x, part_id
+ 'fstype mmc %d:%d' % (x, part_id)
)
if 'ext2' in output:
part_ext2.append(part_id)
@@ -246,7 +246,7 @@ def test_mmc_fatls_fatinfo(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
output = ubman.run_command(
'fatls mmc %d:%s' % (x, part))
if 'Unrecognized filesystem type' in output:
@@ -288,7 +288,7 @@ def test_mmc_fatload_fatwrite(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
addr = utils.find_ram_base(ubman)
devices[x]['addr_%d' % part] = addr
@@ -357,7 +357,7 @@ def test_mmc_ext4ls(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
output = ubman.run_command(
'%sls mmc %d:%s' % (fs, x, part)
)
@@ -392,7 +392,7 @@ def test_mmc_ext4load_ext4write(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
addr = utils.find_ram_base(ubman)
devices[x]['addr_%d' % part] = addr
@@ -454,7 +454,7 @@ def test_mmc_ext2ls(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
output = ubman.run_command(
'%sls mmc %d:%s' % (fs, x, part)
@@ -491,7 +491,7 @@ def test_mmc_ext2load(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
addr = devices[x]['addr_%d' % part]
size = devices[x]['size_%d' % part]
@@ -534,7 +534,7 @@ def test_mmc_ls(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
output = ubman.run_command('ls mmc %d:%s' % (x, part))
if re.search(r'No \w+ table on this device', output):
@@ -566,7 +566,7 @@ def test_mmc_load(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
addr = devices[x]['addr_%d' % part]
size = devices[x]['size_%d' % part]
@@ -609,7 +609,7 @@ def test_mmc_save(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
addr = devices[x]['addr_%d' % part]
size = 0
@@ -656,7 +656,7 @@ def test_mmc_fat_read_write_files(ubman):
for part in partitions:
for y in mmc_modes:
- ubman.run_command('mmc dev %d %d %d' % x, part, y)
+ ubman.run_command('mmc dev %d %d %d' % (x, part, y))
part_detect = 1
addr = utils.find_ram_base(ubman)
count_f = 0
diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 064651c3e23..9be85999d46 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -27,6 +27,16 @@ behavior.
* Setup env__tpm_device_test_skip to True if tests with TPM devices should be
skipped.
+Parallel tests
+--------------
+
+These tests can be run in parallel on sandbox. In that case any action taken
+by one test may be independent of another. For sandbox, care should be taken to
+ensure that tests are independent.
+
+Unfortunately, tests cannot be made independent on real hardware, since there is
+no way to reset the TPM other than restarting the board. Perhaps that would be
+the best approach?
"""
updates = 0
@@ -50,13 +60,8 @@ def force_init(ubman, force=False):
ubman.run_command('tpm2 clear TPM2_RH_PLATFORM')
ubman.run_command('echo --- end of init ---')
-def is_sandbox(ubman):
- # Array slice removes leading/trailing quotes.
- sys_arch = ubman.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
- return sys_arch == 'sandbox'
-
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_init(ubman):
+def test_tpm2_autostart(ubman):
"""Init the software stack to use TPMv2 commands."""
skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
@@ -66,56 +71,6 @@ def test_tpm2_init(ubman):
assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_startup(ubman):
- """Execute a TPM2_Startup command.
-
- Initiate the TPM internal state machine.
- """
- skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
- if skip_test:
- pytest.skip('skip TPM device test')
- ubman.run_command('tpm2 startup TPM2_SU_CLEAR')
- output = ubman.run_command('echo $?')
- assert output.endswith('0')
-
-def tpm2_sandbox_init(ubman):
- """Put sandbox back into a known state so we can run a test
-
- This allows all tests to run in parallel, since no test depends on another.
- """
- ubman.restart_uboot()
- ubman.run_command('tpm2 autostart')
- output = ubman.run_command('echo $?')
- assert output.endswith('0')
-
- skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
- if skip_test:
- pytest.skip('skip TPM device test')
-
-@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_sandbox_self_test_full(ubman):
- """Execute a TPM2_SelfTest (full) command.
-
- Ask the TPM to perform all self tests to also enable full capabilities.
- """
- if is_sandbox(ubman):
- ubman.restart_uboot()
- ubman.run_command('tpm2 autostart')
- output = ubman.run_command('echo $?')
- assert output.endswith('0')
-
- ubman.run_command('tpm2 startup TPM2_SU_CLEAR')
- output = ubman.run_command('echo $?')
- assert output.endswith('0')
-
- skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
- if skip_test:
- pytest.skip('skip TPM device test')
- ubman.run_command('tpm2 self_test full')
- output = ubman.run_command('echo $?')
- assert output.endswith('0')
-
-@pytest.mark.buildconfigspec('cmd_tpm_v2')
def test_tpm2_continue_self_test(ubman):
"""Execute a TPM2_SelfTest (continued) command.
@@ -126,8 +81,6 @@ def test_tpm2_continue_self_test(ubman):
skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
ubman.run_command('tpm2 self_test continue')
output = ubman.run_command('echo $?')
assert output.endswith('0')
@@ -144,9 +97,6 @@ def test_tpm2_clear(ubman):
not have a password set, otherwise this test will fail. ENDORSEMENT and
PLATFORM hierarchies are also available.
"""
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
-
skip_test = ubman.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
@@ -167,8 +117,6 @@ def test_tpm2_change_auth(ubman):
Use the LOCKOUT hierarchy for this. ENDORSEMENT and PLATFORM hierarchies are
also available.
"""
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
force_init(ubman)
ubman.run_command('tpm2 change_auth TPM2_RH_LOCKOUT unicorn')
@@ -193,9 +141,6 @@ def test_tpm2_get_capability(ubman):
There is no expected default values because it would depend on the chip
used. We can still save them in order to check they have changed later.
"""
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
-
force_init(ubman)
ram = utils.find_ram_base(ubman)
@@ -217,8 +162,6 @@ def test_tpm2_dam_parameters(ubman):
the authentication, otherwise the lockout will be engaged after the first
failed authentication attempt.
"""
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
force_init(ubman)
ram = utils.find_ram_base(ubman)
@@ -236,14 +179,12 @@ def test_tpm2_dam_parameters(ubman):
assert 'Property 0x00000211: 0x00000000' in read_cap
@pytest.mark.buildconfigspec('cmd_tpm_v2')
+@pytest.mark.notbuildconfigspec('target_chromebook_coral')
def test_tpm2_pcr_read(ubman):
"""Execute a TPM2_PCR_Read command.
Perform a PCR read of the 10th PCR. Must be zero.
"""
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
-
force_init(ubman)
ram = utils.find_ram_base(ubman)
@@ -261,6 +202,7 @@ def test_tpm2_pcr_read(ubman):
assert '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' in read_pcr
@pytest.mark.buildconfigspec('cmd_tpm_v2')
+@pytest.mark.notbuildconfigspec('target_chromebook_coral')
def test_tpm2_pcr_extend(ubman):
"""Execute a TPM2_PCR_Extend command.
@@ -270,8 +212,6 @@ def test_tpm2_pcr_extend(ubman):
No authentication mechanism is used here, not protecting against packet
replay, yet.
"""
- if is_sandbox(ubman):
- tpm2_sandbox_init(ubman)
force_init(ubman)
ram = utils.find_ram_base(ubman)