From: Ackerley Tng <ackerleytng@google.com>
To: Kees Cook <kees@kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
Will Drewry <wad@chromium.org>, Shuah Khan <shuah@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
thomas.weissschuh@linutronix.de, linux@weissschuh.net
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kvm@vger.kernel.org, Ackerley Tng <ackerleytng@google.com>
Subject: [PATCH RFC 1/4] selftests: harness: Move metadata structs to separate header file
Date: Tue, 14 Apr 2026 11:07:48 -0700 [thread overview]
Message-ID: <20260414-selftest-global-metadata-v1-1-fd223922bc57@google.com> (raw)
In-Reply-To: <20260414-selftest-global-metadata-v1-0-fd223922bc57@google.com>
Move metadata structs to separate header file so that the structs can be
referenced without importing all the static functions, such as
test_harness_run.
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
tools/testing/selftests/kselftest_harness.h | 47 +------------------
.../testing/selftests/kselftest_harness_structs.h | 53 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 45 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 4afaef01c22e9..68cde1556ac41 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -68,6 +68,7 @@
#include <sys/wait.h>
#include <unistd.h>
+#include "kselftest_harness_structs.h"
#include "kselftest.h"
static inline void __kselftest_memset_safe(void *s, int c, size_t n)
@@ -845,27 +846,11 @@ struct __test_results {
char reason[1024]; /* Reason for test result */
};
-struct __test_metadata;
-struct __fixture_variant_metadata;
-
-/* Contains all the information about a fixture. */
-struct __fixture_metadata {
- const char *name;
- struct __test_metadata *tests;
- struct __fixture_variant_metadata *variant;
- struct __fixture_metadata *prev, *next;
-} _fixture_global __attribute__((unused)) = {
+struct __fixture_metadata _fixture_global __attribute__((unused)) = {
.name = "global",
.prev = &_fixture_global,
};
-struct __test_xfail {
- struct __fixture_metadata *fixture;
- struct __fixture_variant_metadata *variant;
- struct __test_metadata *test;
- struct __test_xfail *prev, *next;
-};
-
/**
* XFAIL_ADD() - mark variant + test case combination as expected to fail
* @fixture_name: name of the fixture
@@ -899,13 +884,6 @@ static inline void __register_fixture(struct __fixture_metadata *f)
__LIST_APPEND(__fixture_list, f);
}
-struct __fixture_variant_metadata {
- const char *name;
- const void *data;
- struct __test_xfail *xfails;
- struct __fixture_variant_metadata *prev, *next;
-};
-
static inline void
__register_fixture_variant(struct __fixture_metadata *f,
struct __fixture_variant_metadata *variant)
@@ -913,27 +891,6 @@ __register_fixture_variant(struct __fixture_metadata *f,
__LIST_APPEND(f->variant, variant);
}
-/* Contains all the information for test execution and status checking. */
-struct __test_metadata {
- const char *name;
- void (*fn)(struct __test_metadata *,
- struct __fixture_variant_metadata *);
- pid_t pid; /* pid of test when being run */
- struct __fixture_metadata *fixture;
- void (*teardown_fn)(bool in_parent, struct __test_metadata *_metadata,
- void *self, const void *variant);
- int termsig;
- int exit_code;
- int trigger; /* extra handler after the evaluation */
- int timeout; /* seconds to wait for test timeout */
- bool aborted; /* stopped test due to failed ASSERT */
- bool *no_teardown; /* fixture needs teardown */
- void *self;
- const void *variant;
- struct __test_results *results;
- struct __test_metadata *prev, *next;
-};
-
static inline bool __test_passed(struct __test_metadata *metadata)
{
return metadata->exit_code != KSFT_FAIL &&
diff --git a/tools/testing/selftests/kselftest_harness_structs.h b/tools/testing/selftests/kselftest_harness_structs.h
new file mode 100644
index 0000000000000..cf9d15ad3de0c
--- /dev/null
+++ b/tools/testing/selftests/kselftest_harness_structs.h
@@ -0,0 +1,53 @@
+#ifndef __KSELFTEST_HARNESS_STRUCTS_H
+#define __KSELFTEST_HARNESS_STRUCTS_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+struct __test_metadata;
+struct __fixture_variant_metadata;
+
+/* Contains all the information about a fixture. */
+struct __fixture_metadata {
+ const char *name;
+ struct __test_metadata *tests;
+ struct __fixture_variant_metadata *variant;
+ struct __fixture_metadata *prev, *next;
+};
+
+struct __test_xfail {
+ struct __fixture_metadata *fixture;
+ struct __fixture_variant_metadata *variant;
+ struct __test_metadata *test;
+ struct __test_xfail *prev, *next;
+};
+
+struct __fixture_variant_metadata {
+ const char *name;
+ const void *data;
+ struct __test_xfail *xfails;
+ struct __fixture_variant_metadata *prev, *next;
+};
+
+/* Contains all the information for test execution and status checking. */
+struct __test_metadata {
+ const char *name;
+ void (*fn)(struct __test_metadata *,
+ struct __fixture_variant_metadata *);
+ pid_t pid; /* pid of test when being run */
+ struct __fixture_metadata *fixture;
+ void (*teardown_fn)(bool in_parent, struct __test_metadata *_metadata,
+ void *self, const void *variant);
+ int termsig;
+ int exit_code;
+ int trigger; /* extra handler after the evaluation */
+ int timeout; /* seconds to wait for test timeout */
+ bool aborted; /* stopped test due to failed ASSERT */
+ bool *no_teardown; /* fixture needs teardown */
+ void *self;
+ const void *variant;
+ struct __test_results *results;
+ struct __test_metadata *prev, *next;
+};
+
+#endif
--
2.54.0.rc0.605.g598a273b03-goog
next prev parent reply other threads:[~2026-04-14 18:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 18:07 [PATCH RFC 0/4] selftests: harness: Provide global metadata pointer to allow clean teardown from selftest libraries Ackerley Tng
2026-04-14 18:07 ` Ackerley Tng [this message]
2026-04-14 18:07 ` [PATCH RFC 2/4] selftests: harness: Set global current_test_metadata for each test run Ackerley Tng
2026-04-14 18:07 ` [PATCH RFC 3/4] KVM: selftests: Do teardown from kselftest harness if kselftest_harness is used Ackerley Tng
2026-04-14 18:07 ` [PATCH RFC 4/4] HACK: Show that the teardown function is called from KVM selftests Ackerley Tng
2026-05-12 20:24 ` [PATCH RFC 0/4] selftests: harness: Provide global metadata pointer to allow clean teardown from selftest libraries Sean Christopherson
2026-05-13 1:01 ` Kees Cook
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=20260414-selftest-global-metadata-v1-1-fd223922bc57@google.com \
--to=ackerleytng@google.com \
--cc=kees@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=luto@amacapital.net \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=wad@chromium.org \
/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