On 08/20/2012 07:49 AM, Daniel P. Berrange wrote: > From: "Daniel P. Berrange" <berra...@redhat.com> > > Take advantage of the previously added monitor helpers to > create a test suite for the QEMU JSON monitor impl. As a > proof of concept, this tests the 'qemuMonitorGetStatus' > implementation > --- > .gitignore | 1 + > tests/Makefile.am | 11 +++- > tests/qemumonitorjsontest.c | 150 > ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 161 insertions(+), 1 deletion(-) > create mode 100644 tests/qemumonitorjsontest.c >
> + if (!test) > + return -1; > + > + if (qemuMonitorTestAddItem(test, "query-status", > + "{ " > + " \"return\": { " > + " \"status\": \"running\", " > + " \"singlestep\": false, " > + " \"running\": true " > + " } " > + "}") < 0) > + goto cleanup; > + if (qemuMonitorTestAddItem(test, "query-status", > + "{ " > + " \"return\": { " > + " \"singlestep\": false, " > + " \"running\": false " > + " } " > + "}") < 0) > + goto cleanup; So the trick is to batch up several replies (even if the same command will be queried more than once), > + if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test), > + &running, &reason) < 0) > + goto cleanup; then as each call triggers a monitor command, our batched replies start getting fed back, and we can see that the rest of the qemu driver handled the reply as expected. Looks good; should be easy enough to copy to add more tests of a similar nature. ACK. -- Eric Blake ebl...@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list