Hi Michael,
On 2026-10-06T15:52:14, Michael Haener <[email protected]> wrote:
> tpm: Add tests for CONFIG_TPM_AUTOSTART
>
> Enable CONFIG_TPM_AUTOSTART on sandbox and add two tests which send
> EVT_LAST_STAGE_INIT: one checks that the TPM is started, the other that
> the event does not fail when there is no TPM device.
>
> Signed-off-by: Michael Haener <[email protected]>
>
> configs/sandbox_defconfig | 1 +
> test/dm/tpm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 45 insertions(+)
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> @@ -395,6 +395,7 @@ CONFIG_ECDSA=y
> CONFIG_TPM=y
> +CONFIG_TPM_AUTOSTART=y
As Ilias says below. scripts/event_dump.py lists every spy in the
sandbox image and test_event_dump.py matches the whole list line by
line. A new EVT_LAST_STAGE_INIT entry for tpm_evt_autostart() now
appears after install_smbios_table(), so the test fails from this
patch onwards. Please can you add the line to
test/py/tests/test_event_dump.py in this patch.
> diff --git a/test/dm/tpm.c b/test/dm/tpm.c
> @@ -197,3 +200,44 @@ static int dm_test_tpm_autostart_reinit(struct
> unit_test_state *uts)
> + if (!IS_ENABLED(CONFIG_TPM_AUTOSTART))
> + return 0;
Please return -EAGAIN here (and in the second test) so that the test
shows as skipped rather than passed.
> diff --git a/test/dm/tpm.c b/test/dm/tpm.c
> @@ -197,3 +200,44 @@ static int dm_test_tpm_autostart_reinit(struct
> unit_test_state *uts)
> + ut_assertok(get_tpm_version(TPM_V2, &dev));
> +
> + ut_assert(tpm_report_state(dev, buf, sizeof(buf)));
> + ut_asserteq_str("init_done=0", buf);
> +
> + ut_assertok(event_notify_null(EVT_LAST_STAGE_INIT));
The handler only starts the first device in the uclass, so this test
passes only because the tpm2 node comes before the tpm node in
test.dts - sandbox.dtsi has them the other way round. So you could use
uclass_first_device_err(), as the handler does, and check that it is
the v2 one, or at least add a comment saying that the test relies on
the node order.
Also, event_notify_null() runs every EVT_LAST_STAGE_INIT spy, not just
this one. On sandbox, install_smbios_table() allocates a new
4KB-aligned table, never frees it and moves gd->arch.smbios_start to
the copy, and efi_block_device_create() binds another device. Other
tests won't expect these side effects. I suspect it would be cleaner
to expose the handler as a normal function (e.g. tpm_autostart_init()
in tpm_api.h), call that from the spy and have the test call it
directly. What do you think?
Anyway, so long as this passes CI, it's fine with me.
> diff --git a/test/dm/tpm.c b/test/dm/tpm.c
> @@ -197,3 +200,44 @@ static int dm_test_tpm_autostart_reinit(struct
> unit_test_state *uts)
> + ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_TPM, &dev));
> + ut_assertok(event_notify_null(EVT_LAST_STAGE_INIT));
tpm_evt_autostart() returns 0 on every path, so this assertion can
never fail and the test checks nothing. The useful property is that
the missing-TPM case is silent. Please can you add UTF_CONSOLE and use
ut_assert_console_end() to check that nothing is printed? A similar
check in the first test would confirm that there is no 'TPM startup
failed' warning.
Regards,
Simon