On 03/26/2014 05:53 PM, Roman Bogorodskiy wrote: > At this point unittest covers 4 basic cases: > > - minimal working XML for bhyve > - same as above, but with virtio disk > - ACPI and APIC args test > - MAC address test > --- > tests/Makefile.am | 26 ++++ > .../bhyvexml2argvdata/bhyvexml2argv-acpiapic.args | 3 + > tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.xml | 24 ++++ > tests/bhyvexml2argvdata/bhyvexml2argv-base.args | 3 + > tests/bhyvexml2argvdata/bhyvexml2argv-base.xml | 20 +++ > .../bhyvexml2argv-disk-virtio.args | 3 + > .../bhyvexml2argv-disk-virtio.xml | 20 +++ > tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args | 3 + > tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.xml | 21 +++ > tests/bhyvexml2argvmock.c | 49 +++++++ > tests/bhyvexml2argvtest.c | 153 +++++++++++++++++++++ > 11 files changed, 325 insertions(+) > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.xml > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-base.args > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-base.xml > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.args > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.xml > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args > create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.xml > create mode 100644 tests/bhyvexml2argvmock.c > create mode 100644 tests/bhyvexml2argvtest.c > > diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c > new file mode 100644 > index 0000000..463feab > --- /dev/null > +++ b/tests/bhyvexml2argvtest.c > @@ -0,0 +1,153 @@ > +#include <config.h> > + > +#include "testutils.h" > + > +#ifdef WITH_BHYVE > + > +# include "datatypes.h" > + > +# include "bhyve/bhyve_utils.h" > +# include "bhyve/bhyve_command.h" > + > +# define VIR_FROM_THIS VIR_FROM_BHYVE > + > +static bhyveConn driver; > + > +static virCapsPtr > +testBhyveBuildCapabilities(void) > +{ > + virCapsPtr caps; > + virCapsGuestPtr guest; > + > + if ((caps = virCapabilitiesNew(virArchFromHost(), Getting the arch from the host seems wrong in a test, but it seems the bhyve driver doesn't care about archs. > + 0, 0)) == NULL) > + return NULL; > + > + if ((guest = virCapabilitiesAddGuest(caps, "hvm", > + VIR_ARCH_X86_64, > + "bhyve", > + NULL, 0, NULL)) == NULL) > + goto error; > + > + if (virCapabilitiesAddGuestDomain(guest, > + "bhyve", NULL, NULL, 0, NULL) == NULL) > + goto error; > + > + return caps; > + > + error: > + virObjectUnref(caps); > + return NULL; > +} > + > +static int testCompareXMLToArgvFiles(const char *xml, > + const char *cmdline) > +{ > + char *expectargv = NULL; > + int len; > + char *actualargv = NULL; > + virConnectPtr conn; > + virDomainDefPtr vmdef = NULL; > + virDomainObj vm; > + virCommandPtr cmd = NULL; > + int ret = -1; > + > + > + if (!(conn = virGetConnect())) Does this have any side-effects? It doesn't seem to be used anywhere. > + goto out; > + > + if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, > + 1 << VIR_DOMAIN_VIRT_BHYVE, > + VIR_DOMAIN_XML_INACTIVE))) > + goto out; > + > + vm.def = vmdef; > + > + if (!(cmd = virBhyveProcessBuildBhyveCmd(&driver, &vm))) > + goto out; > + > + if (!(actualargv = virCommandToString(cmd))) > + goto out; > + > + len = virtTestLoadFile(cmdline, &expectargv); > + if (len < 0) > + goto out; > + > + if (len && expectargv[len - 1] == '\n') > + expectargv[len - 1] = '\0'; > + > + if (STRNEQ(expectargv, actualargv)) { > + virtTestDifference(stderr, expectargv, actualargv); > + goto out; > + } > + > + ret = 0; > + > + out: > + VIR_FREE(expectargv); > + VIR_FREE(actualargv); > + virCommandFree(cmd); > + virDomainDefFree(vmdef); > + virObjectUnref(conn); > + return ret; > +} > + > +static int > +testCompareXMLToArgvHelper(const void *data) > +{ > + int ret = -1; > + const char *name = data; > + char *xml = NULL; > + char *args = NULL; > + > + if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml", > + abs_srcdir, name) < 0 || > + virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args", > + abs_srcdir, name) < 0) > + goto cleanup; > + > + ret = testCompareXMLToArgvFiles(xml, args); > + > + cleanup: > + VIR_FREE(xml); > + VIR_FREE(args); > + return ret; > +} > + > +static int > +mymain(void) > +{ > + int ret = 0; > + > + if ((driver.caps = testBhyveBuildCapabilities()) == NULL) > + return EXIT_FAILURE; > + > + if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)) == NULL) > + return EXIT_FAILURE; > + > +# define DO_TEST(name) \ > + do { \ > + if (virtTestRun("BHYVE XML-2-ARGV " name, \ > + testCompareXMLToArgvHelper, name) < 0) \ > + ret = -1; \ > + } while (0) > + > + > + DO_TEST("base"); > + DO_TEST("acpiapic"); > + DO_TEST("disk-virtio"); > + DO_TEST("macaddr"); caps and xmlopt should be unref'd here. > + > + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; > +} > + ACK with the leak fixed and virGetConnect removed (or explained). Jan
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list