kunit: string-stream: Add option to make all lines end with newline

Add an optional feature to string_stream that will append a newline to
any added string that does not already end with a newline. The purpose
of this is so that string_stream can be used to collect log lines.

This is enabled/disabled by calling string_stream_set_append_newlines().

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Richard Fitzgerald
2023-08-28 11:41:04 +01:00
committed by Shuah Khan
parent 4551caca6a
commit a5abe7b201
2 changed files with 28 additions and 7 deletions
+7
View File
@@ -25,6 +25,7 @@ struct string_stream {
spinlock_t lock;
struct kunit *test;
gfp_t gfp;
bool append_newlines;
};
struct kunit;
@@ -47,4 +48,10 @@ bool string_stream_is_empty(struct string_stream *stream);
void string_stream_destroy(struct string_stream *stream);
static inline void string_stream_set_append_newlines(struct string_stream *stream,
bool append_newlines)
{
stream->append_newlines = append_newlines;
}
#endif /* _KUNIT_STRING_STREAM_H */