From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: David Gow <davidgow@google.com>
Cc: <brendan.higgins@linux.dev>, <rmoar@google.com>,
<linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>,
<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>
Subject: Re: [PATCH v2 1/6] kunit: Replace fixed-size log with dynamically-extending buffer
Date: Wed, 9 Aug 2023 15:37:20 +0100 [thread overview]
Message-ID: <cdca5909-1484-ff07-3184-37d6b3463068@opensource.cirrus.com> (raw)
In-Reply-To: <CABVgOS=BrJ82v3_O9wGxTGoPRjH-rSWiTMS6+S=x4yPng_-XFA@mail.gmail.com>
On 9/8/23 13:11, David Gow wrote:
> On Tue, 8 Aug 2023 at 20:35, Richard Fitzgerald
> <rf@opensource.cirrus.com> 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@opensource.cirrus.com>
>> ---
>
> 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).
>
I did start out trying to use the first fragment as the list head.
Trouble with this is that the functions in list.h expect to have a
dummy list_head node that is only the head, but not an actual list
member. It's possible to workaround this but the shenanigans involved is
likely to trip someone up later so reverted to doing the list the way
the API intended.
For the pointers, I did consider embedding the list_head instead of
using a pointer. But then the struct kunit can't refer to the
kunit_case list, it can only take it over. There can only be one list
head because the ->prev and ->next pointers of the first and last
members in the list can only point to one head.
After playing around with it I decided that it wasn't worth trying to
avoid the pointers. At least... it wasn't worth spending a lot of time
trying to avoid them for an initial implementation.
Maybe some magic with typeof() in the kunit_log() would let us use
different types for the members of kunit_suite, kunit_case, kunit?
Then the list_head can be directly embedded in the first two but a
pointer in kunit?
> 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@google.com>
>
...
>> 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?
>
The only aim in this first patch is to make sure that kunit-test.c still
builds. I've added extra newline test cases in later patches.
...
>
> 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.
>
Yes, I had the same thought but decided to leave it as something that
can be done later. But as you say it's doubtful whether it's worth the
extra storage space when the buffer fragments are small. On x86_64
simply adding a length member could add 8 bytes per fragment (because of
rounding). If the size of the fragment buffer is capped at 256 we could
use single byte for the length and hope the compiler doesn't insert
padding between a char and a char[] array.
Take a look at what happens when you log a message to the kernel log and
by comparison this kunit logging is super-lightweight.
(I did look at whether we could re-use the existing kernel log
implementation but decided it was too heavily hardcoded to how the
kernel log works.)
next prev parent reply other threads:[~2023-08-09 14:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 12:35 [PATCH v2 0/6] kunit: Add dynamically-extending log Richard Fitzgerald
2023-08-08 12:35 ` [PATCH v2 1/6] kunit: Replace fixed-size log with dynamically-extending buffer Richard Fitzgerald
2023-08-09 12:11 ` David Gow
2023-08-09 14:37 ` Richard Fitzgerald [this message]
2023-08-08 12:35 ` [PATCH v2 2/6] kunit: kunit-test: Add test cases for extending log buffer Richard Fitzgerald
2023-08-08 21:16 ` Rae Moar
2023-08-09 9:39 ` Richard Fitzgerald
2023-08-09 12:11 ` David Gow
2023-08-09 12:14 ` Richard Fitzgerald
2023-08-08 12:35 ` [PATCH v2 3/6] kunit: Handle logging of lines longer than the fragment buffer size Richard Fitzgerald
2023-08-08 12:35 ` [PATCH v2 4/6] kunit: kunit-test: Add test cases for logging very long lines Richard Fitzgerald
2023-08-08 12:35 ` [PATCH v2 5/6] kunit: kunit-test: Add test of logging only a newline Richard Fitzgerald
2023-08-08 12:35 ` [PATCH v2 6/6] kunit: Don't waste first attempt to format string in kunit_log_append() Richard Fitzgerald
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cdca5909-1484-ff07-3184-37d6b3463068@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=brendan.higgins@linux.dev \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rmoar@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®