kunit: Use string_stream for test log
Replace the fixed-size log buffer with a string_stream so that the log can grow as lines are added. The existing kunit log tests have been updated for using a string_stream as the log. No new test have been added because there are already tests for the underlying string_stream. As the log tests now depend on string_stream functions they cannot build when kunit-test is a module. They have been surrounded by a #if to replace them with skipping version when the test is build as a module. Though this isn't pretty, it avoids moving code to another file while that code is also being changed. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
committed by
Shuah Khan
parent
d1a0d699bf
commit
05e2006ce4
+23
-13
@@ -37,14 +37,21 @@ void kunit_debugfs_init(void)
|
||||
debugfs_rootdir = debugfs_create_dir(KUNIT_DEBUGFS_ROOT, NULL);
|
||||
}
|
||||
|
||||
static void debugfs_print_result(struct seq_file *seq,
|
||||
struct kunit_suite *suite,
|
||||
struct kunit_case *test_case)
|
||||
static void debugfs_print_result(struct seq_file *seq, struct string_stream *log)
|
||||
{
|
||||
if (!test_case || !test_case->log)
|
||||
struct string_stream_fragment *frag_container;
|
||||
|
||||
if (!log)
|
||||
return;
|
||||
|
||||
seq_printf(seq, "%s", test_case->log);
|
||||
/*
|
||||
* Walk the fragments so we don't need to allocate a temporary
|
||||
* buffer to hold the entire string.
|
||||
*/
|
||||
spin_lock(&log->lock);
|
||||
list_for_each_entry(frag_container, &log->fragments, node)
|
||||
seq_printf(seq, "%s", frag_container->fragment);
|
||||
spin_unlock(&log->lock);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -69,10 +76,9 @@ static int debugfs_print_results(struct seq_file *seq, void *v)
|
||||
seq_printf(seq, KUNIT_SUBTEST_INDENT "1..%zd\n", kunit_suite_num_test_cases(suite));
|
||||
|
||||
kunit_suite_for_each_test_case(suite, test_case)
|
||||
debugfs_print_result(seq, suite, test_case);
|
||||
debugfs_print_result(seq, test_case->log);
|
||||
|
||||
if (suite->log)
|
||||
seq_printf(seq, "%s", suite->log);
|
||||
debugfs_print_result(seq, suite->log);
|
||||
|
||||
seq_printf(seq, "%s %d %s\n",
|
||||
kunit_status_to_ok_not_ok(success), 1, suite->name);
|
||||
@@ -105,9 +111,13 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite)
|
||||
struct kunit_case *test_case;
|
||||
|
||||
/* Allocate logs before creating debugfs representation. */
|
||||
suite->log = kzalloc(KUNIT_LOG_SIZE, GFP_KERNEL);
|
||||
kunit_suite_for_each_test_case(suite, test_case)
|
||||
test_case->log = kzalloc(KUNIT_LOG_SIZE, GFP_KERNEL);
|
||||
suite->log = alloc_string_stream(GFP_KERNEL);
|
||||
string_stream_set_append_newlines(suite->log, true);
|
||||
|
||||
kunit_suite_for_each_test_case(suite, test_case) {
|
||||
test_case->log = alloc_string_stream(GFP_KERNEL);
|
||||
string_stream_set_append_newlines(test_case->log, true);
|
||||
}
|
||||
|
||||
suite->debugfs = debugfs_create_dir(suite->name, debugfs_rootdir);
|
||||
|
||||
@@ -121,7 +131,7 @@ void kunit_debugfs_destroy_suite(struct kunit_suite *suite)
|
||||
struct kunit_case *test_case;
|
||||
|
||||
debugfs_remove_recursive(suite->debugfs);
|
||||
kfree(suite->log);
|
||||
string_stream_destroy(suite->log);
|
||||
kunit_suite_for_each_test_case(suite, test_case)
|
||||
kfree(test_case->log);
|
||||
string_stream_destroy(test_case->log);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user