The sparc64 suite builds and installs its subdirectories in shell loops
whose status is that of the last command. For the build that is the
copy of the subdirectory's test script, so "make all" succeeds even
when the drivers tests fail to compile, and FORCE_TARGETS has no effect.

Fold the copy into the status of the subdirectory and let both loops
return failure when no subdirectory succeeds, which matches how the
top-level selftests Makefile treats its targets, or as soon as one fails
when FORCE_TARGETS is set. When a build report is requested, record
each subdirectory as sparc64/<subdir>. Invoke the subdirectories with
$(MAKE) so that they use the parent's jobserver.

Fixes: 3c545084130c ("selftests: sparc64: char: Selftest for privileged ADI 
driver")
Signed-off-by: Sasha Levin <[email protected]>
---
 tools/testing/selftests/sparc64/Makefile | 33 ++++++++++++++++--------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/sparc64/Makefile 
b/tools/testing/selftests/sparc64/Makefile
index 88f7be76f962d..a979c819348a0 100644
--- a/tools/testing/selftests/sparc64/Makefile
+++ b/tools/testing/selftests/sparc64/Makefile
@@ -2,6 +2,8 @@
 ARCH ?= $(shell uname -m 2>/dev/null || echo not)
 override ARCH := $(shell echo $(ARCH) | sed -e s/x86_64/x86/)
 
+include ../build_report.mk
+
 ifneq ($(ARCH),sparc64)
 nothing:
 .PHONY: all clean run_tests install
@@ -18,33 +20,42 @@ TEST_PROGS := run.sh
 include ../lib.mk
 
 all:
-       @for DIR in $(SUBDIRS); do              \
-               BUILD_TARGET=$(OUTPUT)/$$DIR;   \
-               mkdir $$BUILD_TARGET  -p;       \
-               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
+       @ret=$(if $(SUBDIRS),1,0); for DIR in $(SUBDIRS); do    \
+               BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
+               mkdir -p $$BUILD_TARGET &&                      \
+               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$DIR $@;      \
+               status=$$?;                                     \
                #SUBDIR test prog name should be in the form: SUBDIR_test.sh \
                TEST=$$DIR"_test.sh"; \
                if [ -e $$DIR/$$TEST ]; then \
-                       rsync -a $$DIR/$$TEST $$BUILD_TARGET/; \
-               fi \
-       done
+                       rsync -a $$DIR/$$TEST $$BUILD_TARGET/ || \
+                               [ $$status -ne 0 ] || status=1; \
+               fi; \
+               $(call ksft_record_build_status,all,sparc64/$$DIR); \
+               $(if $(FORCE_TARGETS),[ $$status -eq 0 ] || exit $$status;) \
+               [ $$status -eq 0 ] && ret=0;                    \
+       done; exit $$ret
 
 override define INSTALL_RULE
        mkdir -p $(INSTALL_PATH)
        install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) 
$(TEST_FILES)
 
-       @for SUBDIR in $(SUBDIRS); do \
+       @ret=$(if $(SUBDIRS),1,0); for SUBDIR in $(SUBDIRS); do \
                BUILD_TARGET=$(OUTPUT)/$$SUBDIR;        \
-               mkdir $$BUILD_TARGET  -p;       \
+               mkdir -p $$BUILD_TARGET &&              \
                $(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR 
INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
-       done;
+               status=$$?;                             \
+               $(call ksft_record_build_status,install,sparc64/$$SUBDIR); \
+               $(if $(FORCE_TARGETS),[ $$status -eq 0 ] || exit $$status;) \
+               [ $$status -eq 0 ] && ret=0;            \
+       done; exit $$ret
 endef
 
 override define CLEAN
        @for DIR in $(SUBDIRS); do              \
                BUILD_TARGET=$(OUTPUT)/$$DIR;   \
                mkdir $$BUILD_TARGET  -p;       \
-               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
+               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
        done
 endef
 endif
-- 
2.53.0


Reply via email to