diff options
Diffstat (limited to 'test/py')
-rw-r--r-- | test/py/conftest.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_fit_mkimage_validate.py | 58 | ||||
-rw-r--r-- | test/py/tests/test_gpt.py | 27 | ||||
-rw-r--r-- | test/py/tests/test_tpm2.py | 86 |
4 files changed, 100 insertions, 75 deletions
diff --git a/test/py/conftest.py b/test/py/conftest.py index 6c3ac67979a..8ce680a92a0 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -514,8 +514,8 @@ def ubman(request): handle_exception(ubconfig, ubman_fix, log, err, 'Lab timeout', True) except BootFail as err: handle_exception(ubconfig, ubman_fix, log, err, 'Boot fail', True, - ubman.get_spawn_output()) - except Unexpected: + ubman_fix.get_spawn_output()) + except Unexpected as err: handle_exception(ubconfig, ubman_fix, log, err, 'Unexpected test output', False) return ubman_fix 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_gpt.py b/test/py/tests/test_gpt.py index cfc8f1319a9..e6d8792ac1f 100644 --- a/test/py/tests/test_gpt.py +++ b/test/py/tests/test_gpt.py @@ -330,6 +330,33 @@ def test_gpt_write(state_disk_image, ubman): output = ubman.run_command('gpt guid host 0') assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_gpt') +@pytest.mark.buildconfigspec('cmd_part') +@pytest.mark.buildconfigspec('partition_type_guid') +@pytest.mark.requiredtool('sgdisk') +def test_gpt_write_part_type(state_disk_image, ubman): + """Test the gpt command with part type uuid.""" + + output = ubman.run_command('gpt write host 0 "name=part1,type=data,size=1M;name=part2,size=512K,type=system;name=part3,size=65536,type=u-boot-env;name=part4,size=65536,type=375a56f7-d6c9-4e81-b5f0-09d41ca89efe;name=part5,size=-,type=linux"') + assert 'Writing GPT: success!' in output + output = ubman.run_command('part list host 0') + assert '1\t0x00000022\t0x00000821\t"part1"' in output + assert 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' in output + assert '(data)' in output + assert '2\t0x00000822\t0x00000c21\t"part2"' in output + assert 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' in output + assert '(EFI System Partition)' in output + assert '3\t0x00000c22\t0x00000ca1\t"part3"' in output + assert '3de21764-95bd-54bd-a5c3-4abe786f38a8' in output + assert '(u-boot-env)' in output + assert '4\t0x00000ca2\t0x00000d21\t"part4"' in output + assert 'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' in output + assert '(375a56f7-d6c9-4e81-b5f0-09d41ca89efe)' in output + assert '5\t0x00000d22\t0x00001fde\t"part5"' in output + assert '0fc63daf-8483-4772-8e79-3d69d8477de4' in output + assert '(linux)' in output + @pytest.mark.buildconfigspec('cmd_gpt') @pytest.mark.buildconfigspec('cmd_gpt_rename') @pytest.mark.buildconfigspec('cmd_part') 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) |