diff mbox series

[4/4] selftests: Add build infrastructure along with README

Message ID 20240405084410.256788-5-dev.jain@arm.com (mailing list archive)
State New
Headers show
Series A new selftests/ directory for arm compatibility testing | expand

Commit Message

Dev Jain April 5, 2024, 8:44 a.m. UTC
Add arm target, individual Makefile targets, and instructions to build the
tests.

Signed-off-by: Dev Jain <dev.jain@arm.com>
---
 tools/testing/selftests/Makefile            |  1 +
 tools/testing/selftests/arm/Makefile        | 57 +++++++++++++++++++++
 tools/testing/selftests/arm/README          | 31 +++++++++++
 tools/testing/selftests/arm/elf/Makefile    |  6 +++
 tools/testing/selftests/arm/mm/Makefile     |  6 +++
 tools/testing/selftests/arm/signal/Makefile | 30 +++++++++++
 6 files changed, 131 insertions(+)
 create mode 100644 tools/testing/selftests/arm/Makefile
 create mode 100644 tools/testing/selftests/arm/README
 create mode 100644 tools/testing/selftests/arm/elf/Makefile
 create mode 100644 tools/testing/selftests/arm/mm/Makefile
 create mode 100644 tools/testing/selftests/arm/signal/Makefile

Comments

Muhammad Usama Anjum April 6, 2024, 9:15 p.m. UTC | #1
On 4/5/24 1:44 PM, Dev Jain wrote:
> Add arm target, individual Makefile targets, and instructions to build the
> tests.
> 
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>  tools/testing/selftests/Makefile            |  1 +
>  tools/testing/selftests/arm/Makefile        | 57 +++++++++++++++++++++
>  tools/testing/selftests/arm/README          | 31 +++++++++++
>  tools/testing/selftests/arm/elf/Makefile    |  6 +++
>  tools/testing/selftests/arm/mm/Makefile     |  6 +++
>  tools/testing/selftests/arm/signal/Makefile | 30 +++++++++++
>  6 files changed, 131 insertions(+)
>  create mode 100644 tools/testing/selftests/arm/Makefile
>  create mode 100644 tools/testing/selftests/arm/README
>  create mode 100644 tools/testing/selftests/arm/elf/Makefile
>  create mode 100644 tools/testing/selftests/arm/mm/Makefile
>  create mode 100644 tools/testing/selftests/arm/signal/Makefile
Add one recursive .gitignore file or multiple .gitignore files and put
generated object files in it to avoid clutter of generated objects in git
history.

> 
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 15b6a111c3be..8478d94cda4c 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
>  TARGETS += alsa
>  TARGETS += amd-pstate
> +TARGETS += arm
>  TARGETS += arm64
>  TARGETS += bpf
>  TARGETS += breakpoints
> diff --git a/tools/testing/selftests/arm/Makefile b/tools/testing/selftests/arm/Makefile
> new file mode 100644
> index 000000000000..039224bc006e
> --- /dev/null
> +++ b/tools/testing/selftests/arm/Makefile
> @@ -0,0 +1,57 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# When ARCH not overridden for crosscompiling, lookup machine
> +ARCH ?= $(shell uname -m 2>/dev/null || echo not)
> +
> +ifneq (,$(filter $(ARCH),aarch64 arm64 arm armv7l armv8l))
> +ARM_SUBTARGETS ?= mm signal elf
> +else
> +ARM_SUBTARGETS :=
> +endif
> +
> +CFLAGS := -Wall -O2 -g -static
> +
> +# A proper top_srcdir is needed by KSFT(lib.mk)
> +top_srcdir = $(realpath ../../../../)
> +
> +# Additional include paths needed by kselftest.h and local headers
> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
> +
> +CFLAGS += -I$(top_srcdir)/tools/include
Please use KHDR_INCLUDE instead of using absolute path

