selftests/nolibc: also count skipped and failed tests in output
authorWilly Tarreau <w@1wt.eu>
Sun, 4 Jun 2023 12:14:27 +0000 (14:14 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 9 Jun 2023 18:46:10 +0000 (11:46 -0700)
Right now skipped and failed test counts are not reported, and a few
times already we missed skipped ones that ought not to. Let's now
count each category and continue to invite the user to check the
report file when skipped+fail > 0. E.g:

  $ make run-user
    (...)
    CC      nolibc-test
  136 test(s) passed, 2 skipped, 0 failed. See all results in .../run.out

Note that it's important to be careful about the trailing \r on the qemu
output (thanks Zhangjin for noticing).

Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/testing/selftests/nolibc/Makefile

index 44088535682ed9f703ed5e2bad5105ff582e44dd..4a3a105e1fdf7e46e24738ceb2553eb5f59bf4a5 100644 (file)
@@ -130,7 +130,10 @@ libc-test: nolibc-test.c
 # qemu user-land test
 run-user: nolibc-test
        $(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || :
-       $(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR)/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed."
+       $(Q)awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/{s++} \
+                END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f); \
+                if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
+                $(CURDIR)/run.out
 
 initramfs: nolibc-test
        $(QUIET_MKDIR)mkdir -p initramfs
@@ -146,12 +149,18 @@ kernel: initramfs
 # run the tests after building the kernel
 run: kernel
        $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
-       $(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR)/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed."
+       $(Q)awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/{s++} \
+                END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f); \
+                if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
+                $(CURDIR)/run.out
 
 # re-run the tests from an existing kernel
 rerun:
        $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
-       $(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR)/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed."
+       $(Q)awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{f++} /\[SKIPPED\][\r]*$$/{s++} \
+                END{ printf("%d test(s) passed, %d skipped, %d failed.", p, s, f); \
+                if (s+f > 0) printf(" See all results in %s\n", ARGV[1]); else print; }' \
+                $(CURDIR)/run.out
 
 clean:
        $(call QUIET_CLEAN, sysroot)