Message ID | 20250428-ublk_selftests-v1-1-5795f7b00cda@purestorage.com |
---|---|
State | New |
Headers | show |
Series | [1/3] selftests: ublk: kublk: build with -Werror iff CONFIG_WERROR=y | expand |
On Tue, Apr 29, 2025 at 09:11:05AM +0800, Ming Lei wrote: > On Mon, Apr 28, 2025 at 05:10:20PM -0600, Uday Shankar wrote: > > Compiler warnings can catch bugs at compile time. They can also produce > > annoying false positives. Due to this duality, the kernel provides > > CONFIG_WERROR so that the developer can choose whether or not they want > > compiler warnings to fail the build. Use this same config options to > > control whether or not warnings in building kublk fail its build. > > > > Signed-off-by: Uday Shankar <ushankar@purestorage.com> > > --- > > tools/testing/selftests/ublk/Makefile | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile > > index ec4624a283bce2ebeed80509be6573c1b7a3623d..86474cfe8d03b2df3f8c9bc1a5902701a0f72f58 100644 > > --- a/tools/testing/selftests/ublk/Makefile > > +++ b/tools/testing/selftests/ublk/Makefile > > @@ -1,6 +1,8 @@ > > # SPDX-License-Identifier: GPL-2.0 > > > > -CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir) > > +CONFIG = $(top_srcdir)/include/config/auto.conf > > +WERROR = $(if $(shell grep CONFIG_WERROR=y ${CONFIG}),-Werror,) > > +CFLAGS += -O3 -Wl,-no-as-needed -Wall ${WERROR} -I $(top_srcdir) > > LDLIBS += -lpthread -lm -luring > > I think it isn't good to reuse kernel CONFIG_WERROR for test code. > > But it can be done in the following way by passing 'WERROR=1' to make > command line: > > +ifneq ($(WERROR),0) > + CFLAGS += -Werror > +endif I've taken this approach in [1]. It actually passes -Werror by default, but it gives the developer a way to disable it with make WERROR=0 TARGETS=ublk kselftest [1] https://lore.kernel.org/linux-block/20250429-ublk_selftests-v2-1-e970b6d9e4f4@purestorage.com/
diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile index ec4624a283bce2ebeed80509be6573c1b7a3623d..86474cfe8d03b2df3f8c9bc1a5902701a0f72f58 100644 --- a/tools/testing/selftests/ublk/Makefile +++ b/tools/testing/selftests/ublk/Makefile @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir) +CONFIG = $(top_srcdir)/include/config/auto.conf +WERROR = $(if $(shell grep CONFIG_WERROR=y ${CONFIG}),-Werror,) +CFLAGS += -O3 -Wl,-no-as-needed -Wall ${WERROR} -I $(top_srcdir) LDLIBS += -lpthread -lm -luring TEST_PROGS := test_generic_01.sh
Compiler warnings can catch bugs at compile time. They can also produce annoying false positives. Due to this duality, the kernel provides CONFIG_WERROR so that the developer can choose whether or not they want compiler warnings to fail the build. Use this same config options to control whether or not warnings in building kublk fail its build. Signed-off-by: Uday Shankar <ushankar@purestorage.com> --- tools/testing/selftests/ublk/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)