diff options
Diffstat (limited to 'test/py')
-rw-r--r-- | test/py/conftest.py | 14 | ||||
-rw-r--r-- | test/py/tests/test_efi_loader.py | 2 | ||||
-rw-r--r-- | test/py/tests/test_fpga.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_gpt.py | 27 | ||||
-rw-r--r-- | test/py/tests/test_net.py | 2 | ||||
-rw-r--r-- | test/py/tests/test_tpm2.py | 86 |
6 files changed, 53 insertions, 82 deletions
diff --git a/test/py/conftest.py b/test/py/conftest.py index 5aea85647af..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 @@ -711,9 +711,13 @@ def setup_buildconfigspec(item): """ for options in item.iter_markers('buildconfigspec'): - option = options.args[0] - if not ubconfig.buildconfig.get('config_' + option.lower(), None): - pytest.skip('.config feature "%s" not enabled' % option.lower()) + nomatch = True + for arg in options.args: + if ubconfig.buildconfig.get('config_' + arg.lower(), None): + nomatch = False + if nomatch: + argsString = ', '.join(options.args) + pytest.skip(f'.config features "{argsString}" not enabled') for options in item.iter_markers('notbuildconfigspec'): option = options.args[0] if ubconfig.buildconfig.get('config_' + option.lower(), None): diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py index 91f151d09cd..dc58c0d4dbd 100644 --- a/test/py/tests/test_efi_loader.py +++ b/test/py/tests/test_efi_loader.py @@ -98,7 +98,7 @@ def test_efi_setup_dhcp(ubman): global net_set_up net_set_up = True -@pytest.mark.buildconfigspec('net') +@pytest.mark.buildconfigspec('net', 'net_lwip') def test_efi_setup_static(ubman): """Set up the network using a static IP configuration. diff --git a/test/py/tests/test_fpga.py b/test/py/tests/test_fpga.py index 74cd42b910e..299a8653f74 100644 --- a/test/py/tests/test_fpga.py +++ b/test/py/tests/test_fpga.py @@ -506,7 +506,7 @@ def test_fpga_loadfs(ubman): @pytest.mark.buildconfigspec('cmd_fpga_load_secure') @pytest.mark.buildconfigspec('cmd_net') @pytest.mark.buildconfigspec('cmd_dhcp') -@pytest.mark.buildconfigspec('net') +@pytest.mark.buildconfigspec('net', 'net_lwip') def test_fpga_secure_bit_auth(ubman): test_net.test_net_dhcp(ubman) @@ -534,7 +534,7 @@ def test_fpga_secure_bit_auth(ubman): @pytest.mark.buildconfigspec('cmd_fpga_load_secure') @pytest.mark.buildconfigspec('cmd_net') @pytest.mark.buildconfigspec('cmd_dhcp') -@pytest.mark.buildconfigspec('net') +@pytest.mark.buildconfigspec('net', 'net_lwip') def test_fpga_secure_bit_img_auth_kup(ubman): test_net.test_net_dhcp(ubman) 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_net.py b/test/py/tests/test_net.py index 27cdd73fd49..6ef02e53389 100644 --- a/test/py/tests/test_net.py +++ b/test/py/tests/test_net.py @@ -201,7 +201,7 @@ def test_net_dhcp6(ubman): global net6_set_up net6_set_up = True -@pytest.mark.buildconfigspec('net') +@pytest.mark.buildconfigspec('net', 'net_lwip') def test_net_setup_static(ubman): """Set up a static IP configuration. 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) |