1
2
3
4
5
6
7
8
9
10#define _GNU_SOURCE
11#include <fcntl.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16#include "test_util.h"
17
18#include "kvm_util.h"
19#include "asm/kvm.h"
20#include "linux/kvm.h"
21
22void test_vcpu_creation(int first_vcpu_id, int num_vcpus)
23{
24 struct kvm_vm *vm;
25 int i;
26
27 pr_info("Testing creating %d vCPUs, with IDs %d...%d.\n",
28 num_vcpus, first_vcpu_id, first_vcpu_id + num_vcpus - 1);
29
30 vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
31
32 for (i = first_vcpu_id; i < first_vcpu_id + num_vcpus; i++)
33
34 vm_vcpu_add(vm, i);
35
36 kvm_vm_free(vm);
37}
38
39int main(int argc, char *argv[])
40{
41 int kvm_max_vcpu_id = kvm_check_cap(KVM_CAP_MAX_VCPU_ID);
42 int kvm_max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS);
43
44 pr_info("KVM_CAP_MAX_VCPU_ID: %d\n", kvm_max_vcpu_id);
45 pr_info("KVM_CAP_MAX_VCPUS: %d\n", kvm_max_vcpus);
46
47
48
49
50
51
52 if (!kvm_max_vcpu_id)
53 kvm_max_vcpu_id = kvm_max_vcpus;
54
55 TEST_ASSERT(kvm_max_vcpu_id >= kvm_max_vcpus,
56 "KVM_MAX_VCPU_ID (%d) must be at least as large as KVM_MAX_VCPUS (%d).",
57 kvm_max_vcpu_id, kvm_max_vcpus);
58
59 test_vcpu_creation(0, kvm_max_vcpus);
60
61 if (kvm_max_vcpu_id > kvm_max_vcpus)
62 test_vcpu_creation(
63 kvm_max_vcpu_id - kvm_max_vcpus, kvm_max_vcpus);
64
65 return 0;
66}
67