> +
> +export CFLAGS
> +export top_srcdir
> +
> +all:
> +	@for DIR in $(ARM_SUBTARGETS); do				\
> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
> +		mkdir -p $$BUILD_TARGET;			\
> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
> +	done
> +
> +install: all
> +	@for DIR in $(ARM_SUBTARGETS); do				\
> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
> +	done
> +
> +run_tests: all
> +	@for DIR in $(ARM_SUBTARGETS); do				\
> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
> +	done
> +
> +# Avoid any output on non arm on emit_tests
> +emit_tests:
> +	@for DIR in $(ARM_SUBTARGETS); do				\
> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
> +	done
> +
> +clean:
> +	@for DIR in $(ARM_SUBTARGETS); do				\
> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
> +	done
> +
> +.PHONY: all clean install run_tests emit_tests
> diff --git a/tools/testing/selftests/arm/README b/tools/testing/selftests/arm/README
> new file mode 100644
> index 000000000000..1a05c043d7ee
> --- /dev/null
> +++ b/tools/testing/selftests/arm/README
> @@ -0,0 +1,31 @@
> +KSelfTest ARM
> +===============
> +
> +- This is a series of compatibility tests, wherein the source files are
> +  built statically into a 32 bit ELF; they should pass on both 32 and 64
> +  bit kernels. They are not built or run but just skipped completely when
> +  env-variable ARCH is found to be different than 'arm64' or 'arm' and
> +  `uname -m` reports other than 'aarch64', 'armv7l' or 'armv8l'.
> +
> +- Please ensure that the test kernel is built with CONFIG_COMPAT enabled.
Please create a config file and put all the per-requisite configurations in
that. For example, look at tools/testing/selftests/mm/config

> +
> +- Holding true the above, ARM KSFT tests can be run within the KSelfTest
> +  framework using standard Linux top-level-makefile targets. Please set
> +  $(CROSS_COMPILE) to 'arm-linux-gnueabi-' or 'arm-linux-gnueabihf-'.
> +
> +      $ make TARGETS=arm kselftest-clean
> +      $ make $(CROSS_COMPILE) TARGETS=arm kselftest
> +
> +      or
> +
> +      $ make $(CROSS_COMPILE) -C tools/testing/selftests TARGETS=arm \
> +		INSTALL_PATH=<your-installation-path> install
> +
> +      or, alternatively, only specific arm/ subtargets can be picked:
> +
> +      $ make $(CROSS_COMPILE) -C tools/testing/selftests TARGETS=arm \
> +		ARM_SUBTARGETS="signal" INSTALL_PATH=<your-installation-path> \
> +			install
> +
> +   Further details on building and running KFST can be found in:
> +     Documentation/dev-tools/kselftest.rst
Thanks for this well written documentation.

