Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH RFC 0/4] selftests: harness: Provide global metadata pointer to allow clean teardown from selftest libraries
@ 2026-04-14 18:07 Ackerley Tng
  2026-04-14 18:07 ` [PATCH RFC 1/4] selftests: harness: Move metadata structs to separate header file Ackerley Tng
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ackerley Tng @ 2026-04-14 18:07 UTC (permalink / raw)
  To: Kees Cook, Andy Lutomirski, Will Drewry, Shuah Khan,
	Paolo Bonzini, Sean Christopherson, thomas.weissschuh, linux
  Cc: linux-kernel, linux-kselftest, kvm, Ackerley Tng

Hi,

The common kselftest harness provides nice features such as tracking the
number of tests, common pass/fail printouts, and setup/teardown functions.

KVM would like to benefit from the common functionality provided in the
general kselftest harness, but KVM selftests are dependent on a selftest
library.

This selftest library provides common code for setting up virtual machines,
and is designed with assertions within the setup flows to reduce KVM
selftest developer burden of making common assertions.

The common kselftest library assertions (ASSERT_EQ and EXPECT_EQ) are
dependent on access to the _metadata parameter. Any function using the
assertion macros must be parametrized by _metadata.

The KVM selftest library has many nested function calls and it would be
impractical to pass _metadata through all those layers of function calls.

Without _metadata, the KVM selftest library can still reimplement its own
assertion macro (TEST_ASSERT), but it cannot perform teardown on assertion
failure.

Sean suggested using setjmp and longjmp [1] to back to the top level
TEST_F(). I looked at [1] and found myself wishing to use TEST_F() the from
kselftest harness directly. Also, setjmp/longjmp felt like it was
introducing state that could be messed up easily. I also found recent work
that removed setjmp/longjmp from kselftest harness [2].

The kselftests harness is running tests sequentially anyway, and the
function pointers in _metadata wouldn't be changing all that often in most
selftests.

Would maintainers be open to having the kselftest harness expose a pointer
to the metadata globally?

Another option would be to expose the current teardown function pointer
globally instead of the pointer to the entire metadata struct.

kselftest harness macros ASSERT_EQ might also benefit from using the global
pointer instead, which would open the functions up to calls from nested
functions without needing to parametrize those functions with _metadata.

[1] https://lore.kernel.org/all/ZjUwqEXPA5QVItyX@google.com/
[2] https://lore.kernel.org/all/20250610141252-1ee7ae72-dbad-4a80-931c-5b4b14fb07ce@linutronix.de/

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
Ackerley Tng (4):
      selftests: harness: Move metadata structs to separate header file
      selftests: harness: Set global current_test_metadata for each test run
      KVM: selftests: Do teardown from kselftest harness if kselftest_harness is used
      HACK: Show that the teardown function is called from KVM selftests

 tools/testing/selftests/kselftest_harness.h        | 51 +++------------------
 .../testing/selftests/kselftest_harness_structs.h  | 53 ++++++++++++++++++++++
 tools/testing/selftests/kvm/Makefile.kvm           |  1 +
 .../selftests/kvm/kvm_test_harness_selftest.c      | 34 ++++++++++++++
 tools/testing/selftests/kvm/lib/assert.c           | 16 +++++++
 5 files changed, 110 insertions(+), 45 deletions(-)
---
base-commit: 5d0d3623303775d750e122a2542d1a26c8573d38
change-id: 20260414-selftest-global-metadata-7b1f04a405f3

Best regards,
--
Ackerley Tng <ackerleytng@google.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-05-13  1:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH RFC 1/4] selftests: harness: Move metadata structs to separate header file Ackerley Tng
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox