<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/lib/kunit/test.c, branch v6.19.11</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-10-27T17:13:31+00:00</updated>
<entry>
<title>kunit: prevent log overwrite in param_tests</title>
<updated>2025-10-27T17:13:31+00:00</updated>
<author>
<name>Carlos Llamas</name>
<email>cmllamas@google.com</email>
</author>
<published>2025-10-24T19:01:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=8080c67dd57cb968150b668ecbd4a4e4afd56ad4'/>
<id>urn:sha1:8080c67dd57cb968150b668ecbd4a4e4afd56ad4</id>
<content type='text'>
When running parameterized tests, each test case is initialized with
kunit_init_test(). This function takes the test_case-&gt;log as a parameter
but it clears it via string_stream_clear() on each iteration.

This results in only the log from the last parameter being preserved in
the test_case-&gt;log and the results from the previous parameters are lost
from the debugfs entry.

Fix this by manually setting the param_test.log to the test_case-&gt;log
after it has been initialized. This prevents kunit_init_test() from
clearing the log on each iteration.

Link: https://lore.kernel.org/r/20251024190101.2091549-1-cmllamas@google.com
Fixes: 4b59300ba4d2 ("kunit: Add parent kunit for parameterized test context")
Signed-off-by: Carlos Llamas &lt;cmllamas@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Enable direct registration of parameter arrays to a KUnit test</title>
<updated>2025-08-27T05:36:03+00:00</updated>
<author>
<name>Marie Zhussupova</name>
<email>marievic@google.com</email>
</author>
<published>2025-08-26T09:13:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b820b9077b7f4008cc44a40261aefa681c63c7d3'/>
<id>urn:sha1:b820b9077b7f4008cc44a40261aefa681c63c7d3</id>
<content type='text'>
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 &lt;davidgow@google.com&gt;
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Signed-off-by: Marie Zhussupova &lt;marievic@google.com&gt;
[Only output the test plan if using kunit_array_gen_params --David]
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Pass parameterized test context to generate_params()</title>
<updated>2025-08-27T05:36:03+00:00</updated>
<author>
<name>Marie Zhussupova</name>
<email>marievic@google.com</email>
</author>
<published>2025-08-26T09:13:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=b9a214b5f6aa55870b5678f31084f85c0c11ffdc'/>
<id>urn:sha1:b9a214b5f6aa55870b5678f31084f85c0c11ffdc</id>
<content type='text'>
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 &lt;davidgow@google.com&gt;
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Acked-by: Marco Elver &lt;elver@google.com&gt;
Acked-by: Rodrigo Vivi &lt;rodrigo.vivi@intel.com&gt;
Signed-off-by: Marie Zhussupova &lt;marievic@google.com&gt;
[Catch some additional gen_params signatures in drm/xe/tests --David]
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Introduce param_init/exit for parameterized test context management</title>
<updated>2025-08-27T05:36:03+00:00</updated>
<author>
<name>Marie Zhussupova</name>
<email>marievic@google.com</email>
</author>
<published>2025-08-26T09:13:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=241423580e5e8d8b10b14b382379f4928b87be17'/>
<id>urn:sha1:241423580e5e8d8b10b14b382379f4928b87be17</id>
<content type='text'>
Add (*param_init) and (*param_exit) function pointers to
`struct kunit_case`. Users will be able to set them via the new
KUNIT_CASE_PARAM_WITH_INIT() macro.

param_init/exit will be invoked by kunit_run_tests() once before and once
after the parameterized test, respectively. They will receive the
`struct kunit` that holds the parameterized test context; facilitating
init and exit for shared state.

This patch also sets param_init/exit to None in rust/kernel/kunit.rs.

Link: https://lore.kernel.org/r/20250826091341.1427123-3-davidgow@google.com
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Marie Zhussupova &lt;marievic@google.com&gt;
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Add parent kunit for parameterized test context</title>
<updated>2025-08-27T05:36:03+00:00</updated>
<author>
<name>Marie Zhussupova</name>
<email>marievic@google.com</email>
</author>
<published>2025-08-26T09:13:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=4b59300ba4d2362b02c2a9077047bbabceea67d7'/>
<id>urn:sha1:4b59300ba4d2362b02c2a9077047bbabceea67d7</id>
<content type='text'>
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 &lt;davidgow@google.com&gt;
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Signed-off-by: Marie Zhussupova &lt;marievic@google.com&gt;
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: test: Drop CONFIG_MODULE ifdeffery</title>
<updated>2025-07-31T11:51:34+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>thomas.weissschuh@linutronix.de</email>
</author>
<published>2025-07-11T13:31:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=768da2eae8662ca51102794c32d37c17410acbf5'/>
<id>urn:sha1:768da2eae8662ca51102794c32d37c17410acbf5</id>
<content type='text'>
The function stubs exposed by module.h allow the code to compile properly
without the ifdeffery. The generated object code stays the same, as the
compiler can optimize away all the dead code.
As the code is still typechecked developer errors can be detected faster.