> diff --git a/tools/testing/selftests/arm/elf/Makefile b/tools/testing/selftests/arm/elf/Makefile
> new file mode 100644
> index 000000000000..86636fe02994
> --- /dev/null
> +++ b/tools/testing/selftests/arm/elf/Makefile
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2024 ARM Limited
> +
> +TEST_GEN_PROGS := parse_elf
> +
> +include ../../lib.mk
> diff --git a/tools/testing/selftests/arm/mm/Makefile b/tools/testing/selftests/arm/mm/Makefile
> new file mode 100644
> index 000000000000..d8bfa45df98c
> --- /dev/null
> +++ b/tools/testing/selftests/arm/mm/Makefile
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2024 ARM Limited
> +
> +TEST_GEN_PROGS := compat_va
> +
> +include ../../lib.mk
> diff --git a/tools/testing/selftests/arm/signal/Makefile b/tools/testing/selftests/arm/signal/Makefile
> new file mode 100644
> index 000000000000..3540a25de75a
> --- /dev/null
> +++ b/tools/testing/selftests/arm/signal/Makefile
> @@ -0,0 +1,30 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2024 ARM Limited
> +
> +# Additional include paths needed by kselftest.h and local headers
> +CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
> +
> +SRCS := $(filter-out testcases/testcases.c,$(wildcard testcases/*.c))
> +PROGS := $(patsubst %.c,%,$(SRCS))
> +
> +# Generated binaries to be installed by top KSFT script
> +TEST_GEN_PROGS := $(notdir $(PROGS))
> +
> +# Get Kernel headers installed and use them.
> +
> +# Including KSFT lib.mk here will also mangle the TEST_GEN_PROGS list
> +# to account for any OUTPUT target-dirs optionally provided by
> +# the toplevel makefile
> +include ../../lib.mk
> +
> +$(TEST_GEN_PROGS): $(PROGS)
> +	cp $(PROGS) $(OUTPUT)/
> +
> +# Common test-unit targets to build common-layout test-cases executables
> +# Needs secondary expansion to properly include the testcase c-file in pre-reqs
> +COMMON_SOURCES := test_signals.c test_signals_utils.c
> +COMMON_HEADERS := test_signals.h test_signals_utils.h
> +
> +.SECONDEXPANSION:
> +$(PROGS): $$@.c ${COMMON_SOURCES} ${COMMON_HEADERS}
> +	$(CC) $(CFLAGS) ${@}.c ${COMMON_SOURCES} -o $@
Mark Brown April 8, 2024, 12:24 p.m. UTC | #2
On Sun, Apr 07, 2024 at 02:15:15AM +0500, Muhammad Usama Anjum wrote:
> On 4/5/24 1:44 PM, Dev Jain wrote:

> > @@ -0,0 +1,31 @@
> > +KSelfTest ARM
> > +===============
> > +
> > +- This is a series of compatibility tests, wherein the source files are
> > +  built statically into a 32 bit ELF; they should pass on both 32 and 64
> > +  bit kernels. They are not built or run but just skipped completely when
> > +  env-variable ARCH is found to be different than 'arm64' or 'arm' and
> > +  `uname -m` reports other than 'aarch64', 'armv7l' or 'armv8l'.
> > +
> > +- Please ensure that the test kernel is built with CONFIG_COMPAT enabled.

> Please create a config file and put all the per-requisite configurations in
> that. For example, look at tools/testing/selftests/mm/config

Note that arm and arm64 are different architectures, and the kernel
config stuff only applies when building for arm64...
Dev Jain April 11, 2024, 5:15 a.m. UTC | #3
On 4/7/24 02:45, Muhammad Usama Anjum wrote:
>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>> index 15b6a111c3be..8478d94cda4c 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -1,6 +1,7 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   TARGETS += alsa
>>   TARGETS += amd-pstate
>> +TARGETS += arm
>>   TARGETS += arm64
>>   TARGETS += bpf
>>   TARGETS += breakpoints
>> diff --git a/tools/testing/selftests/arm/Makefile b/tools/testing/selftests/arm/Makefile
>> new file mode 100644
>> index 000000000000..039224bc006e
>> --- /dev/null
>> +++ b/tools/testing/selftests/arm/Makefile
>> @@ -0,0 +1,57 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +# When ARCH not overridden for crosscompiling, lookup machine
>> +ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>> +
>> +ifneq (,$(filter $(ARCH),aarch64 arm64 arm armv7l armv8l))
>> +ARM_SUBTARGETS ?= mm signal elf
>> +else
>> +ARM_SUBTARGETS :=
>> +endif
>> +
>> +CFLAGS := -Wall -O2 -g -static
>> +
>> +# A proper top_srcdir is needed by KSFT(lib.mk)
>> +top_srcdir = $(realpath ../../../../)
>> +
>> +# Additional include paths needed by kselftest.h and local headers
>> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
>> +
>> +CFLAGS += -I$(top_srcdir)/tools/include
> Please use KHDR_INCLUDE instead of using absolute path


The reason I had excluded it was that the signal tests won't

build then. What probably happens is that the kernel headers

collide with the headers included by the compiler.
diff mbox series

Patch

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 15b6a111c3be..8478d94cda4c 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -1,6 +1,7 @@ 
 # SPDX-License-Identifier: GPL-2.0
 TARGETS += alsa
 TARGETS += amd-pstate
+TARGETS += arm
 TARGETS += arm64
 TARGETS += bpf
 TARGETS += breakpoints
diff --git a/tools/testing/selftests/arm/Makefile b/tools/testing/selftests/arm/Makefile
new file mode 100644
index 000000000000..039224bc006e
--- /dev/null
+++ b/tools/testing/selftests/arm/Makefile
@@ -0,0 +1,57 @@ 
+# SPDX-License-Identifier: GPL-2.0
+
+# When ARCH not overridden for crosscompiling, lookup machine
+ARCH ?= $(shell uname -m 2>/dev/null || echo not)
+
+ifneq (,$(filter $(ARCH),aarch64 arm64 arm armv7l armv8l))
+ARM_SUBTARGETS ?= mm signal elf
+else
+ARM_SUBTARGETS :=
+endif
+
+CFLAGS := -Wall -O2 -g -static
+
+# A proper top_srcdir is needed by KSFT(lib.mk)
+top_srcdir = $(realpath ../../../../)
+
+# Additional include paths needed by kselftest.h and local headers
+CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
+
+CFLAGS += -I$(top_srcdir)/tools/include
+
+export CFLAGS
+export top_srcdir
+
+all:
+	@for DIR in $(ARM_SUBTARGETS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		mkdir -p $$BUILD_TARGET;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+install: all
+	@for DIR in $(ARM_SUBTARGETS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+run_tests: all
+	@for DIR in $(ARM_SUBTARGETS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+# Avoid any output on non arm on emit_tests
+emit_tests:
+	@for DIR in $(ARM_SUBTARGETS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+clean:
+	@for DIR in $(ARM_SUBTARGETS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+.PHONY: all clean install run_tests emit_tests
diff --git a/tools/testing/selftests/arm/README b/tools/testing/selftests/arm/README
new file mode 100644
index 000000000000..1a05c043d7ee
--- /dev/null
+++ b/tools/testing/selftests/arm/README
@@ -0,0 +1,31 @@ 
+KSelfTest ARM
+===============
+
+- This is a series of compatibility tests, wherein the source files are
+  built statically into a 32 bit ELF; they should pass on both 32 and 64
+  bit kernels. They are not built or run but just skipped completely when
+  env-variable ARCH is found to be different than 'arm64' or 'arm' and
+  `uname -m` reports other than 'aarch64', 'armv7l' or 'armv8l'.
+
+- Please ensure that the test kernel is built with CONFIG_COMPAT enabled.
+
+- Holding true the above, ARM KSFT tests can be run within the KSelfTest
+  framework using standard Linux top-level-makefile targets. Please set
+  $(CROSS_COMPILE) to 'arm-linux-gnueabi-' or 'arm-linux-gnueabihf-'.
+
+      $ make TARGETS=arm kselftest-clean
+      $ make $(CROSS_COMPILE) TARGETS=arm kselftest
+
+      or
+
+      $ make $(CROSS_COMPILE) -C tools/testing/selftests TARGETS=arm \
+		INSTALL_PATH=<your-installation-path> install
+
+      or, alternatively, only specific arm/ subtargets can be picked:
+
+      $ make $(CROSS_COMPILE) -C tools/testing/selftests TARGETS=arm \
+		ARM_SUBTARGETS="signal" INSTALL_PATH=<your-installation-path> \
+			install
+
+   Further details on building and running KFST can be found in:
+     Documentation/dev-tools/kselftest.rst
diff --git a/tools/testing/selftests/arm/elf/Makefile b/tools/testing/selftests/arm/elf/Makefile
new file mode 100644
index 000000000000..86636fe02994
--- /dev/null
+++ b/tools/testing/selftests/arm/elf/Makefile
@@ -0,0 +1,6 @@ 
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 ARM Limited
+
+TEST_GEN_PROGS := parse_elf
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/arm/mm/Makefile b/tools/testing/selftests/arm/mm/Makefile
new file mode 100644
index 000000000000..d8bfa45df98c
--- /dev/null
+++ b/tools/testing/selftests/arm/mm/Makefile
@@ -0,0 +1,6 @@ 
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 ARM Limited
+
+TEST_GEN_PROGS := compat_va
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/arm/signal/Makefile b/tools/testing/selftests/arm/signal/Makefile
new file mode 100644
index 000000000000..3540a25de75a
--- /dev/null
+++ b/tools/testing/selftests/arm/signal/Makefile
@@ -0,0 +1,30 @@ 
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024 ARM Limited
+
+# Additional include paths needed by kselftest.h and local headers
+CFLAGS += -D_GNU_SOURCE -std=gnu99 -I.
+
+SRCS := $(filter-out testcases/testcases.c,$(wildcard testcases/*.c))
+PROGS := $(patsubst %.c,%,$(SRCS))
+
+# Generated binaries to be installed by top KSFT script
+TEST_GEN_PROGS := $(notdir $(PROGS))
+
+# Get Kernel headers installed and use them.
+
+# Including KSFT lib.mk here will also mangle the TEST_GEN_PROGS list
+# to account for any OUTPUT target-dirs optionally provided by
+# the toplevel makefile
+include ../../lib.mk
+
+$(TEST_GEN_PROGS): $(PROGS)
+	cp $(PROGS) $(OUTPUT)/
+
+# Common test-unit targets to build common-layout test-cases executables
+# Needs secondary expansion to properly include the testcase c-file in pre-reqs
+COMMON_SOURCES := test_signals.c test_signals_utils.c
+COMMON_HEADERS := test_signals.h test_signals_utils.h
+
+.SECONDEXPANSION:
+$(PROGS): $$@.c ${COMMON_SOURCES} ${COMMON_HEADERS}
+	$(CC) $(CFLAGS) ${@}.c ${COMMON_SOURCES} -o $@