static int test_virCapabilitiesFormat(const void *opaque) { struct virCapabilitiesFormatData *data = (struct virCapabilitiesFormatData *) opaque; virCapsPtr caps = NULL; char *capsXML = NULL; char *path = NULL; int ret = -1; if (!(caps = buildVirCapabilities(data->max_cells, data->max_cpus_in_cell, data->max_mem_in_cell))) goto cleanup; if (!(capsXML = virCapabilitiesFormatXML(caps))) goto cleanup; if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s.xml", abs_srcdir, data->filename) < 0) goto cleanup; if (virTestCompareToFile(capsXML, path) < 0) goto cleanup; ret = 0; cleanup: VIR_FREE(path); VIR_FREE(capsXML); virObjectUnref(caps); return ret; }
static char * bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; virCapsPtr caps; char *xml = NULL; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; if (!(caps = bhyveDriverGetCapabilities(privconn))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to get Capabilities")); goto cleanup; } if (!(xml = virCapabilitiesFormatXML(caps))) { virReportOOMError(); goto cleanup; } cleanup: virObjectUnref(caps); return xml; }
static int test_virCapabilities(const void *opaque) { struct virCapabilitiesData *data = (struct virCapabilitiesData *) opaque; const char *archStr = virArchToString(data->arch); virCapsPtr caps = NULL; char *capsXML = NULL; char *path = NULL; char *dir = NULL; char *resctrl = NULL; int ret = -1; /* * We want to keep our directory structure clean, so if there's both resctrl * and system used, we need to use slightly different path; a subdir. */ if (virAsprintf(&dir, "%s/vircaps2xmldata/linux-%s%s", abs_srcdir, data->filename, data->resctrl ? "/system" : "") < 0) goto cleanup; if (virAsprintf(&resctrl, "%s/vircaps2xmldata/linux-%s/resctrl", abs_srcdir, data->filename) < 0) goto cleanup; virFileWrapperAddPrefix("/sys/devices/system", dir); virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl); caps = virCapabilitiesNew(data->arch, data->offlineMigrate, data->liveMigrate); if (!caps) goto cleanup; if (virCapabilitiesInitNUMA(caps) < 0 || virCapabilitiesInitCaches(caps) < 0) goto cleanup; virFileWrapperClearPrefixes(); if (!(capsXML = virCapabilitiesFormatXML(caps))) goto cleanup; if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s-%s.xml", abs_srcdir, archStr, data->filename) < 0) goto cleanup; if (virTestCompareToFile(capsXML, path) < 0) goto cleanup; ret = 0; cleanup: VIR_FREE(dir); VIR_FREE(resctrl); VIR_FREE(path); VIR_FREE(capsXML); virObjectUnref(caps); return ret; }
static char *openvzGetCapabilities(virConnectPtr conn) { struct openvz_driver *driver = conn->privateData; char *ret; openvzDriverLock(driver); ret = virCapabilitiesFormatXML(driver->caps); openvzDriverUnlock(driver); return ret; }
static int testCompareFiles(virArch hostmachine, const char *xml_rel, const char *cpuinfo_rel, const char *capabilities_rel) { char *expectxml = NULL; char *actualxml = NULL; FILE *fp1 = NULL, *fp2 = NULL; virCapsPtr caps = NULL; int ret = -1; char *xml = NULL; char *cpuinfo = NULL; char *capabilities = NULL; if (virAsprintf(&xml, "%s/%s", abs_srcdir, xml_rel) < 0 || virAsprintf(&cpuinfo, "%s/%s", abs_srcdir, cpuinfo_rel) < 0 || virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0) goto fail; if (virtTestLoadFile(xml, &expectxml) < 0) goto fail; if (!(fp1 = fopen(cpuinfo, "r"))) goto fail; if (!(fp2 = fopen(capabilities, "r"))) goto fail; if (!(caps = xenHypervisorMakeCapabilitiesInternal(NULL, hostmachine, fp1, fp2))) goto fail; if (!(actualxml = virCapabilitiesFormatXML(caps))) goto fail; if (STRNEQ(expectxml, actualxml)) { virtTestDifference(stderr, expectxml, actualxml); goto fail; } ret = 0; fail: VIR_FREE(expectxml); VIR_FREE(actualxml); VIR_FREE(xml); VIR_FREE(cpuinfo); VIR_FREE(capabilities); VIR_FORCE_FCLOSE(fp1); VIR_FORCE_FCLOSE(fp2); virObjectUnref(caps); return ret; }
static char * parallelsConnectGetCapabilities(virConnectPtr conn) { parallelsConnPtr privconn = conn->privateData; char *xml; parallelsDriverLock(privconn); xml = virCapabilitiesFormatXML(privconn->caps); parallelsDriverUnlock(privconn); return xml; }
static int testCompareFiles(const char *hostmachine, const char *xml_rel, const char *cpuinfo_rel, const char *capabilities_rel) { char xmlData[MAX_FILE]; char *expectxml = &(xmlData[0]); char *actualxml = NULL; FILE *fp1 = NULL, *fp2 = NULL; virCapsPtr caps = NULL; int ret = -1; char xml[PATH_MAX]; char cpuinfo[PATH_MAX]; char capabilities[PATH_MAX]; snprintf(xml, sizeof xml - 1, "%s/%s", abs_srcdir, xml_rel); snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s", abs_srcdir, cpuinfo_rel); snprintf(capabilities, sizeof capabilities - 1, "%s/%s", abs_srcdir, capabilities_rel); if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0) goto fail; if (!(fp1 = fopen(cpuinfo, "r"))) goto fail; if (!(fp2 = fopen(capabilities, "r"))) goto fail; if (!(caps = xenHypervisorMakeCapabilitiesInternal(NULL, hostmachine, fp1, fp2))) goto fail; if (!(actualxml = virCapabilitiesFormatXML(caps))) goto fail; if (STRNEQ(expectxml, actualxml)) { virtTestDifference(stderr, expectxml, actualxml); goto fail; } ret = 0; fail: free(actualxml); VIR_FORCE_FCLOSE(fp1); VIR_FORCE_FCLOSE(fp2); virCapabilitiesFree(caps); return ret; }
static int testQemuCapsXML(const void *opaque) { int ret = -1; const testQemuData *data = opaque; char *capsFile = NULL, *xmlFile = NULL; char *capsData = NULL, *xmlData = NULL; char *capsXml = NULL; virCapsPtr capsProvided = NULL; if (virAsprintf(&xmlFile, "%s/qemucaps2xmldata/%s.xml", abs_srcdir, data->base) < 0) goto cleanup; if (virAsprintf(&capsFile, "%s/qemucaps2xmldata/%s.caps", abs_srcdir, data->base) < 0) goto cleanup; if (virtTestLoadFile(xmlFile, &xmlData) < 0) goto cleanup; if (virtTestLoadFile(capsFile, &capsData) < 0) goto cleanup; if (!(capsProvided = testGetCaps(capsData, data))) goto cleanup; capsXml = virCapabilitiesFormatXML(capsProvided); if (!capsXml) goto cleanup; ret = testCompareXMLToXML(capsXml, xmlData); cleanup: VIR_FREE(xmlFile); VIR_FREE(capsFile); VIR_FREE(capsXml); VIR_FREE(capsData); VIR_FREE(xmlData); virObjectUnref(capsProvided); return ret; }
static int test_virCapabilitiesFormat(const void *opaque) { struct virCapabilitiesFormatData *data = (struct virCapabilitiesFormatData *) opaque; virCapsPtr caps = NULL; char *capsXML = NULL; char *capsFromFile = NULL; char *path = NULL; int ret = -1; if (!(caps = buildVirCapabilities(data->max_cells, data->max_cpus_in_cell, data->max_mem_in_cell))) goto cleanup; if (!(capsXML = virCapabilitiesFormatXML(caps))) { fprintf(stderr, "Unable to format capabilities XML"); goto cleanup; } if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s.xml", abs_srcdir, data->filename) < 0) goto cleanup; if (virFileReadAll(path, 8192, &capsFromFile) < 0) goto cleanup; if (STRNEQ(capsXML, capsFromFile)) { virtTestDifference(stderr, capsFromFile, capsXML); goto cleanup; } ret = 0; cleanup: VIR_FREE(path); VIR_FREE(capsFromFile); VIR_FREE(capsXML); virObjectUnref(caps); return ret; }
virCapsPtr testQemuCapsInit(void) { virCapsPtr caps; virCapsGuestPtr guest; virCapsGuestMachinePtr *machines = NULL; int nmachines = 0; if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false))) return NULL; /* Add dummy 'none' security_driver. This is equal to setting * security_driver = "none" in qemu.conf. */ if (VIR_ALLOC_N(caps->host.secModels, 1) < 0) goto cleanup; caps->host.nsecModels = 1; if (VIR_STRDUP(caps->host.secModels[0].model, "none") < 0 || VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0) goto cleanup; if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) || !(cpuHaswell = virCPUDefCopy(&cpuHaswellData))) goto cleanup; caps->host.cpu = cpuDefault; caps->host.nnumaCell_max = 4; if ((machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686, "/usr/bin/qemu", NULL, nmachines, machines)) == NULL || !virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false)) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL) == NULL) goto cleanup; if ((machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, "/usr/bin/qemu-kvm", NULL, nmachines, machines) == NULL) goto cleanup; machines = NULL; if ((machines = testQemuAllocNewerMachines(&nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64, "/usr/bin/qemu-system-x86_64", NULL, nmachines, machines)) == NULL || !virCapabilitiesAddGuestFeature(guest, "cpuselection", true, false)) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_QEMU, NULL, NULL, 0, NULL) == NULL) goto cleanup; if ((machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, "/usr/bin/kvm", NULL, nmachines, machines) == NULL) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, "/usr/bin/kvm", NULL, 0, NULL) == NULL) goto cleanup; if (testQemuAddPPC64Guest(caps)) goto cleanup; if (testQemuAddPPC64LEGuest(caps)) goto cleanup; if (testQemuAddPPCGuest(caps)) goto cleanup; if (testQemuAddS390Guest(caps)) goto cleanup; if (testQemuAddArmGuest(caps)) goto cleanup; if (testQemuAddAARCH64Guest(caps)) goto cleanup; if (virTestGetDebug()) { char *caps_str; caps_str = virCapabilitiesFormatXML(caps); if (!caps_str) goto cleanup; VIR_TEST_DEBUG("QEMU driver capabilities:\n%s", caps_str); VIR_FREE(caps_str); } return caps; cleanup: virCapabilitiesFreeMachines(machines, nmachines); if (caps->host.cpu != cpuDefault) virCPUDefFree(cpuDefault); if (caps->host.cpu != cpuHaswell) virCPUDefFree(cpuHaswell); virObjectUnref(caps); return NULL; }
virCapsPtr testQemuCapsInit(void) { virCapsPtr caps; virCapsGuestPtr guest; virCapsGuestMachinePtr *machines = NULL; int nmachines = 0; static const char *const xen_machines[] = { "xenner" }; static virCPUFeatureDef host_cpu_features[] = { { (char *) "lahf_lm", -1 }, { (char *) "xtpr", -1 }, { (char *) "cx16", -1 }, { (char *) "tm2", -1 }, { (char *) "est", -1 }, { (char *) "vmx", -1 }, { (char *) "ds_cpl", -1 }, { (char *) "pbe", -1 }, { (char *) "tm", -1 }, { (char *) "ht", -1 }, { (char *) "ss", -1 }, { (char *) "acpi", -1 }, { (char *) "ds", -1 } }; static virCPUDef host_cpu = { VIR_CPU_TYPE_HOST, /* type */ 0, /* mode */ 0, /* match */ VIR_ARCH_X86_64, /* arch */ (char *) "core2duo", /* model */ NULL, /* vendor_id */ 0, /* fallback */ (char *) "Intel", /* vendor */ 1, /* sockets */ 2, /* cores */ 1, /* threads */ ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */ ARRAY_CARDINALITY(host_cpu_features), /* nfeatures_max */ host_cpu_features, /* features */ 0, /* ncells */ 0, /* ncells_max */ NULL, /* cells */ 0, /* cells_cpus */ }; if ((caps = virCapabilitiesNew(host_cpu.arch, 0, 0)) == NULL) return NULL; if ((caps->host.cpu = virCPUDefCopy(&host_cpu)) == NULL || (machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686, "/usr/bin/qemu", NULL, nmachines, machines)) == NULL || !virCapabilitiesAddGuestFeature(guest, "cpuselection", 1, 0)) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, "qemu", NULL, NULL, 0, NULL) == NULL) goto cleanup; if ((machines = testQemuAllocNewerMachines(&nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64, "/usr/bin/qemu-system-x86_64", NULL, nmachines, machines)) == NULL || !virCapabilitiesAddGuestFeature(guest, "cpuselection", 1, 0)) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, "qemu", NULL, NULL, 0, NULL) == NULL) goto cleanup; if ((machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; if (virCapabilitiesAddGuestDomain(guest, "kvm", "/usr/bin/kvm", NULL, nmachines, machines) == NULL) goto cleanup; machines = NULL; nmachines = ARRAY_CARDINALITY(xen_machines); if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_X86_64, "/usr/bin/xenner", NULL, nmachines, machines)) == NULL) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, "kvm", "/usr/bin/kvm", NULL, 0, NULL) == NULL) goto cleanup; if (testQemuAddPPC64Guest(caps)) goto cleanup; if (testQemuAddPPCGuest(caps)) goto cleanup; if (testQemuAddS390Guest(caps)) goto cleanup; if (virTestGetDebug()) { char *caps_str; caps_str = virCapabilitiesFormatXML(caps); if (!caps_str) goto cleanup; fprintf(stderr, "QEMU driver capabilities:\n%s", caps_str); VIR_FREE(caps_str); } return caps; cleanup: virCapabilitiesFreeMachines(machines, nmachines); virObjectUnref(caps); return NULL; }
virCapsPtr testQemuCapsInit(void) { virCapsPtr caps; if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false))) return NULL; /* Add dummy 'none' security_driver. This is equal to setting * security_driver = "none" in qemu.conf. */ if (VIR_ALLOC_N(caps->host.secModels, 1) < 0) goto cleanup; caps->host.nsecModels = 1; if (VIR_STRDUP(caps->host.secModels[0].model, "none") < 0 || VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0) goto cleanup; if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) || !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) || !(cpuPower8 = virCPUDefCopy(&cpuPower8Data)) || !(cpuPower9 = virCPUDefCopy(&cpuPower9Data))) goto cleanup; qemuTestSetHostCPU(caps, NULL); caps->host.nnumaCell_max = 4; if (testQemuAddI686Guest(caps) < 0) goto cleanup; if (testQemuAddX86_64Guest(caps) < 0) goto cleanup; if (testQemuAddPPC64Guest(caps)) goto cleanup; if (testQemuAddPPC64LEGuest(caps)) goto cleanup; if (testQemuAddPPCGuest(caps)) goto cleanup; if (testQemuAddS390Guest(caps)) goto cleanup; if (testQemuAddArmGuest(caps)) goto cleanup; if (testQemuAddAARCH64Guest(caps)) goto cleanup; if (virTestGetDebug()) { char *caps_str; caps_str = virCapabilitiesFormatXML(caps); if (!caps_str) goto cleanup; VIR_TEST_DEBUG("QEMU driver capabilities:\n%s", caps_str); VIR_FREE(caps_str); } return caps; cleanup: caps->host.cpu = NULL; virCPUDefFree(cpuDefault); virCPUDefFree(cpuHaswell); virCPUDefFree(cpuPower8); virObjectUnref(caps); return NULL; }
virCapsPtr testQemuCapsInit(void) { struct utsname utsname; virCapsPtr caps; virCapsGuestPtr guest; virCapsGuestMachinePtr *machines = NULL; int nmachines = 0; static const char *const xen_machines[] = { "xenner" }; static virCPUFeatureDef host_cpu_features[] = { { (char *) "lahf_lm", -1 }, { (char *) "xtpr", -1 }, { (char *) "cx16", -1 }, { (char *) "tm2", -1 }, { (char *) "est", -1 }, { (char *) "vmx", -1 }, { (char *) "ds_cpl", -1 }, { (char *) "pbe", -1 }, { (char *) "tm", -1 }, { (char *) "ht", -1 }, { (char *) "ss", -1 }, { (char *) "acpi", -1 }, { (char *) "ds", -1 } }; static virCPUDef host_cpu = { VIR_CPU_TYPE_HOST, /* type */ 0, /* match */ (char *) "x86_64", /* arch */ (char *) "core2duo", /* model */ (char *) "Intel", /* vendor */ 1, /* sockets */ 2, /* cores */ 1, /* threads */ ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */ host_cpu_features /* features */ }; uname (&utsname); if ((caps = virCapabilitiesNew(utsname.machine, 0, 0)) == NULL) return NULL; if ((caps->host.cpu = virCPUDefCopy(&host_cpu)) == NULL || (machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; caps->ns.parse = qemuDomainDefNamespaceParse; caps->ns.free = qemuDomainDefNamespaceFree; caps->ns.format = qemuDomainDefNamespaceFormatXML; caps->ns.href = qemuDomainDefNamespaceHref; if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32, "/usr/bin/qemu", NULL, nmachines, machines)) == NULL) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, "qemu", NULL, NULL, 0, NULL) == NULL) goto cleanup; if ((machines = testQemuAllocNewerMachines(&nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64, "/usr/bin/qemu-system-x86_64", NULL, nmachines, machines)) == NULL) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, "qemu", NULL, NULL, 0, NULL) == NULL) goto cleanup; if ((machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; if (virCapabilitiesAddGuestDomain(guest, "kvm", "/usr/bin/kvm", NULL, nmachines, machines) == NULL) goto cleanup; machines = NULL; nmachines = ARRAY_CARDINALITY(xen_machines); if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL) goto cleanup; if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64, "/usr/bin/xenner", NULL, nmachines, machines)) == NULL) goto cleanup; machines = NULL; if (virCapabilitiesAddGuestDomain(guest, "kvm", "/usr/bin/kvm", NULL, 0, NULL) == NULL) goto cleanup; if (virTestGetDebug()) { char *caps_str; caps_str = virCapabilitiesFormatXML(caps); if (!caps_str) goto cleanup; fprintf(stderr, "QEMU driver capabilities:\n%s", caps_str); VIR_FREE(caps_str); } return caps; cleanup: virCapabilitiesFreeMachines(machines, nmachines); virCapabilitiesFree(caps); return NULL; }