From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>,
Andrew Jones <ajones@ventanamicro.com>
Subject: [PATCH v3 4/8] KVM: selftests: Add a macro to define a test with one vcpu
Date: Thu, 8 Feb 2024 21:48:40 +0100 [thread overview]
Message-ID: <20240208204844.119326-5-thuth@redhat.com> (raw)
In-Reply-To: <20240208204844.119326-1-thuth@redhat.com>
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>
---
.../selftests/kvm/include/kvm_test_harness.h | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 tools/testing/selftests/kvm/include/kvm_test_harness.h
diff --git a/tools/testing/selftests/kvm/include/kvm_test_harness.h b/tools/testing/selftests/kvm/include/kvm_test_harness.h
new file mode 100644
index 0000000000000..8f7c6858e8e2d
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/kvm_test_harness.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Macros for defining a KVM test
+ *
+ * Copyright (C) 2022, Google LLC.
+ */
+
+#ifndef SELFTEST_KVM_TEST_HARNESS_H
+#define SELFTEST_KVM_TEST_HARNESS_H
+
+#include "kselftest_harness.h"
+
+#define KVM_ONE_VCPU_TEST_SUITE(name) \
+ FIXTURE(name) { \
+ struct kvm_vcpu *vcpu; \
+ }; \
+ \
+ FIXTURE_SETUP(name) { \
+ (void)vm_create_with_one_vcpu(&self->vcpu, NULL); \
+ } \
+ \
+ FIXTURE_TEARDOWN(name) { \
+ kvm_vm_free(self->vcpu->vm); \
+ }
+
+#define KVM_ONE_VCPU_TEST(suite, test, guestcode) \
+static void __suite##_##test(struct kvm_vcpu *vcpu); \
+ \
+TEST_F(suite, test) \
+{ \
+ vcpu_arch_set_entry_point(self->vcpu, guestcode); \
+ __suite##_##test(self->vcpu); \
+} \
+static void __suite##_##test(struct kvm_vcpu *vcpu)
+
+#endif /* SELFTEST_KVM_TEST_HARNESS_H */
--
2.43.0
next prev parent reply other threads:[~2024-02-08 20:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 20:48 [PATCH v3 0/8] Use TAP in some more x86 KVM selftests Thomas Huth
2024-02-08 20:48 ` [PATCH v3 1/8] KVM: selftests: x86: sync_regs_test: Use vcpu_run() where appropriate Thomas Huth
2024-02-08 20:48 ` [PATCH v3 2/8] KVM: selftests: x86: sync_regs_test: Get regs structure before modifying it Thomas Huth
2024-02-08 20:48 ` [PATCH v3 3/8] KVM: selftests: Move setting a vCPU's entry point to a dedicated API Thomas Huth
2024-02-28 19:04 ` Mark Brown
2024-02-28 19:29 ` Sean Christopherson
2024-02-28 21:19 ` Sean Christopherson
2024-02-28 21:29 ` Oliver Upton
2024-02-28 21:34 ` Oliver Upton
2024-02-28 21:34 ` Sean Christopherson
2024-02-28 23:00 ` Raghavendra Rao Ananta
2024-02-29 6:34 ` Oliver Upton
2024-02-28 21:38 ` Mark Brown
2024-02-29 13:12 ` Mark Brown
2024-02-08 20:48 ` Thomas Huth [this message]
2024-02-08 20:48 ` [PATCH v3 5/8] KVM: selftests: x86: Use TAP interface in the sync_regs test Thomas Huth
2024-02-08 20:48 ` [PATCH v3 6/8] KVM: selftests: x86: Use TAP interface in the fix_hypercall test Thomas Huth
2024-02-08 20:48 ` [PATCH v3 7/8] KVM: selftests: x86: Use TAP interface in the vmx_pmu_caps test Thomas Huth
2024-02-08 20:48 ` [PATCH v3 8/8] KVM: selftests: x86: Use TAP interface in the userspace_msr_exit test Thomas Huth
2024-02-27 2:21 ` [PATCH v3 0/8] Use TAP in some more x86 KVM selftests Sean Christopherson
2024-02-28 21:32 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240208204844.119326-5-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=ajones@ventanamicro.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox