On 7/12/21 4:47 PM, Stefan Berger wrote:
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 <stef...@linux.ibm.com>
+ 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);
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?
+ }
+ qobject_unref(rsp_models);
+ }
+ qobject_unref(rsp_tpm);
+ qtest_quit(qts);
+
+ return ret;
+}
diff --git a/tests/qtest/tpm-emu.h b/tests/qtest/tpm-emu.h
index fcb5d7a1d6..c33d99af37 100644
--- a/tests/qtest/tpm-emu.h
+++ b/tests/qtest/tpm-emu.h
@@ -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 */