Skip to content

Commit d5ca590

Browse files
anakryikoborkmann
authored andcommitted
selftests/bpf: Fix silent Makefile output
99aaceb ("selftests: do not use .ONESHELL") removed .ONESHELL, which changes how Makefile "silences" multi-command target recipes. selftests/bpf's Makefile relied (a somewhat unknowingly) on .ONESHELL behavior of silencing all commands within the recipe if the first command contains @ symbol. Removing .ONESHELL exposed this hack. This patch fixes the issue by explicitly silencing each command with $(Q). Also explicitly define fallback rule for building *.o from *.c, instead of relying on non-silent inherited rule. This was causing a non-silent output for bench.o object file. Fixes: 92f7440 ("selftests/bpf: More succinct Makefile output") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 7fb20f9 commit d5ca590

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ endif
102102
OVERRIDE_TARGETS := 1
103103
override define CLEAN
104104
$(call msg,CLEAN)
105-
$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
105+
$(Q)$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
106106
endef
107107

108108
include ../lib.mk
@@ -123,17 +123,21 @@ $(notdir $(TEST_GEN_PROGS) \
123123
$(TEST_GEN_PROGS_EXTENDED) \
124124
$(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ;
125125

126+
$(OUTPUT)/%.o: %.c
127+
$(call msg,CC,,$@)
128+
$(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
129+
126130
$(OUTPUT)/%:%.c
127131
$(call msg,BINARY,,$@)
128-
$(LINK.c) $^ $(LDLIBS) -o $@
132+
$(Q)$(LINK.c) $^ $(LDLIBS) -o $@
129133

130134
$(OUTPUT)/urandom_read: urandom_read.c
131135
$(call msg,BINARY,,$@)
132-
$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) -Wl,--build-id
136+
$(Q)$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) -Wl,--build-id
133137

134138
$(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
135139
$(call msg,CC,,$@)
136-
$(CC) -c $(CFLAGS) -o $@ $<
140+
$(Q)$(CC) -c $(CFLAGS) -o $@ $<
137141

138142
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
139143
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
@@ -181,15 +185,15 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
181185

182186
$(BUILD_DIR)/libbpf $(BUILD_DIR)/bpftool $(BUILD_DIR)/resolve_btfids $(INCLUDE_DIR):
183187
$(call msg,MKDIR,,$@)
184-
mkdir -p $@
188+
$(Q)mkdir -p $@
185189

186190
$(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) | $(BPFTOOL) $(INCLUDE_DIR)
187191
ifeq ($(VMLINUX_H),)
188192
$(call msg,GEN,,$@)
189-
$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
193+
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
190194
else
191195
$(call msg,CP,,$@)
192-
cp "$(VMLINUX_H)" $@
196+
$(Q)cp "$(VMLINUX_H)" $@
193197
endif
194198

195199
$(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids \
@@ -238,28 +242,28 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
238242
# $4 - LDFLAGS
239243
define CLANG_BPF_BUILD_RULE
240244
$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
241-
($(CLANG) $3 -O2 -target bpf -emit-llvm \
245+
$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \
242246
-c $1 -o - || echo "BPF obj compilation failed") | \
243247
$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
244248
endef
245249
# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
246250
define CLANG_NOALU32_BPF_BUILD_RULE
247251
$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
248-
($(CLANG) $3 -O2 -target bpf -emit-llvm \
252+
$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \
249253
-c $1 -o - || echo "BPF obj compilation failed") | \
250254
$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
251255
endef
252256
# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
253257
define CLANG_NATIVE_BPF_BUILD_RULE
254258
$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
255-
($(CLANG) $3 -O2 -emit-llvm \
259+
$(Q)($(CLANG) $3 -O2 -emit-llvm \
256260
-c $1 -o - || echo "BPF obj compilation failed") | \
257261
$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
258262
endef
259263
# Build BPF object using GCC
260264
define GCC_BPF_BUILD_RULE
261265
$(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
262-
$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
266+
$(Q)$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
263267
endef
264268

265269
SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
@@ -301,7 +305,7 @@ ifeq ($($(TRUNNER_OUTPUT)-dir),)
301305
$(TRUNNER_OUTPUT)-dir := y
302306
$(TRUNNER_OUTPUT):
303307
$$(call msg,MKDIR,,$$@)
304-
mkdir -p $$@
308+
$(Q)mkdir -p $$@
305309
endif
306310

307311
# ensure we set up BPF objects generation rule just once for a given
@@ -321,7 +325,7 @@ $(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h: \
321325
$(TRUNNER_OUTPUT)/%.o \
322326
| $(BPFTOOL) $(TRUNNER_OUTPUT)
323327
$$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
324-
$$(BPFTOOL) gen skeleton $$< > $$@
328+
$(Q)$$(BPFTOOL) gen skeleton $$< > $$@
325329
endif
326330

327331
# ensure we set up tests.h header generation rule just once
@@ -345,30 +349,30 @@ $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
345349
$(TRUNNER_BPF_SKELS) \
346350
$$(BPFOBJ) | $(TRUNNER_OUTPUT)
347351
$$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
348-
cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
352+
$(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
349353

350354
$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
351355
%.c \
352356
$(TRUNNER_EXTRA_HDRS) \
353357
$(TRUNNER_TESTS_HDR) \
354358
$$(BPFOBJ) | $(TRUNNER_OUTPUT)
355359
$$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
356-
$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
360+
$(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
357361

358362
# only copy extra resources if in flavored build
359363
$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
360364
ifneq ($2,)
361365
$$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
362-
cp -a $$^ $(TRUNNER_OUTPUT)/
366+
$(Q)cp -a $$^ $(TRUNNER_OUTPUT)/
363367
endif
364368

365369
$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
366370
$(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
367371
$(RESOLVE_BTFIDS) \
368372
| $(TRUNNER_BINARY)-extras
369373
$$(call msg,BINARY,,$$@)
370-
$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
371-
$(RESOLVE_BTFIDS) --no-fail --btf btf_data.o $$@
374+
$(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
375+
$(Q)$(RESOLVE_BTFIDS) --no-fail --btf btf_data.o $$@
372376

373377
endef
374378

@@ -421,17 +425,17 @@ verifier/tests.h: verifier/*.c
421425
) > verifier/tests.h)
422426
$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
423427
$(call msg,BINARY,,$@)
424-
$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
428+
$(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
425429

426430
# Make sure we are able to include and link libbpf against c++.
427431
$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
428432
$(call msg,CXX,,$@)
429-
$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@
433+
$(Q)$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@
430434

431435
# Benchmark runner
432436
$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
433437
$(call msg,CC,,$@)
434-
$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
438+
$(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
435439
$(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
436440
$(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
437441
$(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \
@@ -444,7 +448,7 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
444448
$(OUTPUT)/bench_trigger.o \
445449
$(OUTPUT)/bench_ringbufs.o
446450
$(call msg,BINARY,,$@)
447-
$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
451+
$(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
448452

449453
EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) \
450454
prog_tests/tests.h map_tests/tests.h verifier/tests.h \

0 commit comments

Comments
 (0)