static int testCompareFiles(const char *xml, const char *sexpr) { char *sexprData = NULL; char *gotxml = NULL; int id; char * tty; int vncport; int ret = -1; virDomainDefPtr def = NULL; virConnectPtr conn; struct _xenUnifiedPrivate priv; conn = virGetConnect(); if (!conn) goto fail; if (virTestLoadFile(sexpr, &sexprData) < 0) goto fail; memset(&priv, 0, sizeof(priv)); /* Many puppies died to bring you this code. */ priv.caps = caps; conn->privateData = &priv; if (virMutexInit(&priv.lock) < 0) goto fail; if (xenGetDomIdFromSxprString(sexprData, &id) < 0) goto fail; xenUnifiedLock(&priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id); xenUnifiedUnlock(&priv); if (!(def = xenParseSxprString(sexprData, tty, vncport, caps, xmlopt))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } if (!(gotxml = virDomainDefFormat(def, caps, 0))) goto fail; if (virTestCompareToFile(gotxml, xml) < 0) goto fail; ret = 0; fail: VIR_FREE(sexprData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) { char *xmlData = NULL; char *xmcfgData = NULL; char *gotxmcfgData = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn = NULL; int wrote = 4096; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0) goto fail; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xml, &xmlData) < 0) goto fail; if (virtTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; /* Many puppies died to bring you this code. */ priv.xendConfigVersion = xendConfigVersion; priv.caps = caps; conn->privateData = &priv; if (!(def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto fail; if (!(conf = xenFormatXM(conn, def, xendConfigVersion))) goto fail; if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0) goto fail; gotxmcfgData[wrote] = '\0'; if (STRNEQ(xmcfgData, gotxmcfgData)) { virtTestDifference(stderr, xmcfgData, gotxmcfgData); goto fail; } ret = 0; fail: free(xmlData); free(xmcfgData); free(gotxmcfgData); if (conf) virConfFree(conf); virDomainDefFree(def); virUnrefConnect(conn); return ret; }
static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline, const char *ldcmdline, const char *dmcmdline) { char *actualargv = NULL, *actualld = NULL, *actualdm = NULL; virDomainDefPtr vmdef = NULL; virCommandPtr cmd = NULL, ldcmd = NULL; virConnectPtr conn; int ret = -1; if (!(conn = virGetConnect())) goto out; if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto out; conn->privateData = &driver; if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false))) goto out; if (!(actualargv = virCommandToString(cmd))) goto out; if (!(ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "<device.map>", &actualdm))) goto out; if (actualdm != NULL) virTrimSpaces(actualdm, NULL); if (!(actualld = virCommandToString(ldcmd))) goto out; if (virtTestCompareToFile(actualargv, cmdline) < 0) goto out; if (virtTestCompareToFile(actualld, ldcmdline) < 0) goto out; if (virFileExists(dmcmdline) || actualdm) { if (virtTestCompareToFile(actualdm, dmcmdline) < 0) goto out; } ret = 0; out: VIR_FREE(actualargv); VIR_FREE(actualld); VIR_FREE(actualdm); virCommandFree(cmd); virCommandFree(ldcmd); virDomainDefFree(vmdef); return ret; }
static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion) { char *xmlData = NULL; char *xmcfgData = NULL; char *gotxml = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xml, &xmlData) < 0) goto fail; if (virtTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; /* Many puppies died to bring you this code. */ priv.xendConfigVersion = xendConfigVersion; priv.caps = caps; conn->privateData = &priv; if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0))) goto fail; if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps))) goto fail; if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) goto fail; if (STRNEQ(xmlData, gotxml)) { virtTestDifference(stderr, xmlData, gotxml); goto fail; } ret = 0; fail: if (conf) virConfFree(conf); VIR_FREE(xmlData); VIR_FREE(xmcfgData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
static int testCompareParseXML(const char *xmcfg, const char *xml) { char *gotxmcfgData = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn = NULL; int wrote = 4096; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0) goto fail; conn = virGetConnect(); if (!conn) goto fail; /* Many puppies died to bring you this code. */ priv.caps = caps; conn->privateData = &priv; if (!(def = virDomainDefParseFile(xml, caps, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(def, def, xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } if (!(conf = xenFormatXM(conn, def))) goto fail; if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0) goto fail; gotxmcfgData[wrote] = '\0'; if (virTestCompareToFile(gotxmcfgData, xmcfg) < 0) goto fail; ret = 0; fail: VIR_FREE(gotxmcfgData); if (conf) virConfFree(conf); virDomainDefFree(def); virObjectUnref(conn); return ret; }
static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline) { char *expectargv = NULL; int len; char *actualargv = NULL; virDomainDefPtr vmdef = NULL; virDomainObj vm; virCommandPtr cmd = NULL; virConnectPtr conn; int ret = -1; if (!(conn = virGetConnect())) 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(conn, vmdef, false))) 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); return ret; }
/* * Parses domXML to virDomainDef object, which is then converted to xl.cfg(5) * config and compared with expected config. */ static int testCompareParseXML(const char *xlcfg, const char *xml) { char *gotxlcfgData = NULL; virConfPtr conf = NULL; virConnectPtr conn = NULL; int wrote = 4096; int ret = -1; virDomainDefPtr def = NULL; if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0) goto fail; conn = virGetConnect(); if (!conn) goto fail; if (!(def = virDomainDefParseFile(xml, caps, xmlopt, VIR_DOMAIN_XML_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } if (!(conf = xenFormatXL(def, conn))) goto fail; if (virConfWriteMem(gotxlcfgData, &wrote, conf) < 0) goto fail; gotxlcfgData[wrote] = '\0'; if (virtTestCompareToFile(gotxlcfgData, xlcfg) < 0) goto fail; ret = 0; fail: VIR_FREE(gotxlcfgData); if (conf) virConfFree(conf); virDomainDefFree(def); virObjectUnref(conn); return ret; }
static int testCompareFormatXML(const char *xmcfg, const char *xml) { char *xmcfgData = NULL; char *gotxml = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; conn = virGetConnect(); if (!conn) goto fail; if (virTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; /* Many puppies died to bring you this code. */ priv.caps = caps; conn->privateData = &priv; if (!(conf = virConfReadString(xmcfgData, 0))) goto fail; if (!(def = xenParseXM(conf, caps, xmlopt))) goto fail; if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (virTestCompareToFile(gotxml, xml) < 0) goto fail; ret = 0; fail: if (conf) virConfFree(conf); VIR_FREE(xmcfgData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
/* * Parses xl.cfg(5) config to virDomainDef object, which is then converted to * domXML and compared to expected XML. */ static int testCompareFormatXML(const char *xlcfg, const char *xml) { char *xlcfgData = NULL; char *gotxml = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn; virDomainDefPtr def = NULL; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xlcfg, &xlcfgData) < 0) goto fail; if (!(conf = virConfReadMem(xlcfgData, strlen(xlcfgData), 0))) goto fail; if (!(def = xenParseXL(conf, caps, xmlopt))) goto fail; if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE))) goto fail; if (virtTestCompareToFile(gotxml, xml) < 0) goto fail; ret = 0; fail: if (conf) virConfFree(conf); VIR_FREE(xlcfgData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline, virBitmapPtr extraFlags, const char *migrateFrom, int migrateFd, bool json, bool expectError) { char *expectargv = NULL; int len; char *actualargv = NULL; int ret = -1; virDomainDefPtr vmdef = NULL; virDomainChrSourceDef monitor_chr; virConnectPtr conn; char *log = NULL; char *emulator = NULL; virCommandPtr cmd = NULL; if (!(conn = virGetConnect())) goto fail; len = virtTestLoadFile(cmdline, &expectargv); if (len < 0) goto fail; if (len && expectargv[len - 1] == '\n') expectargv[len - 1] = '\0'; if (!(vmdef = virDomainDefParseFile(driver.caps, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto fail; /* * For test purposes, we may want to fake emulator's output by providing * our own script instead of a real emulator. For this to work we need to * specify a relative path in <emulator/> element, which, however, is not * allowed by RelaxNG schema for domain XML. To work around it we add an * extra '/' at the beginning of relative emulator path so that it looks * like, e.g., "/./qemu.sh" or "/../emulator/qemu.sh" instead of * "./qemu.sh" or "../emulator/qemu.sh" respectively. The following code * detects such paths, strips the extra '/' and makes the path absolute. */ if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { if (!(emulator = strdup(vmdef->emulator + 1))) goto fail; free(vmdef->emulator); vmdef->emulator = NULL; if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s", abs_srcdir, emulator) < 0) goto fail; } if (qemuCapsGet(extraFlags, QEMU_CAPS_DOMID)) vmdef->id = 6; else vmdef->id = -1; memset(&monitor_chr, 0, sizeof(monitor_chr)); monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX; monitor_chr.data.nix.path = (char *)"/tmp/test-monitor"; monitor_chr.data.nix.listen = true; qemuCapsSetList(extraFlags, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, QEMU_CAPS_LAST); if (qemudCanonicalizeMachine(&driver, vmdef) < 0) goto fail; if (qemuCapsGet(extraFlags, QEMU_CAPS_DEVICE)) { qemuDomainPCIAddressSetPtr pciaddrs; if (!(pciaddrs = qemuDomainPCIAddressSetCreate(vmdef))) goto fail; if (qemuAssignDevicePCISlots(vmdef, pciaddrs) < 0) goto fail; qemuDomainPCIAddressSetFree(pciaddrs); } free(virtTestLogContentAndReset()); virResetLastError(); /* We do not call qemuCapsExtractVersionInfo() before calling * qemuBuildCommandLine(), so we should set QEMU_CAPS_PCI_MULTIBUS for * x86_64 and i686 architectures here. */ if (STREQLEN(vmdef->os.arch, "x86_64", 6) || STREQLEN(vmdef->os.arch, "i686", 4)) { qemuCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS); } if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0) goto fail; if (!(cmd = qemuBuildCommandLine(conn, &driver, vmdef, &monitor_chr, json, extraFlags, migrateFrom, migrateFd, NULL, VIR_VM_OP_NO_OP))) goto fail; if (!!virGetLastError() != expectError) { if (virTestGetDebug() && (log = virtTestLogContentAndReset())) fprintf(stderr, "\n%s", log); goto fail; } if (expectError) { /* need to suppress the errors */ virResetLastError(); } if (!(actualargv = virCommandToString(cmd))) goto fail; if (emulator) { /* Skip the abs_srcdir portion of replacement emulator. */ char *start_skip = strstr(actualargv, abs_srcdir); char *end_skip = strstr(actualargv, emulator); if (!start_skip || !end_skip) goto fail; memmove(start_skip, end_skip, strlen(end_skip) + 1); } if (STRNEQ(expectargv, actualargv)) { virtTestDifference(stderr, expectargv, actualargv); goto fail; } ret = 0; fail: free(log); free(emulator); free(expectargv); free(actualargv); virCommandFree(cmd); virDomainDefFree(vmdef); virUnrefConnect(conn); return ret; }
static int testCompareXMLToArgvFiles(bool shouldFail, const char *poolxml, const char *volxml, const char *inputpoolxml, const char *inputvolxml, const char *cmdline, unsigned int flags, int imgformat) { char *volXmlData = NULL; char *poolXmlData = NULL; char *inputpoolXmlData = NULL; char *inputvolXmlData = NULL; char *expectedCmdline = NULL; char *actualCmdline = NULL; int ret = -1; int len; virCommandPtr cmd = NULL; virConnectPtr conn; virStorageVolDefPtr vol = NULL, inputvol = NULL; virStoragePoolDefPtr pool = NULL; virStoragePoolDefPtr inputpool = NULL; virStoragePoolObj poolobj = {.def = NULL }; if (!(conn = virGetConnect())) goto cleanup; if (virtTestLoadFile(poolxml, &poolXmlData) < 0) goto cleanup; if (virtTestLoadFile(volxml, &volXmlData) < 0) goto cleanup; if (inputvolxml && virtTestLoadFile(inputvolxml, &inputvolXmlData) < 0) goto cleanup; if (!(pool = virStoragePoolDefParseString(poolXmlData))) goto cleanup; poolobj.def = pool; if (inputpoolxml) { if (virtTestLoadFile(inputpoolxml, &inputpoolXmlData) < 0) goto cleanup; if (!(inputpool = virStoragePoolDefParseString(inputpoolXmlData))) goto cleanup; } if (!(vol = virStorageVolDefParseString(pool, volXmlData))) goto cleanup; if (inputvolxml && !(inputvol = virStorageVolDefParseString(inputpool, inputvolXmlData))) goto cleanup; testSetVolumeType(vol, pool); testSetVolumeType(inputvol, inputpool); cmd = virStorageBackendCreateQemuImgCmd(conn, &poolobj, vol, inputvol, flags, create_tool, imgformat); if (!cmd) { if (shouldFail) { virResetLastError(); ret = 0; } goto cleanup; } if (!(actualCmdline = virCommandToString(cmd))) goto cleanup; len = virtTestLoadFile(cmdline, &expectedCmdline); if (len < 0) goto cleanup; if (len && expectedCmdline[len-1] == '\n') expectedCmdline[len-1] = '\0'; if (STRNEQ_NULLABLE(expectedCmdline, actualCmdline)) { virtTestDifference(stderr, expectedCmdline, actualCmdline); goto cleanup; } ret = 0; cleanup: virStoragePoolDefFree(pool); virStoragePoolDefFree(inputpool); virStorageVolDefFree(vol); virStorageVolDefFree(inputvol); virCommandFree(cmd); VIR_FREE(actualCmdline); VIR_FREE(expectedCmdline); VIR_FREE(inputpoolXmlData); VIR_FREE(poolXmlData); VIR_FREE(volXmlData); VIR_FREE(inputvolXmlData); virObjectUnref(conn); return ret; }
static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline, virQEMUCapsPtr extraFlags, const char *migrateFrom, int migrateFd, bool json, bool expectError) { char *expectargv = NULL; int len; char *actualargv = NULL; int ret = -1; virDomainDefPtr vmdef = NULL; virDomainChrSourceDef monitor_chr; virConnectPtr conn; char *log = NULL; char *emulator = NULL; virCommandPtr cmd = NULL; if (!(conn = virGetConnect())) goto fail; len = virtTestLoadFile(cmdline, &expectargv); if (len < 0) goto fail; if (len && expectargv[len - 1] == '\n') expectargv[len - 1] = '\0'; if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto fail; /* * For test purposes, we may want to fake emulator's output by providing * our own script instead of a real emulator. For this to work we need to * specify a relative path in <emulator/> element, which, however, is not * allowed by RelaxNG schema for domain XML. To work around it we add an * extra '/' at the beginning of relative emulator path so that it looks * like, e.g., "/./qemu.sh" or "/../emulator/qemu.sh" instead of * "./qemu.sh" or "../emulator/qemu.sh" respectively. The following code * detects such paths, strips the extra '/' and makes the path absolute. */ if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { if (VIR_STRDUP(emulator, vmdef->emulator + 1) < 0) goto fail; VIR_FREE(vmdef->emulator); vmdef->emulator = NULL; if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s", abs_srcdir, emulator) < 0) goto fail; } if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DOMID)) vmdef->id = 6; else vmdef->id = -1; memset(&monitor_chr, 0, sizeof(monitor_chr)); monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX; monitor_chr.data.nix.path = (char *)"/tmp/test-monitor"; monitor_chr.data.nix.listen = true; virQEMUCapsSetList(extraFlags, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, QEMU_CAPS_NO_ACPI, QEMU_CAPS_LAST); if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DEVICE)) qemuDomainAssignAddresses(vmdef, extraFlags, NULL); log = virtTestLogContentAndReset(); VIR_FREE(log); virResetLastError(); if (vmdef->os.arch == VIR_ARCH_X86_64 || vmdef->os.arch == VIR_ARCH_I686) { virQEMUCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS); } if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0) goto fail; if (!(cmd = qemuBuildCommandLine(conn, &driver, vmdef, &monitor_chr, json, extraFlags, migrateFrom, migrateFd, NULL, VIR_NETDEV_VPORT_PROFILE_OP_NO_OP, &testCallbacks))) goto fail; if (!!virGetLastError() != expectError) { if (virTestGetDebug() && (log = virtTestLogContentAndReset())) fprintf(stderr, "\n%s", log); goto fail; } if (expectError) { /* need to suppress the errors */ virResetLastError(); } if (!(actualargv = virCommandToString(cmd))) goto fail; if (emulator) { /* Skip the abs_srcdir portion of replacement emulator. */ char *start_skip = strstr(actualargv, abs_srcdir); char *end_skip = strstr(actualargv, emulator); if (!start_skip || !end_skip) goto fail; memmove(start_skip, end_skip, strlen(end_skip) + 1); } if (STRNEQ(expectargv, actualargv)) { virtTestDifference(stderr, expectargv, actualargv); goto fail; } ret = 0; fail: VIR_FREE(log); VIR_FREE(emulator); VIR_FREE(expectargv); VIR_FREE(actualargv); virCommandFree(cmd); virDomainDefFree(vmdef); virObjectUnref(conn); return ret; }
static int testCompareXMLToArgvFiles(const char *xml, const char *cmd, unsigned long long extraFlags, const char *migrateFrom) { char argvData[MAX_FILE]; char *expectargv = &(argvData[0]); char *actualargv = NULL; const char **argv = NULL; const char **qenv = NULL; const char **tmp = NULL; int ret = -1, len; unsigned long long flags; virDomainDefPtr vmdef = NULL; virDomainChrDef monitor_chr; virConnectPtr conn; if (!(conn = virGetConnect())) goto fail; if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0) goto fail; if (!(vmdef = virDomainDefParseFile(driver.caps, xml, VIR_DOMAIN_XML_INACTIVE))) goto fail; if (extraFlags & QEMUD_CMD_FLAG_DOMID) vmdef->id = 6; else vmdef->id = -1; memset(&monitor_chr, 0, sizeof(monitor_chr)); monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX; monitor_chr.data.nix.path = (char *)"/tmp/test-monitor"; monitor_chr.data.nix.listen = 1; if (!(monitor_chr.info.alias = strdup("monitor"))) goto fail; flags = QEMUD_CMD_FLAG_VNC_COLON | QEMUD_CMD_FLAG_NO_REBOOT | extraFlags; if (qemudCanonicalizeMachine(&driver, vmdef) < 0) goto fail; if (flags & QEMUD_CMD_FLAG_DEVICE) { qemuDomainPCIAddressSetPtr pciaddrs; if (!(pciaddrs = qemuDomainPCIAddressSetCreate(vmdef))) goto fail; if (qemuAssignDevicePCISlots(vmdef, pciaddrs) < 0) goto fail; qemuDomainPCIAddressSetFree(pciaddrs); } if (qemudBuildCommandLine(conn, &driver, vmdef, &monitor_chr, 0, flags, &argv, &qenv, NULL, NULL, migrateFrom, NULL) < 0) goto fail; len = 1; /* for trailing newline */ tmp = qenv; while (*tmp) { len += strlen(*tmp) + 1; tmp++; } tmp = argv; while (*tmp) { len += strlen(*tmp) + 1; tmp++; } if ((actualargv = malloc(sizeof(*actualargv)*len)) == NULL) goto fail; actualargv[0] = '\0'; tmp = qenv; while (*tmp) { if (actualargv[0]) strcat(actualargv, " "); strcat(actualargv, *tmp); tmp++; } tmp = argv; while (*tmp) { if (actualargv[0]) strcat(actualargv, " "); strcat(actualargv, *tmp); tmp++; } strcat(actualargv, "\n"); if (STRNEQ(expectargv, actualargv)) { virtTestDifference(stderr, expectargv, actualargv); goto fail; } ret = 0; fail: free(actualargv); if (argv) { tmp = argv; while (*tmp) { free(*(char**)tmp); tmp++; } free(argv); } if (qenv) { tmp = qenv; while (*tmp) { free(*(char**)tmp); tmp++; } free(qenv); } virDomainDefFree(vmdef); virUnrefConnect(conn); return ret; }
static int testCompareXMLToArgvFiles(const char *xml, const char *cmdline, virQEMUCapsPtr extraFlags, const char *migrateFrom, int migrateFd, virQemuXML2ArgvTestFlags flags) { char *expectargv = NULL; int len; char *actualargv = NULL; int ret = -1; virDomainDefPtr vmdef = NULL; virDomainChrSourceDef monitor_chr; virConnectPtr conn; char *log = NULL; virCommandPtr cmd = NULL; if (!(conn = virGetConnect())) goto out; conn->secretDriver = &fakeSecretDriver; if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) { if (flags & FLAG_EXPECT_PARSE_ERROR) goto ok; goto out; } if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DOMID)) vmdef->id = 6; else vmdef->id = -1; memset(&monitor_chr, 0, sizeof(monitor_chr)); monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX; monitor_chr.data.nix.path = (char *)"/tmp/test-monitor"; monitor_chr.data.nix.listen = true; virQEMUCapsSetList(extraFlags, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, QEMU_CAPS_NO_ACPI, QEMU_CAPS_LAST); if (STREQ(vmdef->os.machine, "pc") && STREQ(vmdef->emulator, "/usr/bin/qemu-system-x86_64")) { VIR_FREE(vmdef->os.machine); if (VIR_STRDUP(vmdef->os.machine, "pc-0.11") < 0) goto out; } if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DEVICE)) { if (qemuDomainAssignAddresses(vmdef, extraFlags, NULL)) { if (flags & FLAG_EXPECT_ERROR) goto ok; goto out; } } log = virtTestLogContentAndReset(); VIR_FREE(log); virResetLastError(); if (vmdef->os.arch == VIR_ARCH_X86_64 || vmdef->os.arch == VIR_ARCH_I686) { virQEMUCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS); } if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0) goto out; if (!(cmd = qemuBuildCommandLine(conn, &driver, vmdef, &monitor_chr, (flags & FLAG_JSON), extraFlags, migrateFrom, migrateFd, NULL, VIR_NETDEV_VPORT_PROFILE_OP_NO_OP, &testCallbacks))) { if (flags & FLAG_EXPECT_FAILURE) { ret = 0; if (virTestGetDebug() > 1) fprintf(stderr, "Got expected error: %s\n", virGetLastErrorMessage()); virResetLastError(); } goto out; } else if (flags & FLAG_EXPECT_FAILURE) { if (virTestGetDebug()) fprintf(stderr, "qemuBuildCommandLine should have failed\n"); goto out; } if (!!virGetLastError() != !!(flags & FLAG_EXPECT_ERROR)) { if (virTestGetDebug() && (log = virtTestLogContentAndReset())) fprintf(stderr, "\n%s", log); 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; } ok: if (flags & FLAG_EXPECT_ERROR) { /* need to suppress the errors */ virResetLastError(); } ret = 0; out: VIR_FREE(log); VIR_FREE(expectargv); VIR_FREE(actualargv); virCommandFree(cmd); virDomainDefFree(vmdef); virObjectUnref(conn); return ret; }
static int testCompareXMLToArgvFiles(bool shouldFail, const char *poolxml, const char *volxml, const char *inputpoolxml, const char *inputvolxml, const char *cmdline, unsigned int flags, int imgformat, unsigned long parse_flags) { char *actualCmdline = NULL; int ret = -1; virCommandPtr cmd = NULL; virConnectPtr conn; virStorageVolDefPtr vol = NULL, inputvol = NULL; virStoragePoolDefPtr pool = NULL; virStoragePoolDefPtr inputpool = NULL; virStoragePoolObj poolobj = {.def = NULL }; if (!(conn = virGetConnect())) goto cleanup; if (!(pool = virStoragePoolDefParseFile(poolxml))) goto cleanup; poolobj.def = pool; if (inputpoolxml) { if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml))) goto cleanup; } if (inputvolxml) parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY; if (!(vol = virStorageVolDefParseFile(pool, volxml, parse_flags))) goto cleanup; if (inputvolxml && !(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0))) goto cleanup; testSetVolumeType(vol, pool); testSetVolumeType(inputvol, inputpool); cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol, inputvol, flags, create_tool, imgformat); if (!cmd) { if (shouldFail) { virResetLastError(); ret = 0; } goto cleanup; } if (!(actualCmdline = virCommandToString(cmd))) goto cleanup; if (virTestCompareToFile(actualCmdline, cmdline) < 0) goto cleanup; ret = 0; cleanup: virStoragePoolDefFree(pool); virStoragePoolDefFree(inputpool); virStorageVolDefFree(vol); virStorageVolDefFree(inputvol); virCommandFree(cmd); VIR_FREE(actualCmdline); virObjectUnref(conn); return ret; }
static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) { char *xmlData = NULL; char *sexprData = NULL; char *gotxml = NULL; int id; char * tty; int vncport; int ret = -1; virDomainDefPtr def = NULL; virConnectPtr conn; struct _xenUnifiedPrivate priv; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xml, &xmlData) < 0) goto fail; if (virtTestLoadFile(sexpr, &sexprData) < 0) goto fail; memset(&priv, 0, sizeof priv); /* Many puppies died to bring you this code. */ priv.xendConfigVersion = xendConfigVersion; priv.caps = caps; conn->privateData = &priv; if (virMutexInit(&priv.lock) < 0) goto fail; id = xenGetDomIdFromSxprString(sexprData, xendConfigVersion); xenUnifiedLock(&priv); tty = xenStoreDomainGetConsolePath(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id); xenUnifiedUnlock(&priv); if (!(def = xenParseSxprString(sexprData, xendConfigVersion, tty, vncport))) goto fail; if (!(gotxml = virDomainDefFormat(def, 0))) goto fail; if (STRNEQ(xmlData, gotxml)) { virtTestDifference(stderr, xmlData, gotxml); goto fail; } ret = 0; fail: free(xmlData); free(sexprData); free(gotxml); virDomainDefFree(def); if (conn) virUnrefConnect(conn); return ret; }