* [PATCH v2 1/4] test: Allow vboot tests to run in parallel
2021-07-23 2:07 [PATCH v2 0/4] test: Try to deal with some co-dependent tests Simon Glass
@ 2021-07-23 2:07 ` Simon Glass
2021-07-23 2:07 ` [PATCH v2 2/4] test: Allow hush " Simon Glass
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2021-07-23 2:07 UTC (permalink / raw)
To: U-Boot Mailing List
Cc: Tom Rini, Heinrich Schuchardt, Stephen Warren, Stephen Warren,
Simon Glass, Thirupathaiah Annapureddy
Update the tests to use separate working directories, so we can run them
in parallel. It also makes it possible to see the individual output files
after the tests have completed.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
(no changes since v1)
test/py/tests/test_vboot.py | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index 6dff6779d17..095e00cce36 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -24,6 +24,7 @@ For configuration verification:
Tests run with both SHA1 and SHA256 hashing.
"""
+import os
import shutil
import struct
import pytest
@@ -34,16 +35,16 @@ import vboot_evil
# Only run the full suite on a few combinations, since it doesn't add any more
# test coverage.
TESTDATA = [
- ['sha1', '', None, False, True],
- ['sha1', '', '-E -p 0x10000', False, False],
- ['sha1', '-pss', None, False, False],
- ['sha1', '-pss', '-E -p 0x10000', False, False],
- ['sha256', '', None, False, False],
- ['sha256', '', '-E -p 0x10000', False, False],
- ['sha256', '-pss', None, False, False],
- ['sha256', '-pss', '-E -p 0x10000', False, False],
- ['sha256', '-pss', None, True, False],
- ['sha256', '-pss', '-E -p 0x10000', True, True],
+ ['sha1-basic', 'sha1', '', None, False, True],
+ ['sha1-pad', 'sha1', '', '-E -p 0x10000', False, False],
+ ['sha1-pss', 'sha1', '-pss', None, False, False],
+ ['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x10000', False, False],
+ ['sha256-basic', 'sha256', '', None, False, False],
+ ['sha256-pad', 'sha256', '', '-E -p 0x10000', False, False],
+ ['sha256-pss', 'sha256', '-pss', None, False, False],
+ ['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x10000', False, False],
+ ['sha256-pss-required', 'sha256', '-pss', None, True, False],
+ ['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x10000', True, True],
]
@pytest.mark.boardspec('sandbox')
@@ -52,9 +53,9 @@ TESTDATA = [
@pytest.mark.requiredtool('fdtget')
@pytest.mark.requiredtool('fdtput')
@pytest.mark.requiredtool('openssl')
-@pytest.mark.parametrize("sha_algo,padding,sign_options,required,full_test",
+@pytest.mark.parametrize("name,sha_algo,padding,sign_options,required,full_test",
TESTDATA)
-def test_vboot(u_boot_console, sha_algo, padding, sign_options, required,
+def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
full_test):
"""Test verified boot signing with mkimage and verification with 'bootm'.
@@ -365,7 +366,9 @@ def test_vboot(u_boot_console, sha_algo, padding, sign_options, required,
run_bootm(sha_algo, 'multi required key', '', False)
cons = u_boot_console
- tmpdir = cons.config.result_dir + '/'
+ tmpdir = os.path.join(cons.config.result_dir, name) + '/'
+ if not os.path.exists(tmpdir):
+ os.mkdir(tmpdir)
datadir = cons.config.source_dir + '/test/py/tests/vboot/'
fit = '%stest.fit' % tmpdir
mkimage = cons.config.build_dir + '/tools/mkimage'
--
2.32.0.432.gabb21c7263-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/4] test: Allow hush tests to run in parallel
2021-07-23 2:07 [PATCH v2 0/4] test: Try to deal with some co-dependent tests Simon Glass
2021-07-23 2:07 ` [PATCH v2 1/4] test: Allow vboot tests to run in parallel Simon Glass
@ 2021-07-23 2:07 ` Simon Glass
2021-07-23 2:07 ` [PATCH v2 3/4] test: Allow tpm2 " Simon Glass
2021-07-23 2:07 ` [PATCH v2 4/4] doc: test: Explain how to run pytests " Simon Glass
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2021-07-23 2:07 UTC (permalink / raw)
To: U-Boot Mailing List
Cc: Tom Rini, Heinrich Schuchardt, Stephen Warren, Stephen Warren,
Simon Glass
The -z tests don't really need to be part of the main set. Separate them
out so we can drop the test setup/cleans functions and thus run all tests
in parallel.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
(no changes since v1)
test/py/tests/test_hush_if_test.py | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/test/py/tests/test_hush_if_test.py b/test/py/tests/test_hush_if_test.py
index d117921a6ac..37c1608bb22 100644
--- a/test/py/tests/test_hush_if_test.py
+++ b/test/py/tests/test_hush_if_test.py
@@ -119,11 +119,6 @@ subtests = (
('test ! ! aaa != aaa -o ! ! bbb = bbb', True),
('test ! ! aaa = aaa -o ! ! bbb != bbb', True),
('test ! ! aaa = aaa -o ! ! bbb = bbb', True),
-
- # -z operator.
-
- ('test -z "$ut_var_nonexistent"', True),
- ('test -z "$ut_var_exists"', False),
)
def exec_hush_if(u_boot_console, expr, result):
@@ -141,12 +136,6 @@ def exec_hush_if(u_boot_console, expr, result):
response = u_boot_console.run_command(cmd)
assert response.strip() == str(result).lower()
-def test_hush_if_test_setup(u_boot_console):
- """Set up environment variables used during the "if" tests."""
-
- u_boot_console.run_command('setenv ut_var_nonexistent')
- u_boot_console.run_command('setenv ut_var_exists 1')
-
@pytest.mark.buildconfigspec('cmd_echo')
@pytest.mark.parametrize('expr,result', subtests)
def test_hush_if_test(u_boot_console, expr, result):
@@ -154,9 +143,12 @@ def test_hush_if_test(u_boot_console, expr, result):
exec_hush_if(u_boot_console, expr, result)
-def test_hush_if_test_teardown(u_boot_console):
- """Clean up environment variables used during the "if" tests."""
-
+def test_hush_z(u_boot_console):
+ """Test the -z operator"""
+ u_boot_console.run_command('setenv ut_var_nonexistent')
+ u_boot_console.run_command('setenv ut_var_exists 1')
+ exec_hush_if(u_boot_console, 'test -z "$ut_var_nonexistent"', True)
+ exec_hush_if(u_boot_console, 'test -z "$ut_var_exists"', False)
u_boot_console.run_command('setenv ut_var_exists')
# We might test this on real filesystems via UMS, DFU, 'save', etc.
--
2.32.0.432.gabb21c7263-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/4] test: Allow tpm2 tests to run in parallel
2021-07-23 2:07 [PATCH v2 0/4] test: Try to deal with some co-dependent tests Simon Glass
2021-07-23 2:07 ` [PATCH v2 1/4] test: Allow vboot tests to run in parallel Simon Glass
2021-07-23 2:07 ` [PATCH v2 2/4] test: Allow hush " Simon Glass
@ 2021-07-23 2:07 ` Simon Glass
2021-07-23 2:07 ` [PATCH v2 4/4] doc: test: Explain how to run pytests " Simon Glass
3 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2021-07-23 2:07 UTC (permalink / raw)
To: U-Boot Mailing List
Cc: Tom Rini, Heinrich Schuchardt, Stephen Warren, Stephen Warren,
Simon Glass
These tests currently run in a particular sequence, with some of them
depending on the actions of earlier tests.
Add a check for sandbox and reset to a known state at the start of each
test, so that all tests can run in parallel.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
(no changes since v1)
test/py/tests/test_tpm2.py | 52 +++++++++++++++++++++++++++++++++-----
1 file changed, 46 insertions(+), 6 deletions(-)
diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 70f906da511..49e7ebfa5bf 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -40,10 +40,14 @@ def force_init(u_boot_console, force=False):
u_boot_console.run_command('tpm2 clear TPM2_RH_PLATFORM')
u_boot_console.run_command('echo --- end of init ---')
+def is_sandbox(cons):
+ # Array slice removes leading/trailing quotes.
+ sys_arch = cons.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1]
+ return sys_arch == 'sandbox'
+
@pytest.mark.buildconfigspec('cmd_tpm_v2')
def test_tpm2_init(u_boot_console):
"""Init the software stack to use TPMv2 commands."""
-
u_boot_console.run_command('tpm2 init')
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
@@ -54,17 +58,43 @@ def test_tpm2_startup(u_boot_console):
Initiate the TPM internal state machine.
"""
+ u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
+
+def tpm2_sandbox_init(u_boot_console):
+ """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.
+ """
+ u_boot_console.restart_uboot()
+ u_boot_console.run_command('tpm2 init')
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
+ u_boot_console.run_command('tpm2 self_test full')
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
+
@pytest.mark.buildconfigspec('cmd_tpm_v2')
-def test_tpm2_self_test_full(u_boot_console):
+def test_tpm2_sandbox_self_test_full(u_boot_console):
"""Execute a TPM2_SelfTest (full) command.
Ask the TPM to perform all self tests to also enable full capabilities.
"""
+ if is_sandbox(u_boot_console):
+ u_boot_console.restart_uboot()
+ u_boot_console.run_command('tpm2 init')
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
+
+ u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
u_boot_console.run_command('tpm2 self_test full')
output = u_boot_console.run_command('echo $?')
@@ -77,7 +107,8 @@ def test_tpm2_continue_self_test(u_boot_console):
Ask the TPM to finish its self tests (alternative to the full test) in order
to enter a fully operational state.
"""
-
+ if is_sandbox(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
u_boot_console.run_command('tpm2 self_test continue')
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
@@ -94,6 +125,8 @@ def test_tpm2_clear(u_boot_console):
not have a password set, otherwise this test will fail. ENDORSEMENT and
PLATFORM hierarchies are also available.
"""
+ if is_sandbox(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
output = u_boot_console.run_command('echo $?')
@@ -112,7 +145,8 @@ def test_tpm2_change_auth(u_boot_console):
Use the LOCKOUT hierarchy for this. ENDORSEMENT and PLATFORM hierarchies are
also available.
"""
-
+ if is_sandbox(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
force_init(u_boot_console)
u_boot_console.run_command('tpm2 change_auth TPM2_RH_LOCKOUT unicorn')
@@ -136,6 +170,8 @@ def test_tpm2_get_capability(u_boot_console):
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(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
force_init(u_boot_console)
ram = u_boot_utils.find_ram_base(u_boot_console)
@@ -158,7 +194,8 @@ def test_tpm2_dam_parameters(u_boot_console):
the authentication, otherwise the lockout will be engaged after the first
failed authentication attempt.
"""
-
+ if is_sandbox(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
force_init(u_boot_console)
ram = u_boot_utils.find_ram_base(u_boot_console)
@@ -181,6 +218,8 @@ def test_tpm2_pcr_read(u_boot_console):
Perform a PCR read of the 0th PCR. Must be zero.
"""
+ if is_sandbox(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
force_init(u_boot_console)
ram = u_boot_utils.find_ram_base(u_boot_console)
@@ -208,7 +247,8 @@ def test_tpm2_pcr_extend(u_boot_console):
No authentication mechanism is used here, not protecting against packet
replay, yet.
"""
-
+ if is_sandbox(u_boot_console):
+ tpm2_sandbox_init(u_boot_console)
force_init(u_boot_console)
ram = u_boot_utils.find_ram_base(u_boot_console)
--
2.32.0.432.gabb21c7263-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread