mirror of https://gitee.com/openkylin/qemu.git
tests: Use QMP to check whether a TPM device model is available
Use QMP to check whether a given TPM device model is available and if it is not the case then do not register the tests that require it. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-id: 20210802215246.1433175-9-stefanb@linux.ibm.com
This commit is contained in:
parent
343776a685
commit
58edc32cfc
|
@ -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,9 +1139,6 @@ 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_tpm_tis(void)
|
||||
|
@ -1518,7 +1514,9 @@ 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);
|
||||
if (tpm_model_is_available("-machine q35", "tpm-tis")) {
|
||||
qtest_add_func("acpi/q35/tpm2-tis", test_acpi_q35_tcg_tpm_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);
|
||||
|
|
|
@ -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,39 @@ 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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
qobject_unref(rsp_models);
|
||||
}
|
||||
qobject_unref(rsp_tpm);
|
||||
qtest_quit(qts);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue