qemuhelptest.c 10.9 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
    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 |
155
            QEMUD_CMD_FLAG_DRIVE_READONLY |
156 157
            QEMUD_CMD_FLAG_SMBIOS_TYPE |
            QEMUD_CMD_FLAG_SPICE,
158
            9001, 1,  83);
159 160 161 162 163 164 165 166 167 168 169
    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 |
170
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
171
            QEMUD_CMD_FLAG_VGA |
172
            QEMUD_CMD_FLAG_0_10 |
173
            QEMUD_CMD_FLAG_ENABLE_KVM |
174 175 176
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET,
177 178 179 180 181 182 183 184 185 186 187 188 189 190
            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 |
191
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
192
            QEMUD_CMD_FLAG_VGA |
193
            QEMUD_CMD_FLAG_0_10 |
194
            QEMUD_CMD_FLAG_PCIDEVICE |
195
            QEMUD_CMD_FLAG_MEM_PATH |
196 197 198 199
            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 已提交
200 201
            QEMUD_CMD_FLAG_TDF |
            QEMUD_CMD_FLAG_NESTING,
202 203 204 205 206 207 208 209 210 211 212 213 214 215
            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 |
216
            QEMUD_CMD_FLAG_DRIVE_SERIAL |
217
            QEMUD_CMD_FLAG_VGA |
218
            QEMUD_CMD_FLAG_0_10 |
219
            QEMUD_CMD_FLAG_PCIDEVICE |
220 221 222 223
            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 已提交
224
            QEMUD_CMD_FLAG_TDF |
225 226
            QEMUD_CMD_FLAG_NESTING |
            QEMUD_CMD_FLAG_SMBIOS_TYPE,
227
            10050, 1,  0);
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
    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 |
245
            QEMUD_CMD_FLAG_MEM_PATH |
246
            QEMUD_CMD_FLAG_ENABLE_KVM |
247
            QEMUD_CMD_FLAG_BALLOON |
248 249 250 251
            QEMUD_CMD_FLAG_SDL |
            QEMUD_CMD_FLAG_RTC_TD_HACK |
            QEMUD_CMD_FLAG_NO_HPET |
            QEMUD_CMD_FLAG_NO_KVM_PIT |
252
            QEMUD_CMD_FLAG_TDF |
D
Daniel P. Berrange 已提交
253
            QEMUD_CMD_FLAG_BOOT_MENU |
254
            QEMUD_CMD_FLAG_NESTING |
255 256
            QEMUD_CMD_FLAG_NAME_PROCESS |
            QEMUD_CMD_FLAG_SMBIOS_TYPE,
257
            10092, 1,  0);
258 259 260 261 262 263 264 265 266 267 268
    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 |
269
            QEMUD_CMD_FLAG_DRIVE_READONLY |
270 271 272
            QEMUD_CMD_FLAG_VGA |
            QEMUD_CMD_FLAG_0_10 |
            QEMUD_CMD_FLAG_ENABLE_KVM |
273
            QEMUD_CMD_FLAG_SDL |
274 275 276 277
            QEMUD_CMD_FLAG_XEN_DOMID |
            QEMUD_CMD_FLAG_MIGRATE_QEMU_UNIX |
            QEMUD_CMD_FLAG_CHARDEV |
            QEMUD_CMD_FLAG_BALLOON |
278
            QEMUD_CMD_FLAG_DEVICE |
279
            QEMUD_CMD_FLAG_SMP_TOPOLOGY |
280
            QEMUD_CMD_FLAG_RTC |
281
            QEMUD_CMD_FLAG_NO_HPET |
282
            QEMUD_CMD_FLAG_BOOT_MENU |
283 284
            QEMUD_CMD_FLAG_NAME_PROCESS |
            QEMUD_CMD_FLAG_SMBIOS_TYPE,
285
            12001, 0,  0);
E
Eric Blake 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299
    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 |
300
            QEMUD_CMD_FLAG_DRIVE_READONLY |
E
Eric Blake 已提交
301 302 303 304 305 306 307 308 309 310 311 312 313 314
            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 |
315
            QEMUD_CMD_FLAG_TDF |
D
Daniel P. Berrange 已提交
316
            QEMUD_CMD_FLAG_BOOT_MENU |
317
            QEMUD_CMD_FLAG_NESTING |
318 319
            QEMUD_CMD_FLAG_NAME_PROCESS |
            QEMUD_CMD_FLAG_SMBIOS_TYPE,
E
Eric Blake 已提交
320
            12003, 1,  0);
321 322 323 324 325 326 327 328 329 330 331

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