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 the order of lines in debugfs logs

Fix bug in debugfs logs that causes an incorrect order of lines in the
debugfs log.

Currently, the test counts lines that show the number of tests passed,
failed, and skipped, as well as any suite diagnostic lines,
appear prior to the individual results, which is a bug.

Ensure the order of printing for the debugfs log is correct. Additionally,
add a KTAP header to so the debugfs logs can be valid KTAP.

This is an example of a log prior to these fixes:

KTAP version 1

# Subtest: kunit_status
1..2
# kunit_status: pass:2 fail:0 skip:0 total:2
# Totals: pass:2 fail:0 skip:0 total:2
ok 1 kunit_status_set_failure_test
ok 2 kunit_status_mark_skipped_test
ok 1 kunit_status

Note the two lines with stats are out of order. This is the same debugfs
log after the fixes (in combination with the third patch to remove the
extra line):

KTAP version 1
1..1
KTAP version 1
# Subtest: kunit_status
1..2
ok 1 kunit_status_set_failure_test
ok 2 kunit_status_mark_skipped_test
# kunit_status: pass:2 fail:0 skip:0 total:2
# Totals: pass:2 fail:0 skip:0 total:2
ok 1 kunit_status

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
f9a301c3 887d85a0

+26 -9
+12 -2
lib/kunit/debugfs.c
··· 55 55 enum kunit_status success = kunit_suite_has_succeeded(suite); 56 56 struct kunit_case *test_case; 57 57 58 - if (!suite || !suite->log) 58 + if (!suite) 59 59 return 0; 60 60 61 - seq_printf(seq, "%s", suite->log); 61 + /* Print KTAP header so the debugfs log can be parsed as valid KTAP. */ 62 + seq_puts(seq, "KTAP version 1\n"); 63 + seq_puts(seq, "1..1\n"); 64 + 65 + /* Print suite header because it is not stored in the test logs. */ 66 + seq_puts(seq, KUNIT_SUBTEST_INDENT "KTAP version 1\n"); 67 + seq_printf(seq, KUNIT_SUBTEST_INDENT "# Subtest: %s\n", suite->name); 68 + seq_printf(seq, KUNIT_SUBTEST_INDENT "1..%zd\n", kunit_suite_num_test_cases(suite)); 62 69 63 70 kunit_suite_for_each_test_case(suite, test_case) 64 71 debugfs_print_result(seq, suite, test_case); 72 + 73 + if (suite->log) 74 + seq_printf(seq, "%s", suite->log); 65 75 66 76 seq_printf(seq, "%s %d %s\n", 67 77 kunit_status_to_ok_not_ok(success), 1, suite->name);
+14 -7
lib/kunit/test.c
··· 152 152 153 153 static void kunit_print_suite_start(struct kunit_suite *suite) 154 154 { 155 - kunit_log(KERN_INFO, suite, KUNIT_SUBTEST_INDENT "KTAP version 1\n"); 156 - kunit_log(KERN_INFO, suite, KUNIT_SUBTEST_INDENT "# Subtest: %s", 155 + /* 156 + * We do not log the test suite header as doing so would 157 + * mean debugfs display would consist of the test suite 158 + * header prior to individual test results. 159 + * Hence directly printk the suite status, and we will 160 + * separately seq_printf() the suite header for the debugfs 161 + * representation. 162 + */ 163 + pr_info(KUNIT_SUBTEST_INDENT "KTAP version 1\n"); 164 + pr_info(KUNIT_SUBTEST_INDENT "# Subtest: %s\n", 157 165 suite->name); 158 - kunit_log(KERN_INFO, suite, KUNIT_SUBTEST_INDENT "1..%zd", 166 + pr_info(KUNIT_SUBTEST_INDENT "1..%zd\n", 159 167 kunit_suite_num_test_cases(suite)); 160 168 } 161 169 ··· 180 172 181 173 /* 182 174 * We do not log the test suite results as doing so would 183 - * mean debugfs display would consist of the test suite 184 - * description and status prior to individual test results. 185 - * Hence directly printk the suite status, and we will 186 - * separately seq_printf() the suite status for the debugfs 175 + * mean debugfs display would consist of an incorrect test 176 + * number. Hence directly printk the suite result, and we will 177 + * separately seq_printf() the suite results for the debugfs 187 178 * representation. 188 179 */ 189 180 if (suite)