Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit: Pass parameterized test context to generate_params()

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.

Link: https://lore.kernel.org/r/20250826091341.1427123-4-davidgow@google.com
Reviewed-by: David Gow <davidgow@google.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Acked-by: Marco Elver <elver@google.com>
Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Marie Zhussupova <marievic@google.com>
[Catch some additional gen_params signatures in drm/xe/tests --David]
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Marie Zhussupova and committed by
Shuah Khan
b9a214b5 24142358

+22 -17
+7 -7
drivers/gpu/drm/xe/tests/xe_pci.c
··· 44 44 * 45 45 * Return: pointer to the next parameter or NULL if no more parameters 46 46 */ 47 - const void *xe_pci_graphics_ip_gen_param(const void *prev, char *desc) 47 + const void *xe_pci_graphics_ip_gen_param(struct kunit *test, const void *prev, char *desc) 48 48 { 49 - return graphics_ip_gen_params(prev, desc); 49 + return graphics_ip_gen_params(test, prev, desc); 50 50 } 51 51 EXPORT_SYMBOL_IF_KUNIT(xe_pci_graphics_ip_gen_param); 52 52 ··· 61 61 * 62 62 * Return: pointer to the next parameter or NULL if no more parameters 63 63 */ 64 - const void *xe_pci_media_ip_gen_param(const void *prev, char *desc) 64 + const void *xe_pci_media_ip_gen_param(struct kunit *test, const void *prev, char *desc) 65 65 { 66 - return media_ip_gen_params(prev, desc); 66 + return media_ip_gen_params(test, prev, desc); 67 67 } 68 68 EXPORT_SYMBOL_IF_KUNIT(xe_pci_media_ip_gen_param); 69 69 ··· 78 78 * 79 79 * Return: pointer to the next parameter or NULL if no more parameters 80 80 */ 81 - const void *xe_pci_id_gen_param(const void *prev, char *desc) 81 + const void *xe_pci_id_gen_param(struct kunit *test, const void *prev, char *desc) 82 82 { 83 - const struct pci_device_id *pci = pci_id_gen_params(prev, desc); 83 + const struct pci_device_id *pci = pci_id_gen_params(test, prev, desc); 84 84 85 85 return pci->driver_data ? pci : NULL; 86 86 } ··· 159 159 * Return: pointer to the next &struct xe_device ready to be used as a parameter 160 160 * or NULL if there are no more Xe devices on the system. 161 161 */ 162 - const void *xe_pci_live_device_gen_param(const void *prev, char *desc) 162 + const void *xe_pci_live_device_gen_param(struct kunit *test, const void *prev, char *desc) 163 163 { 164 164 const struct xe_device *xe = prev; 165 165 struct device *dev = xe ? xe->drm.dev : NULL;
+5 -4
drivers/gpu/drm/xe/tests/xe_pci_test.h
··· 7 7 #define _XE_PCI_TEST_H_ 8 8 9 9 #include <linux/types.h> 10 + #include <kunit/test.h> 10 11 11 12 #include "xe_platform_types.h" 12 13 #include "xe_sriov_types.h" ··· 26 25 27 26 int xe_pci_fake_device_init(struct xe_device *xe); 28 27 29 - const void *xe_pci_graphics_ip_gen_param(const void *prev, char *desc); 30 - const void *xe_pci_media_ip_gen_param(const void *prev, char *desc); 31 - const void *xe_pci_id_gen_param(const void *prev, char *desc); 32 - const void *xe_pci_live_device_gen_param(const void *prev, char *desc); 28 + const void *xe_pci_graphics_ip_gen_param(struct kunit *test, const void *prev, char *desc); 29 + const void *xe_pci_media_ip_gen_param(struct kunit *test, const void *prev, char *desc); 30 + const void *xe_pci_id_gen_param(struct kunit *test, const void *prev, char *desc); 31 + const void *xe_pci_live_device_gen_param(struct kunit *test, const void *prev, char *desc); 33 32 34 33 #endif
+6 -3
include/kunit/test.h
··· 128 128 struct kunit_case { 129 129 void (*run_case)(struct kunit *test); 130 130 const char *name; 131 - const void* (*generate_params)(const void *prev, char *desc); 131 + const void* (*generate_params)(struct kunit *test, 132 + const void *prev, char *desc); 132 133 struct kunit_attributes attr; 133 134 int (*param_init)(struct kunit *test); 134 135 void (*param_exit)(struct kunit *test); ··· 1704 1703 * Define function @name_gen_params which uses @array to generate parameters. 1705 1704 */ 1706 1705 #define KUNIT_ARRAY_PARAM(name, array, get_desc) \ 1707 - static const void *name##_gen_params(const void *prev, char *desc) \ 1706 + static const void *name##_gen_params(struct kunit *test, \ 1707 + const void *prev, char *desc) \ 1708 1708 { \ 1709 1709 typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \ 1710 1710 if (__next - (array) < ARRAY_SIZE((array))) { \ ··· 1726 1724 * Define function @name_gen_params which uses @array to generate parameters. 1727 1725 */ 1728 1726 #define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member) \ 1729 - static const void *name##_gen_params(const void *prev, char *desc) \ 1727 + static const void *name##_gen_params(struct kunit *test, \ 1728 + const void *prev, char *desc) \ 1730 1729 { \ 1731 1730 typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \ 1732 1731 if (__next - (array) < ARRAY_SIZE((array))) { \
+1 -1
kernel/kcsan/kcsan_test.c
··· 1383 1383 * The thread counts are chosen to cover potentially interesting boundaries and 1384 1384 * corner cases (2 to 5), and then stress the system with larger counts. 1385 1385 */ 1386 - static const void *nthreads_gen_params(const void *prev, char *desc) 1386 + static const void *nthreads_gen_params(struct kunit *test, const void *prev, char *desc) 1387 1387 { 1388 1388 long nthreads = (long)prev; 1389 1389
+3 -2
lib/kunit/test.c
··· 700 700 /* Get initial param. */ 701 701 param_desc[0] = '\0'; 702 702 /* TODO: Make generate_params try-catch */ 703 - curr_param = test_case->generate_params(NULL, param_desc); 703 + curr_param = test_case->generate_params(&test, NULL, param_desc); 704 704 test_case->status = KUNIT_SKIPPED; 705 705 kunit_log(KERN_INFO, &test, KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT 706 706 "KTAP version 1\n"); ··· 731 731 732 732 /* Get next param. */ 733 733 param_desc[0] = '\0'; 734 - curr_param = test_case->generate_params(curr_param, param_desc); 734 + curr_param = test_case->generate_params(&test, curr_param, 735 + param_desc); 735 736 } 736 737 /* 737 738 * TODO: Put into a try catch. Since we don't need suite->exit