[PATCH v2 2/3] tpm: Convert sandbox-focussed tests to C

Ilias Apalodimas ilias.apalodimas at linaro.org
Mon Nov 20 09:49:07 CET 2023


Hi Simon, 

On Sat, Nov 11, 2023 at 05:43:37PM -0700, Simon Glass wrote:
> 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.

The python tests restart u-boot though. The problem is a bit different
here. Python tests run late, so if the efi subsystem runs first, future
tpm_init() calls will return -EBUSY.  Perhaps the dm tests run earlier?

> 
> 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 deals with starting up ready for the tests below.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
> Changes in v2:
> - Keep test_tpm2_continue_self_test()
> 
>  test/dm/tpm.c              | 77 +++++++++++++++++++++++++++++++++++++-
>  test/py/tests/test_tpm2.py | 38 +------------------
>  2 files changed, 76 insertions(+), 39 deletions(-)
> 
> diff --git a/test/dm/tpm.c b/test/dm/tpm.c
> index cde933ab2848..f8264af13789 100644
> --- a/test/dm/tpm.c
> +++ b/test/dm/tpm.c
> @@ -50,14 +50,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, UT_TESTF_SCAN_FDT);
> +DM_TEST(dm_test_tpm_init, UT_TESTF_SCAN_FDT);
> +
> +/* Test TPM startup */
> +static int test_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;
> +}
> +
> +static int dm_test_tpm_startup(struct unit_test_state *uts)
> +{
> +	ut_assertok(test_tpm_startup(uts, TPM_V1));
> +	ut_assertok(test_tpm_startup(uts, TPM_V2));
> +
> +	return 0;
> +}
> +DM_TEST(dm_test_tpm_startup, UT_TESTF_SCAN_FDT);
> +
> +/* Test TPM self-test full */
> +static int test_tpm_self_test_full(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));

Replace this sequence with test_tpm_startup().

Probably a c/p mistake but you need to call tpm_self_test_full() as well.

> +
> +	return 0;
> +}
> +
> +static int dm_test_tpm_self_test_full(struct unit_test_state *uts)
> +{
> +	ut_assertok(test_tpm_self_test_full(uts, TPM_V1));
> +	ut_assertok(test_tpm_self_test_full(uts, TPM_V2));
> +
> +	return 0;
> +}
 
[...]

Thanks
/Ilias


More information about the U-Boot mailing list