Re: [PATCH 1/2] selftests/lkdtm: Don't clear dmesg when running tests

From: Joe Lawrence
Date: Wed Jun 24 2020 - 16:13:16 EST


On Wed, Jun 24, 2020 at 10:39:55AM +0200, Petr Mladek wrote:
> On Tue 2020-06-23 23:48:36, Joe Lawrence wrote:
> > On 6/22/20 4:51 AM, Naresh Kamboju wrote:
> > > On Fri, 8 May 2020 at 12:23, Michael Ellerman <mpe@xxxxxxxxxxxxxx> wrote:
> > > >
> > > > It is Very Rude to clear dmesg in test scripts. That's because the
> > > > script may be part of a larger test run, and clearing dmesg
> > > > potentially destroys the output of other tests.
> > > >
> > > > We can avoid using dmesg -c by saving the content of dmesg before the
> > > > test, and then using diff to compare that to the dmesg afterward,
> > > > producing a log with just the added lines.
> > > >
> > > > > > > diff --git a/tools/testing/selftests/lkdtm/run.sh b/tools/testing/selftests/lkdtm/run.sh
> > > > index dadf819148a4..0b409e187c7b 100755
> > > > --- a/tools/testing/selftests/lkdtm/run.sh
> > > > +++ b/tools/testing/selftests/lkdtm/run.sh
> > > > # Record and dump the results
> > > > -dmesg -c >"$LOG"
> > > > +dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$DMESG" - > "$LOG" || true
> > >
> > > We are facing problems with the diff `=%>` part of the option.
> > > This report is from the OpenEmbedded environment.
> > > We have the same problem from livepatch_testcases.
> > >
> > > # selftests lkdtm BUG.sh
> > > lkdtm: BUG.sh_ #
> > > # diff unrecognized option '--changed-group-format=%>'
> > > unrecognized: option_'--changed-group-format=%>' #
> > > # BusyBox v1.27.2 (2020-03-30 164108 UTC) multi-call binary.
> > > v1.27.2: (2020-03-30_164108 #
> > > #
> > > : _ #
> > > # Usage diff [-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2
> > > diff: [-abBdiNqrTstw]_[-L #
> > > # BUG missing 'kernel BUG at' [FAIL]
> > >
> > > Full test output log,
> > > https://qa-reports.linaro.org/lkft/linux-next-oe/build/next-20200621/testrun/2850083/suite/kselftest/test/lkdtm_BUG.sh/log
> > >
> >
> > D'oh! Using diff's changed/unchanged group format was a nice trick to
> > easily fetch the new kernel log messages.
> >
> > I can't think of any simple alternative off the top of my head, so here's a
> > kludgy tested-once awk script:
> >
> > SAVED_DMESG="$(dmesg | tail -n1)"
> > ... tests ...
> > NEW_DMESG=$(dmesg | awk -v last="$SAVED_DMESG" 'p; $0 == last{p=1}')
> >
> > I think timestamps should make each log line unique, but this probably won't
> > handle kernel log buffer overflow.
>
> The test would fail anyway if there was log buffer overflow.
>
> We could check if the last line was still there and
> suggest to increase the log buffer size in the error message.
>

Hi Petr,

This is a good suggestion and I've worked it into the awk script I
wrote last night, check it out at the bottom ...

> > Maybe it would be easier to log a known unique test delimiter msg and then
> > fetch all new messages after that?
>
> The timestamp should be enough to distinguish any message.
>
> But some visual separator between each test is useful anyway. And
> it might include some random string...
>

Ah yeah, you're right about those timestamps again. :)

As for separators, we've already added the "===== TEST: foo =====" for
the livepatch ones... so I think with the timestamp prefix, we're good
enough, no?


I did a bit more hacking to work that awk script into the livepatching
tests. The changes aren't too bad and coding it ourselves lets us drop
the temporary dmesg file business. If this looks good, I can send out
as a real patch, but then that raises a few questions:

1 - f131d9edc29d ("selftests/lkdtm: Don't clear dmesg when running
tests") has already merged, updating that file doesn't look too
difficult, but will need a Fixes tag and should probably go
through Shuah's tree.

2 - We haven't actually merged the livepatch copy yet. I can roll
another version of that patchset, substituting a fix for the
problematic patch, or we could just tack this one on at the end.
In fine with either approach.

-- Joe

-->8-- -->8-- -->8-- -->8-- -->8-- -->8-- -->8-- -->8-- -->8-- -->8--