tests: Add test cases for TPM 1.2 ACPI tables
v4 cover tests: Add test cases for TPM 1.2 ACPI tables
This series of patches adds test case for TPM 1.2 ACPI tables.
Stefan
v4:
- Added patch 10 that checks for availability of a TPM device model using QMP and if not available skips the ACPI table test
v3:
- Define enum TPMVersion for when CONFIG_TPM is not defined affected patches 2 and 6
v2:
- Proper handling of renaming of files holding expected ACPI data
Stefan Berger (10):
tests: Rename TestState to TPMTestState
tests: Add tpm_version field to TPMTestState and fill it
tests: acpi: Prepare for renaming of TPM2 related ACPI files
tests: Add suffix 'tpm2' or 'tpm12' to ACPI table files
tests: acpi: tpm2: Add the renamed ACPI files and drop old ones
tests: tpm: Create TPM 1.2 response in TPM emulator
tests: acpi: prepare for new TPM 1.2 related tables
tests: acpi: Add test cases for TPM 1.2 with TCPA table
tests: acpi: tpm1.2: Add expected TPM 1.2 ACPI blobs
tests: Use QMP to check whether a TPM device model is available
tests/data/acpi/q35/DSDT.tis.tpm12 | Bin 0 -> 8465 bytes
.../data/acpi/q35/{DSDT.tis => DSDT.tis.tpm2} | Bin
tests/data/acpi/q35/TCPA.tis.tpm12 | Bin 0 -> 50 bytes
.../data/acpi/q35/{TPM2.tis => TPM2.tis.tpm2} | Bin
tests/qtest/bios-tables-test.c | 30 ++++++---
tests/qtest/tpm-crb-test.c | 5 +-
tests/qtest/tpm-emu.c | 61 ++++++++++++++++--
tests/qtest/tpm-emu.h | 20 +++++-
tests/qtest/tpm-tis-device-test.c | 3 +-
tests/qtest/tpm-tis-test.c | 3 +-
tests/qtest/tpm-tis-util.c | 2 +-
11 files changed, 100 insertions(+), 24 deletions(-)
create mode 100644 tests/data/acpi/q35/DSDT.tis.tpm12
rename tests/data/acpi/q35/{DSDT.tis => DSDT.tis.tpm2} (100%)
create mode 100644 tests/data/acpi/q35/TCPA.tis.tpm12
rename tests/data/acpi/q35/{TPM2.tis => TPM2.tis.tpm2} (100%)Signature · 1 line
2.31.1
PATCH v4 1/10 tests: Rename TestState to TPMTestState
--- tests/qtest/bios-tables-test.c | 2 +- tests/qtest/tpm-crb-test.c | 4 ++-- tests/qtest/tpm-emu.c | 6 +++--- tests/qtest/tpm-emu.h | 6 +++--- tests/qtest/tpm-tis-device-test.c | 2 +- tests/qtest/tpm-tis-test.c | 2 +- tests/qtest/tpm-tis-util.c | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-)
tests/qtest/bios-tables-test.c +1 -1
@@ -1098,7 +1098,7 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,gchar *tmp_dir_name =g_strdup_printf ("qemu-test_acpi_%s_tcg_%s.XXXXXX" , machine, tpm_if);char *tmp_path =g_dir_make_tmp (tmp_dir_name,NULL ); -TestState test; +TPMTestState test;test_data data;GThread *thread;char *args, *variant =g_strdup_printf (".%s" , tpm_if);
tests/qtest/tpm-crb-test.c +2 -2
@@ -26,7 +26,7 @@ uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;static void tpm_crb_test (const void *data) { -const TestState *s = data; +const TPMTestState *s = data;uint32_t intfid =readl (TPM_CRB_ADDR_BASE +A_CRB_INTF_ID );uint32_t csize =readl (TPM_CRB_ADDR_BASE +A_CRB_CTRL_CMD_SIZE );uint64_t caddr =readq (TPM_CRB_ADDR_BASE +A_CRB_CTRL_CMD_LADDR );
@@ -145,7 +145,7 @@ int main(int argc, char **argv)int ret;char *args, *tmp_path =g_dir_make_tmp ("qemu-tpm-crb-test.XXXXXX" ,NULL );GThread *thread; -TestState test; +TPMTestState test;module_call_init (MODULE_INIT_QOM );g_test_init (&argc, &argv,NULL );
tests/qtest/tpm-emu.c +3 -3
@@ -18,7 +18,7 @@#include "qapi/error.h" #include "tpm-emu.h" -void tpm_emu_test_wait_cond (TestState *s) +void tpm_emu_test_wait_cond (TPMTestState *s) {gint64 end_time =g_get_monotonic_time () +5 *G_TIME_SPAN_SECOND ;
@@ -36,7 +36,7 @@ void tpm_emu_test_wait_cond(TestState *s)static void *tpm_emu_tpm_thread (void *data) { -TestState *s = data; +TPMTestState *s = data;QIOChannel *ioc = s->tpm_ioc; s->tpm_msg = g_new(struct tpm_hdr, 1);
@@ -71,7 +71,7 @@ static void *tpm_emu_tpm_thread(void *data)void *tpm_emu_ctrl_thread (void *data) { -TestState *s = data; +TPMTestState *s = data;QIOChannelSocket *lioc =qio_channel_socket_new ();QIOChannel *ioc;
tests/qtest/tpm-emu.h +3 -3
@@ -26,7 +26,7 @@ struct tpm_hdr {char buffer[]; }QEMU_PACKED ; -typedef struct TestState { +typedef struct TPMTestState { GMutex data_mutex; GCond data_cond; bool data_cond_signal;
@@ -34,9 +34,9 @@ typedef struct TestState {QIOChannel *tpm_ioc;GThread *emu_tpm_thread; struct tpm_hdr *tpm_msg; -} TestState; +} TPMTestState; -void tpm_emu_test_wait_cond (TestState *s); +void tpm_emu_test_wait_cond (TPMTestState *s);void *tpm_emu_ctrl_thread (void *data);#endif /* TESTS_TPM_EMU_H */
tests/qtest/tpm-tis-device-test.c +1 -1
@@ -33,7 +33,7 @@ int main(int argc, char **argv) {char *tmp_path =g_dir_make_tmp ("qemu-tpm-tis-device-test.XXXXXX" ,NULL );GThread *thread; -TestState test; +TPMTestState test;char *args;int ret;
tests/qtest/tpm-tis-test.c +1 -1
@@ -29,7 +29,7 @@ int main(int argc, char **argv)int ret;char *args, *tmp_path =g_dir_make_tmp ("qemu-tpm-tis-test.XXXXXX" ,NULL );GThread *thread; -TestState test; +TPMTestState test;module_call_init (MODULE_INIT_QOM );g_test_init (&argc, &argv,NULL );
tests/qtest/tpm-tis-util.c +1 -1
@@ -373,7 +373,7 @@ void tpm_tis_test_check_access_reg_release(const void *data)*/ void tpm_tis_test_check_transmit (const void *data) { -const TestState *s = data; +const TPMTestState *s = data;uint8_t access;uint32_t sts;uint16_t bcount;
Signature · 1 line
2.31.1
PATCH v4 2/10 tests: Add tpm_version field to TPMTestState and fill it
In reply to Stefan Berger---
v3:
- Added enum TPMVersion for when CONFIG_TPM is not defined
--- tests/qtest/bios-tables-test.c | 5 +++-- tests/qtest/tpm-crb-test.c | 1 + tests/qtest/tpm-emu.c | 13 ++++++++++--- tests/qtest/tpm-emu.h | 8 ++++++++ tests/qtest/tpm-tis-device-test.c | 1 + tests/qtest/tpm-tis-test.c | 1 + 6 files changed, 24 insertions(+), 5 deletions(-)
tests/qtest/bios-tables-test.c +3 -2
@@ -1092,7 +1092,7 @@ static void test_acpi_piix4_tcg_numamem(void)uint64_t tpm_tis_base_addr;static void test_acpi_tcg_tpm (const char *machine,const char *tpm_if, -uint64_t base) +uint64_t base,enum TPMVersion tpm_version) {#ifdef CONFIG_TPM gchar *tmp_dir_name = g_strdup_printf("qemu-test_acpi_%s_tcg_%s.XXXXXX",
@@ -1113,6 +1113,7 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,g_mutex_init (&test.data_mutex);g_cond_init (&test.data_cond); test.data_cond_signal = false; + test.tpm_version = tpm_version; thread =g_thread_new (NULL , tpm_emu_ctrl_thread, &test);tpm_emu_test_wait_cond (&test);
@@ -1145,7 +1146,7 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,static void test_acpi_q35_tcg_tpm_tis (void ) { -test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ); +test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_2_0 ); }static void test_acpi_tcg_dimm_pxm (const char *machine)
tests/qtest/tpm-crb-test.c +1 -0
@@ -156,6 +156,7 @@ int main(int argc, char **argv)g_mutex_init (&test.data_mutex);g_cond_init (&test.data_cond); test.data_cond_signal = false; + test.tpm_version =TPM_VERSION_2_0 ; thread =g_thread_new (NULL , tpm_emu_ctrl_thread, &test);tpm_emu_test_wait_cond (&test);
tests/qtest/tpm-emu.c +10 -3
@@ -56,9 +56,16 @@ static void *tpm_emu_tpm_thread(void *data) s->tpm_msg->code =be32_to_cpu (s->tpm_msg->code);/* reply error */ - s->tpm_msg->tag =cpu_to_be16 (TPM2_ST_NO_SESSIONS ); - s->tpm_msg->len =cpu_to_be32 (sizeof (struct tpm_hdr )); - s->tpm_msg->code =cpu_to_be32 (TPM_RC_FAILURE ); +switch (s->tpm_version) { +case TPM_VERSION_2_0 : + s->tpm_msg->tag =cpu_to_be16 (TPM2_ST_NO_SESSIONS ); + s->tpm_msg->len =cpu_to_be32 (sizeof (struct tpm_hdr )); + s->tpm_msg->code =cpu_to_be32 (TPM_RC_FAILURE ); +break ; +default : +g_debug ("unsupport TPM version %u" , s->tpm_version); +g_assert_not_reached (); + }qio_channel_write (ioc, (char *)s->tpm_msg,be32_to_cpu (s->tpm_msg->len), &error_abort); }
tests/qtest/tpm-emu.h +8 -0
@@ -18,6 +18,7 @@#include "qemu/sockets.h" #include "io/channel.h" +#include "sysemu/tpm.h" struct tpm_hdr {uint16_t tag;
@@ -26,6 +27,12 @@ struct tpm_hdr {char buffer[]; }QEMU_PACKED ; +#ifndef CONFIG_TPM +enum TPMVersion { +TPM_VERSION_2_0 =2 , +}; +#endif + typedef struct TPMTestState { GMutex data_mutex; GCond data_cond;
@@ -34,6 +41,7 @@ typedef struct TPMTestState {QIOChannel *tpm_ioc;GThread *emu_tpm_thread;struct tpm_hdr *tpm_msg; +enum TPMVersion tpm_version; } TPMTestState;void tpm_emu_test_wait_cond (TPMTestState *s);
tests/qtest/tpm-tis-device-test.c +1 -0
@@ -46,6 +46,7 @@ int main(int argc, char **argv)g_mutex_init (&test.data_mutex);g_cond_init (&test.data_cond); test.data_cond_signal = false; + test.tpm_version =TPM_VERSION_2_0 ; thread =g_thread_new (NULL , tpm_emu_ctrl_thread, &test);tpm_emu_test_wait_cond (&test);
tests/qtest/tpm-tis-test.c +1 -0
@@ -40,6 +40,7 @@ int main(int argc, char **argv)g_mutex_init (&test.data_mutex);g_cond_init (&test.data_cond); test.data_cond_signal = false; + test.tpm_version =TPM_VERSION_2_0 ; thread =g_thread_new (NULL , tpm_emu_ctrl_thread, &test);tpm_emu_test_wait_cond (&test);
Signature · 1 line
2.31.1
PATCH v4 3/10 tests: acpi: Prepare for renaming of TPM2 related ACPI files
In reply to Stefan Berger--- tests/data/acpi/q35/DSDT.tis.tpm2 | 0 tests/data/acpi/q35/TPM2.tis.tpm2 | 0 tests/qtest/bios-tables-test-allowed-diff.h | 2 ++ 3 files changed, 2 insertions(+) create mode 100644 tests/data/acpi/q35/DSDT.tis.tpm2 create mode 100644 tests/data/acpi/q35/TPM2.tis.tpm2
tests/data/acpi/q35/DSDT.tis.tpm2 new file +0 -0
tests/data/acpi/q35/TPM2.tis.tpm2 new file +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
@@ -1 +1,3 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/q35/DSDT.tis.tpm2" , +"tests/data/acpi/q35/TPM2.tis.tpm2",
Signature · 1 line
2.31.1
PATCH v4 4/10 tests: Add suffix 'tpm2' or 'tpm12' to ACPI table files
In reply to Stefan Berger--- tests/qtest/bios-tables-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/bios-tables-test.c +2 -1
@@ -1101,7 +1101,8 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,TPMTestState test;test_data data;GThread *thread; -char *args, *variant =g_strdup_printf (".%s" , tpm_if); +const char *suffix = tpm_version ==TPM_VERSION_2_0 ?"tpm2" :"tpm12" ; +char *args, *variant =g_strdup_printf (".%s.%s" , tpm_if, suffix); tpm_tis_base_addr = base;
Signature · 1 line
2.31.1
PATCH v4 5/10 tests: acpi: tpm2: Add the renamed ACPI files and drop old ones
In reply to Stefan Berger--- tests/data/acpi/q35/DSDT.tis | Bin 8465 -> 0 bytes tests/data/acpi/q35/DSDT.tis.tpm2 | Bin 0 -> 8465 bytes tests/data/acpi/q35/TPM2.tis | Bin 76 -> 0 bytes tests/data/acpi/q35/TPM2.tis.tpm2 | Bin 0 -> 76 bytes tests/qtest/bios-tables-test-allowed-diff.h | 2 -- 5 files changed, 2 deletions(-) delete mode 100644 tests/data/acpi/q35/DSDT.tis delete mode 100644 tests/data/acpi/q35/TPM2.tis
tests/data/acpi/q35/DSDT.tis deleted binary +0 -0
tests/data/acpi/q35/DSDT.tis.tpm2 binary +0 -0
tests/data/acpi/q35/TPM2.tis deleted binary +0 -0
tests/data/acpi/q35/TPM2.tis.tpm2 binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
@@ -1,3 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/q35/DSDT.tis.tpm2" , -"tests/data/acpi/q35/TPM2.tis.tpm2",
Signature · 1 line
2.31.1
PATCH v4 6/10 tests: tpm: Create TPM 1.2 response in TPM emulator
In reply to Stefan Berger---
v3:
- Added TPM_VERSION_1_2 enum for when CONFIG_TPM is not defined
--- tests/qtest/tpm-emu.c | 5 +++++ tests/qtest/tpm-emu.h | 4 ++++ 2 files changed, 9 insertions(+)
tests/qtest/tpm-emu.c +5 -0
@@ -62,6 +62,11 @@ static void *tpm_emu_tpm_thread(void *data) s->tpm_msg->len =cpu_to_be32 (sizeof (struct tpm_hdr )); s->tpm_msg->code =cpu_to_be32 (TPM_RC_FAILURE );break ; +case TPM_VERSION_1_2 : + s->tpm_msg->tag =cpu_to_be16 (TPM_TAG_RSP_COMMAND ); + s->tpm_msg->len =cpu_to_be32 (sizeof (struct tpm_hdr )); + s->tpm_msg->code =cpu_to_be32 (TPM_FAIL ); +break ;default :g_debug ("unsupport TPM version %u" , s->tpm_version);g_assert_not_reached ();
tests/qtest/tpm-emu.h +4 -0
@@ -16,6 +16,9 @@#define TPM_RC_FAILURE 0x101#define TPM2_ST_NO_SESSIONS 0x8001 +#define TPM_FAIL 9 +#define TPM_TAG_RSP_COMMAND 0xc4 +#include "qemu/sockets.h" #include "io/channel.h" #include "sysemu/tpm.h"
@@ -29,6 +32,7 @@ struct tpm_hdr {#ifndef CONFIG_TPM enum TPMVersion { +TPM_VERSION_1_2 =1 ,TPM_VERSION_2_0 =2 , };#endif
Signature · 1 line
2.31.1
PATCH v4 7/10 tests: acpi: prepare for new TPM 1.2 related tables
In reply to Stefan Berger--- tests/data/acpi/q35/DSDT.tis.tpm12 | 0 tests/data/acpi/q35/TCPA.tis.tpm12 | 0 tests/qtest/bios-tables-test-allowed-diff.h | 2 ++ 3 files changed, 2 insertions(+) create mode 100644 tests/data/acpi/q35/DSDT.tis.tpm12 create mode 100644 tests/data/acpi/q35/TCPA.tis.tpm12
tests/data/acpi/q35/DSDT.tis.tpm12 new file +0 -0
tests/data/acpi/q35/TCPA.tis.tpm12 new file +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
@@ -1 +1,3 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/q35/DSDT.tis.tpm12" , +"tests/data/acpi/q35/TCPA.tis.tpm12",
Signature · 1 line
2.31.1
PATCH v4 8/10 tests: acpi: Add test cases for TPM 1.2 with TCPA table
In reply to Stefan Berger--- tests/qtest/bios-tables-test.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tests/qtest/bios-tables-test.c +8 -2
@@ -1145,11 +1145,16 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,#endif } -static void test_acpi_q35_tcg_tpm_tis (void ) +static void test_acpi_q35_tcg_tpm2_tis (void ) {test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_2_0 ); } +static void test_acpi_q35_tcg_tpm12_tis (void ) +{ +test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_1_2 ); +} +static void test_acpi_tcg_dimm_pxm (const char *machine) {test_data data;
@@ -1518,7 +1523,8 @@ int main(int argc, char *argv[])return ret; }qtest_add_func ("acpi/q35/oem-fields" , test_acpi_oem_fields_q35); -qtest_add_func ("acpi/q35/tpm-tis" , test_acpi_q35_tcg_tpm_tis); +qtest_add_func ("acpi/q35/tpm2-tis" , test_acpi_q35_tcg_tpm2_tis); +qtest_add_func ("acpi/q35/tpm12-tis" , test_acpi_q35_tcg_tpm12_tis);qtest_add_func ("acpi/piix4" , test_acpi_piix4_tcg);qtest_add_func ("acpi/oem-fields" , test_acpi_oem_fields_pc);qtest_add_func ("acpi/piix4/bridge" , test_acpi_piix4_tcg_bridge);
Signature · 1 line
2.31.1
PATCH v4 9/10 tests: acpi: tpm1.2: Add expected TPM 1.2 ACPI blobs
In reply to Stefan BergerThe TCPA.tis.tpm12 file contains the following:
[000h 0000 4] Signature : "TCPA" [Trusted Computing Platform Alliance table] [004h 0004 4] Table Length : 00000032 [008h 0008 1] Revision : 02 [009h 0009 1] Checksum : 32 [00Ah 0010 6] Oem ID : "BOCHS " [010h 0016 8] Oem Table ID : "BXPC " [018h 0024 4] Oem Revision : 00000001 [01Ch 0028 4] Asl Compiler ID : "BXPC" [020h 0032 4] Asl Compiler Revision : 00000001
[024h 0036 2] Platform Class : 0000 [026h 0038 4] Min Event Log Length : 00010000 [02Ah 0042 8] Event Log Address : 0000000007FF0000
--- tests/data/acpi/q35/DSDT.tis.tpm12 | Bin 0 -> 8465 bytes tests/data/acpi/q35/TCPA.tis.tpm12 | Bin 0 -> 50 bytes tests/qtest/bios-tables-test-allowed-diff.h | 2 -- 3 files changed, 2 deletions(-)
tests/data/acpi/q35/DSDT.tis.tpm12 binary +0 -0
tests/data/acpi/q35/TCPA.tis.tpm12 binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
@@ -1,3 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/q35/DSDT.tis.tpm12" , -"tests/data/acpi/q35/TCPA.tis.tpm12",
Signature · 1 line
2.31.1
PATCH v4 10/10 tests: Use QMP to check whether a TPM device model is available
In reply to Stefan BergerUse QMP to check whether a given TPM device model is available and if it is not the case then skip a test that requires it.
--- tests/qtest/bios-tables-test.c | 14 +++++++------ tests/qtest/tpm-emu.c | 37 ++++++++++++++++++++++++++++++++++ tests/qtest/tpm-emu.h | 2 ++ 3 files changed, 47 insertions(+), 6 deletions(-)
tests/qtest/bios-tables-test.c +8 -6
@@ -1094,7 +1094,6 @@ uint64_t tpm_tis_base_addr;static void test_acpi_tcg_tpm (const char *machine,const char *tpm_if,uint64_t base,enum TPMVersion tpm_version) { -#ifdef CONFIG_TPM gchar *tmp_dir_name =g_strdup_printf ("qemu-test_acpi_%s_tcg_%s.XXXXXX" , machine, tpm_if);char *tmp_path =g_dir_make_tmp (tmp_dir_name,NULL );
@@ -1140,19 +1139,22 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,g_free (tmp_dir_name);g_free (args);free_test_data (&data); -#else -g_test_skip ("TPM disabled" ); -#endif }static void test_acpi_q35_tcg_tpm2_tis (void ) { -test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_2_0 ); +if (!tpm_model_is_available ("-machine q35" ,"tpm-tis" )) +g_test_skip ("TPM disabled" ); +else +test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_2_0 ); }static void test_acpi_q35_tcg_tpm12_tis (void ) { -test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_1_2 ); +if (!tpm_model_is_available ("-machine q35" ,"tpm-tis" )) +g_test_skip ("TPM disabled" ); +else +test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_1_2 ); }static void test_acpi_tcg_dimm_pxm (const char *machine)
tests/qtest/tpm-emu.c +37 -0
@@ -16,6 +16,8 @@#include "backends/tpm/tpm_ioctl.h" #include "io/channel-socket.h" #include "qapi/error.h" +#include "qapi/qmp/qlist.h" +#include "qapi/qmp/qstring.h" #include "tpm-emu.h" void tpm_emu_test_wait_cond (TPMTestState *s)
@@ -192,3 +194,38 @@ void *tpm_emu_ctrl_thread(void *data)object_unref (OBJECT (lioc));return NULL ; } + +bool tpm_model_is_available (const char *args,const char *tpm_if) +{ +QTestState *qts; +QDict *rsp_tpm; +bool ret = false; + + qts =qtest_init (args); +if (!qts) +return false; + + rsp_tpm =qtest_qmp (qts,"{ 'execute': 'query-tpm'}" ); +if (!qdict_haskey (rsp_tpm,"error" )) { +QDict *rsp_models =qtest_qmp (qts, +"{ 'execute': 'query-tpm-models'}" ); +if (qdict_haskey (rsp_models,"return" )) { +QList *models =qdict_get_qlist (rsp_models,"return" ); +QListEntry *e; + + QLIST_FOREACH_ENTRY(models, e) { +QString *s =qobject_to (QString,qlist_entry_obj (e)); +const char *ename =qstring_get_str (s); +if (!strcmp (ename, tpm_if)) { + ret = true; + } + } +qobject_unref (models); + } +qobject_unref (rsp_models); + } +qobject_unref (rsp_tpm); +qtest_quit (qts); + +return ret; +}
tests/qtest/tpm-emu.h +2 -0
@@ -22,6 +22,7 @@#include "qemu/sockets.h" #include "io/channel.h" #include "sysemu/tpm.h" +#include "libqos/libqtest.h" struct tpm_hdr {uint16_t tag;
@@ -50,5 +51,6 @@ typedef struct TPMTestState {void tpm_emu_test_wait_cond (TPMTestState *s);void *tpm_emu_ctrl_thread (void *data); +bool tpm_model_is_available (const char *args,const char *tpm_if);#endif /* TESTS_TPM_EMU_H */
Signature · 1 line
2.31.1
Re: [PATCH v4 10/10] tests: Use QMP to check whether a TPM device model is available
Quoted 11 lines · Stefan Berger
Use QMP to check whether a given TPM device model is available and if it is not the case then skip a test that requires it.
Signed-off-by Stefan Berger <[email protected]>tests/qtest/tpm-emu.c +6
-0+ rsp_tpm =qtest_qmp (qts,"{ 'execute': 'query-tpm'}" ); +if (!qdict_haskey (rsp_tpm,"error" )) { +QDict *rsp_models =qtest_qmp (qts, +"{ 'execute': 'query-tpm-models'}" ); +if (qdict_haskey (rsp_models,"return" )) { +QList *models =qdict_get_qlist (rsp_models,"return" );
tests/qtest/tpm-emu.c void *tpm_emu_ctrl_thread(void *data) · line 223
Quoted 10 lines
tests/qtest/tpm-emu.c +10
-0+QListEntry *e; + + QLIST_FOREACH_ENTRY(models, e) { +QString *s =qobject_to (QString,qlist_entry_obj (e)); +const char *ename =qstring_get_str (s); +if (!strcmp (ename, tpm_if)) { + ret = true; + } + } +qobject_unref (models);
I think this unref was too much. It tipped off s390x but none other (?).
https://travis-ci.com/github/stefanberger/qemu-tpm/builds/232529861
I fixed this in v5 (https://travis-ci.com/github/stefanberger/qemu-tpm)
I think this is generally the right approach for this test case, isn't it?
Quoted 27 lines
tests/qtest/tpm-emu.c +8
-0+ } +qobject_unref (rsp_models); + } +qobject_unref (rsp_tpm); +qtest_quit (qts); + +return ret; +}tests/qtest/tpm-emu.h +2
-0@@ -22,6 +22,7 @@#include "qemu/sockets.h" #include "io/channel.h" #include "sysemu/tpm.h" +#include "libqos/libqtest.h" struct tpm_hdr {uint16_t tag;@@ -50,5 +51,6 @@ typedef struct TPMTestState {void tpm_emu_test_wait_cond (TPMTestState *s);void *tpm_emu_ctrl_thread (void *data); +bool tpm_model_is_available (const char *args,const char *tpm_if);#endif /* TESTS_TPM_EMU_H */
Re: [PATCH v4 10/10] tests: Use QMP to check whether a TPM device model is available
In reply to Stefan BergerHi Stefan,
Quoted 25 lines · Stefan Berger
Use QMP to check whether a given TPM device model is available and if it is not the case then skip a test that requires it.
Signed-off-by Stefan Berger <[email protected]>--- tests/qtest/bios-tables-test.c | 14 +++++++------ tests/qtest/tpm-emu.c | 37 ++++++++++++++++++++++++++++++++++ tests/qtest/tpm-emu.h | 2 ++ 3 files changed, 47 insertions(+), 6 deletions(-)tests/qtest/bios-tables-test.c +0
-1@@ -1094,7 +1094,6 @@ uint64_t tpm_tis_base_addr;static void test_acpi_tcg_tpm (const char *machine,const char *tpm_if,uint64_t base,enum TPMVersion tpm_version) { -#ifdef CONFIG_TPM gchar *tmp_dir_name =g_strdup_printf ("qemu-test_acpi_%s_tcg_%s.XXXXXX" , machine, tpm_if);char *tmp_path =g_dir_make_tmp (tmp_dir_name,NULL );@@ -1140,19 +1139,22 @@ static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if,g_free (tmp_dir_name);g_free (args);
tests/qtest/bios-tables-test.c static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if, · line 1146
Quoted 10 lines
tests/qtest/bios-tables-test.c +1
-4free_test_data (&data); -#else -g_test_skip ("TPM disabled" ); -#endif }static void test_acpi_q35_tcg_tpm2_tis (void ) { -test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_2_0 ); +if (!tpm_model_is_available ("-machine q35" ,"tpm-tis" ))
Style requires { }
tests/qtest/bios-tables-test.c static void test_acpi_tcg_tpm(const char *machine, const char *tpm_if, · line 1155
Quoted 8 lines
tests/qtest/bios-tables-test.c +3
-1+g_test_skip ("TPM disabled" ); + else + test_acpi_tcg_tpm("q35", "tis", 0xFED40000, TPM_VERSION_2_0); }static void test_acpi_q35_tcg_tpm12_tis (void ) { -test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_1_2 );
Can you call this once in main() (before registering the tests) and place this patch before patch #8 "tests: acpi: Add test cases for TPM 1.2 with TCPA table" of this series? Otherwise looks good (beside the unref you already mentioned).
Quoted 59 lines
tests/qtest/bios-tables-test.c +4
-0+if (!tpm_model_is_available ("-machine q35" ,"tpm-tis" )) +g_test_skip ("TPM disabled" ); +else +test_acpi_tcg_tpm ("q35" ,"tis" ,0xFED40000 ,TPM_VERSION_1_2 ); }static void test_acpi_tcg_dimm_pxm (const char *machine)tests/qtest/tpm-emu.c +37
-0@@ -16,6 +16,8 @@#include "backends/tpm/tpm_ioctl.h" #include "io/channel-socket.h" #include "qapi/error.h" +#include "qapi/qmp/qlist.h" +#include "qapi/qmp/qstring.h" #include "tpm-emu.h" void tpm_emu_test_wait_cond (TPMTestState *s)@@ -192,3 +194,38 @@ void *tpm_emu_ctrl_thread(void *data)object_unref (OBJECT (lioc));return NULL ; } + +bool tpm_model_is_available (const char *args,const char *tpm_if) +{ +QTestState *qts; +QDict *rsp_tpm; +bool ret = false; + + qts =qtest_init (args); +if (!qts) +return false; + + rsp_tpm =qtest_qmp (qts,"{ 'execute': 'query-tpm'}" ); +if (!qdict_haskey (rsp_tpm,"error" )) { +QDict *rsp_models =qtest_qmp (qts, +"{ 'execute': 'query-tpm-models'}" ); +if (qdict_haskey (rsp_models,"return" )) { +QList *models =qdict_get_qlist (rsp_models,"return" ); +QListEntry *e; + + QLIST_FOREACH_ENTRY(models, e) { +QString *s =qobject_to (QString,qlist_entry_obj (e)); +const char *ename =qstring_get_str (s); +if (!strcmp (ename, tpm_if)) { + ret = true; + } + } +qobject_unref (models); + } +qobject_unref (rsp_models); + } +qobject_unref (rsp_tpm); +qtest_quit (qts); + +return ret; +}
Quoted 1 line · Stefan Berger
This series of patches adds test case for TPM 1.2 ACPI tables.
Pls feel free to merge through tpm tree.
Quoted 47 lines
Stefan
v4:
- Added patch 10 that checks for availability of a TPM device model using QMP and if not available skips the ACPI table testv3:
- Define enum TPMVersion for whenCONFIG_TPMis not defined affected patches 2 and 6v2:
- Proper handling of renaming of files holding expected ACPI dataStefan Berger (10):
tests: Rename TestState to TPMTestState
tests: Addtpm_versionfield to TPMTestState and fill it
tests: acpi: Prepare for renaming of TPM2 related ACPI files
tests: Add suffix 'tpm2' or 'tpm12' to ACPI table files
tests: acpi: tpm2: Add the renamed ACPI files and drop old ones
tests: tpm: Create TPM 1.2 response in TPM emulator
tests: acpi: prepare for new TPM 1.2 related tables
tests: acpi: Add test cases for TPM 1.2 with TCPA table
tests: acpi: tpm1.2: Add expected TPM 1.2 ACPI blobs
tests: Use QMP to check whether a TPM device model is availabletests/data/acpi/q35/DSDT.tis.tpm12 | Bin 0 -> 8465 bytes .../data/acpi/q35/{DSDT.tis => DSDT.tis.tpm2} | Bin tests/data/acpi/q35/TCPA.tis.tpm12 | Bin 0 -> 50 bytes .../data/acpi/q35/{TPM2.tis => TPM2.tis.tpm2} | Bin tests/qtest/bios-tables-test.c | 30 ++++++--- tests/qtest/tpm-crb-test.c | 5 +- tests/qtest/tpm-emu.c | 61 ++++++++++++++++-- tests/qtest/tpm-emu.h | 20 +++++- tests/qtest/tpm-tis-device-test.c | 3 +- tests/qtest/tpm-tis-test.c | 3 +- tests/qtest/tpm-tis-util.c | 2 +- 11 files changed, 100 insertions(+), 24 deletions(-) create mode 100644 tests/data/acpi/q35/DSDT.tis.tpm12 rename tests/data/acpi/q35/{DSDT.tis => DSDT.tis.tpm2} (100%) create mode 100644 tests/data/acpi/q35/TCPA.tis.tpm12 rename tests/data/acpi/q35/{TPM2.tis => TPM2.tis.tpm2} (100%)Signature · 1 line
2.31.1
Quoted 6 lines · Michael S. Tsirkin
Quoted 1 line · Stefan Berger
This series of patches adds test case for TPM 1.2 ACPI tables.
Pls feel free to merge through tpm tree.
Thanks. I will have to post a v5 since this one had issues on s390x.
Stefan
Quoted 48 lines
Quoted 48 lines
Stefan
v4:
- Added patch 10 that checks for availability of a TPM device model using QMP and if not available skips the ACPI table testv3:
- Define enum TPMVersion for whenCONFIG_TPMis not defined affected patches 2 and 6v2:
- Proper handling of renaming of files holding expected ACPI dataStefan Berger (10):
tests: Rename TestState to TPMTestState
tests: Addtpm_versionfield to TPMTestState and fill it
tests: acpi: Prepare for renaming of TPM2 related ACPI files
tests: Add suffix 'tpm2' or 'tpm12' to ACPI table files
tests: acpi: tpm2: Add the renamed ACPI files and drop old ones
tests: tpm: Create TPM 1.2 response in TPM emulator
tests: acpi: prepare for new TPM 1.2 related tables
tests: acpi: Add test cases for TPM 1.2 with TCPA table
tests: acpi: tpm1.2: Add expected TPM 1.2 ACPI blobs
tests: Use QMP to check whether a TPM device model is availabletests/data/acpi/q35/DSDT.tis.tpm12 | Bin 0 -> 8465 bytes .../data/acpi/q35/{DSDT.tis => DSDT.tis.tpm2} | Bin tests/data/acpi/q35/TCPA.tis.tpm12 | Bin 0 -> 50 bytes .../data/acpi/q35/{TPM2.tis => TPM2.tis.tpm2} | Bin tests/qtest/bios-tables-test.c | 30 ++++++--- tests/qtest/tpm-crb-test.c | 5 +- tests/qtest/tpm-emu.c | 61 ++++++++++++++++-- tests/qtest/tpm-emu.h | 20 +++++- tests/qtest/tpm-tis-device-test.c | 3 +- tests/qtest/tpm-tis-test.c | 3 +- tests/qtest/tpm-tis-util.c | 2 +- 11 files changed, 100 insertions(+), 24 deletions(-)create mode 100644 tests/data/acpi/q35/DSDT.tis.tpm12 rename tests/data/acpi/q35/{DSDT.tis => DSDT.tis.tpm2} (100%) create mode 100644 tests/data/acpi/q35/TCPA.tis.tpm12 rename tests/data/acpi/q35/{TPM2.tis => TPM2.tis.tpm2} (100%)
Signature · 1 line
2.31.1