Linux Kernel Selftest development
 help / color / mirror / Atom feed
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 2/4] selftests: harness: Set global current_test_metadata for each test run
Date: Tue, 14 Apr 2026 11:07:49 -0700	[thread overview]
Message-ID: <20260414-selftest-global-metadata-v1-2-fd223922bc57@google.com> (raw)
In-Reply-To: <20260414-selftest-global-metadata-v1-0-fd223922bc57@google.com>

Set global current_test_metadata for each test run so other test frameworks
can choose to access fields for the current test.

This avoids having to pass _metadata down through functions so that
code defined other functions can still use fields in _metadata.

Test functions t->fn() are executed in series, so during the runtime of the
test function, the function can count on current_test_metadata accurately
being the metadata for the running test.

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
 tools/testing/selftests/kselftest_harness.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 68cde1556ac41..85d9b4527fca6 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1151,6 +1151,8 @@ static bool test_enabled(int argc, char **argv,
 	return !has_positive;
 }
 
+struct __test_metadata *current_test_metadata;
+
 static void __run_test(struct __fixture_metadata *f,
 		       struct __fixture_variant_metadata *variant,
 		       struct __test_metadata *t)
@@ -1182,7 +1184,9 @@ static void __run_test(struct __fixture_metadata *f,
 		t->exit_code = KSFT_FAIL;
 	} else if (child == 0) {
 		setpgrp();
+		current_test_metadata = t;
 		t->fn(t, variant);
+		current_test_metadata = NULL;
 		_exit(t->exit_code);
 	} else {
 		t->pid = child;

-- 
2.54.0.rc0.605.g598a273b03-goog


  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 ` [PATCH RFC 1/4] selftests: harness: Move metadata structs to separate header file Ackerley Tng
2026-04-14 18:07 ` Ackerley Tng [this message]
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-2-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