提交 92a18bb5 编写于 作者: P Peter Krempa

tests: qemu: Use qmp schema data from the qemucapabilities test

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 ad8da38e
......@@ -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;
......
......@@ -17,6 +17,7 @@
*/
#include <config.h>
#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);
}
......@@ -26,5 +26,8 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
virHashTablePtr schema,
virBufferPtr debug);
virJSONValuePtr
testQEMUSchemaGetLatest(void);
virHashTablePtr
testQEMUSchemaLoad(void);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册