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 6/6] tests: Add a TPM TIS I2C swtpm test
Date: Wed, 29 Apr 2026 17:02:24 +0530 [thread overview]
Message-ID: <afHsSJlhvtjYCJ_e@fedora> (raw)
In-Reply-To: <20260428130718.1325177-7-stefanb@linux.ibm.com>
On Tue, Apr 28, 2026 at 01:07:18PM +0000, Stefan Berger wrote:
> Add a test case testing the TPM TIS over I2C with swtpm.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> tests/qtest/meson.build | 5 +-
> tests/qtest/tpm-tis-i2c-swtpm-test.c | 86 ++++++++++++++++++++++++++++
> tests/qtest/tpm-tis-i2c-util.c | 38 ++++++++++++
> tests/qtest/tpm-tis-i2c-util.h | 4 ++
> 4 files changed, 131 insertions(+), 2 deletions(-)
> create mode 100644 tests/qtest/tpm-tis-i2c-swtpm-test.c
>
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 823be192e7..1a94f20f7f 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -241,7 +241,7 @@ qtests_arm = \
> (config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed : []) + \
> (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
> (config_all_devices.has_key('CONFIG_GENERIC_LOADER') ? ['hexloader-test'] : []) + \
> - (config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
> + (config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test', 'tpm-tis-i2c-swtpm-test'] : []) + \
> (config_all_devices.has_key('CONFIG_VEXPRESS') ? ['test-arm-mptimer'] : []) + \
> (config_all_devices.has_key('CONFIG_MICROBIT') ? ['microbit-test'] : []) + \
> (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') ? qtests_stm32l4x5 : []) + \
> @@ -260,7 +260,7 @@ qtests_aarch64 = \
> (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', 'xlnx-versal-trng-test'] : []) + \
> (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2835-i2c-test'] : []) + \
> (config_all_accel.has_key('CONFIG_TCG') and \
> - config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
> + config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test', 'tpm-tis-i2c-swtpm-test'] : []) + \
> (config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed64 : []) + \
> (config_all_devices.has_key('CONFIG_NPCM8XX') ? qtests_npcm8xx : []) + \
> (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
> @@ -398,6 +398,7 @@ qtests = {
> 'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
> 'tpm-tis-test': [io, tpmemu_files, 'tpm-tis-util.c'],
> 'tpm-tis-i2c-test': [io, tpmemu_files, 'tpm-tis-i2c-util.c', 'qtest_aspeed.c'],
> + 'tpm-tis-i2c-swtpm-test': [io, tpmemu_files, 'tpm-tis-i2c-util.c', 'qtest_aspeed.c'],
> 'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
> 'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
> 'virtio-net-failover': test_migration_files,
> diff --git a/tests/qtest/tpm-tis-i2c-swtpm-test.c b/tests/qtest/tpm-tis-i2c-swtpm-test.c
> new file mode 100644
> index 0000000000..54a84251f8
> --- /dev/null
> +++ b/tests/qtest/tpm-tis-i2c-swtpm-test.c
> @@ -0,0 +1,86 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * QTest testcase for TPM TIS over I2C talking to external swtpm
> + *
> + * Copyright (c) 2018, 2026 IBM Corporation
> + * with parts borrowed from migration-test.c that is:
> + * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
> + *
> + * Authors:
> + * Stefan Berger <stefanb@linux.ibm.com>
> + *
> + */
> +
> +#include "qemu/osdep.h"
> +
> +#include "libqtest.h"
> +#include "qemu/module.h"
> +#include "tpm-tests.h"
> +#include "tpm-tis-i2c-util.h"
> +#include "qtest_aspeed.h"
> +
> +typedef struct TestState {
> + char *src_tpm_path;
> + char *dst_tpm_path;
> + char *uri;
> + const char *machine_options;
> + char *ifmodel;
> +} TestState;
> +
> +static void tpm_tis_i2c_swtpm_test(const void *data)
> +{
> + const TestState *ts = data;
> +
> + aspeed_i2c_restart();
> +
> + tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_i2c_transfer,
> + ts->ifmodel, ts->machine_options);
> +}
> +
> +static void tpm_tis_swtpm_migration_test(const void *data)
> +{
> + const TestState *ts = data;
> +
> + aspeed_i2c_restart();
> +
> + tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path,
> + ts->uri, tpm_tis_i2c_transfer,
> + ts->ifmodel, ts->machine_options);
> +}
> +
> +
> +int main(int argc, char **argv)
> +{
> + int ret;
> + TestState ts;
> +
> + ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-i2c-swtpm-test.XXXXXX",
> + NULL);
> + ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-i2c-swtpm-test.XXXXXX",
> + NULL);
> + ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
> + ts.machine_options = "-machine rainier-bmc -accel tcg";
> + ts.ifmodel = g_strdup_printf(
> + "tpm-tis-i2c,bus=aspeed.i2c.bus.%d,address=0x%x",
> + I2C_DEV_BUS_NUM, I2C_SLAVE_ADDR);
> +
> + module_call_init(MODULE_INIT_QOM);
> + g_test_init(&argc, &argv, NULL);
> +
> + aspeed_bus_addr = ast2600_i2c_calc_bus_addr(I2C_DEV_BUS_NUM);
> +
> + qtest_add_data_func("/tpm/tis-i2c-swtpm/test", &ts, tpm_tis_i2c_swtpm_test);
> + qtest_add_data_func("/tpm/tis-i2c-swtpm-migration/test", &ts,
> + tpm_tis_swtpm_migration_test);
> + ret = g_test_run();
> +
> + tpm_util_rmdir(ts.dst_tpm_path);
> + g_free(ts.dst_tpm_path);
> + tpm_util_rmdir(ts.src_tpm_path);
> + g_free(ts.src_tpm_path);
> + g_free(ts.uri);
> + g_free(ts.ifmodel);
> +
> + return ret;
> +}
> diff --git a/tests/qtest/tpm-tis-i2c-util.c b/tests/qtest/tpm-tis-i2c-util.c
> index 6e724a4a47..c73420ec5b 100644
> --- a/tests/qtest/tpm-tis-i2c-util.c
> +++ b/tests/qtest/tpm-tis-i2c-util.c
> @@ -15,6 +15,7 @@
> #include "libqtest-single.h"
> #include "qtest_aspeed.h"
> #include "tpm-tis-i2c-util.h"
> +#include "tpm-emu.h"
>
> uint32_t aspeed_bus_addr;
>
> @@ -62,3 +63,40 @@ void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v)
> }
> aspeed_i2c_writel(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
> }
> +
> +void tpm_tis_i2c_transfer(QTestState *s,
> + const unsigned char *req, size_t req_size,
> + unsigned char *rsp, size_t rsp_size)
> +{
> + uint32_t sts;
> + size_t i;
> +
> + /* request use of locality 0 */
> + tpm_tis_i2c_writeb(s, 0, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
> +
> + tpm_tis_i2c_writel(s, 0, TPM_I2C_REG_STS, TPM_TIS_STS_COMMAND_READY);
> +
> + /* transmit command */
> + for (i = 0; i < req_size; i++) {
> + tpm_tis_i2c_writeb(s, 0, TPM_I2C_REG_DATA_FIFO, req[i]);
> + }
> +
> + /* start processing */
> + tpm_tis_i2c_writeb(s, 0, TPM_I2C_REG_STS, TPM_TIS_STS_TPM_GO);
> +
> + uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
> + do {
> + sts = tpm_tis_i2c_readl(s, 0, TPM_I2C_REG_STS);
> + if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
> + break;
> + }
> + } while (g_get_monotonic_time() < end_time);
> +
> + /* read response */
> + for (i = 0; i < rsp_size; i++) {
> + rsp[i] = tpm_tis_i2c_readb(s, 0, TPM_I2C_REG_DATA_FIFO);
> + }
> + /* relinquish use of locality 0 */
> + tpm_tis_i2c_writeb(s, 0,
> + TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_ACTIVE_LOCALITY);
> +}
> diff --git a/tests/qtest/tpm-tis-i2c-util.h b/tests/qtest/tpm-tis-i2c-util.h
> index 3289545f61..499bf4964a 100644
> --- a/tests/qtest/tpm-tis-i2c-util.h
> +++ b/tests/qtest/tpm-tis-i2c-util.h
> @@ -27,4 +27,8 @@ uint32_t tpm_tis_i2c_readl(QTestState *s, uint8_t locty, uint8_t reg);
> void tpm_tis_i2c_writeb(QTestState *s, uint8_t locty, uint8_t reg, uint8_t v);
> void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v);
>
> +void tpm_tis_i2c_transfer(QTestState *s,
> + const unsigned char *req, size_t req_size,
> + unsigned char *rsp, size_t rsp_size);
> +
> #endif /* TESTS_TPM_TIS_I2C_UTIL_H */
> --
> 2.43.0
>
Reviewed-by: Arun Menon <armenon@redhat.com>
Regards,
Arun Menon
prev parent reply other threads:[~2026-04-29 11:33 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
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 [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=afHsSJlhvtjYCJ_e@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.