From: Marie Zhussupova <marievic@google.com>
To: rmoar@google.com, davidgow@google.com, shuah@kernel.org,
brendan.higgins@linux.dev
Cc: mark.rutland@arm.com, elver@google.com, dvyukov@google.com,
lucas.demarchi@intel.com, thomas.hellstrom@linux.intel.com,
rodrigo.vivi@intel.com, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com, kasan-dev@googlegroups.com,
intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Marie Zhussupova <marievic@google.com>
Subject: [PATCH v2 3/7] kunit: Pass parameterized test context to generate_params()
Date: Mon, 11 Aug 2025 22:17:35 +0000 [thread overview]
Message-ID: <20250811221739.2694336-4-marievic@google.com> (raw)
In-Reply-To: <20250811221739.2694336-1-marievic@google.com>
To enable more complex parameterized testing scenarios,
the generate_params() function needs additional context
beyond just the previously generated parameter. This patch
modifies the generate_params() function signature to
include an extra `struct kunit *test` argument, giving
test users access to the parameterized test context when
generating parameters.
The `struct kunit *test` argument was added as the first parameter
to the function signature as it aligns with the convention
of other KUnit functions that accept `struct kunit *test` first.
This also mirrors the "this" or "self" reference found
in object-oriented programming languages.
This patch also modifies xe_pci_live_device_gen_param()
in xe_pci.c and nthreads_gen_params() in kcsan_test.c
to reflect this signature change.
Signed-off-by: Marie Zhussupova <marievic@google.com>
---
Changes in v2:
- generate_params signature changes in
xe_pci.c and kcsan_test.c were squashed
into a single patch to avoid in-between
breakages in the series.
- The comments and the commit message were changed to
reflect the parameterized testing terminology. See
the patch series cover letter change log for the
definitions.
---
drivers/gpu/drm/xe/tests/xe_pci.c | 2 +-
include/kunit/test.h | 9 ++++++---
kernel/kcsan/kcsan_test.c | 2 +-
lib/kunit/test.c | 5 +++--
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c
index 1d3e2e50c355..62c016e84227 100644
--- a/drivers/gpu/drm/xe/tests/xe_pci.c
+++ b/drivers/gpu/drm/xe/tests/xe_pci.c
@@ -129,7 +129,7 @@ EXPORT_SYMBOL_IF_KUNIT(xe_pci_fake_device_init);
* Return: pointer to the next &struct xe_device ready to be used as a parameter
* or NULL if there are no more Xe devices on the system.
*/
-const void *xe_pci_live_device_gen_param(const void *prev, char *desc)
+const void *xe_pci_live_device_gen_param(struct kunit *test, const void *prev, char *desc)
{
const struct xe_device *xe = prev;
struct device *dev = xe ? xe->drm.dev : NULL;
diff --git a/include/kunit/test.h b/include/kunit/test.h
index d2e1b986b161..b527189d2d1c 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -128,7 +128,8 @@ struct kunit_attributes {
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
- const void* (*generate_params)(const void *prev, char *desc);
+ const void* (*generate_params)(struct kunit *test,
+ const void *prev, char *desc);
struct kunit_attributes attr;
int (*param_init)(struct kunit *test);
void (*param_exit)(struct kunit *test);
@@ -1691,7 +1692,8 @@ do { \
* Define function @name_gen_params which uses @array to generate parameters.
*/
#define KUNIT_ARRAY_PARAM(name, array, get_desc) \
- static const void *name##_gen_params(const void *prev, char *desc) \
+ static const void *name##_gen_params(struct kunit *test, \
+ const void *prev, char *desc) \
{ \
typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
if (__next - (array) < ARRAY_SIZE((array))) { \
@@ -1712,7 +1714,8 @@ do { \
* Define function @name_gen_params which uses @array to generate parameters.
*/
#define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member) \
- static const void *name##_gen_params(const void *prev, char *desc) \
+ static const void *name##_gen_params(struct kunit *test, \
+ const void *prev, char *desc) \
{ \
typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
if (__next - (array) < ARRAY_SIZE((array))) { \
diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
index c2871180edcc..fc76648525ac 100644
--- a/kernel/kcsan/kcsan_test.c
+++ b/kernel/kcsan/kcsan_test.c
@@ -1383,7 +1383,7 @@ static void test_atomic_builtins_missing_barrier(struct kunit *test)
* The thread counts are chosen to cover potentially interesting boundaries and
* corner cases (2 to 5), and then stress the system with larger counts.
*/
-static const void *nthreads_gen_params(const void *prev, char *desc)
+static const void *nthreads_gen_params(struct kunit *test, const void *prev, char *desc)
{
long nthreads = (long)prev;
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index 49a5e6c30c86..01b20702a5a2 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -695,7 +695,7 @@ int kunit_run_tests(struct kunit_suite *suite)
/* Get initial param. */
param_desc[0] = '\0';
/* TODO: Make generate_params try-catch */
- curr_param = test_case->generate_params(NULL, param_desc);
+ curr_param = test_case->generate_params(&test, NULL, param_desc);
test_case->status = KUNIT_SKIPPED;
kunit_log(KERN_INFO, &test, KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT
"KTAP version 1\n");
@@ -726,7 +726,8 @@ int kunit_run_tests(struct kunit_suite *suite)
/* Get next param. */
param_desc[0] = '\0';
- curr_param = test_case->generate_params(curr_param, param_desc);
+ curr_param = test_case->generate_params(&test, curr_param,
+ param_desc);
}
/*
* TODO: Put into a try catch. Since we don't need suite->exit
--
2.51.0.rc0.205.g4a044479a3-goog
next prev parent reply other threads:[~2025-08-11 22:17 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 22:17 [PATCH v2 0/7] kunit: Refactor and extend KUnit's parameterized testing framework Marie Zhussupova
2025-08-11 22:17 ` [PATCH v2 1/7] kunit: Add parent kunit for parameterized test context Marie Zhussupova
2025-08-12 22:22 ` Rae Moar
2025-08-13 9:17 ` David Gow
2025-08-11 22:17 ` [PATCH v2 2/7] kunit: Introduce param_init/exit for parameterized test context management Marie Zhussupova
2025-08-12 22:22 ` Rae Moar
2025-08-13 9:17 ` David Gow
2025-08-11 22:17 ` Marie Zhussupova [this message]
2025-08-12 13:54 ` [PATCH v2 3/7] kunit: Pass parameterized test context to generate_params() Rodrigo Vivi
2025-08-12 22:22 ` Rae Moar
2025-08-13 7:43 ` Marco Elver
2025-08-13 9:18 ` David Gow
2025-08-11 22:17 ` [PATCH v2 4/7] kunit: Enable direct registration of parameter arrays to a KUnit test Marie Zhussupova
2025-08-12 22:23 ` Rae Moar
2025-08-13 9:17 ` David Gow
2025-08-11 22:17 ` [PATCH v2 5/7] kunit: Add example parameterized test with shared resource management using the Resource API Marie Zhussupova
2025-08-12 22:23 ` Rae Moar
2025-08-13 9:17 ` David Gow
2025-08-11 22:17 ` [PATCH v2 6/7] kunit: Add example parameterized test with direct dynamic parameter array setup Marie Zhussupova
2025-08-12 22:23 ` Rae Moar
2025-08-13 9:18 ` David Gow
2025-08-11 22:17 ` [PATCH v2 7/7] Documentation: kunit: Document new parameterized test features Marie Zhussupova
2025-08-12 22:23 ` Rae Moar
2025-08-13 9:18 ` David Gow
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=20250811221739.2694336-4-marievic@google.com \
--to=marievic@google.com \
--cc=brendan.higgins@linux.dev \
--cc=davidgow@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=kasan-dev@googlegroups.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=mark.rutland@arm.com \
--cc=rmoar@google.com \
--cc=rodrigo.vivi@intel.com \
--cc=shuah@kernel.org \
--cc=thomas.hellstrom@linux.intel.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
all inboxes | Powered by JetHome®