Skip to contentSkip to conversation

selftest/powerpc: Re-order *FLAGS to follow lib.mk

PATCH Applied Madhavan Srinivasan 4 participants 7 messages Feb 29, 2024 – May 3, 2024

Subsystems (2)
lore
Share & tools
lore

Madhavan Srinivasan

author maintainer
#0 lore raw

PATCH 1/3 selftest/powerpc: Re-order *FLAGS to follow lib.mk

In some powerpc/ sub-folder Makefiles, CFLAGS are defined before lib.mk include. Clean it up by re-ordering it to follow after the mk include. This is needed to support sub-folders in powerpc/ buildable on its own.

---
 .../selftests/powerpc/benchmarks/Makefile     |  4 ++--
 .../selftests/powerpc/copyloops/Makefile      | 20 +++++++++----------
 .../selftests/powerpc/nx-gzip/Makefile        |  4 ++--
 .../selftests/powerpc/pmu/ebb/Makefile        | 20 +++++++++----------
 .../powerpc/pmu/event_code_tests/Makefile     |  4 ++--
 .../powerpc/pmu/sampling_tests/Makefile       |  4 ++--
 .../selftests/powerpc/primitives/Makefile     |  4 ++--
 .../selftests/powerpc/security/Makefile       |  4 ++--
 .../testing/selftests/powerpc/signal/Makefile |  3 ++-
 .../selftests/powerpc/stringloops/Makefile    | 10 +++++-----
 .../selftests/powerpc/switch_endian/Makefile  |  4 ++--
 .../selftests/powerpc/syscalls/Makefile       |  4 ++--
 tools/testing/selftests/powerpc/vphn/Makefile |  4 ++--
 13 files changed, 45 insertions(+), 44 deletions(-)
tools/testing/selftests/powerpc/benchmarks/Makefile +2 -2
index a32a6ab89914..75f5232c3aec 100644
@@ -4,11 +4,11 @@ TEST_GEN_FILES := exec_target
 
 TEST_FILES := settings
 
-CFLAGS += -O2
-
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+CFLAGS += -O2
+
 $(TEST_GEN_PROGS): ../harness.c
 
 $(OUTPUT)/context_switch: ../utils.c
tools/testing/selftests/powerpc/copyloops/Makefile +10 -10
index 77594e697f2f..72684ed589c0 100644
@@ -1,14 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-# The loops are all 64-bit code
-CFLAGS += -m64
-CFLAGS += -I$(CURDIR)
-CFLAGS += -D SELFTEST
-CFLAGS += -maltivec
-CFLAGS += -mcpu=power4
-
-# Use our CFLAGS for the implicit .S rule & set the asm machine type
-ASFLAGS = $(CFLAGS) -Wa,-mpower4
-
 TEST_GEN_PROGS := copyuser_64_t0 copyuser_64_t1 copyuser_64_t2 \
 		copyuser_p7_t0 copyuser_p7_t1 \
 		memcpy_64_t0 memcpy_64_t1 memcpy_64_t2 \
@@ -21,6 +11,16 @@ EXTRA_SOURCES := validate.c ../harness.c stubs.S
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+# The loops are all 64-bit code
+CFLAGS += -m64
+CFLAGS += -I$(CURDIR)
+CFLAGS += -D SELFTEST
+CFLAGS += -maltivec
+CFLAGS += -mcpu=power4
+
+# Use our CFLAGS for the implicit .S rule & set the asm machine type
+ASFLAGS = $(CFLAGS) -Wa,-mpower4
+
 $(OUTPUT)/copyuser_64_t%:	copyuser_64.S $(EXTRA_SOURCES)
 	$(CC) $(CPPFLAGS) $(CFLAGS) \
 		-D COPY_LOOP=test___copy_tofrom_user_base \
tools/testing/selftests/powerpc/nx-gzip/Makefile +2 -2
index 0785c2e99d40..b40991f902b2 100644
@@ -1,8 +1,8 @@
-CFLAGS = -O3 -m64 -I./include -I../include
-
 TEST_GEN_FILES := gzfht_test gunz_test
 TEST_PROGS := nx-gzip-test.sh
 
 include ../../lib.mk
 
