mbox series

[v2,0/8] selftests: Move test output to diagnostic lines

Message ID 20190424231237.14776-1-keescook@chromium.org (mailing list archive)
Headers show
Series selftests: Move test output to diagnostic lines | expand

Message

Kees Cook April 24, 2019, 11:12 p.m. UTC
This refactors the selftest Makefiles to extract the test running logic
to be reused between "run_tests" and "emit_tests", while also fixing
up the test output to be TAP version 13 compliant:
- added "plan" line
- fixed result line syntax
- moved all test output to be "# "-prefixed as TAP "diagnostic" lines

The prefixing code includes a fallback mode for limited execution
environments.

Additionally, the plan lines are fixed for all callers of kselftest.h.

-Kees

v2:
- fix external make variable "summary=1" through-out series (shuah)
- fix plan line output for all kselftest.h users

Kees Cook (8):
  selftests: Extract single-test shell logic from lib.mk
  selftests: Use runner.sh for emit targets
  selftests: Extract logic for multiple test runs
  selftests: Add plan line and fix result line syntax
  selftests: Distinguish between missing and non-executable
  selftests: Move test output to diagnostic lines
  selftests: Remove KSFT_TAP_LEVEL
  selftests: Add test plan API to kselftest.h and adjust callers

 tools/testing/selftests/.gitignore            |  1 -
 tools/testing/selftests/Makefile              | 24 ++----
 .../selftests/breakpoints/breakpoint_test.c   | 15 +++-
 .../breakpoints/breakpoint_test_arm64.c       |  3 +-
 .../breakpoints/step_after_suspend_test.c     |  8 ++
 .../selftests/capabilities/test_execve.c      |  6 +-
 .../futex/functional/futex_requeue_pi.c       |  1 +
 .../futex_requeue_pi_mismatched_ops.c         |  1 +
 .../futex_requeue_pi_signal_restart.c         |  1 +
 .../futex_wait_private_mapped_file.c          |  1 +
 .../futex/functional/futex_wait_timeout.c     |  1 +
 .../futex_wait_uninitialized_heap.c           |  1 +
 .../futex/functional/futex_wait_wouldblock.c  |  1 +
 tools/testing/selftests/kselftest.h           | 17 +++-
 tools/testing/selftests/kselftest/prefix.pl   | 23 +++++
 tools/testing/selftests/kselftest/runner.sh   | 86 +++++++++++++++++++
 tools/testing/selftests/lib.mk                | 64 +++-----------
 .../selftests/membarrier/membarrier_test.c    |  1 +
 tools/testing/selftests/pidfd/pidfd_test.c    |  1 +
 tools/testing/selftests/sigaltstack/sas.c     |  1 +
 tools/testing/selftests/sync/sync_test.c      |  1 +
 21 files changed, 178 insertions(+), 80 deletions(-)
 create mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100644 tools/testing/selftests/kselftest/runner.sh

Comments

shuah April 25, 2019, 4:52 p.m. UTC | #1
On 4/24/19 5:12 PM,  wrote:
> This refactors the selftest Makefiles to extract the test running logic
> to be reused between "run_tests" and "emit_tests", while also fixing
> up the test output to be TAP version 13 compliant:
> - added "plan" line
> - fixed result line syntax
> - moved all test output to be "# "-prefixed as TAP "diagnostic" lines
> 
> The prefixing code includes a fallback mode for limited execution
> environments.
> 
> Additionally, the plan lines are fixed for all callers of kselftest.h.
> 
> -Kees
> 

Kees,

Just about to apply these to a topic branch to do testing and ran into
checkpatch errors:


WARNING: line over 80 characters - a few
WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
#141: FILE: tools/testing/selftests/kselftest/runner.sh:2:

Can fix them and resend - SPDX one is my main concern.

The plan is to apply these to linux-kselftest ksft-tap-refactor topic
first. I don't want to rush these until we do some testing.

thanks,
-- Shuah
Kees Cook April 25, 2019, 5:05 p.m. UTC | #2
On Thu, Apr 25, 2019 at 9:52 AM shuah <shuah@kernel.org> wrote:
>
> On 4/24/19 5:12 PM,  wrote:
> > This refactors the selftest Makefiles to extract the test running logic
> > to be reused between "run_tests" and "emit_tests", while also fixing
> > up the test output to be TAP version 13 compliant:
> > - added "plan" line
> > - fixed result line syntax
> > - moved all test output to be "# "-prefixed as TAP "diagnostic" lines
> >
> > The prefixing code includes a fallback mode for limited execution
> > environments.
> >
> > Additionally, the plan lines are fixed for all callers of kselftest.h.
> >
> > -Kees
> >
>
> Kees,
>
> Just about to apply these to a topic branch to do testing and ran into
> checkpatch errors:
>
>
> WARNING: line over 80 characters - a few

I only saw one, which is on a string which kernel coding style says to
leave unsplit:

WARNING: line over 80 characters
#55: FILE: tools/testing/selftests/kselftest/runner.sh:19:
+               echo "$TEST_HDR_MSG: Warning: file $TEST is not
executable, correct this."

> WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
> #141: FILE: tools/testing/selftests/kselftest/runner.sh:2:

WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
#37: FILE: tools/testing/selftests/kselftest/runner.sh:2:
 # SPDX-License-Identifier: GPL-2.0

This is a shell script. It can't be on line 1:

$ head -n3 tools/testing/selftests/kselftest/runner.sh
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#

That looks like a bug in checkpatch not resetting the expected line or
something.

> Can fix them and resend - SPDX one is my main concern.

These appear to be false positives; I don't think I need to fix them?
Let me know what you think.

> The plan is to apply these to linux-kselftest ksft-tap-refactor topic
> first. I don't want to rush these until we do some testing.

Absolutely. :)

Thanks!
Kees Cook April 25, 2019, 5:11 p.m. UTC | #3
On Thu, Apr 25, 2019 at 10:05 AM Kees Cook <keescook@chromium.org> wrote:
> WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
> #37: FILE: tools/testing/selftests/kselftest/runner.sh:2:
>  # SPDX-License-Identifier: GPL-2.0
>
> This is a shell script. It can't be on line 1:
>
> $ head -n3 tools/testing/selftests/kselftest/runner.sh
> #!/bin/sh
> # SPDX-License-Identifier: GPL-2.0
> #
>
> That looks like a bug in checkpatch not resetting the expected line or
> something.

It doesn't like patch 3 and doesn't notice that diff offset starts at line 2:

diff --git a/tools/testing/selftests/kselftest/runner.sh
b/tools/testing/selftests/kselftest/runner.sh
index e1117d703887..f12b0a631273 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -2,17 +2,20 @@
 # SPDX-License-Identifier: GPL-2.0
 #
 # Runs a set of tests in a given subdirectory.
+export KSFT_TAP_LEVEL=1

Joe, looks like the problem is here:

                if ($realline == $checklicenseline) {
realline == 2, checklicenseline == 1
so this is skipped, including the "#!/" check to move checklicenseline to 2.
then:
                if ($realline != $checklicenseline &&
                    $rawline =~ /\bSPDX-License-Identifier:/ &&
realline == 2, checklicenseline == 1
throws warning.

Seems like checklicenseline should be unconditionally set to 2 for
".sh" files? I don't see a way to fix this for just missing the #!/
line from a context diff, though...
shuah April 25, 2019, 8:39 p.m. UTC | #4
On 4/25/19 11:05 AM, Kees Cook wrote:
> On Thu, Apr 25, 2019 at 9:52 AM shuah <shuah@kernel.org> wrote:
>>
>> On 4/24/19 5:12 PM,  wrote:
>>> This refactors the selftest Makefiles to extract the test running logic
>>> to be reused between "run_tests" and "emit_tests", while also fixing
>>> up the test output to be TAP version 13 compliant:
>>> - added "plan" line
>>> - fixed result line syntax
>>> - moved all test output to be "# "-prefixed as TAP "diagnostic" lines
>>>
>>> The prefixing code includes a fallback mode for limited execution
>>> environments.
>>>
>>> Additionally, the plan lines are fixed for all callers of kselftest.h.
>>>
>>> -Kees
>>>
>>
>> Kees,
>>
>> Just about to apply these to a topic branch to do testing and ran into
>> checkpatch errors:
>>
>>
>> WARNING: line over 80 characters - a few
> 
> I only saw one, which is on a string which kernel coding style says to
> leave unsplit:
> 
> WARNING: line over 80 characters
> #55: FILE: tools/testing/selftests/kselftest/runner.sh:19:
> +               echo "$TEST_HDR_MSG: Warning: file $TEST is not
> executable, correct this."
> 
>> WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
>> #141: FILE: tools/testing/selftests/kselftest/runner.sh:2:
> 
> WARNING: Misplaced SPDX-License-Identifier tag - use line 1 instead
> #37: FILE: tools/testing/selftests/kselftest/runner.sh:2:
>   # SPDX-License-Identifier: GPL-2.0
> 
> This is a shell script. It can't be on line 1:
> 
> $ head -n3 tools/testing/selftests/kselftest/runner.sh
> #!/bin/sh
> # SPDX-License-Identifier: GPL-2.0
> #
> 
> That looks like a bug in checkpatch not resetting the expected line or
> something.
> 
>> Can fix them and resend - SPDX one is my main concern.
> 
> These appear to be false positives; I don't think I need to fix them?
> Let me know what you think.
> 
>> The plan is to apply these to linux-kselftest ksft-tap-refactor topic
>> first. I don't want to rush these until we do some testing.
> 
> Absolutely. :)
> 
> Thanks!
> 

Kees,

Pushed all 8 patches to 
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest 
ksft-tap-refactor topic branch

I will have time to test tomorrow.

thanks,
-- Shuah
Kees Cook April 25, 2019, 9:19 p.m. UTC | #5
On Thu, Apr 25, 2019 at 1:39 PM shuah <shuah@kernel.org> wrote:
> Pushed all 8 patches to
> https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
> ksft-tap-refactor topic branch
>
> I will have time to test tomorrow.

Awesome! I'm excited. :)

Next I want to update kselftest_harness.h to do header/plan printing...