tests: kvm: Add tests for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_CPU_ID
PATCH 1/1 tests: kvm: Add tests for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_CPU_ID
Signed-off-by Aaron Lewis <[email protected]>
Reviewed-by Peter Shier <[email protected]>
Reviewed-by Marc Orr <[email protected]>
--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/kvm_create_max_vcpus.c | 70 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c
tools/testing/selftests/kvm/.gitignore +1 -0
@@ -6,4 +6,5 @@ /x86_64/vmx_close_while_nested_test /x86_64/vmx_tsc_adjust_test /x86_64/state_test +/x86_64/kvm_create_max_vcpus /dirty_log_test
tools/testing/selftests/kvm/Makefile +1 -0
@@ -20,6 +20,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test TEST_GEN_PROGS_x86_64 += x86_64/smm_test +TEST_GEN_PROGS_x86_64 += x86_64/kvm_create_max_vcpus TEST_GEN_PROGS_x86_64 += dirty_log_test TEST_GEN_PROGS_x86_64 += clear_dirty_log_test
tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.21.0.593.g511ec345e18-goog
Quoted 99 lines · Aaron Lewis
Signed-off-by Aaron Lewis <[email protected]>Reviewed-by Peter Shier <[email protected]>Reviewed-by Marc Orr <[email protected]>--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/kvm_create_max_vcpus.c | 70 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.ctools/testing/selftests/kvm/.gitignore +1
-0@@ -6,4 +6,5 @@ /x86_64/vmx_close_while_nested_test /x86_64/vmx_tsc_adjust_test /x86_64/state_test +/x86_64/kvm_create_max_vcpus /dirty_log_testtools/testing/selftests/kvm/Makefile +1
-0@@ -20,6 +20,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test TEST_GEN_PROGS_x86_64 += x86_64/smm_test +TEST_GEN_PROGS_x86_64 += x86_64/kvm_create_max_vcpus TEST_GEN_PROGS_x86_64 += dirty_log_test TEST_GEN_PROGS_x86_64 += clear_dirty_log_testtools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c new file +60
-0@@ -0,0 +1,70 @@ +/* +* kvm_create_max_vcpus +* +* Copyright (C) 2019, Google LLC. +* +* This work is licensed under the terms of the GNU GPL, version 2. +* +* Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. +*/ + +#define _GNU_SOURCE/* for program_invocation_short_name */ +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "test_util.h" + +#include "kvm_util.h" +#include "asm/kvm.h" +#include "linux/kvm.h" + +void test_vcpu_creation (int first_vcpu_id,int num_vcpus) +{ +struct kvm_vm *vm; +int i; + +printf ("Testing creating %d vCPUs, with IDs %d...%d.\n" , + num_vcpus, first_vcpu_id, first_vcpu_id + num_vcpus -1 ); + + vm =vm_create (VM_MODE_P52V48_4K ,DEFAULT_GUEST_PHY_PAGES ,O_RDWR ); + +for (i =0 ; i < num_vcpus; i++) { +int vcpu_id = first_vcpu_id + i; + +/* This asserts that the vCPU was created. */ +vm_vcpu_add (vm, vcpu_id,0 ,0 ); + } + +kvm_vm_free (vm); +} + +int main (int argc,char *argv[]) +{ +int kvm_max_vcpu_id =kvm_check_cap (KVM_CAP_MAX_VCPU_ID ); +int kvm_max_vcpus =kvm_check_cap (KVM_CAP_MAX_VCPUS ); + +printf ("KVM_CAP_MAX_VCPU_ID: %d\n" , kvm_max_vcpu_id); +printf ("KVM_CAP_MAX_VCPUS: %d\n" , kvm_max_vcpus); + +/* +* Upstream KVM prior to 4.8 does not support KVM_CAP_MAX_VCPU_ID. +* Userspace is supposed to use KVM_CAP_MAX_VCPUS as the maximum ID +* in this case. +*/ +if (!kvm_max_vcpu_id) + kvm_max_vcpu_id = kvm_max_vcpus; + + TEST_ASSERT(kvm_max_vcpu_id >= kvm_max_vcpus, + "KVM_MAX_VCPU_ID (%d) must be at least as large as KVM_MAX_VCPUS (%d).",
tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c line 70
Quoted 10 lines
tools/testing/selftests/kvm/x86_64/kvm_create_max_vcpus.c new file +10
-0+ kvm_max_vcpu_id, kvm_max_vcpus); + +test_vcpu_creation (0 , kvm_max_vcpus); + +if (kvm_max_vcpu_id > kvm_max_vcpus) +test_vcpu_creation ( + kvm_max_vcpu_id - kvm_max_vcpus, kvm_max_vcpus); + +return 0 ; +}
Queued, thanks.
Paolo