qemuhelptest.c 10.6 KB
Newer Older
1 2 3 4
#include <config.h>

#ifdef WITH_QEMU

5 6
# include <stdio.h>
# include <stdlib.h>
7

8 9
# include "testutils.h"
# include "qemu/qemu_conf.h"
10

11
# define MAX_HELP_OUTPUT_SIZE 1024*64
12 13 14

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;

E
Eric Blake 已提交
24 25
static void printMismatchedFlags(unsigned long long got,
                                 unsigned long long expect)
26 27 28
{
    int i;

E
Eric Blake 已提交
29 30 31
    for (i = 0 ; i < (sizeof(got)*CHAR_BIT) ; i++) {
        unsigned long long gotFlag = (got & (1LL << i));
        unsigned long long expectFlag = (expect & (1LL << i));
32 33 34 35 36 37 38
        if (gotFlag && !expectFlag)
            fprintf(stderr, "Extra flag %i\n", i);
        if (!gotFlag && expectFlag)
            fprintf(stderr, "Missing flag %i\n", i);
    }
}

39 40 41 42 43 44
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]);
45 46
    unsigned int version, is_kvm, kvm_version;
    unsigned long long flags;
47 48 49 50 51 52

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

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

53 54
    if (qemudParseHelpStr("QEMU", help, &flags,
                          &version, &is_kvm, &kvm_version) == -1)
55 56 57
        return -1;

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

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

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        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;
    }

79
    if (kvm_version != info->kvm_version) {
80
        fprintf(stderr, "Parsed KVM versions do not match: got %u, expected %u\n",
81
                kvm_version, info->kvm_version);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
        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));

105
# define DO_TEST(name, flags, version, is_kvm, kvm_version)                          \
106 107 108 109 110 111 112
    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)

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    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 |
129
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
130 131
            QEMUD_CMD_FLAG_MEM_PATH |
            QEMUD_CMD_FLAG_TDF,
132
            9001,  1, 74);
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    DO_TEST("kvm-83-rhel56",
            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_PCIDEVICE |
            QEMUD_CMD_FLAG_MEM_PATH |
            QEMUD_CMD_FLAG_BALLOON |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET |
            QEMUD_CMD_FLAG_NO_KVM_PIT |
            QEMUD_CMD_FLAG_TDF |
            QEMUD_CMD_FLAG_DRIVE_READONLY,
            9001, 1,  83);
157 158 159 160 161 162 163 164 165 166 167
    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 |
168
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
169
            QEMUD_CMD_FLAG_VGA |
170
            QEMUD_CMD_FLAG_0_10 |
171
            QEMUD_CMD_FLAG_ENABLE_KVM |
172 173 174
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET,
175 176 177 178 179 180 181 182 183 184 185 186 187 188
            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 |
189
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
190
            QEMUD_CMD_FLAG_VGA |
191
            QEMUD_CMD_FLAG_0_10 |
192
            QEMUD_CMD_FLAG_PCIDEVICE |
193
            QEMUD_CMD_FLAG_MEM_PATH |
194 195 196 197
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET |
            QEMUD_CMD_FLAG_NO_KVM_PIT |
D
Daniel P. Berrange 已提交
198 199
            QEMUD_CMD_FLAG_TDF |
            QEMUD_CMD_FLAG_NESTING,
200 201 202 203 204 205 206 207 208 209 210 211 212 213
            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 |
214
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
215
            QEMUD_CMD_FLAG_VGA |
216
            QEMUD_CMD_FLAG_0_10 |
217
            QEMUD_CMD_FLAG_PCIDEVICE |
218 219 220 221
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET |
            QEMUD_CMD_FLAG_NO_KVM_PIT |
D
Daniel P. Berrange 已提交
222 223
            QEMUD_CMD_FLAG_TDF |
            QEMUD_CMD_FLAG_NESTING,
224
            10050, 1,  0);
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    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 |
242
            QEMUD_CMD_FLAG_MEM_PATH |
243
            QEMUD_CMD_FLAG_ENABLE_KVM |
244
            QEMUD_CMD_FLAG_BALLOON |
245 246 247 248
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET |
            QEMUD_CMD_FLAG_NO_KVM_PIT |
249
            QEMUD_CMD_FLAG_TDF |
D
Daniel P. Berrange 已提交
250
            QEMUD_CMD_FLAG_BOOT_MENU |
251 252
            QEMUD_CMD_FLAG_NESTING |
            QEMUD_CMD_FLAG_NAME_PROCESS,
253
            10092, 1,  0);
254 255 256 257 258 259 260 261 262 263 264
    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 |
265
            QEMUD_CMD_FLAG_DRIVE_READONLY |
266 267 268
            QEMUD_CMD_FLAG_VGA |
            QEMUD_CMD_FLAG_0_10 |
            QEMUD_CMD_FLAG_ENABLE_KVM |
269
            QEMUD_CMD_FLAG_SDL |
270 271 272 273
            QEMUD_CMD_FLAG_XEN_DOMID |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX |
            QEMUD_CMD_FLAG_CHARDEV |
            QEMUD_CMD_FLAG_BALLOON |
274
            QEMUD_CMD_FLAG_DEVICE |
275
            QEMUD_CMD_FLAG_SMP_TOPOLOGY |
276
            QEMUD_CMD_FLAG_RTC |
277
            QEMUD_CMD_FLAG_NO_HPET |
278 279
            QEMUD_CMD_FLAG_BOOT_MENU |
            QEMUD_CMD_FLAG_NAME_PROCESS,
280
            12001, 0,  0);
E
Eric Blake 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294
    DO_TEST("qemu-kvm-0.12.3",
            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 |
295
            QEMUD_CMD_FLAG_DRIVE_READONLY |
E
Eric Blake 已提交
296 297 298 299 300 301 302 303 304 305 306 307 308 309
            QEMUD_CMD_FLAG_VGA |
            QEMUD_CMD_FLAG_0_10 |
            QEMUD_CMD_FLAG_PCIDEVICE |
            QEMUD_CMD_FLAG_MEM_PATH |
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX |
            QEMUD_CMD_FLAG_CHARDEV |
            QEMUD_CMD_FLAG_BALLOON |
            QEMUD_CMD_FLAG_DEVICE |
            QEMUD_CMD_FLAG_SMP_TOPOLOGY |
            QEMUD_CMD_FLAG_RTC |
            QEMUD_CMD_FLAG_VNET_HOST |
            QEMUD_CMD_FLAG_NO_HPET |
            QEMUD_CMD_FLAG_NO_KVM_PIT |
310
            QEMUD_CMD_FLAG_TDF |
D
Daniel P. Berrange 已提交
311
            QEMUD_CMD_FLAG_BOOT_MENU |
312 313
            QEMUD_CMD_FLAG_NESTING |
            QEMUD_CMD_FLAG_NAME_PROCESS,
E
Eric Blake 已提交
314
            12003, 1,  0);
315 316 317 318 319 320 321 322 323 324 325

    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 */