2017-03-03 20:32:23 +08:00
|
|
|
/*
|
|
|
|
* QMP protocol test cases
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Markus Armbruster <armbru@redhat.com>,
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "libqtest.h"
|
|
|
|
#include "qapi/error.h"
|
2018-02-27 07:13:27 +08:00
|
|
|
#include "qapi/qapi-visit-introspect.h"
|
|
|
|
#include "qapi/qapi-visit-misc.h"
|
2018-02-01 19:18:39 +08:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2018-02-01 19:18:38 +08:00
|
|
|
#include "qapi/qmp/qlist.h"
|
2017-03-03 20:32:23 +08:00
|
|
|
#include "qapi/qobject-input-visitor.h"
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
#include "qapi/util.h"
|
2017-03-03 20:32:23 +08:00
|
|
|
#include "qapi/visitor.h"
|
qmp: introduce QMPCapability
There were no QMP capabilities defined. Define the first capability,
"oob", to allow out-of-band messages.
After this patch, we will allow QMP clients to enable QMP capabilities
when sending the first "qmp_capabilities" command. Originally we are
starting QMP session with no arguments like:
{ "execute": "qmp_capabilities" }
Now we can enable some QMP capabilities using (take OOB as example,
which is the only capability that we support):
{ "execute": "qmp_capabilities",
"arguments": { "enable": [ "oob" ] } }
When the "arguments" key is not provided, no capability is enabled.
For capability "oob", the monitor needs to be run on a dedicated IO
thread, otherwise the command will fail. For example, trying to enable
OOB on a MUXed typed QMP monitor will fail.
One thing to mention is that QMP capabilities are per-monitor, and also
when the connection is closed due to some reason, the capabilities will
be reset.
Also, touch up qmp-test.c to test the new bits.
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180309090006.10018-11-peterx@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: touch up commit message]
Signed-off-by: Eric Blake <eblake@redhat.com>
2018-03-09 16:59:53 +08:00
|
|
|
#include "qapi/qmp/qstring.h"
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
const char common_args[] = "-nodefaults -machine none";
|
|
|
|
|
|
|
|
static const char *get_error_class(QDict *resp)
|
|
|
|
{
|
|
|
|
QDict *error = qdict_get_qdict(resp, "error");
|
|
|
|
const char *desc = qdict_get_try_str(error, "desc");
|
|
|
|
|
|
|
|
g_assert(desc);
|
|
|
|
return error ? qdict_get_try_str(error, "class") : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_version(QObject *version)
|
|
|
|
{
|
|
|
|
Visitor *v;
|
|
|
|
VersionInfo *vinfo;
|
|
|
|
|
|
|
|
g_assert(version);
|
2017-03-03 20:32:39 +08:00
|
|
|
v = qobject_input_visitor_new(version);
|
2017-03-03 20:32:23 +08:00
|
|
|
visit_type_VersionInfo(v, "version", &vinfo, &error_abort);
|
|
|
|
qapi_free_VersionInfo(vinfo);
|
|
|
|
visit_free(v);
|
|
|
|
}
|
|
|
|
|
2017-09-12 01:20:06 +08:00
|
|
|
static void test_malformed(QTestState *qts)
|
2017-03-03 20:32:23 +08:00
|
|
|
{
|
|
|
|
QDict *resp;
|
|
|
|
|
|
|
|
/* Not even a dictionary */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "null");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* No "execute" key */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{}");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* "execute" isn't a string */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': true }");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* "arguments" isn't a dictionary */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'arguments': [] }");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* extra key */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'no-such-cmd', 'extra': true }");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_qmp_protocol(void)
|
|
|
|
{
|
|
|
|
QDict *resp, *q, *ret;
|
|
|
|
QList *capabilities;
|
2017-09-12 01:20:06 +08:00
|
|
|
QTestState *qts;
|
2017-03-03 20:32:23 +08:00
|
|
|
|
2018-03-27 09:36:19 +08:00
|
|
|
qts = qtest_init_without_qmp_handshake(false, common_args);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test greeting */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp_receive(qts);
|
2017-03-03 20:32:23 +08:00
|
|
|
q = qdict_get_qdict(resp, "QMP");
|
|
|
|
g_assert(q);
|
|
|
|
test_version(qdict_get(q, "version"));
|
|
|
|
capabilities = qdict_get_qlist(q, "capabilities");
|
2018-03-23 22:08:21 +08:00
|
|
|
g_assert(capabilities && qlist_empty(capabilities));
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test valid command before handshake */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test malformed commands before handshake */
|
2017-09-12 01:20:06 +08:00
|
|
|
test_malformed(qts);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test handshake */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
|
2017-03-03 20:32:23 +08:00
|
|
|
ret = qdict_get_qdict(resp, "return");
|
|
|
|
g_assert(ret && !qdict_size(ret));
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test repeated handshake */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'qmp_capabilities' }");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "CommandNotFound");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test valid command */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'query-version' }");
|
2017-03-03 20:32:23 +08:00
|
|
|
test_version(qdict_get(resp, "return"));
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test malformed commands */
|
2017-09-12 01:20:06 +08:00
|
|
|
test_malformed(qts);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test 'id' */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'query-name', 'id': 'cookie#1' }");
|
2017-03-03 20:32:23 +08:00
|
|
|
ret = qdict_get_qdict(resp, "return");
|
|
|
|
g_assert(ret);
|
|
|
|
g_assert_cmpstr(qdict_get_try_str(resp, "id"), ==, "cookie#1");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
|
|
|
/* Test command failure with 'id' */
|
2017-09-12 01:20:06 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'execute': 'human-monitor-command', 'id': 2 }");
|
2017-03-03 20:32:23 +08:00
|
|
|
g_assert_cmpstr(get_error_class(resp), ==, "GenericError");
|
|
|
|
g_assert_cmpint(qdict_get_int(resp, "id"), ==, 2);
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2017-03-03 20:32:23 +08:00
|
|
|
|
2017-09-12 01:20:06 +08:00
|
|
|
qtest_quit(qts);
|
2017-03-03 20:32:23 +08:00
|
|
|
}
|
|
|
|
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
/* Out-of-band tests */
|
|
|
|
|
|
|
|
char tmpdir[] = "/tmp/qmp-test-XXXXXX";
|
|
|
|
char *fifo_name;
|
|
|
|
|
|
|
|
static void setup_blocking_cmd(void)
|
|
|
|
{
|
|
|
|
if (!mkdtemp(tmpdir)) {
|
|
|
|
g_error("mkdtemp: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
fifo_name = g_strdup_printf("%s/fifo", tmpdir);
|
|
|
|
if (mkfifo(fifo_name, 0666)) {
|
|
|
|
g_error("mkfifo: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup_blocking_cmd(void)
|
|
|
|
{
|
|
|
|
unlink(fifo_name);
|
|
|
|
rmdir(tmpdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_cmd_that_blocks(QTestState *s, const char *id)
|
|
|
|
{
|
2018-08-06 14:53:22 +08:00
|
|
|
qtest_qmp_send(s, "{ 'execute': 'blockdev-add', 'id': %s,"
|
|
|
|
" 'arguments': {"
|
|
|
|
" 'driver': 'blkdebug', 'node-name': %s,"
|
|
|
|
" 'config': %s,"
|
|
|
|
" 'image': { 'driver': 'null-co' } } }",
|
|
|
|
id, id, fifo_name);
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unblock_blocked_cmd(void)
|
|
|
|
{
|
|
|
|
int fd = open(fifo_name, O_WRONLY);
|
|
|
|
g_assert(fd >= 0);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_oob_cmd_that_fails(QTestState *s, const char *id)
|
|
|
|
{
|
2018-08-06 14:53:22 +08:00
|
|
|
qtest_qmp_send(s, "{ 'exec-oob': 'migrate-pause', 'id': %s }", id);
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void recv_cmd_id(QTestState *s, const char *id)
|
|
|
|
{
|
|
|
|
QDict *resp = qtest_qmp_receive(s);
|
|
|
|
|
|
|
|
g_assert_cmpstr(qdict_get_try_str(resp, "id"), ==, id);
|
|
|
|
qobject_unref(resp);
|
|
|
|
}
|
|
|
|
|
2018-03-26 14:39:01 +08:00
|
|
|
static void test_qmp_oob(void)
|
|
|
|
{
|
|
|
|
QTestState *qts;
|
|
|
|
QDict *resp, *q;
|
|
|
|
const QListEntry *entry;
|
|
|
|
QList *capabilities;
|
|
|
|
QString *qstr;
|
|
|
|
|
|
|
|
qts = qtest_init_without_qmp_handshake(true, common_args);
|
|
|
|
|
|
|
|
/* Check the greeting message. */
|
|
|
|
resp = qtest_qmp_receive(qts);
|
|
|
|
q = qdict_get_qdict(resp, "QMP");
|
|
|
|
g_assert(q);
|
|
|
|
capabilities = qdict_get_qlist(q, "capabilities");
|
|
|
|
g_assert(capabilities && !qlist_empty(capabilities));
|
|
|
|
entry = qlist_first(capabilities);
|
|
|
|
g_assert(entry);
|
|
|
|
qstr = qobject_to(QString, entry->value);
|
|
|
|
g_assert(qstr);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qstr), ==, "oob");
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2018-03-26 14:39:01 +08:00
|
|
|
|
|
|
|
/* Try a fake capability, it should fail. */
|
|
|
|
resp = qtest_qmp(qts,
|
|
|
|
"{ 'execute': 'qmp_capabilities', "
|
|
|
|
" 'arguments': { 'enable': [ 'cap-does-not-exist' ] } }");
|
|
|
|
g_assert(qdict_haskey(resp, "error"));
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2018-03-26 14:39:01 +08:00
|
|
|
|
|
|
|
/* Now, enable OOB in current QMP session, it should succeed. */
|
|
|
|
resp = qtest_qmp(qts,
|
|
|
|
"{ 'execute': 'qmp_capabilities', "
|
|
|
|
" 'arguments': { 'enable': [ 'oob' ] } }");
|
|
|
|
g_assert(qdict_haskey(resp, "return"));
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2018-03-26 14:39:01 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try any command that does not support OOB but with OOB flag. We
|
|
|
|
* should get failure.
|
|
|
|
*/
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 16:53:38 +08:00
|
|
|
resp = qtest_qmp(qts, "{ 'exec-oob': 'query-cpus' }");
|
2018-03-26 14:39:01 +08:00
|
|
|
g_assert(qdict_haskey(resp, "error"));
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
2018-03-26 14:39:01 +08:00
|
|
|
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
/* OOB command overtakes slow in-band command */
|
|
|
|
setup_blocking_cmd();
|
|
|
|
send_cmd_that_blocks(qts, "ib-blocks-1");
|
2018-08-06 14:53:22 +08:00
|
|
|
qtest_qmp_send(qts, "{ 'execute': 'query-name', 'id': 'ib-quick-1' }");
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
send_oob_cmd_that_fails(qts, "oob-1");
|
|
|
|
recv_cmd_id(qts, "oob-1");
|
|
|
|
unblock_blocked_cmd();
|
|
|
|
recv_cmd_id(qts, "ib-blocks-1");
|
2018-07-03 16:53:32 +08:00
|
|
|
recv_cmd_id(qts, "ib-quick-1");
|
2018-07-03 16:53:42 +08:00
|
|
|
|
2018-07-03 16:53:43 +08:00
|
|
|
/* Even malformed in-band command fails in-band */
|
2018-07-03 16:53:42 +08:00
|
|
|
send_cmd_that_blocks(qts, "blocks-2");
|
2018-08-06 14:53:22 +08:00
|
|
|
qtest_qmp_send(qts, "{ 'id': 'err-2' }");
|
2018-07-03 16:53:42 +08:00
|
|
|
unblock_blocked_cmd();
|
|
|
|
recv_cmd_id(qts, "blocks-2");
|
2018-07-03 16:53:43 +08:00
|
|
|
recv_cmd_id(qts, "err-2");
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
cleanup_blocking_cmd();
|
2018-03-26 14:39:01 +08:00
|
|
|
|
|
|
|
qtest_quit(qts);
|
|
|
|
}
|
|
|
|
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
/* Query smoke tests */
|
|
|
|
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
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-status", 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);
|
2017-08-24 16:46:10 +08:00
|
|
|
g_assert_cmpint(qapi_enum_parse(&QapiErrorClass_lookup, error_class,
|
2017-08-24 16:45:57 +08:00
|
|
|
-1, &error_abort),
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
==, expected_error_class);
|
|
|
|
}
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
|
|
|
|
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 */
|
2018-03-08 20:48:56 +08:00
|
|
|
/* Success depends on launching SEV guest */
|
|
|
|
"query-sev-launch-measure",
|
2018-03-08 20:48:42 +08:00
|
|
|
/* Success depends on Host or Hypervisor SEV support */
|
|
|
|
"query-sev",
|
2018-03-08 20:48:59 +08:00
|
|
|
"query-sev-capabilities",
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
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);
|
|
|
|
|
2018-04-19 23:01:43 +08:00
|
|
|
qobject_unref(resp);
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
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;
|
2018-01-05 00:05:19 +08:00
|
|
|
char *test_name;
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
|
|
|
|
/* 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);
|
2018-01-05 00:05:19 +08:00
|
|
|
g_free(test_name);
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
qmp: Get rid of x-oob-test command
tests/qmp-test tests an out-of-band command overtaking a slow in-band
command. To do that, it needs:
1. An in-band command that *reliably* takes long enough to be
overtaken.
2. An out-of-band command to do the overtaking.
3. To avoid delays, a way to make the in-band command complete quickly
after it was overtaken.
To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:
* With "lock": true, it waits for a global semaphore.
* With "lock": false, it signals the global semaphore.
To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.
Note that waiting for a semaphore violates the rules for oob-capable
commands. Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).
Having an externally visible QMP command that may hang the monitor is
not nice. Let's apply a little more ingenuity to the problem. Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.
For 1., use
{"execute": "blockdev-add", "id": ID1,
"arguments": {
"driver": "blkdebug", "node-name": ID1, "config": FIFO,
"image": { "driver": "null-co"}}}
where ID1 is an arbitrary string, and FIFO is the name of the FIFO.
For 2., use
{"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}
where ID2 is a different arbitrary string. Since there's no migration
to pause, the command will fail, but that's fine; instant failure is
still a test of out-of-band responses overtaking in-band commands.
For 3., open FIFO for writing.
Drop QMP command x-oob-test.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-6-armbru@redhat.com>
[Error checking tweaked]
2018-07-03 16:53:31 +08:00
|
|
|
/* Preconfig tests */
|
|
|
|
|
2018-05-17 19:28:44 +08:00
|
|
|
static void test_qmp_preconfig(void)
|
|
|
|
{
|
|
|
|
QDict *rsp, *ret;
|
2018-08-06 14:53:43 +08:00
|
|
|
QTestState *qs = qtest_initf("%s --preconfig", common_args);
|
2018-05-17 19:28:44 +08:00
|
|
|
|
|
|
|
/* preconfig state */
|
|
|
|
/* enabled commands, no error expected */
|
|
|
|
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-commands' }")));
|
|
|
|
|
|
|
|
/* forbidden commands, expected error */
|
|
|
|
g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
|
|
|
|
|
|
|
|
/* check that query-status returns preconfig state */
|
|
|
|
rsp = qtest_qmp(qs, "{ 'execute': 'query-status' }");
|
|
|
|
ret = qdict_get_qdict(rsp, "return");
|
|
|
|
g_assert(ret);
|
|
|
|
g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig");
|
|
|
|
qobject_unref(rsp);
|
|
|
|
|
|
|
|
/* exit preconfig state */
|
2018-07-05 17:14:02 +08:00
|
|
|
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'x-exit-preconfig' }")));
|
2018-05-17 19:28:44 +08:00
|
|
|
qtest_qmp_eventwait(qs, "RESUME");
|
|
|
|
|
|
|
|
/* check that query-status returns running state */
|
|
|
|
rsp = qtest_qmp(qs, "{ 'execute': 'query-status' }");
|
|
|
|
ret = qdict_get_qdict(rsp, "return");
|
|
|
|
g_assert(ret);
|
|
|
|
g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "running");
|
|
|
|
qobject_unref(rsp);
|
|
|
|
|
2018-07-05 17:14:02 +08:00
|
|
|
/* check that x-exit-preconfig returns error after exiting preconfig */
|
|
|
|
g_assert(qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'x-exit-preconfig' }")));
|
2018-05-17 19:28:44 +08:00
|
|
|
|
|
|
|
/* enabled commands, no error expected */
|
|
|
|
g_assert(!qmp_rsp_is_err(qtest_qmp(qs, "{ 'execute': 'query-cpus' }")));
|
|
|
|
|
|
|
|
qtest_quit(qs);
|
|
|
|
}
|
|
|
|
|
2017-03-03 20:32:23 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
QmpSchema schema;
|
|
|
|
int ret;
|
|
|
|
|
2017-03-03 20:32:23 +08:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
qtest_add_func("qmp/protocol", test_qmp_protocol);
|
2018-03-26 14:39:01 +08:00
|
|
|
qtest_add_func("qmp/oob", test_qmp_oob);
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
qmp_schema_init(&schema);
|
|
|
|
add_query_tests(&schema);
|
2018-05-17 19:28:44 +08:00
|
|
|
qtest_add_func("qmp/preconfig", test_qmp_preconfig);
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
|
|
|
|
ret = g_test_run();
|
2017-03-03 20:32:23 +08:00
|
|
|
|
tests/qmp-test: Add generic, basic test of query commands
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>
[Typos in code under #ifndef and in the commit message fixed]
2017-08-11 22:19:08 +08:00
|
|
|
qmp_schema_cleanup(&schema);
|
|
|
|
return ret;
|
2017-03-03 20:32:23 +08:00
|
|
|
}
|