From 92a18bb5676ea9a3a73e2d2ce197a2655ef4d3b5 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 9 Jul 2018 15:44:52 +0200 Subject: [PATCH] tests: qemu: Use qmp schema data from the qemucapabilities test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add helpers that allow using the latest schema from the replies from an actual qemu which are recorded for the purpose of the qemucapabilities test instead of an unsynced copy stored in qemuqapischema.json. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tests/qemumonitorjsontest.c | 13 +++++--- tests/testutilsqemuschema.c | 65 +++++++++++++++++++++++++++++++++++-- tests/testutilsqemuschema.h | 3 ++ 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index c85bcbfc3b..9039cef423 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2860,7 +2860,8 @@ mymain(void) virQEMUDriver driver; testQemuMonitorJSONSimpleFuncData simpleFunc; struct testQAPISchemaData qapiData; - char *metaschema = NULL; + virJSONValuePtr metaschema = NULL; + char *metaschemastr = NULL; #if !WITH_YAJL fputs("libvirt not compiled with JSON support, skipping this test\n", stderr); @@ -3062,20 +3063,22 @@ mymain(void) DO_TEST_QAPI_SCHEMA("alternate 2", "blockdev-add/arg-type", false, "{\"driver\":\"qcow2\",\"file\": 1234}"); - if (!(metaschema = virTestLoadFilePath("qemuqapischema.json", NULL))) { - VIR_TEST_VERBOSE("failed to load qapi schema\n"); + if (!(metaschema = testQEMUSchemaGetLatest()) || + !(metaschemastr = virJSONValueToString(metaschema, false))) { + VIR_TEST_VERBOSE("failed to load latest qapi schema\n"); ret = -1; goto cleanup; } DO_TEST_QAPI_SCHEMA("schema-meta", "query-qmp-schema/ret-type", true, - metaschema); + metaschemastr); #undef DO_TEST_QAPI_SCHEMA cleanup: - VIR_FREE(metaschema); + VIR_FREE(metaschemastr); + virJSONValueFree(metaschema); virHashFree(qapiData.schema); qemuTestDriverFree(&driver); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 46bbc4f1e5..1cec5265e1 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -17,6 +17,7 @@ */ #include #include "testutils.h" +#include "testutilsqemu.h" #include "testutilsqemuschema.h" #include "qemu/qemu_qapi.h" @@ -516,13 +517,71 @@ testQEMUSchemaValidate(virJSONValuePtr obj, } +/** + * testQEMUSchemaGetLatest: + * + * Returns the schema data as the qemu monitor would reply from the latest + * replies file used for qemucapabilitiestest for the x86_64 architecture. + */ +virJSONValuePtr +testQEMUSchemaGetLatest(void) +{ + char *capsLatestFile = NULL; + char *capsLatest = NULL; + char *schemaReply; + char *end; + virJSONValuePtr reply = NULL; + virJSONValuePtr schema = NULL; + + if (!(capsLatestFile = testQemuGetLatestCapsForArch(abs_srcdir "/qemucapabilitiesdata", + "x86_64", "replies"))) { + VIR_TEST_VERBOSE("failed to find latest caps replies\n"); + return NULL; + } + + VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile); + + if (virTestLoadFile(capsLatestFile, &capsLatest) < 0) + goto cleanup; + + if (!(schemaReply = strstr(capsLatest, "\"execute\": \"query-qmp-schema\"")) || + !(schemaReply = strstr(schemaReply, "\n\n")) || + !(end = strstr(schemaReply + 2, "\n\n"))) { + VIR_TEST_VERBOSE("failed to find reply to 'query-qmp-schema' in '%s'\n", + capsLatestFile); + goto cleanup; + } + + schemaReply += 2; + *end = '\0'; + + if (!(reply = virJSONValueFromString(schemaReply))) { + VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%s'\n", + capsLatestFile); + goto cleanup; + } + + if (!(schema = virJSONValueObjectStealArray(reply, "return"))) { + VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'\n", + capsLatestFile); + goto cleanup; + } + + cleanup: + VIR_FREE(capsLatestFile); + VIR_FREE(capsLatest); + virJSONValueFree(reply); + return schema; +} + + virHashTablePtr testQEMUSchemaLoad(void) { - virJSONValuePtr schemajson; + virJSONValuePtr schema; - if (!(schemajson = virTestLoadFileJSON("qemuqapischema.json", NULL))) + if (!(schema = testQEMUSchemaGetLatest())) return NULL; - return virQEMUQAPISchemaConvert(schemajson); + return virQEMUQAPISchemaConvert(schema); } diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index cb383db174..c69435f420 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -26,5 +26,8 @@ testQEMUSchemaValidate(virJSONValuePtr obj, virHashTablePtr schema, virBufferPtr debug); +virJSONValuePtr +testQEMUSchemaGetLatest(void); + virHashTablePtr testQEMUSchemaLoad(void);