lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <lfplzm3dmmkployo2bw2oyhbzwhev4hriamd64th6my2xpsrkv@obol3k6z4u2z>
Date: Thu, 28 Aug 2025 17:19:19 -0500
From: Lucas De Marchi <lucas.demarchi@...el.com>
To: David Gow <davidgow@...gle.com>
CC: Marie Zhussupova <marievic@...gle.com>, <marievictoria875@...il.com>,
	<rmoar@...gle.com>, <shuah@...nel.org>, <brendan.higgins@...ux.dev>,
	<mark.rutland@....com>, <elver@...gle.com>, <dvyukov@...gle.com>,
	<thomas.hellstrom@...ux.intel.com>, <rodrigo.vivi@...el.com>,
	<linux-kselftest@...r.kernel.org>, <kunit-dev@...glegroups.com>,
	<kasan-dev@...glegroups.com>, <intel-xe@...ts.freedesktop.org>,
	<dri-devel@...ts.freedesktop.org>, <linux-kernel@...r.kernel.org>, "Stephen
 Rothwell" <sfr@...b.auug.org.au>
Subject: Re: [PATCH v4 3/7] kunit: Pass parameterized test context to
 generate_params()

On Tue, Aug 26, 2025 at 05:13:33PM +0800, David Gow wrote:
>From: Marie Zhussupova <marievic@...gle.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.
>
>Reviewed-by: David Gow <davidgow@...gle.com>
>Reviewed-by: Rae Moar <rmoar@...gle.com>
>Acked-by: Marco Elver <elver@...gle.com>
>Acked-by: Rodrigo Vivi <rodrigo.vivi@...el.com>
>Signed-off-by: Marie Zhussupova <marievic@...gle.com>
>[Catch some additional gen_params signatures in drm/xe/tests --David]
>Signed-off-by: David Gow <davidgow@...gle.com>
>---
>
>Changes in v4:
>v3: https://lore.kernel.org/linux-kselftest/20250815103604.3857930-4-marievic@google.com/
>- Fixup some additional generate_params signature changes in xe_pci.
>- These are also available as a separate patch here:
>  https://lore.kernel.org/linux-kselftest/20250821135447.1618942-1-davidgow@google.com/
>
>Changes in v3:
>v2: https://lore.kernel.org/all/20250811221739.2694336-4-marievic@google.com/
>- Commit message formatting.
>
>Changes in v2:
>v1: https://lore.kernel.org/all/20250729193647.3410634-4-marievic@google.com/
>    https://lore.kernel.org/all/20250729193647.3410634-5-marievic@google.com/
>    https://lore.kernel.org/all/20250729193647.3410634-6-marievic@google.com/
>- 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      | 14 +++++++-------
> drivers/gpu/drm/xe/tests/xe_pci_test.h |  9 +++++----


Acked-by: Lucas De Marchi <lucas.demarchi@...el.com>

thanks
Lucas De Marchi

> include/kunit/test.h                   |  9 ++++++---
> kernel/kcsan/kcsan_test.c              |  2 +-
> lib/kunit/test.c                       |  5 +++--
> 5 files changed, 22 insertions(+), 17 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c
>index 9c715e59f030..f707e0a54295 100644
>--- a/drivers/gpu/drm/xe/tests/xe_pci.c
>+++ b/drivers/gpu/drm/xe/tests/xe_pci.c
>@@ -44,9 +44,9 @@ KUNIT_ARRAY_PARAM(pci_id, pciidlist, xe_pci_id_kunit_desc);
>  *
>  * Return: pointer to the next parameter or NULL if no more parameters
>  */
>-const void *xe_pci_graphics_ip_gen_param(const void *prev, char *desc)
>+const void *xe_pci_graphics_ip_gen_param(struct kunit *test, const void *prev, char *desc)
> {
>-	return graphics_ip_gen_params(prev, desc);
>+	return graphics_ip_gen_params(test, prev, desc);
> }
> EXPORT_SYMBOL_IF_KUNIT(xe_pci_graphics_ip_gen_param);
>
>@@ -61,9 +61,9 @@ EXPORT_SYMBOL_IF_KUNIT(xe_pci_graphics_ip_gen_param);
>  *
>  * Return: pointer to the next parameter or NULL if no more parameters
>  */
>-const void *xe_pci_media_ip_gen_param(const void *prev, char *desc)
>+const void *xe_pci_media_ip_gen_param(struct kunit *test, const void *prev, char *desc)
> {
>-	return media_ip_gen_params(prev, desc);
>+	return media_ip_gen_params(test, prev, desc);
> }
> EXPORT_SYMBOL_IF_KUNIT(xe_pci_media_ip_gen_param);
>
>@@ -78,9 +78,9 @@ EXPORT_SYMBOL_IF_KUNIT(xe_pci_media_ip_gen_param);
>  *
>  * Return: pointer to the next parameter or NULL if no more parameters
>  */
>-const void *xe_pci_id_gen_param(const void *prev, char *desc)
>+const void *xe_pci_id_gen_param(struct kunit *test, const void *prev, char *desc)
> {
>-	const struct pci_device_id *pci = pci_id_gen_params(prev, desc);
>+	const struct pci_device_id *pci = pci_id_gen_params(test, prev, desc);
>
> 	return pci->driver_data ? pci : NULL;
> }
>@@ -159,7 +159,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/drivers/gpu/drm/xe/tests/xe_pci_test.h b/drivers/gpu/drm/xe/tests/xe_pci_test.h
>index ce4d2b86b778..6d8bc56f7bde 100644
>--- a/drivers/gpu/drm/xe/tests/xe_pci_test.h
>+++ b/drivers/gpu/drm/xe/tests/xe_pci_test.h
>@@ -7,6 +7,7 @@
> #define _XE_PCI_TEST_H_
>
> #include <linux/types.h>
>+#include <kunit/test.h>
>
> #include "xe_platform_types.h"
> #include "xe_sriov_types.h"
>@@ -25,9 +26,9 @@ struct xe_pci_fake_data {
>
> int xe_pci_fake_device_init(struct xe_device *xe);
>
>-const void *xe_pci_graphics_ip_gen_param(const void *prev, char *desc);
>-const void *xe_pci_media_ip_gen_param(const void *prev, char *desc);
>-const void *xe_pci_id_gen_param(const void *prev, char *desc);
>-const void *xe_pci_live_device_gen_param(const void *prev, char *desc);
>+const void *xe_pci_graphics_ip_gen_param(struct kunit *test, const void *prev, char *desc);
>+const void *xe_pci_media_ip_gen_param(struct kunit *test, const void *prev, char *desc);
>+const void *xe_pci_id_gen_param(struct kunit *test, const void *prev, char *desc);
>+const void *xe_pci_live_device_gen_param(struct kunit *test, const void *prev, char *desc);
>
> #endif
>diff --git a/include/kunit/test.h b/include/kunit/test.h
>index fc8fd55b2dfb..8eba1b03c3e3 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);
>@@ -1703,7 +1704,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))) {					\
>@@ -1724,7 +1726,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 49ab81faaed9..a13a090bb2a7 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 0fe61dec5a96..50705248abad 100644
>--- a/lib/kunit/test.c
>+++ b/lib/kunit/test.c
>@@ -700,7 +700,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");
>@@ -731,7 +731,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.261.g7ce5a0a67e-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