The powerpc suite and its pmu subdirectory install and list their tests
in shell loops whose status is that of the last subdirectory, so a
failure in any other subdirectory is lost and FORCE_TARGETS has no
effect on them.

Make the installation and runlist loops fail only when no subdirectory
succeeds, which matches how the top-level selftests Makefile treats its
targets, and stop at the first failure when FORCE_TARGETS is set. When a
build report is requested, record each subdirectory as powerpc/<subdir>
or powerpc/pmu/<subdir>, including the builds of the subdirectories, so
that a failure is visible even when make itself succeeds.

The subdirectories are still built as prerequisites of "all", so a
subdirectory that fails to build still fails the build of the suite as
before; only the reporting of that failure is added.

Fixes: 6faeeea44b84 ("selftests: Add install support for the powerpc tests")
Fixes: 822a04957cc5 ("selftests/powerpc: Convert pmu Makefile to for loop 
style")
Signed-off-by: Sasha Levin <[email protected]>
---
 tools/testing/selftests/powerpc/Makefile     | 20 +++++++++++++++-----
 tools/testing/selftests/powerpc/pmu/Makefile | 20 +++++++++++++++-----
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/powerpc/Makefile 
b/tools/testing/selftests/powerpc/Makefile
index b175e94e1901d..8349196c934d5 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -37,9 +37,11 @@ endif
 all: $(SUB_DIRS)
 
 $(SUB_DIRS):
-       BUILD_TARGET=$(OUTPUT)/$@; mkdir -p $$BUILD_TARGET; $(MAKE) 
OUTPUT=$$BUILD_TARGET -k -C $@ all
+       BUILD_TARGET=$(OUTPUT)/$@; mkdir -p $$BUILD_TARGET && $(MAKE) 
OUTPUT=$$BUILD_TARGET -k -C $@ all; \
+       status=$$?; $(call ksft_record_build_status,all,powerpc/$@); exit 
$$status
 
 include ../lib.mk
+include $(selfdir)/build_report.mk
 include ./flags.mk
 
 override define RUN_TESTS
@@ -50,17 +52,25 @@ override define RUN_TESTS
 endef
 
 override define INSTALL_RULE
-       +@for TARGET in $(SUB_DIRS); do \
+       +@ret=$(if $(SUB_DIRS),1,0); for TARGET in $(SUB_DIRS); do \
                BUILD_TARGET=$(OUTPUT)/$$TARGET;        \
                $(MAKE) OUTPUT=$$BUILD_TARGET 
INSTALL_PATH=$$INSTALL_PATH/$$TARGET -C $$TARGET install;\
-       done;
+               status=$$?;                             \
+               $(call ksft_record_build_status,install,powerpc/$$TARGET); \
+               $(if $(FORCE_TARGETS),[ $$status -eq 0 ] || exit $$status;) \
+               [ $$status -eq 0 ] && ret=0;            \
+       done; exit $$ret
 endef
 
 emit_tests:
-       +@for TARGET in $(SUB_DIRS); do \
+       +@ret=$(if $(SUB_DIRS),1,0); for TARGET in $(SUB_DIRS); do \
                BUILD_TARGET=$(OUTPUT)/$$TARGET;        \
                $(MAKE) OUTPUT=$$BUILD_TARGET COLLECTION=$(COLLECTION)/$$TARGET 
-s -C $$TARGET $@;\
-       done;
+               status=$$?;                             \
+               $(call ksft_record_build_status,install,powerpc/$$TARGET); \
+               $(if $(FORCE_TARGETS),[ $$status -eq 0 ] || exit $$status;) \
+               [ $$status -eq 0 ] && ret=0;            \
+       done; exit $$ret
 
 override define CLEAN
        +@for TARGET in $(SUB_DIRS); do \
diff --git a/tools/testing/selftests/powerpc/pmu/Makefile 
b/tools/testing/selftests/powerpc/pmu/Makefile
index 7e9dbf3d0d092..7b3ef1decbfbb 100644
--- a/tools/testing/selftests/powerpc/pmu/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -7,6 +7,7 @@ EXTRA_SOURCES := ../harness.c event.c lib.c ../utils.c
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include $(selfdir)/build_report.mk
 include ../flags.mk
 
 SUB_DIRS := ebb sampling_tests event_code_tests
@@ -26,7 +27,8 @@ $(OUTPUT)/count_stcx_fail: loop.S $(EXTRA_SOURCES)
 $(OUTPUT)/per_event_excludes: ../utils.c
 
 $(SUB_DIRS):
-       BUILD_TARGET=$(OUTPUT)/$@; mkdir -p $$BUILD_TARGET; $(MAKE) 
OUTPUT=$$BUILD_TARGET -k -C $@ all
+       BUILD_TARGET=$(OUTPUT)/$@; mkdir -p $$BUILD_TARGET && $(MAKE) 
OUTPUT=$$BUILD_TARGET -k -C $@ all; \
+       status=$$?; $(call ksft_record_build_status,all,powerpc/pmu/$@); exit 
$$status
 
 DEFAULT_RUN_TESTS := $(RUN_TESTS)
 override define RUN_TESTS
@@ -42,18 +44,26 @@ emit_tests:
                BASENAME_TEST=`basename $$TEST`;        \
                echo "$(COLLECTION):$$BASENAME_TEST";   \
        done
-       +@for TARGET in $(SUB_DIRS); do \
+       +@ret=$(if $(SUB_DIRS),1,0); for TARGET in $(SUB_DIRS); do \
                BUILD_TARGET=$(OUTPUT)/$$TARGET; \
                $(MAKE) OUTPUT=$$BUILD_TARGET COLLECTION=$(COLLECTION)/$$TARGET 
-s -C $$TARGET emit_tests; \
-       done;
+               status=$$?; \
+               $(call ksft_record_build_status,install,powerpc/pmu/$$TARGET); \
+               $(if $(FORCE_TARGETS),[ $$status -eq 0 ] || exit $$status;) \
+               [ $$status -eq 0 ] && ret=0; \
+       done; exit $$ret
 
 DEFAULT_INSTALL_RULE := $(INSTALL_RULE)
 override define INSTALL_RULE
        $(DEFAULT_INSTALL_RULE)
-       +@for TARGET in $(SUB_DIRS); do \
+       +@ret=$(if $(SUB_DIRS),1,0); for TARGET in $(SUB_DIRS); do \
                BUILD_TARGET=$(OUTPUT)/$$TARGET; \
                $(MAKE) OUTPUT=$$BUILD_TARGET 
INSTALL_PATH=$$INSTALL_PATH/$$TARGET -C $$TARGET install; \
-       done;
+               status=$$?; \
+               $(call ksft_record_build_status,install,powerpc/pmu/$$TARGET); \
+               $(if $(FORCE_TARGETS),[ $$status -eq 0 ] || exit $$status;) \
+               [ $$status -eq 0 ] && ret=0; \
+       done; exit $$ret
 endef
 
 DEFAULT_CLEAN := $(CLEAN)
-- 
2.53.0


Reply via email to