diff options
| author | Simon Glass <[email protected]> | 2025-05-24 07:06:35 -0600 |
|---|---|---|
| committer | Ilias Apalodimas <[email protected]> | 2025-06-10 19:35:26 +0300 |
| commit | edc4bfd2e32a58b09e88f8a12e5e97d72232c6ff (patch) | |
| tree | 873af99dc92dd4509f16de4bc003dcf9753ecb04 /test/dm | |
| parent | 1f144b61740d4e0acf15cc82911bc6129f2f814e (diff) | |
tpm: Convert sandbox-focussed tests to C
Some of the Python tests are a pain because they don't reset the TPM
state before each test. Driver model tests do this, so convert the
tests to C.
This means that these tests won't run on real hardware, but we have
tests which do TPM init, so there is still enough coverage.
Rename and update the Python tpm_init test to use 'tpm autostart',
since this fully initializes the TPM and performs the self tests.
Signed-off-by: Simon Glass <[email protected]>
Reviewed-by: Ilias Apalodimas <[email protected]>
Signed-off-by: Ilias Apalodimas <[email protected]>
Diffstat (limited to 'test/dm')
| -rw-r--r-- | test/dm/tpm.c | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/test/dm/tpm.c b/test/dm/tpm.c index 962a3fd1943..87c5c416daa 100644 --- a/test/dm/tpm.c +++ b/test/dm/tpm.c @@ -49,14 +49,87 @@ static int test_tpm_init(struct unit_test_state *uts, enum tpm_version version) return 0; } -static int dm_test_tpm(struct unit_test_state *uts) +static int dm_test_tpm_init(struct unit_test_state *uts) { ut_assertok(test_tpm_init(uts, TPM_V1)); ut_assertok(test_tpm_init(uts, TPM_V2)); return 0; } -DM_TEST(dm_test_tpm, UTF_SCAN_FDT); +DM_TEST(dm_test_tpm_init, UTF_SCAN_FDT); + +/* check TPM startup */ +static int check_tpm_startup(struct unit_test_state *uts, + enum tpm_version version) +{ + struct udevice *dev; + + /* check probe success */ + ut_assertok(get_tpm_version(version, &dev)); + + ut_assertok(tpm_init(dev)); + ut_assertok(tpm_startup(dev, TPM_ST_CLEAR)); + + return 0; +} + +/* test TPM startup */ +static int dm_test_tpm_startup(struct unit_test_state *uts) +{ + ut_assertok(check_tpm_startup(uts, TPM_V1)); + ut_assertok(check_tpm_startup(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm_startup, UTF_SCAN_FDT); + +static int check_tpm_self_test_full(struct unit_test_state *uts, + enum tpm_version version) +{ + struct udevice *dev; + + ut_assertok(check_tpm_startup(uts, version)); + + ut_assertok(get_tpm_version(version, &dev)); + ut_assertok(tpm_self_test_full(dev)); + + return 0; +} + +/* Test TPM self-test full */ +static int dm_test_tpm_self_test_full(struct unit_test_state *uts) +{ + ut_assertok(check_tpm_self_test_full(uts, TPM_V1)); + ut_assertok(check_tpm_self_test_full(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm_self_test_full, UTF_SCAN_FDT); + +/* Test TPM self-test continue */ +static int test_tpm_self_test_cont(struct unit_test_state *uts, + enum tpm_version version) +{ + struct udevice *dev; + + /* check probe success */ + ut_assertok(get_tpm_version(version, &dev)); + + ut_assertok(tpm_init(dev)); + ut_assertok(tpm_startup(dev, TPM_ST_CLEAR)); + ut_assertok(tpm_continue_self_test(dev)); + + return 0; +} + +static int dm_test_tpm_self_test_cont(struct unit_test_state *uts) +{ + ut_assertok(test_tpm_self_test_cont(uts, TPM_V1)); + ut_assertok(test_tpm_self_test_cont(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm_self_test_cont, UTF_SCAN_FDT); /* Test report_state */ static int dm_test_tpm_report_state(struct unit_test_state *uts) |
