summary refs log tree commit diff
path: root/tests/plugin_supported_cpuid.c
blob: 0acb1341b2b8d57560ee7941b6e01563ebc2e1f6 (plain) (blame)
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
/*
 * Copyright 2018 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "crosvm.h"

int main(int argc, char** argv) {
    struct crosvm *crosvm;
    int ret = crosvm_connect(&crosvm);
    if (ret) {
        fprintf(stderr, "failed to connect to crosvm: %d\n", ret);
        return 1;
    }

    struct kvm_cpuid_entry2 cpuids[100];
    int n_entries;
    ret = crosvm_get_supported_cpuid(crosvm, 1, cpuids, &n_entries);
    if (ret >= 0) {
        fprintf(stderr,
                "expected crosvm_get_supported_cpuids to fail with E2BIG\n");
        return 1;
    }

    ret = crosvm_get_supported_cpuid(crosvm, 100, cpuids, &n_entries);
    if (ret < 0) {
        fprintf(stderr,
                "unexpected failure of crosvm_get_supported_cpuids: %d\n", ret);
        return 1;
    }

    if (n_entries <= 1) {
        fprintf(stderr,
                "unexpected number of supported cpuid entries: %d\n",
                n_entries);
        return 1;
    }

    ret = crosvm_get_emulated_cpuid(crosvm, 1, cpuids, &n_entries);
    if (ret >= 0) {
        fprintf(stderr,
                "expected crosvm_get_emulated_cpuids to fail with E2BIG\n");
        return 1;
    }

    ret = crosvm_get_emulated_cpuid(crosvm, 100, cpuids, &n_entries);
    if (ret < 0) {
        fprintf(stderr,
                "unexpected failure of crosvm_get_emulated_cpuid: %d\n", ret);
        return 1;
    }

    if (n_entries < 1) {
        fprintf(stderr,
                "unexpected number of emulated cpuid entries: %d\n", n_entries);
        return 1;
    }

    return 0;
}