vircaps2xmltest.c 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (C) Red Hat, Inc. 2014
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include <config.h>

#include "testutils.h"
#include "capabilities.h"
#include "virbitmap.h"
24
#include "virfilewrapper.h"
25 26 27 28


#define VIR_FROM_THIS VIR_FROM_NONE

29
struct virCapabilitiesData {
30
    const char *filename;
31 32 33
    virArch arch;
    bool offlineMigrate;
    bool liveMigrate;
34 35 36
};

static int
37
test_virCapabilities(const void *opaque)
38
{
39 40
    struct virCapabilitiesData *data = (struct virCapabilitiesData *) opaque;
    const char *archStr = virArchToString(data->arch);
41 42 43
    virCapsPtr caps = NULL;
    char *capsXML = NULL;
    char *path = NULL;
44
    char *system = NULL;
45
    char *resctrl = NULL;
46 47
    int ret = -1;

48 49
    if (virAsprintf(&system, "%s/vircaps2xmldata/linux-%s/system",
                    abs_srcdir, data->filename) < 0)
50 51
        goto cleanup;

52 53 54 55
    if (virAsprintf(&resctrl, "%s/vircaps2xmldata/linux-%s/resctrl",
                    abs_srcdir, data->filename) < 0)
        goto cleanup;

56
    virFileWrapperAddPrefix("/sys/devices/system", system);
57
    virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl);
58 59 60 61 62
    caps = virCapabilitiesNew(data->arch, data->offlineMigrate, data->liveMigrate);

    if (!caps)
        goto cleanup;

63 64
    if (virCapabilitiesInitNUMA(caps) < 0 ||
        virCapabilitiesInitCaches(caps) < 0)
65 66
        goto cleanup;

67
    virFileWrapperClearPrefixes();
68

69
    if (!(capsXML = virCapabilitiesFormatXML(caps)))
70 71
        goto cleanup;

72 73
    if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s-%s.xml",
                    abs_srcdir, archStr, data->filename) < 0)
74 75
        goto cleanup;

76
    if (virTestCompareToFile(capsXML, path) < 0)
77 78 79 80 81
        goto cleanup;

    ret = 0;

 cleanup:
82
    VIR_FREE(system);
83
    VIR_FREE(resctrl);
84 85 86 87 88 89 90 91 92 93 94
    VIR_FREE(path);
    VIR_FREE(capsXML);
    virObjectUnref(caps);
    return ret;
}

static int
mymain(void)
{
    int ret = 0;

95
#define DO_TEST_FULL(filename, arch, offlineMigrate, liveMigrate) \
96 97 98
    do { \
        struct virCapabilitiesData data = {filename, arch, \
                                           offlineMigrate, \
99
                                           liveMigrate}; \
100 101
        if (virTestRun(filename, test_virCapabilities, &data) < 0) \
            ret = -1; \
102 103
    } while (0)

104 105
    DO_TEST_FULL("basic", VIR_ARCH_X86_64, false, false);
    DO_TEST_FULL("basic", VIR_ARCH_AARCH64, true, false);
106

107
    DO_TEST_FULL("caches", VIR_ARCH_X86_64, true, true);
108

109
    DO_TEST_FULL("resctrl", VIR_ARCH_X86_64, true, true);
110
    DO_TEST_FULL("resctrl-cmt", VIR_ARCH_X86_64, true, true);
111 112 113
    DO_TEST_FULL("resctrl-cdp", VIR_ARCH_X86_64, true, true);
    DO_TEST_FULL("resctrl-skx", VIR_ARCH_X86_64, true, true);
    DO_TEST_FULL("resctrl-skx-twocaches", VIR_ARCH_X86_64, true, true);
114
    DO_TEST_FULL("resctrl-fake-feature", VIR_ARCH_X86_64, true, true);
115

116 117 118
    return ret;
}

119
VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virnumamock.so")