Signed-off-by: Thomas Weißschuh &lt;thomas.weissschuh@linutronix.de&gt;
Acked-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Daniel Gomez &lt;da.gomez@samsung.com&gt;
Link: https://lore.kernel.org/r/20250711-kunit-ifdef-modules-v2-3-39443decb1f8@linutronix.de
Signed-off-by: Daniel Gomez &lt;da.gomez@samsung.com&gt;
</content>
</entry>
<entry>
<title>kunit: Make default kunit_test timeout configurable via both a module parameter and a Kconfig option</title>
<updated>2025-06-27T21:00:05+00:00</updated>
<author>
<name>Marie Zhussupova</name>
<email>marievic@google.com</email>
</author>
<published>2025-06-26T17:17:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=5ac244b9cc8f49c945c5be67ed7d6f8ac6ed9321'/>
<id>urn:sha1:5ac244b9cc8f49c945c5be67ed7d6f8ac6ed9321</id>
<content type='text'>
To accommodate varying hardware performance and use cases,
the default kunit test case timeout (currently 300 seconds)
is now configurable. Users can adjust the timeout by
either setting the 'timeout' module parameter or the
KUNIT_DEFAULT_TIMEOUT Kconfig option to their desired
timeout in seconds.

Link: https://lore.kernel.org/r/20250626171730.1765004-1-marievic@google.com
Signed-off-by: Marie Zhussupova &lt;marievic@google.com&gt;
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Adjust kunit_test timeout based on test_{suite,case} speed</title>
<updated>2025-06-25T02:47:39+00:00</updated>
<author>
<name>Ujwal Jain</name>
<email>ujwaljain@google.com</email>
</author>
<published>2025-06-14T08:47:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=63d0a9123120a2e10861ac7f6dc474bee653d3b2'/>
<id>urn:sha1:63d0a9123120a2e10861ac7f6dc474bee653d3b2</id>
<content type='text'>
Currently, the in-kernel kunit test case timeout is 300 seconds. (There
is a separate timeout mechanism for the whole test execution in
kunit.py, but that's unrelated.) However, tests marked 'slow' or 'very
slow' may timeout, particularly on slower machines.

Implement a multiplier to the test-case timeout, so that slower tests
have longer to complete:
- DEFAULT -&gt; 1x default timeout
- KUNIT_SPEED_SLOW -&gt; 3x default timeout
- KUNIT_SPEED_VERY_SLOW -&gt; 12x default timeout

A further change is planned to allow user configuration of the
default/base timeout to allow people with faster or slower machines to
adjust these to their use-cases.

Link: https://lore.kernel.org/r/20250614084711.2654593-2-davidgow@google.com
Signed-off-by: Ujwal Jain &lt;ujwaljain@google.com&gt;
Co-developed-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Introduce autorun option</title>
<updated>2025-01-15T16:04:06+00:00</updated>
<author>
<name>Stanislav Kinsburskii</name>
<email>skinsburskii@linux.microsoft.com</email>
</author>
<published>2024-10-28T21:54:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=31691914c392675bdc65d1e72dd8d129a1f0014f'/>
<id>urn:sha1:31691914c392675bdc65d1e72dd8d129a1f0014f</id>
<content type='text'>
The new option controls tests run on boot or module load. With the new
debugfs "run" dentry allowing to run tests on demand, an ability to disable
automatic tests run becomes a useful option in case of intrusive tests.

The option is set to true by default to preserve the existent behavior. It
can be overridden by either the corresponding module option or by the
corresponding config build option.

Link: https://lore.kernel.org/r/173015245931.4747.16419517391658830640.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net
Signed-off-by: Stanislav Kinsburskii &lt;skinsburskii@linux.microsoft.com&gt;
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Acked-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>kunit: Device wrappers should also manage driver name</title>
<updated>2024-08-26T13:03:46+00:00</updated>
<author>
<name>David Gow</name>
<email>davidgow@google.com</email>
</author>
<published>2024-08-16T04:51:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f2c6dbd220170c2396fb019ead67fbada1e23ebd'/>
<id>urn:sha1:f2c6dbd220170c2396fb019ead67fbada1e23ebd</id>
<content type='text'>
kunit_driver_create() accepts a name for the driver, but does not copy
it, so if that name is either on the stack, or otherwise freed, we end
up with a use-after-free when the driver is cleaned up.

Instead, strdup() the name, and manage it as another KUnit allocation.
As there was no existing kunit_kstrdup(), we add one. Further, add a
kunit_ variant of strdup_const() and kfree_const(), so we don't need to
allocate and manage the string in the majority of cases where it's a
constant.

However, these are inline functions, and is_kernel_rodata() only works
for built-in code. This causes problems in two cases:
- If kunit is built as a module, __{start,end}_rodata is not defined.
- If a kunit test using these functions is built as a module, it will
  suffer the same fate.

This fixes a KASAN splat with overflow.overflow_allocation_test, when
built as a module.

Restrict the is_kernel_rodata() case to when KUnit is built as a module,
which fixes the first case, at the cost of losing the optimisation.

Also, make kunit_{kstrdup,kfree}_const non-inline, so that other modules
using them will not accidentally depend on is_kernel_rodata(). If KUnit
is built-in, they'll benefit from the optimisation, if KUnit is not,
they won't, but the string will be properly duplicated.

Fixes: d03c720e03bd ("kunit: Add APIs for managing devices")
Reported-by: Nico Pache &lt;npache@redhat.com&gt;
Closes: https://groups.google.com/g/kunit-dev/c/81V9b9QYON0
Reviewed-by: Kees Cook &lt;kees@kernel.org&gt;
Reviewed-by: Maxime Ripard &lt;mripard@kernel.org&gt;
Reviewed-by: Rae Moar &lt;rmoar@google.com&gt;
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Tested-by: Rae Moar &lt;rmoar@google.com&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
</feed>
