diff options
| author | Marie Zhussupova <marievic@google.com> | 2025-08-26 17:13:31 +0800 |
|---|---|---|
| committer | Shuah Khan <skhan@linuxfoundation.org> | 2025-08-26 23:36:03 -0600 |
| commit | 4b59300ba4d2362b02c2a9077047bbabceea67d7 (patch) | |
| tree | b268c071b5b25b37f084e0583ed797fd07c1a8cc /include/kunit | |
| parent | 922d1dde441ad1060bc1ec005fd792774a274999 (diff) | |
kunit: Add parent kunit for parameterized test context
Currently, KUnit parameterized tests lack a mechanism to share
resources across parameter runs because the same `struct kunit`
instance is cleaned up and reused for each run.
This patch introduces parameterized test context, enabling test
users to share resources between parameter runs. It also allows
setting up resources that need to be available for all parameter
runs only once, which is helpful in cases where setup is expensive.
To establish a parameterized test context, this patch adds a
parent pointer field to `struct kunit`. This allows resources added
to the parent `struct kunit` to be shared and accessible across all
parameter runs.
In kunit_run_tests(), the default `struct kunit` created is now
designated to act as the parameterized test context whenever a test
is parameterized.
Subsequently, a new `struct kunit` is made for each parameter run, and
its parent pointer is set to the `struct kunit` that holds the
parameterized test context.
Link: https://lore.kernel.org/r/20250826091341.1427123-2-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>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'include/kunit')
| -rw-r--r-- | include/kunit/test.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/include/kunit/test.h b/include/kunit/test.h index d958ee53050e..9766403afd56 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -268,14 +268,18 @@ struct kunit_suite_set { * * @priv: for user to store arbitrary data. Commonly used to pass data * created in the init function (see &struct kunit_suite). + * @parent: reference to the parent context of type struct kunit that can + * be used for storing shared resources. * * Used to store information about the current context under which the test * is running. Most of this data is private and should only be accessed - * indirectly via public functions; the one exception is @priv which can be - * used by the test writer to store arbitrary data. + * indirectly via public functions; the two exceptions are @priv and @parent + * which can be used by the test writer to store arbitrary data and access the + * parent context, respectively. */ struct kunit { void *priv; + struct kunit *parent; /* private: internal use only. */ const char *name; /* Read only after initialization! */ |