]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kunit: prevent log overwrite in param_tests
authorCarlos Llamas <cmllamas@google.com>
Fri, 24 Oct 2025 19:01:00 +0000 (19:01 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 27 Oct 2025 17:13:31 +0000 (11:13 -0600)
When running parameterized tests, each test case is initialized with
kunit_init_test(). This function takes the test_case->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->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->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 <cmllamas@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/test.c

index bb66ea1a3eaccf6537b8985f36df58e930134a43..62eb529824c657b128827c09c7ee8d85794173cf 100644 (file)
@@ -745,7 +745,8 @@ int kunit_run_tests(struct kunit_suite *suite)
                                        .param_index = ++test.param_index,
                                        .parent = &test,
                                };
-                               kunit_init_test(&param_test, test_case->name, test_case->log);
+                               kunit_init_test(&param_test, test_case->name, NULL);
+                               param_test.log = test_case->log;
                                kunit_run_case_catch_errors(suite, test_case, &param_test);
 
                                if (param_desc[0] == '\0') {