コード例 #1
0
ファイル: cputest.c プロジェクト: soulxu/libvirt-xuhj
static int
cpuTestCompareXML(const char *arch,
                  const virCPUDefPtr cpu,
                  const char *name)
{
    char *xml = NULL;
    char *expected = NULL;
    char *actual = NULL;
    int ret = -1;

    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
                    abs_srcdir, arch, name) < 0)
        goto cleanup;

    if (virtTestLoadFile(xml, &expected) < 0)
        goto cleanup;

    if (!(actual = virCPUDefFormat(cpu, NULL, 0)))
        goto cleanup;

    if (STRNEQ(expected, actual)) {
        virtTestDifference(stderr, expected, actual);
        goto cleanup;
    }

    ret = 0;

cleanup:
    free(xml);
    free(expected);
    free(actual);
    return ret;
}
コード例 #2
0
ファイル: cputest.c プロジェクト: candhare/libvirt
static int
cpuTestCompareXML(const char *arch,
                  virCPUDef *cpu,
                  const char *name,
                  bool updateCPU)
{
    char *xml = NULL;
    char *actual = NULL;
    int ret = -1;

    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
                    abs_srcdir, arch, name) < 0)
        goto cleanup;

    if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU)))
        goto cleanup;

    if (virtTestCompareToFile(actual, xml) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    VIR_FREE(xml);
    VIR_FREE(actual);
    return ret;
}
コード例 #3
0
static int
cpuTestCompareXML(const char *arch,
                  const virCPUDefPtr cpu,
                  const char *name,
                  unsigned int flags)
{
    char *xml = NULL;
    char *expected = NULL;
    char *actual = NULL;
    int ret = -1;

    if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
                    abs_srcdir, arch, name) < 0)
        goto cleanup;

    if (virtTestLoadFile(xml, &expected) < 0)
        goto cleanup;

    if (!(actual = virCPUDefFormat(cpu, flags)))
        goto cleanup;

    if (STRNEQ(expected, actual)) {
        if (virTestGetVerbose())
            fprintf(stderr, "\nCompared to %s-%s.xml", arch, name);
        virtTestDifference(stderr, expected, actual);
        goto cleanup;
    }

    ret = 0;

cleanup:
    VIR_FREE(xml);
    VIR_FREE(expected);
    VIR_FREE(actual);
    return ret;
}
コード例 #4
0
ファイル: cpu.c プロジェクト: rmarwaha/libvirt1
char *
cpuBaselineXML(const char **xmlCPUs,
               unsigned int ncpus,
               const char **models,
               unsigned int nmodels)
{
    xmlDocPtr doc = NULL;
    xmlXPathContextPtr ctxt = NULL;
    virCPUDefPtr *cpus = NULL;
    virCPUDefPtr cpu = NULL;
    char *cpustr;
    unsigned int i;

    VIR_DEBUG("ncpus=%u, nmodels=%u", ncpus, nmodels);
    if (xmlCPUs) {
        for (i = 0; i < ncpus; i++)
            VIR_DEBUG("xmlCPUs[%u]=%s", i, NULLSTR(xmlCPUs[i]));
    }
    if (models) {
        for (i = 0; i < nmodels; i++)
            VIR_DEBUG("models[%u]=%s", i, NULLSTR(models[i]));
    }

    if (xmlCPUs == NULL && ncpus != 0) {
        virCPUReportError(VIR_ERR_INTERNAL_ERROR,
                "%s", _("nonzero ncpus doesn't match with NULL xmlCPUs"));
        return NULL;
    }

    if (ncpus < 1) {
        virCPUReportError(VIR_ERR_INVALID_ARG, "%s", _("No CPUs given"));
        return NULL;
    }

    if (VIR_ALLOC_N(cpus, ncpus))
        goto no_memory;

    for (i = 0; i < ncpus; i++) {
        if (!(doc = virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition)"), &ctxt)))
            goto error;

        cpus[i] = virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_HOST);
        if (cpus[i] == NULL)
            goto error;

        xmlXPathFreeContext(ctxt);
        xmlFreeDoc(doc);
        ctxt = NULL;
        doc = NULL;
    }

    if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels)))
        goto error;

    cpustr = virCPUDefFormat(cpu, 0);

cleanup:
    if (cpus) {
        for (i = 0; i < ncpus; i++)
            virCPUDefFree(cpus[i]);
        VIR_FREE(cpus);
    }
    virCPUDefFree(cpu);
    xmlXPathFreeContext(ctxt);
    xmlFreeDoc(doc);

    return cpustr;

no_memory:
    virReportOOMError();
error:
    cpustr = NULL;
    goto cleanup;
}