On Tue, 8 Aug 2023 at 20:35, Richard Fitzgerald
<rf@xxxxxxxxxxxxxxxxxxxxx> wrote:
Re-implement the log buffer as a list of buffer fragments that can
be extended as the size of the log info grows.
When using parameterization the test case can run many times and create
a large amount of log. It's not really practical to keep increasing the
size of the fixed buffer every time a test needs more space. And a big
fixed buffer wastes memory.
The original char *log pointer is replaced by a pointer to a list of
struct kunit_log_frag, each containing a fixed-size buffer.
kunit_log_append() now attempts to append to the last kunit_log_frag in
the list. If there isn't enough space it will append a new kunit_log_frag
to the list. This simple implementation does not attempt to completely
fill the buffer in every kunit_log_frag.
The 'log' member of kunit_suite, kunit_test_case and kunit_suite must be a
pointer because the API of kunit_log() requires that is the same type in
all three structs. As kunit.log is a pointer to the 'log' of the current
kunit_case, it must be a pointer in the other two structs.
The existing kunit-test.c log tests have been updated to build against the
new fragmented log implementation.
Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
---
Looks good to me.
A few small notes inline below, mostly around the possibility of
either embedding the list_head in the kunit_case struct directly
(rather than using a pointer), or of pointing directly to the first
fragment, rather than a separately-allocated struct list_head. Neither
are showstoppers, though (and if it increases complexity at all, it's
possibly premature optimization).
Otherwise, some test nitpicks and the fact that this will need a
trivial rebase due to the module filtering stuff landing in
kselftest/kunit.
Reviewed-by: David Gow <davidgow@xxxxxxxxxx>
static void kunit_log_newline_test(struct kunit *test)
{
+ struct kunit_log_frag *frag;
+
kunit_info(test, "Add newline\n");
if (test->log) {
- KUNIT_ASSERT_NOT_NULL_MSG(test, strstr(test->log, "Add newline\n"),
- "Missing log line, full log:\n%s", test->log);
- KUNIT_EXPECT_NULL(test, strstr(test->log, "Add newline\n\n"));
+ frag = list_first_entry(test->log, struct kunit_log_frag, list);
+ KUNIT_ASSERT_NOT_NULL_MSG(test, strstr(frag->buf, "Add newline\n"),
+ "Missing log line, full log:\n%s", frag->buf);
I'm not super thrilled that this only operates on the first fragment.
Could we at least note that this is not the "full log" in the
assertion message here, and maybe also assert that the log hasn't
grown to a second fragment?
Yes, I had the same thought but decided to leave it as something that
I was going to wonder whether or not we should cache the length of the
current fragment somewhere, but thinking about it, it's probably not
worth it given we're only measuring a single fragment, and it's capped
at 256 bytes.