xref: /linux/tools/testing/selftests/kvm/include/kvm_test_harness.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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 */
37