[PATCH v2 1/3] selftests: ublk: kublk: build with -Werror iff WERROR!=0

Uday Shankar posted 3 patches 9 months, 2 weeks ago
[PATCH v2 1/3] selftests: ublk: kublk: build with -Werror iff WERROR!=0
Posted by Uday Shankar 9 months, 2 weeks ago
Compiler warnings can catch bugs at compile time; thus, heeding them is
usually a good idea. Turn warnings into errors by default for the kublk
build so that anyone making changes is forced to heed them. Compiler
warnings can also sometimes produce annoying false positives, so provide
a flag WERROR that the developer can use as follows to have the build
and selftests run go through even if there are warnings:

make WERROR=0 TARGETS=ublk kselftest

Signed-off-by: Uday Shankar <ushankar@purestorage.com>
---
 tools/testing/selftests/ublk/Makefile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile
index ec4624a283bce2ebeed80509be6573c1b7a3623d..529ab98a2633a2278bc0df8b26500905d60d2bec 100644
--- a/tools/testing/selftests/ublk/Makefile
+++ b/tools/testing/selftests/ublk/Makefile
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0
 
 CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)
+ifneq ($(WERROR),0)
+	CFLAGS += -Werror
+endif
+
 LDLIBS += -lpthread -lm -luring
 
 TEST_PROGS := test_generic_01.sh

-- 
2.34.1
Re: [PATCH v2 1/3] selftests: ublk: kublk: build with -Werror iff WERROR!=0
Posted by Ming Lei 9 months, 2 weeks ago
On Tue, Apr 29, 2025 at 04:41:03PM -0600, Uday Shankar wrote:
> Compiler warnings can catch bugs at compile time; thus, heeding them is
> usually a good idea. Turn warnings into errors by default for the kublk
> build so that anyone making changes is forced to heed them. Compiler
> warnings can also sometimes produce annoying false positives, so provide
> a flag WERROR that the developer can use as follows to have the build
> and selftests run go through even if there are warnings:
> 
> make WERROR=0 TARGETS=ublk kselftest

I thought WERROR is 0 default, but actually the default value is 1.

Just tried gcc 14/15 and clang 18/20, looks everything works fine.

For kernel selftests, I guess the usual way is to do it explicitly
by passing 'make -C tools/testing/selftests TARGETS=ublk'.

Even though the build fails for people who is running the test on purpose,
or doling whole kernel selfests, they still can:

- report the failure

- skip ublk test by adding 'SKIP_TARGETS=ublk' to command line

Also this ways has been used by perf, lib/api, lib/subcmd and lib/sysmbol in
linux kernel tools/, so I feel the change should be doable, but let Jens decide
if it is fine to pass -Werror at default:

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Otherwise, it still can be enabled conditionally with default off.


Thanks,
Ming