[libvirt] [PATCH 00/18] qemumonitorjsontest: Introduce some tests

and fix some bugs I've ran into while writing the tests. Michal Privoznik (18): qemuMonitorJSONGetVirtType: Fix error message qemumonitorjsontest: Test qemuMonitorJSONSystemPowerdown qemuMonitorJSONSendKey: Avoid double free qemuMonitorTestFree: Join worker thread unconditionally qemumonitorjsontest: Extend the test for yet another monitor commands qemumonitorjsontest: Test qemuMonitorJSONGetCPUInfo qemumonitorjsontest: Test qemuMonitorJSONGetVirtType qemumonitorjsontest: Test qemuMonitorJSONGetBalloonInfo qemumonitorjsontest: Test qemuMonitorJSONGetBlockInfo qemumonitorjsontest: Test qemuMonitorJSONGetBlockStatsInfo qemumonitorjsontest: Test qemuMonitorJSONGetMigrationCacheSize qemumonitorjsontest: Test qemuMonitorJSONGetMigrationStatus qemumonitorjsontest: Test qemuMonitorJSONGetSpiceMigrationStatus qemumonitorjsontest: Test qemuMonitorJSONGetPtyPaths qemumonitorjsontest: Test qemuMonitorJSONSendKey qemumonitorjsontest: Test qemuMonitorJSONSetBlockIoThrottle qemumonitorjsontest: Test qemuMonitorJSONGetTargetArch qemumonitorjsontest: Test qemuMonitorJSONGetMigrationCapability src/qemu/qemu_monitor_json.c | 5 +- tests/qemumonitorjsontest.c | 955 ++++++++++++++++++++++++++++++++++++++++++- tests/qemumonitortestutils.c | 3 +- 3 files changed, 959 insertions(+), 4 deletions(-) -- 1.8.1.5

When querying for kvm, we try to find 'enabled' field. Hence the error message should report we haven't found 'enabled' and not 'running' (which is not even in the reply). Probably a typo or copy-paste error. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 2d84161..fc57c00 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1300,7 +1300,7 @@ int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon, if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("info kvm reply missing 'running' field")); + _("info kvm reply missing 'enabled' field")); ret = -1; goto cleanup; } -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
When querying for kvm, we try to find 'enabled' field. Hence the error message should report we haven't found 'enabled' and not 'running' (which is not even in the reply). Probably a typo or copy-paste error.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK.
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 2d84161..fc57c00 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1300,7 +1300,7 @@ int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("info kvm reply missing 'running' field")); + _("info kvm reply missing 'enabled' field")); ret = -1; goto cleanup; }
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Right now, we are testing qemuMonitorSystemPowerdown instead of qemuMonitorJSONSystemPowerdown. It makes no harm, as both functions have the same header and the former is just a wrapper over the latter. But we should be consistent as we're testing the JSON functions only in here. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 0fb8d65..6f218ea 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1080,7 +1080,7 @@ mymain(void) DO_TEST(GetDeviceAliases); DO_TEST(CPU); DO_TEST_SIMPLE("qmp_capabilities", qemuMonitorJSONSetCapabilities); - DO_TEST_SIMPLE("system_powerdown", qemuMonitorSystemPowerdown); + DO_TEST_SIMPLE("system_powerdown", qemuMonitorJSONSystemPowerdown); DO_TEST_SIMPLE("system_reset", qemuMonitorJSONSystemReset); DO_TEST_SIMPLE("migrate_cancel", qemuMonitorJSONMigrateCancel); DO_TEST_SIMPLE("inject-nmi", qemuMonitorJSONInjectNMI); -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Right now, we are testing qemuMonitorSystemPowerdown instead of qemuMonitorJSONSystemPowerdown. It makes no harm, as both functions have the same header and the former is just a wrapper over the latter. But we should be consistent as we're testing the JSON functions only in here.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Actually, I think we should do the opposite, and test only the wrapper functions that the rest of qemu_driver.c and friends will be calling. For example, testQemuMonitorJSONGetVersion() calls into qemuMonitorGetVersion, not qemuMonitorJSONGetVersion. Besides, I can't help but wonder if we should someday switch qemu_monitor.c into a callback struct, rather than it's current hard-coded callouts into _text or _json, and where qemu_monitor_json.h could be drastically reduced in size (just a few functions needed to register the callback driver, and most of the functions listed as static and just plug their address into the callback struct) - it would make for less duplication work when adding support for a new QMP command. But for that to work, the qemuMonitorJSON functions can't be called by the testsuite. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Oct 02, 2013 at 11:42:13AM -0600, Eric Blake wrote:
On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Right now, we are testing qemuMonitorSystemPowerdown instead of qemuMonitorJSONSystemPowerdown. It makes no harm, as both functions have the same header and the former is just a wrapper over the latter. But we should be consistent as we're testing the JSON functions only in here.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Actually, I think we should do the opposite, and test only the wrapper functions that the rest of qemu_driver.c and friends will be calling. For example, testQemuMonitorJSONGetVersion() calls into qemuMonitorGetVersion, not qemuMonitorJSONGetVersion.
Well this test suite was specifically targetting only the JSON monitor impl, not the text mode impl, so calling the JSON functions is right IMHO. There is separate testing for the text mode monitor Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 02.10.2013 20:08, Daniel P. Berrange wrote:
On Wed, Oct 02, 2013 at 11:42:13AM -0600, Eric Blake wrote:
On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Right now, we are testing qemuMonitorSystemPowerdown instead of qemuMonitorJSONSystemPowerdown. It makes no harm, as both functions have the same header and the former is just a wrapper over the latter. But we should be consistent as we're testing the JSON functions only in here.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Actually, I think we should do the opposite, and test only the wrapper functions that the rest of qemu_driver.c and friends will be calling. For example, testQemuMonitorJSONGetVersion() calls into qemuMonitorGetVersion, not qemuMonitorJSONGetVersion.
Well this test suite was specifically targetting only the JSON monitor impl, not the text mode impl, so calling the JSON functions is right IMHO.
There is separate testing for the text mode monitor
Daniel
Does this mean ACK, esp. if other patches calling JSON functions were acked? Michal

