From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Simon Glass <sjg@chromium.org>
Cc: "U-Boot Mailing List" <u-boot@lists.denx.de>,
"Andrew Scull" <ascull@google.com>,
"Dzmitry Sankouski" <dsankouski@gmail.com>,
"Etienne Carriere" <etienne.carriere@linaro.org>,
"Marek Behún" <kabel@kernel.org>,
"Nikhil M Jain" <n-jain1@ti.com>,
"Ramon Fried" <rfried.dev@gmail.com>,
"Sean Anderson" <sean.anderson@seco.com>
Subject: Re: [PATCH 1/2] tpm: Separate out the TPM tests for v1 and v2
Date: Tue, 21 Feb 2023 15:04:01 +0200 [thread overview]
Message-ID: <Y/TBQWU76N5TR2mo@hera> (raw)
In-Reply-To: <20230220212736.885114-1-sjg@chromium.org>
On Mon, Feb 20, 2023 at 02:27:35PM -0700, Simon Glass wrote:
> Currently there is only one test and it only works on TPM v2. Update it
> to work on v1.2 as well, using a new function to pick up the required
> TPM.
>
> Update sandbox to include both a v1.2 and v2 TPM so that this works.
> Split out the existing test into two pieces, one for init and one for
> the v2-only report_state feature.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> arch/sandbox/dts/test.dts | 4 +++
> test/dm/tpm.c | 60 +++++++++++++++++++++++++++++++++------
> 2 files changed, 55 insertions(+), 9 deletions(-)
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index 05e09128a38..d72d7a567a7 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -1367,6 +1367,10 @@
> compatible = "sandbox,tpm2";
> };
>
> + tpm {
> + compatible = "google,sandbox-tpm";
> + };
> +
> uart0: serial {
> compatible = "sandbox,serial";
> bootph-all;
> diff --git a/test/dm/tpm.c b/test/dm/tpm.c
> index dca540bb561..7d880012090 100644
> --- a/test/dm/tpm.c
> +++ b/test/dm/tpm.c
> @@ -11,24 +11,66 @@
> #include <test/test.h>
> #include <test/ut.h>
>
> -/* Basic test of the TPM uclass */
> +/*
> + * get_tpm_version() - Get a TPM of the given version
> + *
> + * @version: Version to get
> + * @devp: Returns the TPM device
> + * Returns: 0 if OK, -ENODEV if not found
> + */
> +static int get_tpm_version(enum tpm_version version, struct udevice **devp)
> +{
> + struct udevice *dev;
> +
> + /*
> + * For now we have to probe each TPM, since the version is set up in
> + * of_to_plat(). We could require TPMs to declare their version when
> + * probed, to avoid this
> + */
> + uclass_foreach_dev_probe(UCLASS_TPM, dev) {
> + if (tpm_get_version(dev) == version) {
> + *devp = dev;
> + return 0;
> + }
> + }
> +
> + return -ENODEV;
> +}
> +
> +/* Basic test of initing a TPM */
> +static int test_tpm_init(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));
> +
> + return 0;
> +}
> +
> static int dm_test_tpm(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);
> +
> +/* Test report_state */
> +static int dm_test_tpm_report_state(struct unit_test_state *uts)
> {
> struct udevice *dev;
> char buf[50];
>
> /* check probe success */
> - ut_assertok(uclass_first_device_err(UCLASS_TPM, &dev));
> - ut_assert(tpm_is_v2(dev));
> + 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(tpm_init(dev));
> - /*
> - * tpm_auto_start will rerun tpm_init, but handles the
> - * -EBUSY return code internally.
> - */
> ut_assertok(tpm_auto_start(dev));
>
> ut_assert(tpm_report_state(dev, buf, sizeof(buf)));
> @@ -36,4 +78,4 @@ static int dm_test_tpm(struct unit_test_state *uts)
>
> return 0;
> }
> -DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT);
> +DM_TEST(dm_test_tpm_report_state, UT_TESTF_SCAN_FDT);
> --
> 2.39.2.637.g21b0678d19-goog
>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
prev parent reply other threads:[~2023-02-21 13:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-20 21:27 [PATCH 1/2] tpm: Separate out the TPM tests for v1 and v2 Simon Glass
2023-02-20 21:27 ` [PATCH 2/2] tpm: Implement tpm_auto_start() for TPMv1.2 Simon Glass
2023-02-21 13:03 ` Ilias Apalodimas
2023-02-21 13:08 ` Simon Glass
2023-02-21 13:10 ` Ilias Apalodimas
2023-02-21 13:17 ` Simon Glass
2023-02-21 13:04 ` Ilias Apalodimas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/TBQWU76N5TR2mo@hera \
--to=ilias.apalodimas@linaro.org \
--cc=ascull@google.com \
--cc=dsankouski@gmail.com \
--cc=etienne.carriere@linaro.org \
--cc=kabel@kernel.org \
--cc=n-jain1@ti.com \
--cc=rfried.dev@gmail.com \
--cc=sean.anderson@seco.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox