Example #1
0
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 int version, is_kvm, kvm_version;
    unsigned long long flags;

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

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

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

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

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

    return 0;
}
Example #2
0
static int testHelpStrParsing(const void *data)
{
    const struct testInfo *info = data;
    char *path = NULL;
    char *help = NULL;
    unsigned int version, kvm_version;
    bool is_kvm;
    virQEMUCapsPtr flags = NULL;
    int ret = -1;
    char *got = NULL;
    char *expected = NULL;

    if (virAsprintf(&path, "%s/qemuhelpdata/%s", abs_srcdir, info->name) < 0)
        return -1;

    if (virTestLoadFile(path, &help) < 0)
        goto cleanup;

    if (!(flags = virQEMUCapsNew()))
        goto cleanup;

    if (virQEMUCapsParseHelpStr("QEMU", help, flags,
                                &version, &is_kvm, &kvm_version, false, NULL) == -1) {
        if (info->error && virGetLastError()->code == info->error)
            ret = 0;
        goto cleanup;
    }

# ifndef WITH_YAJL
    if (virQEMUCapsGet(info->flags, QEMU_CAPS_MONITOR_JSON))
        virQEMUCapsSet(flags, QEMU_CAPS_MONITOR_JSON);
# endif

    VIR_FREE(path);
    VIR_FREE(help);
    if (virAsprintf(&path, "%s/qemuhelpdata/%s-device", abs_srcdir,
                    info->name) < 0)
        goto cleanup;

    if (virTestLoadFile(path, &help) < 0)
        goto cleanup;

    if (virQEMUCapsParseDeviceStr(flags, help) < 0)
        goto cleanup;

    got = virQEMUCapsFlagsString(flags);
    expected = virQEMUCapsFlagsString(info->flags);
    if (!got || !expected)
        goto cleanup;

    if (STRNEQ(got, expected)) {
        VIR_TEST_DEBUG("%s: computed flags do not match: got %s, expected %s\n",
            info->name, got, expected);

        if (virTestGetDebug())
            printMismatchedFlags(flags, info->flags);

        goto cleanup;
    }

    if (version != info->version) {
        fprintf(stderr, "%s: parsed versions do not match: got %u, expected %u\n",
                info->name, version, info->version);
        goto cleanup;
    }

    if (is_kvm != info->is_kvm) {
        fprintf(stderr,
                "%s: parsed is_kvm flag does not match: got %u, expected %u\n",
                info->name, is_kvm, info->is_kvm);
        goto cleanup;
    }

    if (kvm_version != info->kvm_version) {
        fprintf(stderr,
                "%s: parsed KVM versions do not match: got %u, expected %u\n",
                info->name, kvm_version, info->kvm_version);
        goto cleanup;
    }

    ret = 0;
 cleanup:
    VIR_FREE(path);
    VIR_FREE(help);
    virObjectUnref(flags);
    VIR_FREE(got);
    VIR_FREE(expected);
    return ret;
}