On Thu, Oct 03, 2013 at 12:44:20PM +0200, Michal Privoznik wrote:
On 02.10.2013 20:08, Daniel P. Berrange wrote:
On Wed, Oct 02, 2013 at 11:42:13AM -0600, Eric Blake wrote:
On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Right now, we are testing qemuMonitorSystemPowerdown instead of qemuMonitorJSONSystemPowerdown. It makes no harm, as both functions have the same header and the former is just a wrapper over the latter. But we should be consistent as we're testing the JSON functions only in here.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Actually, I think we should do the opposite, and test only the wrapper functions that the rest of qemu_driver.c and friends will be calling. For example, testQemuMonitorJSONGetVersion() calls into qemuMonitorGetVersion, not qemuMonitorJSONGetVersion.
Well this test suite was specifically targetting only the JSON monitor impl, not the text mode impl, so calling the JSON functions is right IMHO.
There is separate testing for the text mode monitor
Daniel
Does this mean ACK, esp. if other patches calling JSON functions were acked?
Yes, sorry, ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

After successful @cmd construction the memory where @keys points to is part of @cmd. Avoid double freeing it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index fc57c00..cd6cb72 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3452,6 +3452,9 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, if (!cmd) goto cleanup; + /* @keys is part of @cmd now. Avoid double free */ + keys = NULL; + if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
After successful @cmd construction the memory where @keys points to is part of @cmd. Avoid double freeing it.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 3 +++ 1 file changed, 3 insertions(+)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

The thread needs to be joined no matter if it was still running when qemuMonitorTestFree is called or not. The worker is thread spawned in qemuMonitorTestNew() and has to be joined. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitortestutils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index cd43c7b..4989183 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -354,8 +354,7 @@ qemuMonitorTestFree(qemuMonitorTestPtr test) virObjectUnref(test->vm); - if (test->running) - virThreadJoin(&test->thread); + virThreadJoin(&test->thread); if (timer != -1) virEventRemoveTimeout(timer); -- 1.8.1.5

