[libvirt] [PATCH] test: Add JSON test for query-tpm-types

Add a test case for query-tpm-models QMP command. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> --- tests/qemumonitorjsontest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) Index: libvirt/tests/qemumonitorjsontest.c =================================================================== --- libvirt.orig/tests/qemumonitorjsontest.c +++ libvirt/tests/qemumonitorjsontest.c @@ -25,6 +25,7 @@ #include "qemu/qemu_conf.h" #include "virthread.h" #include "virerror.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -440,6 +441,59 @@ cleanup: static int +testQemuMonitorJSONGetTPMModels(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + int ret = -1; + char **tpmmodels = NULL; + int ntpmmodels = 0; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-tpm-models", + "{ " + " \"return\": [ " + " \"passthrough\"" + " ]" + "}") < 0) + goto cleanup; + + if ((ntpmmodels = qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(test), + &tpmmodels)) < 0) + goto cleanup; + + if (ntpmmodels != 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "ntpmmodels %d is not 1", ntpmmodels); + goto cleanup; + } + +#define CHECK(i, wantname) \ + do { \ + if (STRNEQ(tpmmodels[i], (wantname))) { \ + virReportError(VIR_ERR_INTERNAL_ERROR, \ + "name %s is not %s", \ + tpmmodels[i], (wantname)); \ + goto cleanup; \ + } \ + } while (0) + + CHECK(0, "passthrough"); + +#undef CHECK + + ret = 0; + +cleanup: + qemuMonitorTestFree(test); + virStringFreeList(tpmmodels); + return ret; +} + + +static int mymain(void) { int ret = 0; @@ -465,6 +519,7 @@ mymain(void) DO_TEST(GetMachines); DO_TEST(GetCPUDefinitions); DO_TEST(GetCommands); + DO_TEST(GetTPMModels); virObjectUnref(xmlopt);

On Mon, Apr 22, 2013 at 08:53:24AM -0400, Stefan Berger wrote:
Add a test case for query-tpm-models QMP command.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
--- tests/qemumonitorjsontest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
Index: libvirt/tests/qemumonitorjsontest.c =================================================================== --- libvirt.orig/tests/qemumonitorjsontest.c +++ libvirt/tests/qemumonitorjsontest.c @@ -25,6 +25,7 @@ #include "qemu/qemu_conf.h" #include "virthread.h" #include "virerror.h" +#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE @@ -440,6 +441,59 @@ cleanup:
static int +testQemuMonitorJSONGetTPMModels(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
Don't cast 'void *'
+ qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt); + int ret = -1; + char **tpmmodels = NULL; + int ntpmmodels = 0; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "query-tpm-models", + "{ " + " \"return\": [ " + " \"passthrough\"" + " ]" + "}") < 0) + goto cleanup; + + if ((ntpmmodels = qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(test),
Whitespace damaged patch
+ &tpmmodels)) < 0) + goto cleanup; + + if (ntpmmodels != 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "ntpmmodels %d is not 1", ntpmmodels); + goto cleanup; + } + +#define CHECK(i, wantname) \ + do { \ + if (STRNEQ(tpmmodels[i], (wantname))) { \
More damage
+ virReportError(VIR_ERR_INTERNAL_ERROR, \ + "name %s is not %s", \ + tpmmodels[i], (wantname)); \
More damage
+ goto cleanup; \ + } \ + } while (0) + + CHECK(0, "passthrough"); + +#undef CHECK + + ret = 0; + +cleanup: + qemuMonitorTestFree(test); + virStringFreeList(tpmmodels); + return ret; +}
Please use git-send email in future - your mail program is trashing the formatting which makes reviewing more painful. 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 04/25/2013 07:06 AM, Daniel P. Berrange wrote:
On Mon, Apr 22, 2013 at 08:53:24AM -0400, Stefan Berger wrote:
Add a test case for query-tpm-models QMP command.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
--- tests/qemumonitorjsontest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
Index: libvirt/tests/qemumonitorjsontest.c =================================================================== --- libvirt.orig/tests/qemumonitorjsontest.c +++ libvirt/tests/qemumonitorjsontest.c @@ -25,6 +25,7 @@ #include "qemu/qemu_conf.h" #include "virthread.h" #include "virerror.h" +#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE @@ -440,6 +441,59 @@ cleanup:
static int +testQemuMonitorJSONGetTPMModels(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; Don't cast 'void *'
I has to be casted due to the const. Adding const before virDomainXMLOptionPtr xmlopt doesn't help it. Also, it's c&p. Stefan

On Thu, Apr 25, 2013 at 08:52:40AM -0400, Stefan Berger wrote:
On 04/25/2013 07:06 AM, Daniel P. Berrange wrote:
On Mon, Apr 22, 2013 at 08:53:24AM -0400, Stefan Berger wrote:
Add a test case for query-tpm-models QMP command.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
--- tests/qemumonitorjsontest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
Index: libvirt/tests/qemumonitorjsontest.c =================================================================== --- libvirt.orig/tests/qemumonitorjsontest.c +++ libvirt/tests/qemumonitorjsontest.c @@ -25,6 +25,7 @@ #include "qemu/qemu_conf.h" #include "virthread.h" #include "virerror.h" +#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE @@ -440,6 +441,59 @@ cleanup:
static int +testQemuMonitorJSONGetTPMModels(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; Don't cast 'void *'
I has to be casted due to the const. Adding const before virDomainXMLOptionPtr xmlopt doesn't help it. Also, it's c&p.
Ah, ok then. 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 :|
participants (2)
-
Daniel P. Berrange
-
Stefan Berger