On 10/02/2013 11:09 AM, Michal Privoznik wrote:
So far, we're unit testing some basic functions and some (so
called)
simple functions (e.g. "qmp_capabilities", "system_powerdown").
However,
there are more functions which expect simple "{'return': {}}" reply,
but
takes more args to construct the command (for instance "set_link"). This
patch aims on such functions.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tests/qemumonitorjsontest.c | 97 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
+#define GEN_TEST_FUNC(funcName, ...) \
+static int \
+testQemuMonitorJSON ## funcName(const void *opaque) \
+{ \
+ const testQemuMonitorJSONSimpleFuncDataPtr data = \
+ (const testQemuMonitorJSONSimpleFuncDataPtr) opaque; \
+ virDomainXMLOptionPtr xmlopt = data->xmlopt; \
+ qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); \
+ const char *reply = data->reply; \
+ int ret = -1; \
+ \
+ if (!test) \
+ return -1; \
+ \
+ if (!reply) \
+ reply = "{\"return\":{}}";
\
+ \
+ if (qemuMonitorTestAddItem(test, data->cmd, reply) < 0) \
+ goto cleanup; \
+ \
+ if (funcName(qemuMonitorTestGetMonitor(test), __VA_ARGS__) < 0) \
Again, I think we should be calling the public function in
qemu_monitor.h, not the version in qemu_monitor_json. To do that,
you'll need to do something like:
#define GEN_TEST_FUNC(funcSuffix, ...)
...
testQemuMonitor ## funcSuffix()
...
if (qemuMonitor ## funcSuffix(qemuMonitorTestGetMonitor(test),
__VA_ARGS__) < 0
+
+GEN_TEST_FUNC(qemuMonitorJSONSetLink, "vnet0",
VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
and call it like:
GEN_TEST_FUNC(SetLink, "vnet0", VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
+GEN_TEST_FUNC(qemuMonitorJSONDriveMirror, "vdb",
"/foo/bar", NULL, 1024,
+ VIR_DOMAIN_BLOCK_REBASE_SHALLOW & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)
Umm - that's a fancy way to write 0. Did you mean to s/&/|/
@@ -1086,6 +1154,35 @@ mymain(void)
DO_TEST_SIMPLE("inject-nmi", qemuMonitorJSONInjectNMI);
DO_TEST_SIMPLE("system_wakeup", qemuMonitorJSONSystemWakeup);
DO_TEST_SIMPLE("nbd-server-stop", qemuMonitorJSONNBDServerStop);
+ DO_TEST_GEN(qemuMonitorJSONSetLink);
Again, I think you want:
DO_TEST_GEN(SetLink);
to go through the public wrapper.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org