On Wed, Oct 02, 2013 at 07:09:53PM +0200, Michal Privoznik wrote:
The thread needs to be joined no matter if it was still running when qemuMonitorTestFree is called or not. The worker is thread spawned in qemuMonitorTestNew() and has to be joined.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitortestutils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index cd43c7b..4989183 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -354,8 +354,7 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
virObjectUnref(test->vm);
- if (test->running) - virThreadJoin(&test->thread); + virThreadJoin(&test->thread);
if (timer != -1) virEventRemoveTimeout(timer);
qemuMonitorTestNew() will call virMonitorTestFree() from an 'error' label and this label can be reached even from places where virThreadCreate was not yet run. So I think this will cause a hang in those cases. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

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@redhat.com> --- tests/qemumonitorjsontest.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 6f218ea..f52e970 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1037,6 +1037,69 @@ cleanup: return ret; } +#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) \ + goto cleanup; \ + \ + ret = 0; \ +cleanup: \ + qemuMonitorTestFree(test); \ + return ret; \ +} + +GEN_TEST_FUNC(qemuMonitorJSONSetLink, "vnet0", VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN) +GEN_TEST_FUNC(qemuMonitorJSONBlockResize, "vda", 123456) +GEN_TEST_FUNC(qemuMonitorJSONSetVNCPassword, "secret_password") +GEN_TEST_FUNC(qemuMonitorJSONSetPassword, "spice", "secret_password", "disconnect") +GEN_TEST_FUNC(qemuMonitorJSONExpirePassword, "spice", "123456") +GEN_TEST_FUNC(qemuMonitorJSONSetBalloon, 1024) +GEN_TEST_FUNC(qemuMonitorJSONSetCPU, 1, true) +GEN_TEST_FUNC(qemuMonitorJSONEjectMedia, "hdc", true) +GEN_TEST_FUNC(qemuMonitorJSONChangeMedia, "hdc", "/foo/bar", NULL) +GEN_TEST_FUNC(qemuMonitorJSONSaveVirtualMemory, 0, 1024, "/foo/bar") +GEN_TEST_FUNC(qemuMonitorJSONSavePhysicalMemory, 0, 1024, "/foo/bar") +GEN_TEST_FUNC(qemuMonitorJSONSetMigrationSpeed, 1024) +GEN_TEST_FUNC(qemuMonitorJSONSetMigrationDowntime, 1) +GEN_TEST_FUNC(qemuMonitorJSONMigrate, QEMU_MONITOR_MIGRATE_BACKGROUND & + QEMU_MONITOR_MIGRATE_NON_SHARED_DISK & + QEMU_MONITOR_MIGRATE_NON_SHARED_INC, "tcp:localhost:12345") +GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol") +GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE, + "localhost", 12345, 12346, NULL) +GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "some_dummy_netdevstr") +GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0") +GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0") +GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr") +GEN_TEST_FUNC(qemuMonitorJSONSetDrivePassphrase, "vda", "secret_passhprase") +GEN_TEST_FUNC(qemuMonitorJSONDriveMirror, "vdb", "/foo/bar", NULL, 1024, + VIR_DOMAIN_BLOCK_REBASE_SHALLOW & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT) +GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "/foo/bar1", "/foo/bar2", 1024) +GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb", NULL, NULL) +GEN_TEST_FUNC(qemuMonitorJSONScreendump, "/foo/bar") +GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false) +GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345) +GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true) +GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1") + static int mymain(void) { @@ -1065,6 +1128,11 @@ mymain(void) if (virtTestRun(# FNC, 1, testQemuMonitorJSONSimpleFunc, &simpleFunc) < 0) \ ret = -1 +#define DO_TEST_GEN(name, ...) \ + simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.xmlopt = xmlopt, __VA_ARGS__ }; \ + if (virtTestRun(# name, 1, testQemuMonitorJSON ## name, &simpleFunc) < 0) \ + ret = -1 + DO_TEST(GetStatus); DO_TEST(GetVersion); DO_TEST(GetMachines); @@ -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); + DO_TEST_GEN(qemuMonitorJSONBlockResize); + DO_TEST_GEN(qemuMonitorJSONSetVNCPassword); + DO_TEST_GEN(qemuMonitorJSONSetPassword); + DO_TEST_GEN(qemuMonitorJSONExpirePassword); + DO_TEST_GEN(qemuMonitorJSONSetBalloon); + DO_TEST_GEN(qemuMonitorJSONSetCPU); + DO_TEST_GEN(qemuMonitorJSONEjectMedia); + DO_TEST_GEN(qemuMonitorJSONChangeMedia); + DO_TEST_GEN(qemuMonitorJSONSaveVirtualMemory); + DO_TEST_GEN(qemuMonitorJSONSavePhysicalMemory); + DO_TEST_GEN(qemuMonitorJSONSetMigrationSpeed); + DO_TEST_GEN(qemuMonitorJSONSetMigrationDowntime); + DO_TEST_GEN(qemuMonitorJSONMigrate); + DO_TEST_GEN(qemuMonitorJSONDump); + DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate); + DO_TEST_GEN(qemuMonitorJSONAddNetdev); + DO_TEST_GEN(qemuMonitorJSONRemoveNetdev); + DO_TEST_GEN(qemuMonitorJSONDelDevice); + DO_TEST_GEN(qemuMonitorJSONAddDevice); + DO_TEST_GEN(qemuMonitorJSONSetDrivePassphrase); + DO_TEST_GEN(qemuMonitorJSONDriveMirror); + DO_TEST_GEN(qemuMonitorJSONBlockCommit); + DO_TEST_GEN(qemuMonitorJSONDrivePivot); + DO_TEST_GEN(qemuMonitorJSONScreendump); + DO_TEST_GEN(qemuMonitorJSONOpenGraphics); + DO_TEST_GEN(qemuMonitorJSONNBDServerStart); + DO_TEST_GEN(qemuMonitorJSONNBDServerAdd); + DO_TEST_GEN(qemuMonitorJSONDetachCharDev); virObjectUnref(xmlopt); -- 1.8.1.5

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@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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f52e970..6eb26a1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1100,6 +1100,82 @@ GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345) GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true) GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1") + +static int +testQemuMonitorJSONqemuMonitorJSONGetCPUInfo(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + pid_t *cpupids = NULL; + pid_t expected_cpupids[] = {17622, 17623, 17624, 17625}; + int ncpupids; + size_t i; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-cpus", + "{" + " \"return\": [" + " {" + " \"current\": true," + " \"CPU\": 0," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17622" + " }," + " {" + " \"current\": false," + " \"CPU\": 1," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17623" + " }," + " {" + " \"current\": false," + " \"CPU\": 2," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17624" + " }," + " {" + " \"current\": false," + " \"CPU\": 3," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17625" + " }" + " ]," + " \"id\": \"libvirt-7\"" + "}") < 0) + goto cleanup; + + ncpupids = qemuMonitorJSONGetCPUInfo(qemuMonitorTestGetMonitor(test), &cpupids); + + if (ncpupids != 4) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Expecting ncpupids = 4 but got %d", ncpupids); + goto cleanup; + } + + for (i = 0; i < ncpupids; i++) { + if (cpupids[i] != expected_cpupids[i]) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Expecting cpupids[%zu] = %d but got %d", + i, expected_cpupids[i], cpupids[i]); + goto cleanup; + } + } + + ret = 0; + +cleanup: + VIR_FREE(cpupids); + qemuMonitorTestFree(test); + return ret; +} + static int mymain(void) { @@ -1183,6 +1259,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONNBDServerStart); DO_TEST_GEN(qemuMonitorJSONNBDServerAdd); DO_TEST_GEN(qemuMonitorJSONDetachCharDev); + DO_TEST(qemuMonitorJSONGetCPUInfo); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
+ " {" + " \"current\": false," + " \"CPU\": 2," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17624" + " }," + " {" + " \"current\": false," + " \"CPU\": 3," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17625" + " }"
In the past, we've had a bug report about the case when cpu ids returned by this command are not contiguous. Should you try that here, to make sure we've handled it correctly? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 02.10.2013 20:31, Eric Blake wrote:
On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
+ " {" + " \"current\": false," + " \"CPU\": 2," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17624" + " }," + " {" + " \"current\": false," + " \"CPU\": 3," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17625" + " }"
In the past, we've had a bug report about the case when cpu ids returned by this command are not contiguous. Should you try that here, to make sure we've handled it correctly?
The issue was not in the monitor itself rather than in higher levels. But it doesn't hurt adjusting some numbers neither. Michal

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 6eb26a1..587b66f 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1177,6 +1177,43 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetVirtType(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + int virtType; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-kvm", + "{" + " \"return\": {" + " \"enabled\": true," + " \"present\": true" + " }," + " \"id\": \"libvirt-8\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetVirtType(qemuMonitorTestGetMonitor(test), &virtType) < 0) + goto cleanup; + + if (virtType != VIR_DOMAIN_VIRT_KVM) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Unexpected virt type: %d", virtType); + goto cleanup; + } + + ret = 0; + +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1260,6 +1297,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONNBDServerAdd); DO_TEST_GEN(qemuMonitorJSONDetachCharDev); DO_TEST(qemuMonitorJSONGetCPUInfo); + DO_TEST(qemuMonitorJSONGetVirtType); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
static int +testQemuMonitorJSONqemuMonitorJSONGetVirtType(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + int virtType; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-kvm", + "{" + " \"return\": {" + " \"enabled\": true," + " \"present\": true" + " }," + " \"id\": \"libvirt-8\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetVirtType(qemuMonitorTestGetMonitor(test), &virtType) < 0) + goto cleanup; + + if (virtType != VIR_DOMAIN_VIRT_KVM) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Unexpected virt type: %d", virtType); + goto cleanup; + }
This should also test the case where the command returns failure (commandnotfound) and/or returns success but "enabled":false, to make sure we don't report VIR_DOMAIN_VIRT_KVM in those cases. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 587b66f..ba2de45 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1214,6 +1214,42 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + unsigned long long currmem; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-balloon", + "{" + " \"return\": {" + " \"actual\": 4294967296" + " }," + " \"id\": \"libvirt-9\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetBalloonInfo(qemuMonitorTestGetMonitor(test), &currmem) < 0) + goto cleanup; + + if (currmem != (4294967296/1024)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Unexpected currmem value: %llu", currmem); + goto cleanup; + } + + ret = 0; + +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1298,6 +1334,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONDetachCharDev); DO_TEST(qemuMonitorJSONGetCPUInfo); DO_TEST(qemuMonitorJSONGetVirtType); + DO_TEST(qemuMonitorJSONGetBalloonInfo); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
+ + if (qemuMonitorJSONGetBalloonInfo(qemuMonitorTestGetMonitor(test), &currmem) < 0) + goto cleanup;
I guess Dan is in favor of the direct calls, in which case this is fine (I'd still rather go through the wrappers, so we can get rid of duplication in qemu_monitor_json.h). The rest of the test looks fine, so I'm not going to hold up an improvement to the testsuite in favor of a refactoring not yet done. ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 143 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index ba2de45..7a851bd 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1250,6 +1250,148 @@ cleanup: } static int +testHashEqualQemuDomainDiskInfo(const void *value1, const void *value2) +{ + const struct qemuDomainDiskInfo *info1 = value1, *info2 = value2; + + return memcmp(info1, info2, sizeof(*info1)); +} + +static int +testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + virHashTablePtr blockDevices = NULL, expectedBlockDevices = NULL; + struct qemuDomainDiskInfo *info; + + if (!test) + return -1; + + if (!(blockDevices = virHashCreate(32, (virHashDataFree) free)) || + !(expectedBlockDevices = virHashCreate(32, (virHashDataFree) (free)))) + goto cleanup; + + if (VIR_ALLOC(info) < 0) + goto cleanup; + + if (virHashAddEntry(expectedBlockDevices, "virtio-disk0", info) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Unable to create expectedBlockDevices hash table"); + goto cleanup; + } + + if (VIR_ALLOC(info) < 0) + goto cleanup; + + if (virHashAddEntry(expectedBlockDevices, "virtio-disk1", info) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Unable to create expectedBlockDevices hash table"); + goto cleanup; + } + + if (VIR_ALLOC(info) < 0) + goto cleanup; + + info->locked = true; + info->removable = true; + if (virHashAddEntry(expectedBlockDevices, "ide0-1-0", info) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Unable to create expectedBlockDevices hash table"); + goto cleanup; + } + + if (qemuMonitorTestAddItem(test, "query-block", + "{" + " \"return\": [" + " {" + " \"io-status\": \"ok\"," + " \"device\": \"drive-virtio-disk0\"," + " \"locked\": false," + " \"removable\": false," + " \"inserted\": {" + " \"iops_rd\": 0," + " \"iops_wr\": 0," + " \"ro\": false," + " \"backing_file_depth\": 0," + " \"drv\": \"qcow2\"," + " \"iops\": 0," + " \"bps_wr\": 0," + " \"encrypted\": false," + " \"bps\": 0," + " \"bps_rd\": 0," + " \"file\": \"/home/zippy/work/tmp/gentoo.qcow2\"," + " \"encryption_key_missing\": false" + " }," + " \"type\": \"unknown\"" + " }," + " {" + " \"io-status\": \"ok\"," + " \"device\": \"drive-virtio-disk1\"," + " \"locked\": false," + " \"removable\": false," + " \"inserted\": {" + " \"iops_rd\": 0," + " \"iops_wr\": 0," + " \"ro\": false," + " \"backing_file_depth\": 0," + " \"drv\": \"raw\"," + " \"iops\": 0," + " \"bps_wr\": 0," + " \"encrypted\": false," + " \"bps\": 0," + " \"bps_rd\": 0," + " \"file\": \"/home/zippy/test.bin\"," + " \"encryption_key_missing\": false" + " }," + " \"type\": \"unknown\"" + " }," + " {" + " \"io-status\": \"ok\"," + " \"device\": \"drive-ide0-1-0\"," + " \"locked\": true," + " \"removable\": true," + " \"inserted\": {" + " \"iops_rd\": 0," + " \"iops_wr\": 0," + " \"ro\": true," + " \"backing_file_depth\": 0," + " \"drv\": \"raw\"," + " \"iops\": 0," + " \"bps_wr\": 0," + " \"encrypted\": false," + " \"bps\": 0," + " \"bps_rd\": 0," + " \"file\": \"/home/zippy/tmp/install-amd64-minimal-20121210.iso\"," + " \"encryption_key_missing\": false" + " }," + " \"tray_open\": false," + " \"type\": \"unknown\"" + " }" + " ]," + " \"id\": \"libvirt-10\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetBlockInfo(qemuMonitorTestGetMonitor(test), blockDevices) < 0) + goto cleanup; + + if (!virHashEqual(blockDevices, expectedBlockDevices, testHashEqualQemuDomainDiskInfo)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Hashtable is different to the expected one"); + goto cleanup; + } + + ret = 0; +cleanup: + virHashFree(blockDevices); + virHashFree(expectedBlockDevices); + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1335,6 +1477,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetCPUInfo); DO_TEST(qemuMonitorJSONGetVirtType); DO_TEST(qemuMonitorJSONGetBalloonInfo); + DO_TEST(qemuMonitorJSONGetBlockInfo); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 143 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

