Files
Jerry Snitselaar b58904e25f kunit: Enable direct registration of parameter arrays to a KUnit test
JIRA: https://issues.redhat.com/browse/RHEL-147902
Upstream-Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit b820b9077b7f4008cc44a40261aefa681c63c7d3
Author: Marie Zhussupova <marievic@google.com>
Date: Tue Aug 26 17:13:34 2025 +0800

    kunit: Enable direct registration of parameter arrays to a KUnit test

    KUnit parameterized tests currently support two primary methods f
    or getting parameters:
    1.  Defining custom logic within a generate_params() function.
    2.  Using the KUNIT_ARRAY_PARAM() and KUNIT_ARRAY_PARAM_DESC()
	macros with a pre-defined static array and passing
	the created *_gen_params() to KUNIT_CASE_PARAM().

    These methods present limitations when dealing with dynamically
    generated parameter arrays, or in scenarios where populating parameters
    sequentially via generate_params() is inefficient or overly complex.

    This patch addresses these limitations by adding a new `params_array`
    field to `struct kunit`, of the type `kunit_params`. The
    `struct kunit_params` is designed to store the parameter array itself,
    along with essential metadata including the parameter count, parameter
    size, and a get_description() function for providing custom descriptions
    for individual parameters.

    The `params_array` field can be populated by calling the new
    kunit_register_params_array() macro from within a param_init() function.
    This will register the array as part of the parameterized test context.
    The user will then need to pass kunit_array_gen_params() to the
    KUNIT_CASE_PARAM_WITH_INIT() macro as the generator function, if not
    providing their own. kunit_array_gen_params() is a KUnit helper that will
    use the registered array to generate parameters.

    The arrays passed to KUNIT_ARRAY_PARAM(,DESC) will also be registered to
    the parameterized test context for consistency as well as for higher
    availability of the parameter count that will be used for outputting a KTAP
    test plan for a parameterized test.

    This modification provides greater flexibility to the KUnit framework,
    allowing  testers to easily register and utilize both dynamic and static
    parameter arrays.

    Link: https://lore.kernel.org/r/20250826091341.1427123-5-davidgow@google.com
    Reviewed-by: David Gow <davidgow@google.com>
    Reviewed-by: Rae Moar <rmoar@google.com>
    Signed-off-by: Marie Zhussupova <marievic@google.com>
    [Only output the test plan if using kunit_array_gen_params --David]
    Signed-off-by: David Gow <davidgow@google.com>
    Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

(cherry picked from commit b820b9077b7f4008cc44a40261aefa681c63c7d3)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2026-04-06 17:36:35 -07:00
..
2023-12-18 13:28:08 -07:00
2024-05-06 14:22:02 -06:00