From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, dhildenb@redhat.com,
ehabkost@redhat.com, david@gibson.dropbear.id.au
Subject: [Qemu-devel] [PATCH 1/2] tests: add qtest_qmp_device_add_qdict() helper
Date: Fri, 30 Aug 2019 07:07:22 -0400 [thread overview]
Message-ID: <20190830110723.15096-2-imammedo@redhat.com> (raw)
In-Reply-To: <20190830110723.15096-1-imammedo@redhat.com>
Add an API that takes QDict directly, so users could skip steps
of first building json dictionary and converting it back to
QDict in existing qtest_qmp_device_add() and instead use QDict
directly without intermediate conversion.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
tests/libqtest.h | 12 ++++++++++++
tests/libqtest.c | 29 +++++++++++++++++++----------
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 07ea35867c..0788f70954 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -948,6 +948,18 @@ QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
void qtest_cb_for_every_machine(void (*cb)(const char *machine),
bool skip_old_versioned);
+/**
+ * qtest_qmp_device_add_qdict:
+ * @qts: QTestState instance to operate on
+ * @drv: Name of the device that should be added
+ * @arguments: QDict with properties for the device to intialize
+ *
+ * Generic hot-plugging test via the device_add QMP command with properties
+ * supplied in form of QDict. Use NULL for empty properties list.
+ */
+void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
+ const QDict *arguments);
+
/**
* qtest_qmp_device_add:
* @qts: QTestState instance to operate on
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 2713b86cf7..13d52f5cf3 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -1250,28 +1250,37 @@ QDict *qtest_qmp_receive_success(QTestState *s,
}
/*
- * Generic hot-plugging test via the device_add QMP command.
+ * Generic hot-plugging test via the device_add QMP commands.
*/
+void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
+ const QDict *arguments)
+{
+ QDict *resp;
+ QDict *args = arguments ? qdict_clone_shallow(arguments) : qdict_new();
+
+ g_assert(!qdict_haskey(args, "driver"));
+ qdict_put_str(args, "driver", drv);
+ resp = qtest_qmp(qts, "{'execute': 'device_add', 'arguments': %p}", args);
+ g_assert(resp);
+ g_assert(!qdict_haskey(resp, "event")); /* We don't expect any events */
+ g_assert(!qdict_haskey(resp, "error"));
+ qobject_unref(resp);
+}
+
void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
const char *fmt, ...)
{
- QDict *args, *response;
+ QDict *args;
va_list ap;
va_start(ap, fmt);
args = qdict_from_vjsonf_nofail(fmt, ap);
va_end(ap);
- g_assert(!qdict_haskey(args, "driver") && !qdict_haskey(args, "id"));
- qdict_put_str(args, "driver", driver);
+ g_assert(!qdict_haskey(args, "id"));
qdict_put_str(args, "id", id);
- response = qtest_qmp(qts, "{'execute': 'device_add', 'arguments': %p}",
- args);
- g_assert(response);
- g_assert(!qdict_haskey(response, "event")); /* We don't expect any events */
- g_assert(!qdict_haskey(response, "error"));
- qobject_unref(response);
+ qtest_qmp_device_add_qdict(qts, driver, args);
}
static void device_deleted_cb(void *opaque, const char *name, QDict *data)
--
2.18.1
next prev parent reply other threads:[~2019-08-30 11:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-30 11:07 [Qemu-devel] [PATCH 0/2] tests: cpu-plug-test: fix x86 device_add cpu-foo test cases Igor Mammedov
2019-08-30 11:07 ` Igor Mammedov [this message]
2019-08-30 11:07 ` [Qemu-devel] [PATCH 2/2] tests: cpu-plug-test: fix device_add for pc/q35 machines Igor Mammedov
2019-09-03 21:50 ` [Qemu-devel] [PATCH 0/2] tests: cpu-plug-test: fix x86 device_add cpu-foo test cases Eduardo Habkost
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=20190830110723.15096-2-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=dhildenb@redhat.com \
--cc=ehabkost@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@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).