On 04/25/2018 11:15 AM, Peter Krempa wrote: > Add a test infrastructure that will allow testing the JSON object > generator used for generating data to use with blockdev-add. > > The resulting disk including the backing chain is validated to conform > to the QAPI schema and the expected output files. > > The first test cases make sure that libvirt will not allow nodenames > exceeding 31 chars. > > Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> > --- > tests/Makefile.am | 3 + > tests/qemublocktest.c | 227 +++++++++++++++++++++ > .../xml2json/nodename-long-format.xml | 12 ++ > .../xml2json/nodename-long-protocol.xml | 12 ++ > 4 files changed, 254 insertions(+) > create mode 100644 tests/qemublocktestdata/xml2json/nodename-long-format.xml > create mode 100644 tests/qemublocktestdata/xml2json/nodename-long-protocol.xml > [...]] > +struct testQemuDiskXMLToJSONData { > + virQEMUDriverPtr driver; > + virHashTablePtr schema; > + virJSONValuePtr schemaroot; > + const char *name; > + bool fail; If there was a const char *expt; which would have at least a subset of the expected error message, then you'd really know if the failure was for what you were testing as opposed to some other random failure (without needing to turn on debug). Nothing that needs to change for an R-by, but just a random thought as I ran the test w/ debug mode for the errors: internal error: node-name '0123456789ABCDEF0123456789ABCDEF' too long for qemu and internal error: node-name '0123456789ABCDEF0123456789ABCDEF0' too long for qemu > + > + virJSONValuePtr *props; > + size_t nprops; > + > + virQEMUCapsPtr qemuCaps; > +}; > + > + [...] > +static int > +testQemuDiskXMLToPropsValidateFile(const void *opaque) > +{ > + struct testQemuDiskXMLToJSONData *data = (void *) opaque; > + virBuffer buf = VIR_BUFFER_INITIALIZER; > + char *jsonpath = NULL; > + char *jsonstr = NULL; > + char *actual = NULL; > + int ret = -1; > + size_t i; > + > + if (data->fail) > + return EXIT_AM_SKIP; > + > + if (virAsprintf(&jsonpath, "%s%s.json", > + testQemuDiskXMLToJSONPath, data->name) < 0) > + goto cleanup; > + > + for (i = 0; i < data->nprops; i++) { > + if (!(jsonstr = virJSONValueToString(data->props[i], true))) > + goto cleanup; > + > + virBufferAdd(&buf, jsonstr, -1); Coverity informed me @jsonstr would be leaked each time through the loop. Probably could just be local to this loop too. > + } > + > + if (virBufferCheckError(&buf) < 0) > + goto cleanup; > + > + actual = virBufferContentAndReset(&buf); > + > + ret = virTestCompareToFile(actual, jsonpath); > + > + cleanup: > + VIR_FREE(jsonpath); > + VIR_FREE(jsonstr); > + VIR_FREE(actual); > + return ret; > +} > + > + Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx> John [...] -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list