Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Add a macro to define a test with one vcpu

Most tests are currently not giving any proper output for the user
to see how much sub-tests have already been run, or whether new
sub-tests are part of a binary or not. So it would be good to
support TAP output in the KVM selftests. There is already a nice
framework for this in the kselftest_harness.h header which we can
use. But since we also need a vcpu in most KVM selftests, it also
makes sense to introduce our own wrapper around this which takes
care of creating a VM with one vcpu, so we don't have to repeat
this boilerplate in each and every test. Thus let's introduce
a KVM_ONE_VCPU_TEST() macro here which takes care of this.

Suggested-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/all/Y2v+B3xxYKJSM%2FfH@google.com/
Signed-off-by: Thomas Huth <thuth@redhat.com>
Link: https://lore.kernel.org/r/20240208204844.119326-5-thuth@redhat.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

authored by

Thomas Huth and committed by
Sean Christopherson
55f2cf88 53a43dd4

+36
+36
tools/testing/selftests/kvm/include/kvm_test_harness.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Macros for defining a KVM test 4 + * 5 + * Copyright (C) 2022, Google LLC. 6 + */ 7 + 8 + #ifndef SELFTEST_KVM_TEST_HARNESS_H 9 + #define SELFTEST_KVM_TEST_HARNESS_H 10 + 11 + #include "kselftest_harness.h" 12 + 13 + #define KVM_ONE_VCPU_TEST_SUITE(name) \ 14 + FIXTURE(name) { \ 15 + struct kvm_vcpu *vcpu; \ 16 + }; \ 17 + \ 18 + FIXTURE_SETUP(name) { \ 19 + (void)vm_create_with_one_vcpu(&self->vcpu, NULL); \ 20 + } \ 21 + \ 22 + FIXTURE_TEARDOWN(name) { \ 23 + kvm_vm_free(self->vcpu->vm); \ 24 + } 25 + 26 + #define KVM_ONE_VCPU_TEST(suite, test, guestcode) \ 27 + static void __suite##_##test(struct kvm_vcpu *vcpu); \ 28 + \ 29 + TEST_F(suite, test) \ 30 + { \ 31 + vcpu_arch_set_entry_point(self->vcpu, guestcode); \ 32 + __suite##_##test(self->vcpu); \ 33 + } \ 34 + static void __suite##_##test(struct kvm_vcpu *vcpu) 35 + 36 + #endif /* SELFTEST_KVM_TEST_HARNESS_H */