While the reply can be reused test qemuMonitorJSONGetBlockExtent and qemuMonitorJSONGetBlockExtent too. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 212 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 7a851bd..7ba8ad2 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1392,6 +1392,217 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetBlockStatsInfo(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + long long rd_req, rd_bytes, rd_total_times; + long long wr_req, wr_bytes, wr_total_times; + long long flush_req, flush_total_times, errs; + int nparams; + unsigned long long extent; + + const char *reply = + "{" + " \"return\": [" + " {" + " \"device\": \"drive-virtio-disk0\"," + " \"parent\": {" + " \"stats\": {" + " \"flush_total_time_ns\": 0," + " \"wr_highest_offset\": 5256018944," + " \"wr_total_time_ns\": 0," + " \"wr_bytes\": 0," + " \"rd_total_time_ns\": 0," + " \"flush_operations\": 0," + " \"wr_operations\": 0," + " \"rd_bytes\": 0," + " \"rd_operations\": 0" + " }" + " }," + " \"stats\": {" + " \"flush_total_time_ns\": 0," + " \"wr_highest_offset\": 10406001664," + " \"wr_total_time_ns\": 530699221," + " \"wr_bytes\": 2845696," + " \"rd_total_time_ns\": 640616474," + " \"flush_operations\": 0," + " \"wr_operations\": 174," + " \"rd_bytes\": 28505088," + " \"rd_operations\": 1279" + " }" + " }," + " {" + " \"device\": \"drive-virtio-disk1\"," + " \"parent\": {" + " \"stats\": {" + " \"flush_total_time_ns\": 0," + " \"wr_highest_offset\": 0," + " \"wr_total_time_ns\": 0," + " \"wr_bytes\": 0," + " \"rd_total_time_ns\": 0," + " \"flush_operations\": 0," + " \"wr_operations\": 0," + " \"rd_bytes\": 0," + " \"rd_operations\": 0" + " }" + " }," + " \"stats\": {" + " \"flush_total_time_ns\": 0," + " \"wr_highest_offset\": 0," + " \"wr_total_time_ns\": 0," + " \"wr_bytes\": 0," + " \"rd_total_time_ns\": 8232156," + " \"flush_operations\": 0," + " \"wr_operations\": 0," + " \"rd_bytes\": 348160," + " \"rd_operations\": 85" + " }" + " }," + " {" + " \"device\": \"drive-ide0-1-0\"," + " \"parent\": {" + " \"stats\": {" + " \"flush_total_time_ns\": 0," + " \"wr_highest_offset\": 0," + " \"wr_total_time_ns\": 0," + " \"wr_bytes\": 0," + " \"rd_total_time_ns\": 0," + " \"flush_operations\": 0," + " \"wr_operations\": 0," + " \"rd_bytes\": 0," + " \"rd_operations\": 0" + " }" + " }," + " \"stats\": {" + " \"flush_total_time_ns\": 0," + " \"wr_highest_offset\": 0," + " \"wr_total_time_ns\": 0," + " \"wr_bytes\": 0," + " \"rd_total_time_ns\": 1004952," + " \"flush_operations\": 0," + " \"wr_operations\": 0," + " \"rd_bytes\": 49250," + " \"rd_operations\": 16" + " }" + " }" + " ]," + " \"id\": \"libvirt-11\"" + "}"; + + if (!test) + return -1; + + /* fill in seven times - we are gonna ask seven times later on */ + if (qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || + qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || + qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || + qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || + qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || + qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || + qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0) + goto cleanup; + +#define CHECK0(var, value) \ + if (var != value) { \ + virReportError(VIR_ERR_INTERNAL_ERROR, \ + "Invalid " #var " value: %lld, expected %d", \ + var, value); \ + goto cleanup; \ + } + +#define CHECK(RD_REQ, RD_BYTES, RD_TOTAL_TIMES, WR_REQ, WR_BYTES, WR_TOTAL_TIMES, \ + FLUSH_REQ, FLUSH_TOTAL_TIMES, ERRS) \ + CHECK0(rd_req, RD_REQ) \ + CHECK0(rd_bytes, RD_BYTES) \ + CHECK0(rd_total_times, RD_TOTAL_TIMES) \ + CHECK0(wr_req, WR_REQ) \ + CHECK0(wr_bytes, WR_BYTES) \ + CHECK0(wr_total_times, WR_TOTAL_TIMES) \ + CHECK0(flush_req, FLUSH_REQ) \ + CHECK0(flush_total_times, FLUSH_TOTAL_TIMES) \ + CHECK0(errs, ERRS) + + if (qemuMonitorJSONGetBlockStatsInfo(qemuMonitorTestGetMonitor(test), "virtio-disk0", + &rd_req, &rd_bytes, &rd_total_times, + &wr_req, &wr_bytes, &wr_total_times, + &flush_req, &flush_total_times, &errs) < 0) + goto cleanup; + + CHECK(1279, 28505088, 640616474, 174, 2845696, 530699221, 0, 0, -1) + + if (qemuMonitorJSONGetBlockStatsInfo(qemuMonitorTestGetMonitor(test), "virtio-disk1", + &rd_req, &rd_bytes, &rd_total_times, + &wr_req, &wr_bytes, &wr_total_times, + &flush_req, &flush_total_times, &errs) < 0) + goto cleanup; + + CHECK(85, 348160, 8232156, 0, 0, 0, 0, 0, -1) + + if (qemuMonitorJSONGetBlockStatsInfo(qemuMonitorTestGetMonitor(test), "ide0-1-0", + &rd_req, &rd_bytes, &rd_total_times, + &wr_req, &wr_bytes, &wr_total_times, + &flush_req, &flush_total_times, &errs) < 0) + goto cleanup; + + CHECK(16, 49250, 1004952, 0, 0, 0, 0, 0, -1) + + if (qemuMonitorJSONGetBlockStatsParamsNumber(qemuMonitorTestGetMonitor(test), + &nparams) < 0) + goto cleanup; + + if (nparams != 8) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Invalid number of stats: %d, expected 8", + nparams); + goto cleanup; + } + + if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "virtio-disk0", + &extent) < 0) + goto cleanup; + + if (extent != 5256018944) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Invalid extent: %llu, expected 5256018944", + extent); + goto cleanup; + } + + if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "virtio-disk1", + &extent) < 0) + goto cleanup; + + if (extent != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Invalid extent: %llu, expected 0", + extent); + goto cleanup; + } + + if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "ide0-1-0", + &extent) < 0) + goto cleanup; + + if (extent != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Invalid extent: %llu, expected 0", + extent); + goto cleanup; + } + + ret = 0; + +#undef CHECK +#undef CHECK0 + +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1478,6 +1689,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetVirtType); DO_TEST(qemuMonitorJSONGetBalloonInfo); DO_TEST(qemuMonitorJSONGetBlockInfo); + DO_TEST(qemuMonitorJSONGetBlockStatsInfo); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:09 AM, Michal Privoznik wrote:
While the reply can be reused test qemuMonitorJSONGetBlockExtent and qemuMonitorJSONGetBlockExtent too.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 212 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 7ba8ad2..52df486 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1603,6 +1603,42 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetMigrationCacheSize(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + unsigned long long cacheSize; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-migrate-cache-size", + "{" + " \"return\": 67108864," + " \"id\": \"libvirt-12\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetMigrationCacheSize(qemuMonitorTestGetMonitor(test), + &cacheSize) < 0) + goto cleanup; + + if (cacheSize != 67108864) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Invalid cacheSize: %llu, expected 67108864", + cacheSize); + goto cleanup; + } + + ret = 0; + +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1690,6 +1726,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetBalloonInfo); DO_TEST(qemuMonitorJSONGetBlockInfo); DO_TEST(qemuMonitorJSONGetBlockStatsInfo); + DO_TEST(qemuMonitorJSONGetMigrationCacheSize); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
ACK -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 52df486..576288b 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1639,6 +1639,55 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetMigrationStatus(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + qemuMonitorMigrationStatus status, expectedStatus; + + if (!test) + return -1; + + memset(&expectedStatus, 0, sizeof(expectedStatus)); + + expectedStatus.status = QEMU_MONITOR_MIGRATION_STATUS_ACTIVE; + expectedStatus.total_time = 47; + expectedStatus.ram_total = 1611038720; + expectedStatus.ram_remaining = 1605013504; + expectedStatus.ram_transferred = 3625548; + + if (qemuMonitorTestAddItem(test, "query-migrate", + "{" + " \"return\": {" + " \"status\": \"active\"," + " \"total-time\": 47," + " \"ram\": {" + " \"total\": 1611038720," + " \"remaining\": 1605013504," + " \"transferred\": 3625548" + " }" + " }," + " \"id\": \"libvirt-13\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetMigrationStatus(qemuMonitorTestGetMonitor(test), &status) < 0) + goto cleanup; + + if (memcmp(&status, &expectedStatus, sizeof(status)) != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Invalid migration status"); + goto cleanup; + } + + ret = 0; +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1727,6 +1776,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetBlockInfo); DO_TEST(qemuMonitorJSONGetBlockStatsInfo); DO_TEST(qemuMonitorJSONGetMigrationCacheSize); + DO_TEST(qemuMonitorJSONGetMigrationStatus); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
ACK -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 576288b..b6adb35 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1688,6 +1688,45 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetSpiceMigrationStatus(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + bool spiceMigrated; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-spice", + "{" + " \"return\": {" + " \"migrated\": true," + " \"enabled\": false," + " \"mouse-mode\": \"client\"" + " }," + " \"id\": \"libvirt-14\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitorTestGetMonitor(test), + &spiceMigrated) < 0) + goto cleanup; + + if (!spiceMigrated) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Invalid spice migration status: %d, expecting 1", + spiceMigrated); + goto cleanup; + } + + ret = 0; +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1777,6 +1816,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetBlockStatsInfo); DO_TEST(qemuMonitorJSONGetMigrationCacheSize); DO_TEST(qemuMonitorJSONGetMigrationStatus); + DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
ACK -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index b6adb35..14c64fd 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1727,6 +1727,72 @@ cleanup: } static int +testHashEqualString(const void *value1, const void *value2) +{ + return strcmp(value1, value2); +} + +static int +testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + virHashTablePtr paths = NULL, expectedPaths = NULL; + + if (!test) + return -1; + + if (!(paths = virHashCreate(32, (virHashDataFree) free)) || + !(expectedPaths = virHashCreate(32, NULL))) + goto cleanup; + + if (virHashAddEntry(expectedPaths, "charserial1", (void *) "/dev/pts/21") < 0 || + virHashAddEntry(expectedPaths, "charserial0", (void *) "/dev/pts/20") < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Unable to create expectedPaths hash table"); + goto cleanup; + } + + if (qemuMonitorTestAddItem(test, "query-chardev", + "{" + " \"return\": [" + " {" + " \"filename\": \"pty:/dev/pts/21\"," + " \"label\": \"charserial1\"" + " }," + " {" + " \"filename\": \"pty:/dev/pts/20\"," + " \"label\": \"charserial0\"" + " }," + " {" + " \"filename\": \"unix:/var/lib/libvirt/qemu/gentoo.monitor,server\"," + " \"label\": \"charmonitor\"" + " }" + " ]," + " \"id\": \"libvirt-15\"" + "}") < 0) + goto cleanup; + + if (qemuMonitorJSONGetPtyPaths(qemuMonitorTestGetMonitor(test), + paths) < 0) + goto cleanup; + + if (!virHashEqual(paths, expectedPaths, testHashEqualString)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Hashtable is different to the expected one"); + goto cleanup; + } + + ret = 0; +cleanup: + virHashFree(paths); + virHashFree(expectedPaths); + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1817,6 +1883,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetMigrationCacheSize); DO_TEST(qemuMonitorJSONGetMigrationStatus); DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus); + DO_TEST(qemuMonitorJSONGetPtyPaths); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 14c64fd..2c5c452 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1793,6 +1793,31 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONSendKey(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + unsigned int keycodes[] = {43, 26, 46, 46, 32}; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "send-key", + "{\"return\": {}, \"id\": \"libvirt-16\"}") < 0) + goto cleanup; + + if (qemuMonitorJSONSendKey(qemuMonitorTestGetMonitor(test), + 0, keycodes, ARRAY_CARDINALITY(keycodes)) < 0) + goto cleanup; + + ret = 0; +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1884,6 +1909,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetMigrationStatus); DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus); DO_TEST(qemuMonitorJSONGetPtyPaths); + DO_TEST(qemuMonitorJSONSendKey); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
static int +testQemuMonitorJSONqemuMonitorJSONSendKey(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + unsigned int keycodes[] = {43, 26, 46, 46, 32};
Is sending the same keycode more than once in a single batch really supported? The guest will see the key pushed only once. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

And so do qemuMonitorJSONGetBlockIoThrottle. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 185 +++++++++++++++++++++++++++----------------- 1 file changed, 115 insertions(+), 70 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 2c5c452..9e9dbcc 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -40,6 +40,77 @@ struct _testQemuMonitorJSONSimpleFuncData { const char *reply; }; +const char *queryBlockReply = +"{" +" \"return\": [" +" {" +" \"io-status\": \"ok\"," +" \"device\": \"drive-virtio-disk0\"," +" \"locked\": false," +" \"removable\": false," +" \"inserted\": {" +" \"iops_rd\": 5," +" \"iops_wr\": 6," +" \"ro\": false," +" \"backing_file_depth\": 0," +" \"drv\": \"qcow2\"," +" \"iops\": 4," +" \"bps_wr\": 3," +" \"encrypted\": false," +" \"bps\": 1," +" \"bps_rd\": 2," +" \"file\": \"/home/zippy/work/tmp/gentoo.qcow2\"," +" \"encryption_key_missing\": false" +" }," +" \"type\": \"unknown\"" +" }," +" {" +" \"io-status\": \"ok\"," +" \"device\": \"drive-virtio-disk1\"," +" \"locked\": false," +" \"removable\": false," +" \"inserted\": {" +" \"iops_rd\": 0," +" \"iops_wr\": 0," +" \"ro\": false," +" \"backing_file_depth\": 0," +" \"drv\": \"raw\"," +" \"iops\": 0," +" \"bps_wr\": 0," +" \"encrypted\": false," +" \"bps\": 0," +" \"bps_rd\": 0," +" \"file\": \"/home/zippy/test.bin\"," +" \"encryption_key_missing\": false" +" }," +" \"type\": \"unknown\"" +" }," +" {" +" \"io-status\": \"ok\"," +" \"device\": \"drive-ide0-1-0\"," +" \"locked\": true," +" \"removable\": true," +" \"inserted\": {" +" \"iops_rd\": 0," +" \"iops_wr\": 0," +" \"ro\": true," +" \"backing_file_depth\": 0," +" \"drv\": \"raw\"," +" \"iops\": 0," +" \"bps_wr\": 0," +" \"encrypted\": false," +" \"bps\": 0," +" \"bps_rd\": 0," +" \"file\": \"/home/zippy/tmp/install-amd64-minimal-20121210.iso\"," +" \"encryption_key_missing\": false" +" }," +" \"tray_open\": false," +" \"type\": \"unknown\"" +" }" +" ]," +" \"id\": \"libvirt-10\"" +"}"; + static int testQemuMonitorJSONGetStatus(const void *data) { @@ -1302,76 +1373,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data) goto cleanup; } - if (qemuMonitorTestAddItem(test, "query-block", - "{" - " \"return\": [" - " {" - " \"io-status\": \"ok\"," - " \"device\": \"drive-virtio-disk0\"," - " \"locked\": false," - " \"removable\": false," - " \"inserted\": {" - " \"iops_rd\": 0," - " \"iops_wr\": 0," - " \"ro\": false," - " \"backing_file_depth\": 0," - " \"drv\": \"qcow2\"," - " \"iops\": 0," - " \"bps_wr\": 0," - " \"encrypted\": false," - " \"bps\": 0," - " \"bps_rd\": 0," - " \"file\": \"/home/zippy/work/tmp/gentoo.qcow2\"," - " \"encryption_key_missing\": false" - " }," - " \"type\": \"unknown\"" - " }," - " {" - " \"io-status\": \"ok\"," - " \"device\": \"drive-virtio-disk1\"," - " \"locked\": false," - " \"removable\": false," - " \"inserted\": {" - " \"iops_rd\": 0," - " \"iops_wr\": 0," - " \"ro\": false," - " \"backing_file_depth\": 0," - " \"drv\": \"raw\"," - " \"iops\": 0," - " \"bps_wr\": 0," - " \"encrypted\": false," - " \"bps\": 0," - " \"bps_rd\": 0," - " \"file\": \"/home/zippy/test.bin\"," - " \"encryption_key_missing\": false" - " }," - " \"type\": \"unknown\"" - " }," - " {" - " \"io-status\": \"ok\"," - " \"device\": \"drive-ide0-1-0\"," - " \"locked\": true," - " \"removable\": true," - " \"inserted\": {" - " \"iops_rd\": 0," - " \"iops_wr\": 0," - " \"ro\": true," - " \"backing_file_depth\": 0," - " \"drv\": \"raw\"," - " \"iops\": 0," - " \"bps_wr\": 0," - " \"encrypted\": false," - " \"bps\": 0," - " \"bps_rd\": 0," - " \"file\": \"/home/zippy/tmp/install-amd64-minimal-20121210.iso\"," - " \"encryption_key_missing\": false" - " }," - " \"tray_open\": false," - " \"type\": \"unknown\"" - " }" - " ]," - " \"id\": \"libvirt-10\"" - "}") < 0) + if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0) goto cleanup; if (qemuMonitorJSONGetBlockInfo(qemuMonitorTestGetMonitor(test), blockDevices) < 0) @@ -1818,6 +1820,48 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + virDomainBlockIoTuneInfo info, expectedInfo; + + if (!test) + return -1; + + expectedInfo = (virDomainBlockIoTuneInfo) {1, 2, 3, 4, 5, 6}; + + if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0 || + qemuMonitorTestAddItemParams(test, "block_set_io_throttle", + "{\"return\":{}}", + "device", "\"drive-virtio-disk1\"", + "bps", "1", "bps_rd", "2", "bps_wr", "3", + "iops", "4", "iops_rd", "5", "iops_wr", "6", + NULL, NULL) < 0) + goto cleanup; + + if (qemuMonitorJSONGetBlockIoThrottle(qemuMonitorTestGetMonitor(test), + "drive-virtio-disk0", &info) < 0) + goto cleanup; + + if (memcmp(&info, &expectedInfo, sizeof(info) != 0)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Invalid @info"); + goto cleanup; + } + + if (qemuMonitorJSONSetBlockIoThrottle(qemuMonitorTestGetMonitor(test), + "drive-virtio-disk1", &info) < 0) + goto cleanup; + + ret = 0; +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1910,6 +1954,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus); DO_TEST(qemuMonitorJSONGetPtyPaths); DO_TEST(qemuMonitorJSONSendKey); + DO_TEST(qemuMonitorJSONSetBlockIoThrottle); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
And so do qemuMonitorJSONGetBlockIoThrottle.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 185 +++++++++++++++++++++++++++----------------- 1 file changed, 115 insertions(+), 70 deletions(-)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 9e9dbcc..5636fb6 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1862,6 +1862,43 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + char *arch; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-target", + "{" + " \"return\": {" + " \"arch\": \"x86_64\"" + " }," + " \"id\": \"libvirt-21\"" + "}") < 0) + goto cleanup; + + if (!(arch = qemuMonitorJSONGetTargetArch(qemuMonitorTestGetMonitor(test)))) + goto cleanup; + + if (STRNEQ(arch, "x86_64")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Unexpected architecture %s, expecting x86_64", + arch); + goto cleanup; + } + + ret = 0; +cleanup: + VIR_FREE(arch); + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1955,6 +1992,7 @@ mymain(void) DO_TEST(qemuMonitorJSONGetPtyPaths); DO_TEST(qemuMonitorJSONSendKey); DO_TEST(qemuMonitorJSONSetBlockIoThrottle); + DO_TEST(qemuMonitorJSONGetTargetArch); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
ACK -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

And so do qemuMonitorJSONSetMigrationCapability. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 5636fb6..6e6cfaf 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1899,6 +1899,51 @@ cleanup: } static int +testQemuMonitorJSONqemuMonitorJSONGetMigrationCapability(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + int cap; + const char *reply = + "{" + " \"return\": [" + " {" + " \"state\": false," + " \"capability\": \"xbzrle\"" + " }" + " ]," + " \"id\": \"libvirt-22\"" + "}"; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-migrate-capabilities", reply) < 0 || + qemuMonitorTestAddItem(test, "migrate-set-capabilities", + "{\"return\":{}}") < 0) + goto cleanup; + + cap = qemuMonitorJSONGetMigrationCapability(qemuMonitorTestGetMonitor(test), + QEMU_MONITOR_MIGRATION_CAPS_XBZRLE); + if (cap != 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Unexpected capability: %d, expecting 1", + cap); + goto cleanup; + } + + if (qemuMonitorJSONSetMigrationCapability(qemuMonitorTestGetMonitor(test), + QEMU_MONITOR_MIGRATION_CAPS_XBZRLE) < 0) + goto cleanup; + + ret = 0; +cleanup: + qemuMonitorTestFree(test); + return ret; +} + +static int mymain(void) { int ret = 0; @@ -1993,6 +2038,7 @@ mymain(void) DO_TEST(qemuMonitorJSONSendKey); DO_TEST(qemuMonitorJSONSetBlockIoThrottle); DO_TEST(qemuMonitorJSONGetTargetArch); + DO_TEST(qemuMonitorJSONGetMigrationCapability); virObjectUnref(xmlopt); -- 1.8.1.5

On 10/02/2013 11:10 AM, Michal Privoznik wrote:
And so do qemuMonitorJSONSetMigrationCapability.
s/And so/Also/
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemumonitorjsontest.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
ACK -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Michal Privoznik