From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL v2 02/47] tests/qmp-test: Add generic, basic test of query commands
Date: Fri, 1 Sep 2017 17:37:13 +0200 [thread overview]
Message-ID: <20170901153758.8628-3-armbru@redhat.com> (raw)
In-Reply-To: <20170901153758.8628-1-armbru@redhat.com>
A command is a query if it has no side effect and yields a result.
Such commands are typically named query-FOO, but there are exceptions.
The basic idea is to find candidates with query-qmp-schema, filter out
the ones that aren't queries with an explicit blacklist, and test the
remaining ones against a QEMU with no special arguments.
The current blacklist is just add-fd.
The test can't do queries with arguments, because it knows nothing
about the arguments. No coverage for query-cpu-model-baseline,
query-cpu-model-comparison, query-cpu-model-expansion, query-rocker,
query-rocker-ports, query-rocker-of-dpa-flows, and
query-rocker-of-dpa-groups.
Most tested commands are expected to succeed. The test does not check
the return value then.
query-balloon and query-vm-generation-id are expected to fail because
they need a virtio-balloon / vmgenid device to succeed, and this test
is too dumb to set one up. Could be addressed later.
query-acpi-ospm-status and query-hotpluggable-cpus are expected to
fail because they require features provided only by special machine
types, and this test is too dumb to set that up. Could also be
addressed later.
Several commands may either be functional or stubs that always fail,
depending on build configuration. Ideally, the stubs shouldn't be in
query-qmp-schema, but that requires QAPI schema compile-time
configuration, which we don't have, yet. Until we do, we need to
figure out whether a command is a stub. When we have a suitable
CONFIG_FOO preprocessor symbol is available, use that. Else,
simply blacklist the command for now.
We get basic test coverage for the following commands, except as
noted:
qom-list-types
query-acpi-ospm-status (expected to fail)
query-balloon (expected to fail)
query-block
query-block-jobs
query-blockstats
query-chardev
query-chardev-backends
query-command-line-options
query-commands
query-cpu-definitions (blacklisted for now)
query-cpus
query-dump
query-dump-guest-memory-capability
query-events
query-fdsets
query-gic-capabilities (blacklisted for now)
query-hotpluggable-cpus (expected to fail)
query-iothreads
query-kvm
query-machines
query-memdev
query-memory-devices
query-mice
query-migrate
query-migrate-cache-size
query-migrate-capabilities
query-migrate-parameters
query-name
query-named-block-nodes
query-pci (blacklisted for now)
query-qmp-schema
query-rx-filter
query-spice
query-status
query-target
query-tpm
query-tpm-models
query-tpm-types
query-uuid
query-version
query-vm-generation-id (expected to fail)
query-vnc
query-vnc-servers
query-xen-replication-status
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1502461148-10154-1-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[Commit message typo fixed]
---
tests/qmp-test.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 181 insertions(+), 1 deletion(-)
diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index 5d0260b2be..e5fb17c201 100644
--- a/tests/qmp-test.c
+++ b/tests/qmp-test.c
@@ -15,6 +15,7 @@
#include "qapi-visit.h"
#include "qapi/error.h"
#include "qapi/qobject-input-visitor.h"
+#include "qapi/util.h"
#include "qapi/visitor.h"
const char common_args[] = "-nodefaults -machine none";
@@ -129,11 +130,190 @@ static void test_qmp_protocol(void)
qtest_end();
}
+static int query_error_class(const char *cmd)
+{
+ static struct {
+ const char *cmd;
+ int err_class;
+ } fails[] = {
+ /* Success depends on build configuration: */
+#ifndef CONFIG_SPICE
+ "query-spice", ERROR_CLASS_COMMAND_NOT_FOUND,
+#endif
+#ifndef CONFIG_VNC
+ "query-vnc", ERROR_CLASS_GENERIC_ERROR },
+ "query-vnc-servers", ERROR_CLASS_GENERIC_ERROR },
+#endif
+#ifndef CONFIG_REPLICATION
+ "query-xen-replication-spice", ERROR_CLASS_COMMAND_NOT_FOUND,
+#endif
+ /* Likewise, and require special QEMU command-line arguments: */
+ { "query-acpi-ospm-status", ERROR_CLASS_GENERIC_ERROR },
+ { "query-balloon", ERROR_CLASS_DEVICE_NOT_ACTIVE },
+ { "query-hotpluggable-cpus", ERROR_CLASS_GENERIC_ERROR },
+ { "query-vm-generation-id", ERROR_CLASS_GENERIC_ERROR },
+ { NULL, -1 }
+ };
+ int i;
+
+ for (i = 0; fails[i].cmd; i++) {
+ if (!strcmp(cmd, fails[i].cmd)) {
+ return fails[i].err_class;
+ }
+ }
+ return -1;
+}
+
+static void test_query(const void *data)
+{
+ const char *cmd = data;
+ int expected_error_class = query_error_class(cmd);
+ QDict *resp, *error;
+ const char *error_class;
+
+ qtest_start(common_args);
+
+ resp = qmp("{ 'execute': %s }", cmd);
+ error = qdict_get_qdict(resp, "error");
+ error_class = error ? qdict_get_str(error, "class") : NULL;
+
+ if (expected_error_class < 0) {
+ g_assert(qdict_haskey(resp, "return"));
+ } else {
+ g_assert(error);
+ g_assert_cmpint(qapi_enum_parse(QapiErrorClass_lookup, error_class,
+ QAPI_ERROR_CLASS__MAX, -1,
+ &error_abort),
+ ==, expected_error_class);
+ }
+ QDECREF(resp);
+
+ qtest_end();
+}
+
+static bool query_is_blacklisted(const char *cmd)
+{
+ const char *blacklist[] = {
+ /* Not actually queries: */
+ "add-fd",
+ /* Success depends on target arch: */
+ "query-cpu-definitions", /* arm, i386, ppc, s390x */
+ "query-gic-capabilities", /* arm */
+ /* Success depends on target-specific build configuration: */
+ "query-pci", /* CONFIG_PCI */
+ NULL
+ };
+ int i;
+
+ for (i = 0; blacklist[i]; i++) {
+ if (!strcmp(cmd, blacklist[i])) {
+ return true;
+ }
+ }
+ return false;
+}
+
+typedef struct {
+ SchemaInfoList *list;
+ GHashTable *hash;
+} QmpSchema;
+
+static void qmp_schema_init(QmpSchema *schema)
+{
+ QDict *resp;
+ Visitor *qiv;
+ SchemaInfoList *tail;
+
+ qtest_start(common_args);
+ resp = qmp("{ 'execute': 'query-qmp-schema' }");
+
+ qiv = qobject_input_visitor_new(qdict_get(resp, "return"));
+ visit_type_SchemaInfoList(qiv, NULL, &schema->list, &error_abort);
+ visit_free(qiv);
+
+ QDECREF(resp);
+ qtest_end();
+
+ schema->hash = g_hash_table_new(g_str_hash, g_str_equal);
+
+ /* Build @schema: hash table mapping entity name to SchemaInfo */
+ for (tail = schema->list; tail; tail = tail->next) {
+ g_hash_table_insert(schema->hash, tail->value->name, tail->value);
+ }
+}
+
+static SchemaInfo *qmp_schema_lookup(QmpSchema *schema, const char *name)
+{
+ return g_hash_table_lookup(schema->hash, name);
+}
+
+static void qmp_schema_cleanup(QmpSchema *schema)
+{
+ qapi_free_SchemaInfoList(schema->list);
+ g_hash_table_destroy(schema->hash);
+}
+
+static bool object_type_has_mandatory_members(SchemaInfo *type)
+{
+ SchemaInfoObjectMemberList *tail;
+
+ g_assert(type->meta_type == SCHEMA_META_TYPE_OBJECT);
+
+ for (tail = type->u.object.members; tail; tail = tail->next) {
+ if (!tail->value->has_q_default) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void add_query_tests(QmpSchema *schema)
+{
+ SchemaInfoList *tail;
+ SchemaInfo *si, *arg_type, *ret_type;
+ const char *test_name;
+
+ /* Test the query-like commands */
+ for (tail = schema->list; tail; tail = tail->next) {
+ si = tail->value;
+ if (si->meta_type != SCHEMA_META_TYPE_COMMAND) {
+ continue;
+ }
+
+ if (query_is_blacklisted(si->name)) {
+ continue;
+ }
+
+ arg_type = qmp_schema_lookup(schema, si->u.command.arg_type);
+ if (object_type_has_mandatory_members(arg_type)) {
+ continue;
+ }
+
+ ret_type = qmp_schema_lookup(schema, si->u.command.ret_type);
+ if (ret_type->meta_type == SCHEMA_META_TYPE_OBJECT
+ && !ret_type->u.object.members) {
+ continue;
+ }
+
+ test_name = g_strdup_printf("qmp/%s", si->name);
+ qtest_add_data_func(test_name, si->name, test_query);
+ }
+}
+
int main(int argc, char *argv[])
{
+ QmpSchema schema;
+ int ret;
+
g_test_init(&argc, &argv, NULL);
qtest_add_func("qmp/protocol", test_qmp_protocol);
+ qmp_schema_init(&schema);
+ add_query_tests(&schema);
- return g_test_run();
+ ret = g_test_run();
+
+ qmp_schema_cleanup(&schema);
+ return ret;
}
--
2.13.5
next prev parent reply other threads:[~2017-09-01 15:38 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-01 15:37 [Qemu-devel] [PULL v2 00/47] QAPI patches for 2017-09-01 Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 01/47] qapi: Fix error handling code on alternate conflict Markus Armbruster
2017-09-01 15:37 ` Markus Armbruster [this message]
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 03/47] qobject: Explain how QNum works, and why Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 04/47] qdict: Add qdict_put_null() helper, and put it to use Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 05/47] qlit: move qlit from check-qjson to qobject/ Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 06/47] qlit: use QLit prefix consistently Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 07/47] qlit: Change compound literals to initializers Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 08/47] qlit: rename compare_litqobj_to_qobj() to qlit_equal_qobject() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 09/47] qlit: make qlit_equal_qobject return a bool Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 10/47] qlit: make qlit_equal_qobject() take const arguments Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 11/47] qlit: add QLIT_QNULL and QLIT_BOOL Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 12/47] qlit: Replace open-coded qnum_get_int() by call Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 13/47] tests/check-qlit: New, covering qobject/qlit.c Markus Armbruster
2017-09-05 20:38 ` Eric Blake
2017-09-06 5:39 ` Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 14/47] qlit: Tighten QLit dict vs QDict comparison Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 15/47] qlit: Tighten QLit list vs QList comparison Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 16/47] qapi-schema: Document how generated documentation is ordered Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 17/47] qapi-schema: Introspection doc is in the wrong section, fix Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 18/47] qapi-schema: Rocker doc section contains unrelated stuff, fix Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 19/47] qapi-schema: Collect sockets stuff in qapi/sockets.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 20/47] qapi-schema: Collect run state stuff in qapi/run-state.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 21/47] qapi-schema: Collect char device stuff in qapi/char.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 22/47] qapi-schema: Collect net device stuff in qapi/net.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 23/47] qapi-schema: Collect UI stuff in qapi/ui.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 24/47] qapi-schema: Collect migration stuff in qapi/migration.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 25/47] qapi-schema: Collect transaction stuff in qapi/transaction.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 26/47] qapi-schema: Collect TPM stuff in qapi/tpm.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 27/47] qapi-schema: Move block events from event.json to block.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 28/47] qapi-schema: Fold event.json back into qapi-schema.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 29/47] qapi-schema: Make block-core.json self-contained Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 30/47] qapi-schema: Move queries from common.json to qapi-schema.json Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 31/47] qapi-schema: Improve section headings Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 32/47] qapi: Update qapi-code-gen.txt examples to match current code Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 33/47] qapi: Drop superfluous qapi_enum_parse() parameter max Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 34/47] tpm: Clean up driver registration & lookup Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 35/47] tpm: Clean up model " Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 36/47] hmp: Use qapi_enum_parse() in hmp_migrate_set_capability() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 37/47] hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 38/47] block: Use qemu_enum_parse() in blkdebug_debug_breakpoint() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 39/47] quorum: Use qapi_enum_parse() in quorum_open() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 40/47] crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 41/47] qapi: Use qapi_enum_parse() in input_type_enum() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 42/47] qapi: Avoid unnecessary use of enum lookup table's sentinel Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 43/47] qapi: Generate FOO_str() macro for QAPI enum FOO Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 44/47] qapi: Mechanically convert FOO_lookup[...] to FOO_str(...) Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 45/47] qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup() Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 46/47] qapi: Change data type of the FOO_lookup generated for enum FOO Markus Armbruster
2017-09-01 15:37 ` [Qemu-devel] [PULL v2 47/47] qapi: drop the sentinel in enum array Markus Armbruster
2017-09-04 10:01 ` [Qemu-devel] [PULL v2 00/47] QAPI patches for 2017-09-01 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170901153758.8628-3-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).