From c80b5a0a22b673d5a02e64626a8dfc2f738be7d9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 21 Oct 2022 08:03:40 +0200 Subject: [PATCH 1/2] selftests/nolibc: Add 7 tests for memcmp() This adds 7 combinations of input values for memcmp() using signed and unsigned bytes, which will trigger on the original code before Rasmus' fix. This is mostly aimed at helping backporters verify their work, and showing how tests for corner cases can be added to the selftests suite. Before the fix it reports: 12 memcmp_20_20 = 0 [OK] 13 memcmp_20_60 = -64 [OK] 14 memcmp_60_20 = 64 [OK] 15 memcmp_20_e0 = 64 [FAIL] 16 memcmp_e0_20 = -64 [FAIL] 17 memcmp_80_e0 = -96 [OK] 18 memcmp_e0_80 = 96 [OK] And after: 12 memcmp_20_20 = 0 [OK] 13 memcmp_20_60 = -64 [OK] 14 memcmp_60_20 = 64 [OK] 15 memcmp_20_e0 = -192 [OK] 16 memcmp_e0_20 = 192 [OK] 17 memcmp_80_e0 = -96 [OK] 18 memcmp_e0_80 = 96 [OK] Cc: Rasmus Villemoes Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/nolibc-test.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 78bced95ac63..f14f5076fb6d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -565,6 +565,13 @@ int run_stdlib(int min, int max) CASE_TEST(strchr_foobar_z); EXPECT_STRZR(1, strchr("foobar", 'z')); break; CASE_TEST(strrchr_foobar_o); EXPECT_STREQ(1, strrchr("foobar", 'o'), "obar"); break; CASE_TEST(strrchr_foobar_z); EXPECT_STRZR(1, strrchr("foobar", 'z')); break; + CASE_TEST(memcmp_20_20); EXPECT_EQ(1, memcmp("aaa\x20", "aaa\x20", 4), 0); break; + CASE_TEST(memcmp_20_60); EXPECT_LT(1, memcmp("aaa\x20", "aaa\x60", 4), 0); break; + CASE_TEST(memcmp_60_20); EXPECT_GT(1, memcmp("aaa\x60", "aaa\x20", 4), 0); break; + CASE_TEST(memcmp_20_e0); EXPECT_LT(1, memcmp("aaa\x20", "aaa\xe0", 4), 0); break; + CASE_TEST(memcmp_e0_20); EXPECT_GT(1, memcmp("aaa\xe0", "aaa\x20", 4), 0); break; + CASE_TEST(memcmp_80_e0); EXPECT_LT(1, memcmp("aaa\x80", "aaa\xe0", 4), 0); break; + CASE_TEST(memcmp_e0_80); EXPECT_GT(1, memcmp("aaa\xe0", "aaa\x80", 4), 0); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ From 4a95be7ed7669311350d041ca6cd37bf96f92d8c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 26 Oct 2022 07:45:08 +0200 Subject: [PATCH 2/2] selftests/nolibc: Always rebuild the sysroot when running a test Paul and I got trapped a few times by not seeing the effects of applying a patch to the nolibc source code until a "make clean" was issued in the nolibc directory. It's particularly annoying when trying to confirm that a proposed patch really solves a problem (or that reverting it reintroduces the problem). The reason for the sysroot not being rebuilt was that it can be quite slow. But in fact it's only slow after a "make clean" issued at the kernel's topdir, because it's the main "make headers" that can take a tens of seconds; as long as "usr/include" still contains headers, the "headers_install" phase is only a quick "rsync", and rebuilding the whole nolibc sysroot takes a bit less than one second, which is perfectly acceptable for a test, even more once the time lost caused by misleading results is factored in. This patch marks the sysroot target as phony and starts by clearing the previous sysroot for the current architecture before reinstalling it. Thanks to this, applying a patch to nolibc makes the effect immediately visible to "make nolibc-test": $ time make -j -C tools/testing/selftests/nolibc nolibc-test make: Entering directory '/k/tools/testing/selftests/nolibc' MKDIR sysroot/x86/include make[1]: Entering directory '/k/tools/include/nolibc' make[2]: Entering directory '/k' make[2]: Leaving directory '/k' make[2]: Entering directory '/k' INSTALL /k/tools/testing/selftests/nolibc/sysroot/sysroot/include make[2]: Leaving directory '/k' make[1]: Leaving directory '/k/tools/include/nolibc' CC nolibc-test make: Leaving directory '/k/tools/testing/selftests/nolibc' real 0m0.869s user 0m0.716s sys 0m0.149s Cc: "Paul E. McKenney" Link: https://lore.kernel.org/all/20221021155645.GK5600@paulmck-ThinkPad-P17-Gen-1/ Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney --- tools/testing/selftests/nolibc/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 69ea659caca9..22f1e1d73fa8 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -95,6 +95,7 @@ all: run sysroot: sysroot/$(ARCH)/include sysroot/$(ARCH)/include: + $(Q)rm -rf sysroot/$(ARCH) sysroot/sysroot $(QUIET_MKDIR)mkdir -p sysroot $(Q)$(MAKE) -C ../../../include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone $(Q)mv sysroot/sysroot sysroot/$(ARCH) @@ -133,3 +134,5 @@ clean: $(Q)rm -rf initramfs $(call QUIET_CLEAN, run.out) $(Q)rm -rf run.out + +.PHONY: sysroot/$(ARCH)/include