+CFLAGS = -O3 -m64 -I./include -I../include
+
 $(TEST_GEN_FILES): gzip_vas.c ../utils.c
tools/testing/selftests/powerpc/pmu/ebb/Makefile +10 -10
index 010160690227..b3946ce17e0c 100644
@@ -4,16 +4,6 @@ include ../../../../../build/Build.include
 noarg:
 	$(MAKE) -C ../../
 
-# The EBB handler is 64-bit code and everything links against it
-CFLAGS += -m64
-
-TMPOUT = $(OUTPUT)/TMPDIR/
-# Toolchains may build PIE by default which breaks the assembly
-no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
-        $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -no-pie -x c - -o "$$TMP", -no-pie)
-
-LDFLAGS += $(no-pie-option)
-
 TEST_GEN_PROGS := reg_access_test event_attributes_test cycles_test	\
 	 cycles_with_freeze_test pmc56_overflow_test		\
 	 ebb_vs_cpu_event_test cpu_event_vs_ebb_test		\
@@ -29,6 +19,16 @@ TEST_GEN_PROGS := reg_access_test event_attributes_test cycles_test	\
 top_srcdir = ../../../../../..
 include ../../../lib.mk
 
+# The EBB handler is 64-bit code and everything links against it
+CFLAGS += -m64
+
+TMPOUT = $(OUTPUT)/TMPDIR/
+# Toolchains may build PIE by default which breaks the assembly
+no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
+        $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -no-pie -x c - -o "$$TMP", -no-pie)
+
+LDFLAGS += $(no-pie-option)
+
 $(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
 	       ebb.c ebb_handler.S trace.c busy_loop.S
 
tools/testing/selftests/powerpc/pmu/event_code_tests/Makefile +2 -2
index 4e07d7046457..509d4b235b9e 100644
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-CFLAGS += -m64
-
 TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_test group_constraint_pmc_count_test \
 	group_constraint_repeat_test group_constraint_radix_scope_qual_test reserved_bits_mmcra_sample_elig_mode_test \
 	group_constraint_mmcra_sample_test invalid_event_code_test reserved_bits_mmcra_thresh_ctl_test \
@@ -12,4 +10,6 @@ TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_te
 top_srcdir = ../../../../../..
 include ../../../lib.mk
 
+CFLAGS += -m64
+
 $(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c ../sampling_tests/misc.h ../sampling_tests/misc.c
tools/testing/selftests/powerpc/pmu/sampling_tests/Makefile +2 -2
index 9e67351fb252..d45892151e05 100644
@@ -1,6 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-CFLAGS += -m64
-
 TEST_GEN_PROGS := mmcr0_exceptionbits_test mmcr0_cc56run_test mmcr0_pmccext_test \
 		   mmcr0_pmcjce_test mmcr0_fc56_pmc1ce_test mmcr0_fc56_pmc56_test \
 		   mmcr1_comb_test mmcr2_l2l3_test mmcr2_fcs_fch_test \
@@ -12,4 +10,6 @@ TEST_GEN_PROGS := mmcr0_exceptionbits_test mmcr0_cc56run_test mmcr0_pmccext_test
 top_srcdir = ../../../../../..
 include ../../../lib.mk
 
+CFLAGS += -m64
+
 $(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c misc.c misc.h ../loop.S ../branch_loops.S
tools/testing/selftests/powerpc/primitives/Makefile +2 -2
index 9b9491a63213..6dc5c5a42ca9 100644
@@ -1,9 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
-CFLAGS += -I$(CURDIR)
-
 TEST_GEN_PROGS := load_unaligned_zeropad
 
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+CFLAGS += -I$(CURDIR)
+
 $(TEST_GEN_PROGS): ../harness.c
tools/testing/selftests/powerpc/security/Makefile +2 -2
index e0d979ab0204..0a08386be969 100644
@@ -5,10 +5,10 @@ TEST_PROGS := mitigation-patching.sh
 
 top_srcdir = ../../../../..
 
-CFLAGS += $(KHDR_INCLUDES)
-
 include ../../lib.mk
 
+CFLAGS += $(KHDR_INCLUDES)
+
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
 
 $(OUTPUT)/spectre_v2: CFLAGS += -m64
tools/testing/selftests/powerpc/signal/Makefile +2 -1
index f679d260afc8..b15d5dbccc24 100644
@@ -3,7 +3,6 @@ TEST_GEN_PROGS := signal signal_tm sigfuz sigreturn_vdso sig_sc_double_restart
 TEST_GEN_PROGS += sigreturn_kernel
 TEST_GEN_PROGS += sigreturn_unaligned
 
-CFLAGS += -maltivec
 $(OUTPUT)/signal_tm: CFLAGS += -mhtm
 $(OUTPUT)/sigfuz: CFLAGS += -pthread -m64
 
@@ -12,4 +11,6 @@ TEST_FILES := settings
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+CFLAGS += -maltivec
+
 $(TEST_GEN_PROGS): ../harness.c ../utils.c signal.S
tools/testing/selftests/powerpc/stringloops/Makefile +5 -5
index 9c39f55a58ff..87c8c8f238da 100644
@@ -1,7 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-# The loops are all 64-bit code
-CFLAGS += -I$(CURDIR)
-
 EXTRA_SOURCES := ../harness.c
 
 build_32bit = $(shell if ($(CC) $(CFLAGS) -m32 -o /dev/null memcmp.c >/dev/null 2>&1) then echo "1"; fi)
@@ -27,9 +24,12 @@ $(OUTPUT)/strlen_32: CFLAGS += -m32
 TEST_GEN_PROGS += strlen_32
 endif
 
-ASFLAGS = $(CFLAGS)
-
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+# The loops are all 64-bit code
+CFLAGS += -I$(CURDIR)
+
+ASFLAGS = $(CFLAGS)
+
 $(TEST_GEN_PROGS): $(EXTRA_SOURCES)
tools/testing/selftests/powerpc/switch_endian/Makefile +2 -2
index bdc081afedb0..8f0c2a1d3333 100644
@@ -1,13 +1,13 @@
 # SPDX-License-Identifier: GPL-2.0
 TEST_GEN_PROGS := switch_endian_test
 
-ASFLAGS += -O2 -Wall -g -nostdlib -m64
-
 EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S
 
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+ASFLAGS += -O2 -Wall -g -nostdlib -m64
+
 $(OUTPUT)/switch_endian_test: ASFLAGS += -I $(OUTPUT)
 $(OUTPUT)/switch_endian_test: $(OUTPUT)/check-reversed.S
 
tools/testing/selftests/powerpc/syscalls/Makefile +2 -2
index ee1740ddfb0c..83dc33500773 100644
@@ -1,9 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
 TEST_GEN_PROGS := ipc_unmuxed rtas_filter
 
-CFLAGS += $(KHDR_INCLUDES)
-
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+CFLAGS += $(KHDR_INCLUDES)
+
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
tools/testing/selftests/powerpc/vphn/Makefile +2 -2
index cf65cbf33085..ddc09a20b80f 100644
@@ -1,10 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0-only
 TEST_GEN_PROGS := test-vphn
 
-CFLAGS += -m64 -I$(CURDIR)
-
 top_srcdir = ../../../../..
 include ../../lib.mk
 
+CFLAGS += -m64 -I$(CURDIR)
+
 $(TEST_GEN_PROGS): ../harness.c
 
Signature · 1 line
2.43.2
author maintainer
#1 lore raw

PATCH 2/3 selftest/powerpc: Add flags.mk to support pmu buildable

When running make -C powerpc/pmu run_tests from top level selftests directory, currently this error is being reported

make: Entering directory '/home/maddy/linux/tools/testing/selftests/powerpc/pmu' Makefile:40: warning: overriding recipe for target 'emit_tests' ../../lib.mk:111: warning: ignoring old recipe for target 'emit_tests'
gcc -m64 count_instructions.c ../harness.c event.c lib.c ../utils.c loop.S -o /home/maddy/selftest_output//count_instructions
In file included from count_instructions.c:13:
event.h:12:10: fatal error: utils.h: No such file or directory
12 | #include "utils.h"
| ^~~~~~~~~
compilation terminated.

This is due to missing of include path in CFLAGS. That is, CFLAGS and GIT_VERSION macros are defined in the powerpc/ folder Makefile which in this case not involved.

To address the failure incase of executing specific sub-folder test directly, a new rule file has been addded by the patch called "flags.mk" under selftest/powerpc/ folder and is linked to all the Makefile of powerpc/pmu sub-folders.

---
Changelog RFC:
- Rename the rule file as flags.mk
- Added additional patches to support other sub-folders under powerpc/ to be buildable on it own.
link to RFC:
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/

 tools/testing/selftests/powerpc/flags.mk             | 12 ++++++++++++
 tools/testing/selftests/powerpc/pmu/Makefile         |  1 +
 tools/testing/selftests/powerpc/pmu/ebb/Makefile     |  1 +
 .../selftests/powerpc/pmu/event_code_tests/Makefile  |  1 +
 .../selftests/powerpc/pmu/sampling_tests/Makefile    |  1 +
 5 files changed, 16 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/flags.mk
tools/testing/selftests/powerpc/flags.mk new file +12 -0
new file mode 100644
index 000000000000..28374f470126
@@ -0,0 +1,12 @@
+#This checks for any ENV variables and add those.
+
+#ifeq ($(GIT_VERSION),)
+GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown")
+export GIT_VERSION
+#endif
+
+#ifeq ($(CFLAGS),)
+CFLAGS := -std=gnu99 -O2 -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(selfdir)/powerpc/include $(CFLAGS)
+export CFLAGS
+#endif
+
tools/testing/selftests/powerpc/pmu/Makefile +1 -0
index a284fa874a9f..1fcacae1b188 100644
@@ -7,6 +7,7 @@ EXTRA_SOURCES := ../harness.c event.c lib.c ../utils.c
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 all: $(TEST_GEN_PROGS) ebb sampling_tests event_code_tests
 
tools/testing/selftests/powerpc/pmu/ebb/Makefile +1 -0
index b3946ce17e0c..1b39af7c10db 100644
@@ -18,6 +18,7 @@ TEST_GEN_PROGS := reg_access_test event_attributes_test cycles_test	\
 
 top_srcdir = ../../../../../..
 include ../../../lib.mk
+include ../../flags.mk
 
 # The EBB handler is 64-bit code and everything links against it
 CFLAGS += -m64
tools/testing/selftests/powerpc/pmu/event_code_tests/Makefile +1 -0
index 509d4b235b9e..fdb080b3fa65 100644
@@ -9,6 +9,7 @@ TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_te
 
 top_srcdir = ../../../../../..
 include ../../../lib.mk
+include ../../flags.mk
 
 CFLAGS += -m64
 
tools/testing/selftests/powerpc/pmu/sampling_tests/Makefile +1 -0
index d45892151e05..9f79bec5fce7 100644
@@ -9,6 +9,7 @@ TEST_GEN_PROGS := mmcr0_exceptionbits_test mmcr0_cc56run_test mmcr0_pmccext_test
 
 top_srcdir = ../../../../../..
 include ../../../lib.mk
+include ../../flags.mk
 
 CFLAGS += -m64
 
Signature · 1 line
2.43.2
author maintainer
#5 lore raw

PATCH 3/3 selftest/powerpc: make sub-folders buildable on it own

In reply to Madhavan Srinivasan

Build breaks when executing make with run_tests for sub-folders under powerpc. This is because, CFLAGS and GIT_VERSION macros are defined in Makefile of toplevel powerpc folder.

make: Entering directory '/home/maddy/linux/tools/testing/selftests/powerpc/mm'
gcc hugetlb_vs_thp_test.c ../harness.c ../utils.c -o /home/maddy/selftest_output//hugetlb_vs_thp_test
hugetlb_vs_thp_test.c:6:10: fatal error: utils.h: No such file or directory

    6 | #include "utils.h"
      |          ^~~~~~~~~

compilation terminated.

Fix this by adding the flags.mk in each sub-folder Makefile. Also remove the CFLAGS and GIT_VERSION macros from powerpc/ folder Makefile since the same is definied in flags.mk

---
 tools/testing/selftests/powerpc/Makefile                 | 7 +------
 tools/testing/selftests/powerpc/alignment/Makefile       | 1 +
 tools/testing/selftests/powerpc/benchmarks/Makefile      | 1 +
 tools/testing/selftests/powerpc/cache_shape/Makefile     | 1 +
 tools/testing/selftests/powerpc/copyloops/Makefile       | 1 +
 tools/testing/selftests/powerpc/dexcr/Makefile           | 1 +
 tools/testing/selftests/powerpc/dscr/Makefile            | 1 +
 tools/testing/selftests/powerpc/eeh/Makefile             | 1 +
 tools/testing/selftests/powerpc/math/Makefile            | 1 +
 tools/testing/selftests/powerpc/mce/Makefile             | 1 +
 tools/testing/selftests/powerpc/mm/Makefile              | 1 +
 tools/testing/selftests/powerpc/nx-gzip/Makefile         | 1 +
 tools/testing/selftests/powerpc/papr_attributes/Makefile | 3 ++-
 tools/testing/selftests/powerpc/papr_sysparm/Makefile    | 1 +
 tools/testing/selftests/powerpc/papr_vpd/Makefile        | 1 +
 tools/testing/selftests/powerpc/primitives/Makefile      | 1 +
 tools/testing/selftests/powerpc/ptrace/Makefile          | 1 +
 tools/testing/selftests/powerpc/security/Makefile        | 1 +
 tools/testing/selftests/powerpc/signal/Makefile          | 1 +
 tools/testing/selftests/powerpc/stringloops/Makefile     | 1 +
 tools/testing/selftests/powerpc/switch_endian/Makefile   | 1 +
 tools/testing/selftests/powerpc/syscalls/Makefile        | 1 +
 tools/testing/selftests/powerpc/tm/Makefile              | 1 +
 tools/testing/selftests/powerpc/vphn/Makefile            | 1 +
 24 files changed, 25 insertions(+), 7 deletions(-)
tools/testing/selftests/powerpc/Makefile +1 -6
index c376151982c4..2f299fd04d2d 100644
@@ -7,12 +7,6 @@ ARCH := $(shell echo $(ARCH) | sed -e s/ppc.*/powerpc/)
 
 ifeq ($(ARCH),powerpc)
 
-GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown")
-
-CFLAGS := -std=gnu99 -O2 -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CURDIR)/include $(CFLAGS)
-
-export CFLAGS
-
 SUB_DIRS = alignment		\
 	   benchmarks		\
 	   cache_shape		\
@@ -46,6 +40,7 @@ $(SUB_DIRS):
 	BUILD_TARGET=$(OUTPUT)/$@; mkdir -p $$BUILD_TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -k -C $@ all
 
 include ../lib.mk
+include ./flags.mk
 
 override define RUN_TESTS
 	+@for TARGET in $(SUB_DIRS); do \
tools/testing/selftests/powerpc/alignment/Makefile +1 -0
index 93e9af37449d..66d5d7aaeb20 100644
@@ -3,5 +3,6 @@ TEST_GEN_PROGS := copy_first_unaligned alignment_handler
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
tools/testing/selftests/powerpc/benchmarks/Makefile +1 -0
index 75f5232c3aec..1321922038d0 100644
@@ -6,6 +6,7 @@ TEST_FILES := settings
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS += -O2
 
tools/testing/selftests/powerpc/cache_shape/Makefile +1 -0
index 689f6c8ebcd8..3a3ca956ac66 100644
@@ -3,5 +3,6 @@ TEST_GEN_PROGS := cache_shape
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
tools/testing/selftests/powerpc/copyloops/Makefile +1 -0
index 72684ed589c0..42940f92d832 100644
@@ -10,6 +10,7 @@ EXTRA_SOURCES := validate.c ../harness.c stubs.S
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 # The loops are all 64-bit code
 CFLAGS += -m64
tools/testing/selftests/powerpc/dexcr/Makefile +1 -0
index 76210f2bcec3..523947a38d17 100644
@@ -2,6 +2,7 @@ TEST_GEN_PROGS := hashchk_test
 TEST_GEN_FILES := lsdexcr
 
 include ../../lib.mk
+include ../flags.mk
 
 $(OUTPUT)/hashchk_test: CFLAGS += -fno-pie $(call cc-option,-mno-rop-protect)
 
tools/testing/selftests/powerpc/dscr/Makefile +1 -0
index 9289d5febe1e..9fa9cb5bd989 100644
@@ -5,6 +5,7 @@ TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test	\
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(OUTPUT)/dscr_default_test: LDLIBS += -lpthread
 $(OUTPUT)/dscr_explicit_test: LDLIBS += -lpthread
tools/testing/selftests/powerpc/eeh/Makefile +1 -0
index ae963eb2dc5b..70797716f2b5 100644
@@ -7,3 +7,4 @@ TEST_FILES := eeh-functions.sh settings
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
tools/testing/selftests/powerpc/math/Makefile +1 -0
index 3948f7c510aa..b14fd2e0c6a8 100644
@@ -3,6 +3,7 @@ TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal fpu_denormal vmx_syscall vm
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c
 $(TEST_GEN_PROGS): CFLAGS += -O2 -g -pthread -m64 -maltivec
tools/testing/selftests/powerpc/mce/Makefile +1 -0
index 2424513982d9..ce4ed679aaaf 100644
@@ -3,5 +3,6 @@
 TEST_GEN_PROGS := inject-ra-err
 
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c
tools/testing/selftests/powerpc/mm/Makefile +1 -0
index 4a6608beef0e..aab058ecb352 100644
@@ -13,6 +13,7 @@ TEST_GEN_FILES := tempfile
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
 
tools/testing/selftests/powerpc/nx-gzip/Makefile +1 -0
index b40991f902b2..480d8ba94cf7 100644
@@ -2,6 +2,7 @@ TEST_GEN_FILES := gzfht_test gunz_test
 TEST_PROGS := nx-gzip-test.sh
 
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS = -O3 -m64 -I./include -I../include
 
tools/testing/selftests/powerpc/papr_attributes/Makefile +2 -1
index e899712d49db..406429499022 100644
@@ -3,5 +3,6 @@ TEST_GEN_PROGS := attr_test
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
-$(TEST_GEN_PROGS): ../harness.c ../utils.c
\ No newline at end of file
+$(TEST_GEN_PROGS): ../harness.c ../utils.c
tools/testing/selftests/powerpc/papr_sysparm/Makefile +1 -0
index 7f79e437634a..fed4f2414dbf 100644
@@ -6,6 +6,7 @@ TEST_GEN_PROGS := papr_sysparm
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
 
tools/testing/selftests/powerpc/papr_vpd/Makefile +1 -0
index 06b719703bfd..b09852e40882 100644
@@ -6,6 +6,7 @@ TEST_GEN_PROGS := papr_vpd
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
 
tools/testing/selftests/powerpc/primitives/Makefile +1 -0
index 6dc5c5a42ca9..23bd9a7590dd 100644
@@ -3,6 +3,7 @@ TEST_GEN_PROGS := load_unaligned_zeropad
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS += -I$(CURDIR)
 
tools/testing/selftests/powerpc/ptrace/Makefile +1 -0
index 1b39b86849da..59ca01d8567e 100644
@@ -26,6 +26,7 @@ LOCAL_HDRS += $(patsubst %,$(selfdir)/powerpc/ptrace/%,$(wildcard *.h))
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 TM_TESTS := $(patsubst %,$(OUTPUT)/%,$(TM_TESTS))
 TESTS_64 := $(patsubst %,$(OUTPUT)/%,$(TESTS_64))
tools/testing/selftests/powerpc/security/Makefile +1 -0
index 0a08386be969..33286039724a 100644
@@ -6,6 +6,7 @@ TEST_PROGS := mitigation-patching.sh
 top_srcdir = ../../../../..
 
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS += $(KHDR_INCLUDES)
 
tools/testing/selftests/powerpc/signal/Makefile +1 -0
index b15d5dbccc24..ece95bd52be9 100644
@@ -10,6 +10,7 @@ TEST_FILES := settings
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS += -maltivec
 
tools/testing/selftests/powerpc/stringloops/Makefile +1 -0
index 87c8c8f238da..4c9d9a58c9d1 100644
@@ -26,6 +26,7 @@ endif
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 # The loops are all 64-bit code
 CFLAGS += -I$(CURDIR)
tools/testing/selftests/powerpc/switch_endian/Makefile +1 -0
index 8f0c2a1d3333..0da2e0a74264 100644
@@ -5,6 +5,7 @@ EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 ASFLAGS += -O2 -Wall -g -nostdlib -m64
 
tools/testing/selftests/powerpc/syscalls/Makefile +1 -0
index 83dc33500773..3bc07af88f0e 100644
@@ -3,6 +3,7 @@ TEST_GEN_PROGS := ipc_unmuxed rtas_filter
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS += $(KHDR_INCLUDES)
 
tools/testing/selftests/powerpc/tm/Makefile +1 -0
index 3876805c2f31..f13f0ab36007 100644
@@ -11,6 +11,7 @@ TEST_FILES := settings
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 $(TEST_GEN_PROGS): ../harness.c ../utils.c
 
tools/testing/selftests/powerpc/vphn/Makefile +1 -0
index ddc09a20b80f..61d519a076c6 100644
@@ -3,6 +3,7 @@ TEST_GEN_PROGS := test-vphn
 
 top_srcdir = ../../../../..
 include ../../lib.mk
+include ../flags.mk
 
 CFLAGS += -m64 -I$(CURDIR)
 
Signature · 1 line
2.43.2
Tested-by Tested-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] selftest/powerpc: Add flags.mk to support pmu buildable

In reply to Madhavan Srinivasan
Quoted 21 lines · Madhavan Srinivasan

When running make -C powerpc/pmu run_tests from top level selftests directory, currently this error is being reported

make: Entering directory '/home/maddy/linux/tools/testing/selftests/powerpc/pmu' Makefile:40: warning: overriding recipe for target 'emit_tests' ../../lib.mk:111: warning: ignoring old recipe for target 'emit_tests'
gcc -m64 count_instructions.c ../harness.c event.c lib.c ../utils.c loop.S -o /home/maddy/selftest_output//count_instructions
In file included from count_instructions.c:13:
event.h:12:10: fatal error: utils.h: No such file or directory
12 | #include "utils.h"
| ^~~~~~~~~
compilation terminated.

This is due to missing of include path in CFLAGS. That is, CFLAGS and GIT_VERSION macros are defined in the powerpc/ folder Makefile which in this case not involved.

Quoted 8 lines

To address the failure incase of executing specific sub-folder test directly, a new rule file has been addded by the patch called "flags.mk" under selftest/powerpc/ folder and is linked to all the Makefile of powerpc/pmu sub-folders.

---

Fixes the reported problem for me.

While at it, FWIW I have also tested the remaining 2 patches and no problems were seen.

For the other 2 patches in the series

— Sachin

#3 lore raw

Re: [PATCH 2/3] selftest/powerpc: Add flags.mk to support pmu buildable

In reply to Madhavan Srinivasan
Quoted 13 lines · Madhavan Srinivasan

When running make -C powerpc/pmu run_tests from top level selftests directory, currently this error is being reported

make: Entering directory '/home/maddy/linux/tools/testing/selftests/powerpc/pmu' Makefile:40: warning: overriding recipe for target 'emit_tests' ../../lib.mk:111: warning: ignoring old recipe for target 'emit_tests'
gcc -m64 count_instructions.c ../harness.c event.c lib.c ../utils.c loop.S -o /home/maddy/selftest_output//count_instructions
In file included from count_instructions.c:13:
event.h:12:10: fatal error: utils.h: No such file or directory
12 | #include "utils.h"
| ^~~~~~~~~
compilation terminated.

Quoted 8 lines

This is due to missing of include path in CFLAGS. That is, CFLAGS and GIT_VERSION macros are defined in the powerpc/ folder Makefile which in this case not involved.

To address the failure incase of executing specific sub-folder test directly, a new rule file has been addded by the patch called "flags.mk" under selftest/powerpc/ folder and is linked to all the Makefile of powerpc/pmu sub-folders.

This patch made my selftest build go from ~10s to ~50s !

I tracked it down to "git describe" being run hundreds of times.

tools/testing/selftests/powerpc/flags.mk line 3

Quoted 9 lines
tools/testing/selftests/powerpc/flags.mk new file +3 -0
new file mode 100644
index 000000000000..28374f470126
@@ -0,0 +1,12 @@
+#This checks for any ENV variables and add those.
+
+#ifeq ($(GIT_VERSION),)

This isn't right, # is a comment in make syntax, so this line is just a comment. It needs to be "ifeq".

tools/testing/selftests/powerpc/flags.mk line 4

Quoted 1 line
tools/testing/selftests/powerpc/flags.mk new file +1 -0
+GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown")

Using '=' here means Make re-runs the command every time the variable is used. Previously that was OK because the variable was set once and then exported. But now that it's a Make variable in each file it leads to "git describe" being run a few hundred times.

I've squashed in those fixes, no need to send a v2.

cheers

author maintainer
#4 lore raw

Re: [PATCH 2/3] selftest/powerpc: Add flags.mk to support pmu buildable

Quoted 26 lines · Michael Ellerman
Quoted 13 lines · Madhavan Srinivasan

When running make -C powerpc/pmu run_tests from top level selftests directory, currently this error is being reported

make: Entering directory '/home/maddy/linux/tools/testing/selftests/powerpc/pmu' Makefile:40: warning: overriding recipe for target 'emit_tests' ../../lib.mk:111: warning: ignoring old recipe for target 'emit_tests'
gcc -m64 count_instructions.c ../harness.c event.c lib.c ../utils.c loop.S -o /home/maddy/selftest_output//count_instructions
In file included from count_instructions.c:13:
event.h:12:10: fatal error: utils.h: No such file or directory
12 | #include "utils.h"
| ^~~~~~~~~
compilation terminated.

Quoted 8 lines

This is due to missing of include path in CFLAGS. That is, CFLAGS and GIT_VERSION macros are defined in the powerpc/ folder Makefile which in this case not involved.

To address the failure incase of executing specific sub-folder test directly, a new rule file has been addded by the patch called "flags.mk" under selftest/powerpc/ folder and is linked to all the Makefile of powerpc/pmu sub-folders.

This patch made my selftest build go from ~10s to ~50s !

I tracked it down to "git describe" being run hundreds of times.

Quoted 12 lines

tools/testing/selftests/powerpc/flags.mk line 3

Quoted 9 lines
tools/testing/selftests/powerpc/flags.mk new file +3 -0
new file mode 100644
index 000000000000..28374f470126
@@ -0,0 +1,12 @@
+#This checks for any ENV variables and add those.
+
+#ifeq ($(GIT_VERSION),)

This isn't right, # is a comment in make syntax, so this line is just a comment. It needs to be "ifeq".

oops, my bad :(
But nice catch. Thanks

Maddy

Quoted 11 lines

tools/testing/selftests/powerpc/flags.mk line 4

Quoted 2 lines
tools/testing/selftests/powerpc/flags.mk new file +1 -0
+GIT_VERSION = $(shell git describe --always --long --dirty || echo "unknown")

Using '=' here means Make re-runs the command every time the variable is used. Previously that was OK because the variable was set once and then exported. But now that it's a Make variable in each file it leads to "git describe" being run a few hundred times.

I've squashed in those fixes, no need to send a v2.

cheers

#6 lore raw
In reply to Madhavan Srinivasan
Quoted 8 lines · Madhavan Srinivasan

In some powerpc/ sub-folder Makefiles, CFLAGS are defined before lib.mk include. Clean it up by re-ordering it to follow after the mk include. This is needed to support sub-folders in powerpc/ buildable on its own.

[...]

Applied to powerpc/next.

[1/3] selftest/powerpc: Re-order *FLAGS to follow lib.mk

      https://git.kernel.org/powerpc/c/37496845c812db2a470d51088a59ee38156e8058
[2/3] selftest/powerpc: Add flags.mk to support pmu buildable
      https://git.kernel.org/powerpc/c/5553a79387e92ffd812a49fdcf679f392281f6a9
[3/3] selftest/powerpc: make sub-folders buildable on it own
      https://git.kernel.org/powerpc/c/108e5e683333615023265a9a73a29d4c2fa16c70

cheers