Skip to content

Commit 55f2cf8

Browse files
huthsean-jc
authored andcommitted
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>
1 parent 53a43dd commit 55f2cf8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 */

0 commit comments

Comments
 (0)