qemuhelptest.c 7.4 KB
Newer Older
1 2 3 4 5 6 7 8
#include <config.h>

#ifdef WITH_QEMU

#include <stdio.h>
#include <stdlib.h>

#include "testutils.h"
9
#include "qemu/qemu_conf.h"
10 11 12 13 14

#define MAX_HELP_OUTPUT_SIZE 1024*64

struct testInfo {
    const char *name;
15 16 17 18
    unsigned long long flags;
    unsigned int version;
    unsigned int is_kvm;
    unsigned int kvm_version;
19 20 21 22 23
};

static char *progname;
static char *abs_srcdir;

24 25 26 27 28 29 30 31 32 33 34 35 36 37
static void printMismatchedFlags(int got, int expect)
{
    int i;

    for (i = 0 ; i < (sizeof(got)*8) ; i++) {
        int gotFlag = (got & (1 << i));
        int expectFlag = (expect & (1 << i));
        if (gotFlag && !expectFlag)
            fprintf(stderr, "Extra flag %i\n", i);
        if (!gotFlag && expectFlag)
            fprintf(stderr, "Missing flag %i\n", i);
    }
}

38 39 40 41 42 43
static int testHelpStrParsing(const void *data)
{
    const struct testInfo *info = data;
    char path[PATH_MAX];
    char helpStr[MAX_HELP_OUTPUT_SIZE];
    char *help = &(helpStr[0]);
44 45
    unsigned int version, is_kvm, kvm_version;
    unsigned long long flags;
46 47 48 49 50 51 52 53 54 55

    snprintf(path, PATH_MAX, "%s/qemuhelpdata/%s", abs_srcdir, info->name);

    if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0)
        return -1;

    if (qemudParseHelpStr(help, &flags, &version, &is_kvm, &kvm_version) == -1)
        return -1;

    if (flags != info->flags) {
56
        fprintf(stderr, "Computed flags do not match: got 0x%llx, expected 0x%llx\n",
57
                flags, info->flags);
58 59 60 61

        if (getenv("VIR_TEST_DEBUG"))
            printMismatchedFlags(flags, info->flags);

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        return -1;
    }

    if (version != info->version) {
        fprintf(stderr, "Parsed versions do not match: got %u, expected %u\n",
                version, info->version);
        return -1;
    }

    if (is_kvm != info->is_kvm) {
        fprintf(stderr, "Parsed is_kvm flag does not match: got %u, expected %u\n",
                is_kvm, info->is_kvm);
        return -1;
    }

77
    if (kvm_version != info->kvm_version) {
78
        fprintf(stderr, "Parsed KVM versions do not match: got %u, expected %u\n",
79
                kvm_version, info->kvm_version);
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
        return -1;
    }

    return 0;
}

static int
mymain(int argc, char **argv)
{
    int ret = 0;
    char cwd[PATH_MAX];

    progname = argv[0];

    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname);
        return (EXIT_FAILURE);
    }

    abs_srcdir = getenv("abs_srcdir");
    if (!abs_srcdir)
        abs_srcdir = getcwd(cwd, sizeof(cwd));

