Individual test files may fail to compile when headers or kernel features
required by that test are absent. Currently this aborts the entire build.

Make the per-test compilation non-fatal in permissive mode: remove the
output object on failure and print a SKIP-TEST marker to stderr. Guard the
BTFIDS post-processing step so it is skipped when the object file is
absent. The linker step will later ignore absent objects, allowing the
remaining tests to build and run.

Use plain printf and $(Q) instead of $(call msg,...) in the BTFIDS block:
the msg macro expands to @printf, which is a make-recipe construct and is
invalid as a shell command inside an if-then-fi body; $(Q) restores echo
suppression at the recipe level where it is meaningful.

Note on bisectability: this change is gated entirely behind PERMISSIVE, so
default builds (BPF_STRICT_BUILD!=0) compile and run identically at every
commit. In PERMISSIVE mode, this commit alone is incomplete: the linker
still rejects missing objects and the runtime still aborts on NULL function
pointers; those issues are addressed by the two commits that follow in this
series.

Signed-off-by: Ricardo B. Marlière <[email protected]>
---
 tools/testing/selftests/bpf/Makefile | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile 
b/tools/testing/selftests/bpf/Makefile
index 608e6dff0392..f0545ee6b32a 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -717,11 +717,14 @@ $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o:         
        \
                      $(TRUNNER_TESTS_DIR)/%.c                          \
                      | $(TRUNNER_OUTPUT)/%.test.d
        $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
-       $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -MMD -MT $$@ -c $(CURDIR)/$$< 
$$(LDLIBS) -o $$(@F)
+       $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -MMD -MT $$@ -c $(CURDIR)/$$< 
$$(LDLIBS) -o $$(@F) $(if $(PERMISSIVE),|| \
+               ($(RM) $$(@F); printf '  %-12s %s\n' 'SKIP-TEST' '$$(notdir 
$$@)' 1>&2))
        $$(if $$(TEST_NEEDS_BTFIDS),                                            
\
-               $$(call msg,BTFIDS,$(TRUNNER_BINARY),$$@)                       
\
+               $(Q)if [ -f $$@ ]; then                                         
\
+               printf '  %-8s%s %s\n' "BTFIDS" " [$(TRUNNER_BINARY)]" 
"$$(notdir $$@)"; \
                $(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@;   
\
-               $(RESOLVE_BTFIDS) --patch_btfids [email protected]_ids $$@)
+               $(RESOLVE_BTFIDS) --patch_btfids [email protected]_ids $$@;               
\
+               fi)
 
 $(TRUNNER_TEST_OBJS:.o=.d): $(TRUNNER_OUTPUT)/%.test.d:                        
\
                            $(TRUNNER_TESTS_DIR)/%.c                    \

-- 
2.54.0


Reply via email to