Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit: fix bug in debugfs logs of parameterized tests

Fix bug in debugfs logs that causes individual parameterized results to not
appear because the log is reinitialized (cleared) when each parameter is
run.

Ensure these results appear in the debugfs logs, increase log size to
allow for the size of parameterized results. As a result, append lines to
the log directly rather than using an intermediate variable that can cause
stack size warnings due to the increased log size.

Here is the debugfs log of ext4_inode_test which uses parameterized tests
before the fix:

KTAP version 1

# Subtest: ext4_inode_test
1..1
# Totals: pass:16 fail:0 skip:0 total:16
ok 1 ext4_inode_test

As you can see, this log does not include any of the individual
parametrized results.

After (in combination with the next two fixes to remove extra empty line
and ensure KTAP valid format):

KTAP version 1
1..1
KTAP version 1
# Subtest: ext4_inode_test
1..1
KTAP version 1
# Subtest: inode_test_xtimestamp_decoding
ok 1 1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits
... (the rest of the individual parameterized tests)
ok 16 2446-05-10 Upper bound of 32bit >=0 timestamp. All extra
# inode_test_xtimestamp_decoding: pass:16 fail:0 skip:0 total:16
ok 1 inode_test_xtimestamp_decoding
# Totals: pass:16 fail:0 skip:0 total:16
ok 1 ext4_inode_test

Signed-off-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Rae Moar and committed by
Shuah Khan
887d85a0 60684c2b

+13 -7
+1 -1
include/kunit/test.h
··· 34 34 struct kunit; 35 35 36 36 /* Size of log associated with test. */ 37 - #define KUNIT_LOG_SIZE 512 37 + #define KUNIT_LOG_SIZE 1500 38 38 39 39 /* Maximum size of parameter description string. */ 40 40 #define KUNIT_PARAM_DESC_SIZE 128
+12 -6
lib/kunit/test.c
··· 114 114 */ 115 115 void kunit_log_append(char *log, const char *fmt, ...) 116 116 { 117 - char line[KUNIT_LOG_SIZE]; 118 117 va_list args; 119 - int len_left; 118 + int len, log_len, len_left; 120 119 121 120 if (!log) 122 121 return; 123 122 124 - len_left = KUNIT_LOG_SIZE - strlen(log) - 1; 123 + log_len = strlen(log); 124 + len_left = KUNIT_LOG_SIZE - log_len - 1; 125 125 if (len_left <= 0) 126 126 return; 127 127 128 + /* Evaluate length of line to add to log */ 128 129 va_start(args, fmt); 129 - vsnprintf(line, sizeof(line), fmt, args); 130 + len = vsnprintf(NULL, 0, fmt, args) + 1; 130 131 va_end(args); 131 132 132 - strncat(log, line, len_left); 133 + /* Print formatted line to the log */ 134 + va_start(args, fmt); 135 + vsnprintf(log + log_len, min(len, len_left), fmt, args); 136 + va_end(args); 137 + 133 138 } 134 139 EXPORT_SYMBOL_GPL(kunit_log_append); 135 140 ··· 442 437 struct kunit_try_catch_context context; 443 438 struct kunit_try_catch *try_catch; 444 439 445 - kunit_init_test(test, test_case->name, test_case->log); 446 440 try_catch = &test->try_catch; 447 441 448 442 kunit_try_catch_init(try_catch, ··· 536 532 struct kunit test = { .param_value = NULL, .param_index = 0 }; 537 533 struct kunit_result_stats param_stats = { 0 }; 538 534 test_case->status = KUNIT_SKIPPED; 535 + 536 + kunit_init_test(&test, test_case->name, test_case->log); 539 537 540 538 if (!test_case->generate_params) { 541 539 /* Non-parameterised test. */