aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest/tpm-emu.c
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.ibm.com>2021-08-02 17:52:44 -0400
committerStefan Berger <stefanb@linux.ibm.com>2021-08-31 17:33:12 -0400
commit58edc32cfc796d56336a283aace5bdb5de25dc80 (patch)
treea776a408895a8fd1090becc37570e32d26217cdd /tests/qtest/tpm-emu.c
parent343776a68528a132ff9068bb0731f584b38ff2ea (diff)
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
Diffstat (limited to 'tests/qtest/tpm-emu.c')
-rw-r--r--tests/qtest/tpm-emu.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c
index 32c704194b..2994d1cf42 100644
--- a/tests/qtest/tpm-emu.c
+++ b/tests/qtest/tpm-emu.c
@@ -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;
+}