#define DO_TEST(name, flags, version, is_kvm, kvm_version)                          \
    do {                                                                            \
        const struct testInfo info = { name, flags, version, is_kvm, kvm_version }; \
        if (virtTestRun("QEMU Help String Parsing " name,                           \
                        1, testHelpStrParsing, &info) < 0)                          \
            ret = -1;                                                               \
    } while (0)

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    DO_TEST("qemu-0.9.1",
            QEMUD_CMD_FLAG_KQEMU |
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_NAME,
            9001,  0,  0);
    DO_TEST("kvm-74",
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_DRIVE_BOOT |
            QEMUD_CMD_FLAG_NAME |
            QEMUD_CMD_FLAG_VNET_HDR |
            QEMUD_CMD_FLAG_MIGRATE_KVM_STDIO |
            QEMUD_CMD_FLAG_KVM |
127 128
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
            QEMUD_CMD_FLAG_MEM_PATH,
129 130 131 132 133 134 135 136 137 138 139 140
            9001,  1, 74);
    DO_TEST("qemu-0.10.5",
            QEMUD_CMD_FLAG_KQEMU |
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_NAME |
            QEMUD_CMD_FLAG_UUID |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
141
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
142
            QEMUD_CMD_FLAG_VGA |
143
            QEMUD_CMD_FLAG_0_10 |
144 145
            QEMUD_CMD_FLAG_ENABLE_KVM |
            QEMUD_CMD_FLAG_SDL,
146 147 148 149 150 151 152 153 154 155 156 157 158 159
            10005, 0,  0);
    DO_TEST("qemu-kvm-0.10.5",
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_DRIVE_BOOT |
            QEMUD_CMD_FLAG_NAME |
            QEMUD_CMD_FLAG_UUID |
            QEMUD_CMD_FLAG_VNET_HDR |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
            QEMUD_CMD_FLAG_KVM |
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
160
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
161
            QEMUD_CMD_FLAG_VGA |
162
            QEMUD_CMD_FLAG_0_10 |
163
            QEMUD_CMD_FLAG_PCIDEVICE |
164 165
            QEMUD_CMD_FLAG_MEM_PATH |
            QEMUD_CMD_FLAG_SDL,
166 167 168 169 170 171 172 173 174 175 176 177 178 179
            10005, 1,  0);
    DO_TEST("kvm-86",
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_DRIVE_BOOT |
            QEMUD_CMD_FLAG_NAME |
            QEMUD_CMD_FLAG_UUID |
            QEMUD_CMD_FLAG_VNET_HDR |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
            QEMUD_CMD_FLAG_KVM |
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
180
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
181
            QEMUD_CMD_FLAG_VGA |
182
            QEMUD_CMD_FLAG_0_10 |
183 184
            QEMUD_CMD_FLAG_PCIDEVICE |
            QEMUD_CMD_FLAG_SDL,
185
            10050, 1,  0);
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    DO_TEST("qemu-kvm-0.11.0-rc2",
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_DRIVE_BOOT |
            QEMUD_CMD_FLAG_NAME |
            QEMUD_CMD_FLAG_UUID |
            QEMUD_CMD_FLAG_VNET_HDR |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
            QEMUD_CMD_FLAG_KVM |
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
            QEMUD_CMD_FLAG_VGA |
            QEMUD_CMD_FLAG_0_10 |
            QEMUD_CMD_FLAG_PCIDEVICE |
203
            QEMUD_CMD_FLAG_MEM_PATH |
204
            QEMUD_CMD_FLAG_ENABLE_KVM |
205 206
            QEMUD_CMD_FLAG_BALLOON |
            QEMUD_CMD_FLAG_SDL,
207
            10092, 1,  0);
208 209 210 211 212 213 214 215 216 217 218 219 220 221
    DO_TEST("qemu-0.12.1",
            QEMUD_CMD_FLAG_VNC_COLON |
            QEMUD_CMD_FLAG_NO_REBOOT |
            QEMUD_CMD_FLAG_DRIVE |
            QEMUD_CMD_FLAG_NAME |
            QEMUD_CMD_FLAG_UUID |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC |
            QEMUD_CMD_FLAG_DRIVE_CACHE_V2 |
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
            QEMUD_CMD_FLAG_VGA |
            QEMUD_CMD_FLAG_0_10 |
            QEMUD_CMD_FLAG_ENABLE_KVM |
222
            QEMUD_CMD_FLAG_SDL |
223 224 225 226
            QEMUD_CMD_FLAG_XEN_DOMID |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX |
            QEMUD_CMD_FLAG_CHARDEV |
            QEMUD_CMD_FLAG_BALLOON |
227 228
            QEMUD_CMD_FLAG_DEVICE |
            QEMUD_CMD_FLAG_SMP_TOPOLOGY,
229
            12001, 0,  0);
230 231 232 233 234 235 236 237 238 239 240

    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

VIRT_TEST_MAIN(mymain)

#else

int main (void) { return (77); /* means 'test skipped' for automake */ }

#endif /* WITH_QEMU */