qemuhelptest.c 5.0 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#include <config.h>

#ifdef WITH_QEMU

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

#include "testutils.h"
#include "qemu_conf.h"

#define MAX_HELP_OUTPUT_SIZE 1024*64

struct testInfo {
    const char *name;
    unsigned flags;
    unsigned version;
    unsigned is_kvm;
    unsigned kvm_version;
};

static char *progname;
static char *abs_srcdir;

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]);
    unsigned flags, version, is_kvm, kvm_version;

    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) {
        fprintf(stderr, "Computed flags do not match: got 0x%x, expected 0x%x\n",
                flags, info->flags);
        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;
    }

    if (kvm_version != kvm_version) {
        fprintf(stderr, "Parsed KVM versions do not match: got %u, expected %u\n",
                version, kvm_version);
        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)

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    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 |
108 109
            QEMUD_CMD_FLAG_DRIVE_FORMAT |
            QEMUD_CMD_FLAG_MEM_PATH,
110 111 112 113 114 115 116 117 118 119 120 121
            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 |
122 123
            QEMUD_CMD_FLAG_VGA |
            QEMUD_CMD_FLAG_0_10,
124 125 126 127 128 129 130 131 132 133 134 135 136 137
            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 |
138
            QEMUD_CMD_FLAG_VGA |
139
            QEMUD_CMD_FLAG_0_10 |
140 141
            QEMUD_CMD_FLAG_PCIDEVICE |
            QEMUD_CMD_FLAG_MEM_PATH,
142 143 144 145 146 147 148 149 150 151 152 153 154 155
            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 |
156
            QEMUD_CMD_FLAG_VGA |
157 158
            QEMUD_CMD_FLAG_0_10 |
            QEMUD_CMD_FLAG_PCIDEVICE,
159
            10050, 1,  0);
160 161 162 163 164 165 166 167 168 169 170

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