Hello!
KUnit offers a parameterized testing framework, where tests can be run multiple times with different inputs.
Currently, the same `struct kunit` is used for each parameter execution. After each run, the test instance gets cleaned up. This creates the following limitations:
a. There is no way to store resources that are accessible across the individual parameter test executions. b. It's not possible to pass additional context besides the previous parameter to `generate_params()` to get the next parameter. c. Test users are restricted to using pre-defined static arrays of parameter objects or `generate_params()` to define their parameters. There is no flexibility to pass a custom dynamic array without using `generate_params()`, which can be complex if generating the next parameter depends on more than just the single previous parameter (e.g., two or more previous parameters).
This patch series resolves these limitations by:
1. [P 1] Giving each parameterized test execution its own `struct kunit`. This aligns more with the definition of a `struct kunit` as a running instance of a test. It will also remove the need to manage state, such as resetting the `test->priv` field or the `test->status_comment` after every parameter run.
2. [P 1] Introducing a parent pointer of type `struct kunit`. Behind the scenes, a parent instance for the parameterized tests will be created. It won't be used to execute any test logic, but will instead be used as a context for shared resources. Each individual running instance of a test will now have a reference to that parent instance and thus, have access to those resources.
3. [P 2] Introducing `param_init()` and `param_exit()` functions that can set up and clean up the parent instance of the parameterized tests. They will run once before and after the parameterized series and provide a way for the user to access the parent instance to add the parameter array or any other resources to it, including custom ones to the `test->parent->priv` field or to `test->parent->resources` via the Resource API (link below).
https://elixir.bootlin.com/linux/v6.16-rc7/source/include/kunit/resource.h
4. [P 3, 4 & 5] Passing the parent `struct kunit` as an additional parameter to `generate_params()`. This provides `generate_params()` with more available context, making parameter generation much more flexible. The `generate_params()` implementations in the KCSAN and drm/xe tests have been adapted to match the new function pointer signature.
5. [P 6] Introducing a `params_data` field in `struct kunit`. This will allow the parent instance of a test to have direct storage of the parameter array, enabling features like using dynamic parameter arrays or using context beyond just the previous parameter.
Thank you! -Marie
Marie Zhussupova (9): kunit: Add parent kunit for parameterized test context kunit: Introduce param_init/exit for parameterized test shared context management kunit: Pass additional context to generate_params for parameterized testing kcsan: test: Update parameter generator to new signature drm/xe: Update parameter generator to new signature kunit: Enable direct registration of parameter arrays to a KUnit test kunit: Add example parameterized test with shared resources and direct static parameter array setup kunit: Add example parameterized test with direct dynamic parameter array setup Documentation: kunit: Document new parameterized test features
Documentation/dev-tools/kunit/usage.rst | 455 +++++++++++++++++++++++- drivers/gpu/drm/xe/tests/xe_pci.c | 2 +- include/kunit/test.h | 98 ++++- kernel/kcsan/kcsan_test.c | 2 +- lib/kunit/kunit-example-test.c | 207 +++++++++++ lib/kunit/test.c | 82 ++++- 6 files changed, 818 insertions(+), 28 deletions(-)