kunit: fix bug of extra newline characters in debugfs logs
authorRae Moar <rmoar@google.com>
Wed, 8 Mar 2023 20:39:52 +0000 (20:39 +0000)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 10 Mar 2023 20:59:43 +0000 (13:59 -0700)
commit2c6a96dad5797e57b4cf04101d6c8d5c7a571603
treee19212faf62e375b494418da13873e4a4dae30f7
parentf9a301c3317daa921375da0aec82462ddf019928
kunit: fix bug of extra newline characters in debugfs logs

Fix bug of the extra newline characters in debugfs logs. When a
line is added to debugfs with a newline character at the end,
an extra line appears in the debugfs log.

This is due to a discrepancy between how the lines are printed and how they
are added to the logs. Remove this discrepancy by checking if a newline
character is present before adding a newline character. This should closely
match the printk behavior.

Add kunit_log_newline_test to provide test coverage for this issue.  (Also,
move kunit_log_test above suite definition to remove the unnecessary
declaration prior to the suite definition)

As an example, say we add these two lines to the log:

kunit_log(..., "KTAP version 1\n");
kunit_log(..., "1..1");

The debugfs log before this fix:

 KTAP version 1

 1..1

The debugfs log after this fix:

 KTAP version 1
 1..1

Signed-off-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
include/kunit/test.h
lib/kunit/kunit-test.c
lib/kunit/test.c