mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kunit: prevent log overwrite in param_tests
@ 2025-10-24 19:01 Carlos Llamas
  2025-10-25  2:01 ` David Gow
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Llamas @ 2025-10-24 19:01 UTC (permalink / raw)
  To: Brendan Higgins, David Gow, Rae Moar, Shuah Khan, Marie Zhussupova
  Cc: kernel-team, linux-kernel, Tiffany Yang, Carlos Llamas,
	open list:KERNEL UNIT TESTING FRAMEWORK (KUnit),
	open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)

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.

Fixes: 4b59300ba4d2 ("kunit: Add parent kunit for parameterized test context")
Signed-off-by: Carlos Llamas <cmllamas@google.com>
---
 lib/kunit/test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index bb66ea1a3eac..62eb529824c6 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -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') {
-- 
2.51.1.821.gb6fe4d2222-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-25  2:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-24 19:01 [PATCH] kunit: prevent log overwrite in param_tests Carlos Llamas
2025-10-25  2:01 ` David Gow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®