All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arun Menon <armenon@redhat.com>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: qemu-devel@nongnu.org, marcandre.lureau@redhat.com
Subject: Re: [PATCH 3/6] tests: Set sizes for arrays of expected TPM responses and requests
Date: Wed, 29 Apr 2026 16:59:16 +0530	[thread overview]
Message-ID: <afHrjFrMrxroKArd@fedora> (raw)
In-Reply-To: <20260428130718.1325177-4-stefanb@linux.ibm.com>

Hi,

On Tue, Apr 28, 2026 at 01:07:15PM +0000, Stefan Berger wrote:
> Set the sizes of byte arrays holding TPM requests and responses to avoid a
> terminating NUL byte to be added and to only compare the expected part of
> responses.
> 
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>  tests/qtest/tpm-tests.c |  4 ++--
>  tests/qtest/tpm-util.c  | 10 +++++-----
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index 197714f8d9..dcbf5457ed 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -59,7 +59,7 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
>      tpm_util_startup(s, tx);
>      tpm_util_pcrextend(s, tx);
>  
> -    static const unsigned char tpm_pcrread_resp[] =
> +    static const unsigned char tpm_pcrread_resp[62] =
>          "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
>          "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
>          "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"

Can we define it as an initializer list instead of a string literal like
below?

static const unsigned char tpm_pcrread_resp[] = {0x80, 0x01, 0x00,
0x00,...};

This one avoids the null terminator.

static const unsigned char tpm_pcrread_resp[] =
          {0x80,0x01,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,
           0x00,0x16,0x00,0x00,0x00,0x01,0x00,0x0b,0x03,0x00,0x04,0x00,
           0x00,0x00,0x00,0x01,0x00,0x20,0xf6,0x85,0x98,0xe5,0x86,0x8d,
           0xe6,0x8b,0x97,0x29,0x99,0x60,0xf2,0x71,0x7d,0x17,0x67,0x89,
           0xa4,0x2f,0x9a,0xae,0xa8,0xc7,0xb7,0xaa,0x79,0xa8,0x62,0x56,
           0xc1,0xde};

static const unsigned char tpm_pcrextend[] =
          {0x80,0x02,0x00,0x00,0x00,0x41,0x00,0x00,0x01,0x82,0x00,0x00,
           0x00,0x0a,0x00,0x00,0x00,0x09,0x40,0x00,0x00,0x09,0x00,0x00,
           0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x0b,0x74,0x65,0x73,
           0x74,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
           0x00,0x00,0x00,0x00,0x00};

static const unsigned char tpm_pcrextend_resp[] =
          {0x80,0x02,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,
           0x00,0x00,0x00,0x00,0x01,0x00,0x00};

static const unsigned char tpm_pcrread[] =
          {0x80,0x01,0x00,0x00,0x00,0x14,0x00,0x00,0x01,0x7e,0x00,0x00,
           0x00,0x01,0x00,0x0b,0x03,0x00,0x04,0x00};

> @@ -105,7 +105,7 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
>      tpm_util_startup(src_qemu, tx);
>      tpm_util_pcrextend(src_qemu, tx);
>  
> -    static const unsigned char tpm_pcrread_resp[] =
> +    static const unsigned char tpm_pcrread_resp[62] =
>          "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
>          "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
>          "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
> index 2cb2dd4796..1a47099807 100644
> --- a/tests/qtest/tpm-util.c
> +++ b/tests/qtest/tpm-util.c
> @@ -54,9 +54,9 @@ void tpm_util_crb_transfer(QTestState *s,
>  void tpm_util_startup(QTestState *s, tx_func *tx)
>  {
>      unsigned char buffer[1024];
> -    static const unsigned char tpm_startup[] =
> +    static const unsigned char tpm_startup[12] =
>          "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
> -    static const unsigned char tpm_startup_resp[] =
> +    static const unsigned char tpm_startup_resp[10] =
>          "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
>  
>      tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
> @@ -68,14 +68,14 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
>  void tpm_util_pcrextend(QTestState *s, tx_func *tx)
>  {
>      unsigned char buffer[1024];
> -    static const unsigned char tpm_pcrextend[] =
> +    static const unsigned char tpm_pcrextend[65] =
>          "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
>          "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
>          "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>          "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>          "\x00";
>  
> -    static const unsigned char tpm_pcrextend_resp[] =
> +    static const unsigned char tpm_pcrextend_resp[19] =
>          "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>          "\x01\x00\x00";
>  
> @@ -89,7 +89,7 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
>                        const unsigned char *exp_resp, size_t exp_resp_size)
>  {
>      unsigned char buffer[1024];
> -    static const unsigned char tpm_pcrread[] =
> +    static const unsigned char tpm_pcrread[20] =
>          "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
>          "\x03\x00\x04\x00";
>  
> -- 
> 2.43.0
> 

Regards,
Arun Menon



  reply	other threads:[~2026-04-29 11:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28 13:07 [PATCH 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
2026-04-28 13:07 ` [PATCH 1/6] tests: Move TPM I2C bus read/write functions to common files Stefan Berger
2026-04-29 11:29   ` Arun Menon
2026-04-28 13:07 ` [PATCH 2/6] tests: Have TPM I2C read/write functions take QTestState as first parameter Stefan Berger
2026-04-29 11:30   ` Arun Menon
2026-04-28 13:07 ` [PATCH 3/6] tests: Set sizes for arrays of expected TPM responses and requests Stefan Berger
2026-04-29 11:29   ` Arun Menon [this message]
2026-04-28 13:07 ` [PATCH 4/6] tests: Rename id of tpmdev to tpm0 Stefan Berger
2026-04-29 11:30   ` Arun Menon
2026-04-28 13:07 ` [PATCH 5/6] tests: Implement aspeed_i2c_restart to reenable selection of master Stefan Berger
2026-04-29 11:32   ` Arun Menon
2026-04-29 12:13     ` Stefan Berger
2026-04-28 13:07 ` [PATCH 6/6] tests: Add a TPM TIS I2C swtpm test Stefan Berger
2026-04-29 11:32   ` Arun Menon

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=afHrjFrMrxroKArd@fedora \
    --to=armenon@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.