diff mbox series

[v5,01/11] kselftest: arm64: add skeleton Makefile

Message ID 20190902112932.36129-2-cristian.marussi@arm.com (mailing list archive)
State New
Headers show
Series Add arm64/signal initial kselftest support | expand

Commit Message

Cristian Marussi Sept. 2, 2019, 11:29 a.m. UTC
Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
framework; keep these new arm64 KSFT testcases separated into distinct
subdirs inside tools/testing/selftests/arm64/ depending on the specific
subsystem targeted.

Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
location of Kernel headers as installed by KSFT framework.

Merge with

commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
		     tagged pointers to kernel")

while moving such KSFT tags tests inside their own subdirectory
(arm64/tags).

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
v4 --> v5
- rebased on arm64/for-next/core
- merged this patch with KSFT arm64 tags patch, while moving the latter
  into its own subdir
- moved kernel header includes search mechanism from KSFT arm64
  SIGNAL Makefile
- export proper top_srcdir ENV for lib.mk
v3 --> v4
- comment reword
- simplified documentation in README
- dropped README about standalone
---
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/arm64/Makefile        | 70 +++++++++++++++++--
 tools/testing/selftests/arm64/README          | 20 ++++++
 tools/testing/selftests/arm64/tags/Makefile   | 10 +++
 .../arm64/{ => tags}/run_tags_test.sh         |  0
 .../selftests/arm64/{ => tags}/tags_test.c    |  0
 6 files changed, 95 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/arm64/README
 create mode 100644 tools/testing/selftests/arm64/tags/Makefile
 rename tools/testing/selftests/arm64/{ => tags}/run_tags_test.sh (100%)
 rename tools/testing/selftests/arm64/{ => tags}/tags_test.c (100%)

Comments

Amit Daniel Kachhap Sept. 3, 2019, 9:26 a.m. UTC | #1
Hi Cristian,

On 9/2/19 4:59 PM, Cristian Marussi wrote:
> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
> framework; keep these new arm64 KSFT testcases separated into distinct
> subdirs inside tools/testing/selftests/arm64/ depending on the specific
> subsystem targeted.
>
> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
> location of Kernel headers as installed by KSFT framework.
>
> Merge with
>
> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
>                    tagged pointers to kernel")
>
> while moving such KSFT tags tests inside their own subdirectory
> (arm64/tags).
>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> ---
> v4 --> v5
> - rebased on arm64/for-next/core
> - merged this patch with KSFT arm64 tags patch, while moving the latter
>    into its own subdir
> - moved kernel header includes search mechanism from KSFT arm64
>    SIGNAL Makefile
This approach breaks the compilation of individual test cases which need
to export includes individually.

make -C tools/testing/selftests/arm64/signal

../../lib.mk:25: ../../../../scripts/subarch.include: No such file or
directory
Makefile:25: warning: overriding recipe for target 'clean'
../../lib.mk:123: warning: ignoring old recipe for target 'clean'
make: *** No rule to make target '../../../../scripts/subarch.include'.
Stop.

However tags test works well,
make -C tools/testing/selftests/arm64/tags

aarch64-none-linux-gnu-gcc     tags_test.c  -o
/home/amikac01/work/MTE_WORK/linux-server/linux/tools/testing/selftests/arm64/tags/tags_test


Thanks,
Amit Daniel

> - export proper top_srcdir ENV for lib.mk
> v3 --> v4
> - comment reword
> - simplified documentation in README
> - dropped README about standalone
> ---
>   tools/testing/selftests/Makefile              |  1 +
>   tools/testing/selftests/arm64/Makefile        | 70 +++++++++++++++++--
>   tools/testing/selftests/arm64/README          | 20 ++++++
>   tools/testing/selftests/arm64/tags/Makefile   | 10 +++
>   .../arm64/{ => tags}/run_tags_test.sh         |  0
>   .../selftests/arm64/{ => tags}/tags_test.c    |  0
>   6 files changed, 95 insertions(+), 6 deletions(-)
>   create mode 100644 tools/testing/selftests/arm64/README
>   create mode 100644 tools/testing/selftests/arm64/tags/Makefile
>   rename tools/testing/selftests/arm64/{ => tags}/run_tags_test.sh (100%)
>   rename tools/testing/selftests/arm64/{ => tags}/tags_test.c (100%)
>
> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
> index 25b43a8c2b15..1722dae9381a 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -1,5 +1,6 @@
>   # SPDX-License-Identifier: GPL-2.0
>   TARGETS = android
> +TARGETS += arm64
>   TARGETS += bpf
>   TARGETS += breakpoints
>   TARGETS += capabilities
> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
> index a61b2e743e99..5dbb0ffdfc9a 100644
> --- a/tools/testing/selftests/arm64/Makefile
> +++ b/tools/testing/selftests/arm64/Makefile
> @@ -1,11 +1,69 @@
>   # SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2019 ARM Limited
>
> -# ARCH can be overridden by the user for cross compiling
> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
> +# When ARCH not overridden for crosscompiling, lookup machine
> +ARCH ?= $(shell uname -m)
> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>
> -ifneq (,$(filter $(ARCH),aarch64 arm64))
> -TEST_GEN_PROGS := tags_test
> -TEST_PROGS := run_tags_test.sh
> +ifeq ("x$(ARCH)", "xarm64")
> +SUBDIRS := tags
> +else
> +SUBDIRS :=
>   endif
>
> -include ../lib.mk
> +CFLAGS := -Wall -O2 -g
> +
> +# A proper top_srcdir is needed by KSFT(lib.mk)
> +top_srcdir = ../../../../..
> +
> +# Additional include paths needed by kselftest.h and local headers
> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
> +
> +# Guessing where the Kernel headers could have been installed
> +# depending on ENV config
> +ifeq ($(KBUILD_OUTPUT),)
> +khdr_dir = $(top_srcdir)/usr/include
> +else
> +# the KSFT preferred location when KBUILD_OUTPUT is set
> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
> +endif
> +
> +CFLAGS += -I$(khdr_dir)
> +
> +export CC
> +export CFLAGS
> +export top_srcdir
> +
> +all:
> +     @for DIR in $(SUBDIRS); do                              \
> +             BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
> +             mkdir -p $$BUILD_TARGET;                        \
> +             make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
> +     done
> +
> +install: all
> +     @for DIR in $(SUBDIRS); do                              \
> +             BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
> +             make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
> +     done
> +
> +run_tests: all
> +     @for DIR in $(SUBDIRS); do                              \
> +             BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
> +             make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
> +     done
> +
> +# Avoid any output on non arm64 on emit_tests
> +emit_tests: all
> +     @for DIR in $(SUBDIRS); do                              \
> +             BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
> +             make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
> +     done
> +
> +clean:
> +     @for DIR in $(SUBDIRS); 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/arm64/README b/tools/testing/selftests/arm64/README
> new file mode 100644
> index 000000000000..aca892e62a6c
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/README
> @@ -0,0 +1,20 @@
> +KSelfTest ARM64
> +===============
> +
> +- These tests are arm64 specific and so not built or run but just skipped
> +  completely when env-variable ARCH is found to be different than 'arm64'
> +  and `uname -m` reports other than 'aarch64'.
> +
> +- Holding true the above, ARM64 KSFT tests can be run within the KSelfTest
> +  framework using standard Linux top-level-makefile targets:
> +
> +      $ make TARGETS=arm64 kselftest-clean
> +      $ make TARGETS=arm64 kselftest
> +
> +      or
> +
> +      $ make -C tools/testing/selftests TARGETS=arm64 \
> +             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/arm64/tags/Makefile b/tools/testing/selftests/arm64/tags/Makefile
> new file mode 100644
> index 000000000000..76205533135b
> --- /dev/null
> +++ b/tools/testing/selftests/arm64/tags/Makefile
> @@ -0,0 +1,10 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# ARCH can be overridden by the user for cross compiling
> +ARCH ?= $(shell uname -m 2>/dev/null || echo not)
> +
> +ifneq (,$(filter $(ARCH),aarch64 arm64))
> +TEST_GEN_PROGS := tags_test
> +TEST_PROGS := run_tags_test.sh
> +endif
> +
> +include ../../lib.mk
> diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/tags/run_tags_test.sh
> similarity index 100%
> rename from tools/testing/selftests/arm64/run_tags_test.sh
> rename to tools/testing/selftests/arm64/tags/run_tags_test.sh
> diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c
> similarity index 100%
> rename from tools/testing/selftests/arm64/tags_test.c
> rename to tools/testing/selftests/arm64/tags/tags_test.c
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Cristian Marussi Sept. 3, 2019, 9:45 a.m. UTC | #2
Hi Amit

On 03/09/2019 10:26, Amit Kachhap wrote:
> 
> Hi Cristian,
> 
> On 9/2/19 4:59 PM, Cristian Marussi wrote:
>> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
>> framework; keep these new arm64 KSFT testcases separated into distinct
>> subdirs inside tools/testing/selftests/arm64/ depending on the specific
>> subsystem targeted.
>>
>> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
>> location of Kernel headers as installed by KSFT framework.
>>
>> Merge with
>>
>> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
>> 		     tagged pointers to kernel")
>>
>> while moving such KSFT tags tests inside their own subdirectory
>> (arm64/tags).
>>
>> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
>> ---
>> v4 --> v5
>> - rebased on arm64/for-next/core
>> - merged this patch with KSFT arm64 tags patch, while moving the latter
>>    into its own subdir
>> - moved kernel header includes search mechanism from KSFT arm64
>>    SIGNAL Makefile
> This approach breaks the compilation of individual test cases which need 
> to export includes individually.
> 
> make -C tools/testing/selftests/arm64/signal
> 
> ../../lib.mk:25: ../../../../scripts/subarch.include: No such file or 
> directory
> Makefile:25: warning: overriding recipe for target 'clean'
> ../../lib.mk:123: warning: ignoring old recipe for target 'clean'
> make: *** No rule to make target '../../../../scripts/subarch.include'. 
> Stop.
> 

Having removed standalone mode in signal I was not expecting to be able
to run distinct arm64 subsystems as before with:

$ make -C tools/testing/selftests/arm64/signal
(which was not a standard KSFT thing)

but only using standard targets way like:

$ make -C tools/testing/selftests TARGETS=arm64 

or 

$ make -C tools/testing/selftests TARGETS=arm64 \
		INSTALL_PATH=<your-installation-path> install

or

$ make TARGETS=arm64 kselftest

which runs all tests inside arm64 as a whole.
(I should have changed arm64 README accordingly)


> However tags test works well,
> make -C tools/testing/selftests/arm64/tags
> 
> aarch64-none-linux-gnu-gcc     tags_test.c  -o 
> /home/amikac01/work/MTE_WORK/linux-server/linux/tools/testing/selftests/arm64/tags/tags_test
> 

But I'll have a look why tags expose different behavior.

> 
> Thanks,
> Amit Daniel


Thanks

Cristian
> 
>> - export proper top_srcdir ENV for lib.mk
>> v3 --> v4
>> - comment reword
>> - simplified documentation in README
>> - dropped README about standalone
>> ---
>>   tools/testing/selftests/Makefile              |  1 +
>>   tools/testing/selftests/arm64/Makefile        | 70 +++++++++++++++++--
>>   tools/testing/selftests/arm64/README          | 20 ++++++
>>   tools/testing/selftests/arm64/tags/Makefile   | 10 +++
>>   .../arm64/{ => tags}/run_tags_test.sh         |  0
>>   .../selftests/arm64/{ => tags}/tags_test.c    |  0
>>   6 files changed, 95 insertions(+), 6 deletions(-)
>>   create mode 100644 tools/testing/selftests/arm64/README
>>   create mode 100644 tools/testing/selftests/arm64/tags/Makefile
>>   rename tools/testing/selftests/arm64/{ => tags}/run_tags_test.sh (100%)
>>   rename tools/testing/selftests/arm64/{ => tags}/tags_test.c (100%)
>>
>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>> index 25b43a8c2b15..1722dae9381a 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -1,5 +1,6 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   TARGETS = android
>> +TARGETS += arm64
>>   TARGETS += bpf
>>   TARGETS += breakpoints
>>   TARGETS += capabilities
>> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
>> index a61b2e743e99..5dbb0ffdfc9a 100644
>> --- a/tools/testing/selftests/arm64/Makefile
>> +++ b/tools/testing/selftests/arm64/Makefile
>> @@ -1,11 +1,69 @@
>>   # SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2019 ARM Limited
>>   
>> -# ARCH can be overridden by the user for cross compiling
>> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>> +# When ARCH not overridden for crosscompiling, lookup machine
>> +ARCH ?= $(shell uname -m)
>> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>>   
>> -ifneq (,$(filter $(ARCH),aarch64 arm64))
>> -TEST_GEN_PROGS := tags_test
>> -TEST_PROGS := run_tags_test.sh
>> +ifeq ("x$(ARCH)", "xarm64")
>> +SUBDIRS := tags
>> +else
>> +SUBDIRS :=
>>   endif
>>   
>> -include ../lib.mk
>> +CFLAGS := -Wall -O2 -g
>> +
>> +# A proper top_srcdir is needed by KSFT(lib.mk)
>> +top_srcdir = ../../../../..
>> +
>> +# Additional include paths needed by kselftest.h and local headers
>> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
>> +
>> +# Guessing where the Kernel headers could have been installed
>> +# depending on ENV config
>> +ifeq ($(KBUILD_OUTPUT),)
>> +khdr_dir = $(top_srcdir)/usr/include
>> +else
>> +# the KSFT preferred location when KBUILD_OUTPUT is set
>> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
>> +endif
>> +
>> +CFLAGS += -I$(khdr_dir)
>> +
>> +export CC
>> +export CFLAGS
>> +export top_srcdir
>> +
>> +all:
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		mkdir -p $$BUILD_TARGET;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +install: all
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +run_tests: all
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +# Avoid any output on non arm64 on emit_tests
>> +emit_tests: all
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +clean:
>> +	@for DIR in $(SUBDIRS); 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/arm64/README b/tools/testing/selftests/arm64/README
>> new file mode 100644
>> index 000000000000..aca892e62a6c
>> --- /dev/null
>> +++ b/tools/testing/selftests/arm64/README
>> @@ -0,0 +1,20 @@
>> +KSelfTest ARM64
>> +===============
>> +
>> +- These tests are arm64 specific and so not built or run but just skipped
>> +  completely when env-variable ARCH is found to be different than 'arm64'
>> +  and `uname -m` reports other than 'aarch64'.
>> +
>> +- Holding true the above, ARM64 KSFT tests can be run within the KSelfTest
>> +  framework using standard Linux top-level-makefile targets:
>> +
>> +      $ make TARGETS=arm64 kselftest-clean
>> +      $ make TARGETS=arm64 kselftest
>> +
>> +      or
>> +
>> +      $ make -C tools/testing/selftests TARGETS=arm64 \
>> +		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/arm64/tags/Makefile b/tools/testing/selftests/arm64/tags/Makefile
>> new file mode 100644
>> index 000000000000..76205533135b
>> --- /dev/null
>> +++ b/tools/testing/selftests/arm64/tags/Makefile
>> @@ -0,0 +1,10 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +# ARCH can be overridden by the user for cross compiling
>> +ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>> +
>> +ifneq (,$(filter $(ARCH),aarch64 arm64))
>> +TEST_GEN_PROGS := tags_test
>> +TEST_PROGS := run_tags_test.sh
>> +endif
>> +
>> +include ../../lib.mk
>> diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/tags/run_tags_test.sh
>> similarity index 100%
>> rename from tools/testing/selftests/arm64/run_tags_test.sh
>> rename to tools/testing/selftests/arm64/tags/run_tags_test.sh
>> diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c
>> similarity index 100%
>> rename from tools/testing/selftests/arm64/tags_test.c
>> rename to tools/testing/selftests/arm64/tags/tags_test.c
>>
Dave Martin Sept. 4, 2019, 11:47 a.m. UTC | #3
On Mon, Sep 02, 2019 at 12:29:22pm +0100, Cristian Marussi wrote:
> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
> framework; keep these new arm64 KSFT testcases separated into distinct

Nit: this isn't true any more, since the tags tests already added the
arm64 subsystem here.

> subdirs inside tools/testing/selftests/arm64/ depending on the specific
> subsystem targeted.
> 
> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
> location of Kernel headers as installed by KSFT framework.

This:

> Merge with
> 
> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
> 		     tagged pointers to kernel")
> 
> while moving such KSFT tags tests inside their own subdirectory
> (arm64/tags).

...could be put under the tearoff, but it doesn't really belong in the
commit message IMHO.

I suggest rewriting the commit message to reflect the current
situation (but it can be kept brief).

Basically, what this patch now seems to do is to prepare for adding
more arm64 tests, by moving the tags tests into their own subdirectory
and extending the existing skeleton Makefile as appropriate.

> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> ---
> v4 --> v5
> - rebased on arm64/for-next/core
> - merged this patch with KSFT arm64 tags patch, while moving the latter
>   into its own subdir
> - moved kernel header includes search mechanism from KSFT arm64
>   SIGNAL Makefile
> - export proper top_srcdir ENV for lib.mk
> v3 --> v4
> - comment reword
> - simplified documentation in README
> - dropped README about standalone
> ---

[...]

> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
> index a61b2e743e99..5dbb0ffdfc9a 100644
> --- a/tools/testing/selftests/arm64/Makefile
> +++ b/tools/testing/selftests/arm64/Makefile
> @@ -1,11 +1,69 @@
>  # SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2019 ARM Limited

Change of copyright?  This isn't pure Arm IP upstream IIUC.

Maybe just drop it: Makefiles don't usually contain significant IP, so
many have no copyright message anyway.

> -# ARCH can be overridden by the user for cross compiling
> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
> +# When ARCH not overridden for crosscompiling, lookup machine
> +ARCH ?= $(shell uname -m)
> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>  
> -ifneq (,$(filter $(ARCH),aarch64 arm64))
> -TEST_GEN_PROGS := tags_test
> -TEST_PROGS := run_tags_test.sh
> +ifeq ("x$(ARCH)", "xarm64")
> +SUBDIRS := tags
> +else
> +SUBDIRS :=
>  endif
>  
> -include ../lib.mk
> +CFLAGS := -Wall -O2 -g
> +
> +# A proper top_srcdir is needed by KSFT(lib.mk)
> +top_srcdir = ../../../../..
> +
> +# Additional include paths needed by kselftest.h and local headers
> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
> +
> +# Guessing where the Kernel headers could have been installed
> +# depending on ENV config
> +ifeq ($(KBUILD_OUTPUT),)
> +khdr_dir = $(top_srcdir)/usr/include
> +else
> +# the KSFT preferred location when KBUILD_OUTPUT is set
> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
> +endif

Looking at this, can we just pass the directory in from the toplevel
"all" rule instead of guessing?

Maybe don't churn this for now though.  It's something that could be
looked at later.

[...]

Apart from the comments above, the patch looks reasonable to me.

Cheers
---Dave
Cristian Marussi Sept. 5, 2019, 1:45 p.m. UTC | #4
On 04/09/2019 12:47, Dave Martin wrote:
> On Mon, Sep 02, 2019 at 12:29:22pm +0100, Cristian Marussi wrote:
>> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
>> framework; keep these new arm64 KSFT testcases separated into distinct
> 
> Nit: this isn't true any more, since the tags tests already added the
> arm64 subsystem here.

Ok
> 
>> subdirs inside tools/testing/selftests/arm64/ depending on the specific
>> subsystem targeted.
>>
>> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
>> location of Kernel headers as installed by KSFT framework.
> 
> This:
> 
>> Merge with
>>
>> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
>> 		     tagged pointers to kernel")
>>
>> while moving such KSFT tags tests inside their own subdirectory
>> (arm64/tags).
> 
> ...could be put under the tearoff, but it doesn't really belong in the
> commit message IMHO.
> 
> I suggest rewriting the commit message to reflect the current
> situation (but it can be kept brief).
> 
> Basically, what this patch now seems to do is to prepare for adding
> more arm64 tests, by moving the tags tests into their own subdirectory
> and extending the existing skeleton Makefile as appropriate.
> 

Ok
>> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
>> ---
>> v4 --> v5
>> - rebased on arm64/for-next/core
>> - merged this patch with KSFT arm64 tags patch, while moving the latter
>>   into its own subdir
>> - moved kernel header includes search mechanism from KSFT arm64
>>   SIGNAL Makefile
>> - export proper top_srcdir ENV for lib.mk
>> v3 --> v4
>> - comment reword
>> - simplified documentation in README
>> - dropped README about standalone
>> ---
> 
> [...]
> 
>> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
>> index a61b2e743e99..5dbb0ffdfc9a 100644
>> --- a/tools/testing/selftests/arm64/Makefile
>> +++ b/tools/testing/selftests/arm64/Makefile
>> @@ -1,11 +1,69 @@
>>  # SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2019 ARM Limited
> 
> Change of copyright?  This isn't pure Arm IP upstream IIUC.
> 
> Maybe just drop it: Makefiles don't usually contain significant IP, so
> many have no copyright message anyway.
> 
Right. I'll drop.
>> -# ARCH can be overridden by the user for cross compiling
>> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>> +# When ARCH not overridden for crosscompiling, lookup machine
>> +ARCH ?= $(shell uname -m)
>> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>>  
>> -ifneq (,$(filter $(ARCH),aarch64 arm64))
>> -TEST_GEN_PROGS := tags_test
>> -TEST_PROGS := run_tags_test.sh
>> +ifeq ("x$(ARCH)", "xarm64")
>> +SUBDIRS := tags
>> +else
>> +SUBDIRS :=
>>  endif
>>  
>> -include ../lib.mk
>> +CFLAGS := -Wall -O2 -g
>> +
>> +# A proper top_srcdir is needed by KSFT(lib.mk)
>> +top_srcdir = ../../../../..
>> +
>> +# Additional include paths needed by kselftest.h and local headers
>> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
>> +
>> +# Guessing where the Kernel headers could have been installed
>> +# depending on ENV config
>> +ifeq ($(KBUILD_OUTPUT),)
>> +khdr_dir = $(top_srcdir)/usr/include
>> +else
>> +# the KSFT preferred location when KBUILD_OUTPUT is set
>> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
>> +endif
> 
> Looking at this, can we just pass the directory in from the toplevel
> "all" rule instead of guessing?
> 
Do you mean toplevel in KSFT ?
I think it's how should be done at the end, but I was trying to keep this series on
arm64/ lands only. (also maybe I'm missing something obvious in KSFT handling of this
situation....even though many other KSFT use built CFLAGS like: -I../../../usr/include
or similar)

> Maybe don't churn this for now though.  It's something that could be
> looked at later.
> 

Ok. I'll leave here and fix it to avoid relative paths...which could be problematic
when exported to lower level Makefiles.

Cheers

Cristian

> [...]
> 
> Apart from the comments above, the patch looks reasonable to me.
> 
> Cheers
> ---Dave
>
Dave Martin Sept. 5, 2019, 2:18 p.m. UTC | #5
On Thu, Sep 05, 2019 at 02:45:39PM +0100, Cristian Marussi wrote:
> On 04/09/2019 12:47, Dave Martin wrote:
> > On Mon, Sep 02, 2019 at 12:29:22pm +0100, Cristian Marussi wrote:
> >> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
> >> framework; keep these new arm64 KSFT testcases separated into distinct
> > 
> > Nit: this isn't true any more, since the tags tests already added the
> > arm64 subsystem here.
> 
> Ok
> > 
> >> subdirs inside tools/testing/selftests/arm64/ depending on the specific
> >> subsystem targeted.
> >>
> >> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
> >> location of Kernel headers as installed by KSFT framework.
> > 
> > This:
> > 
> >> Merge with
> >>
> >> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
> >> 		     tagged pointers to kernel")
> >>
> >> while moving such KSFT tags tests inside their own subdirectory
> >> (arm64/tags).
> > 
> > ...could be put under the tearoff, but it doesn't really belong in the
> > commit message IMHO.
> > 
> > I suggest rewriting the commit message to reflect the current
> > situation (but it can be kept brief).
> > 
> > Basically, what this patch now seems to do is to prepare for adding
> > more arm64 tests, by moving the tags tests into their own subdirectory
> > and extending the existing skeleton Makefile as appropriate.
> > 
> 
> Ok
> >> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> >> ---
> >> v4 --> v5
> >> - rebased on arm64/for-next/core
> >> - merged this patch with KSFT arm64 tags patch, while moving the latter
> >>   into its own subdir
> >> - moved kernel header includes search mechanism from KSFT arm64
> >>   SIGNAL Makefile
> >> - export proper top_srcdir ENV for lib.mk
> >> v3 --> v4
> >> - comment reword
> >> - simplified documentation in README
> >> - dropped README about standalone
> >> ---
> > 
> > [...]
> > 
> >> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
> >> index a61b2e743e99..5dbb0ffdfc9a 100644
> >> --- a/tools/testing/selftests/arm64/Makefile
> >> +++ b/tools/testing/selftests/arm64/Makefile
> >> @@ -1,11 +1,69 @@
> >>  # SPDX-License-Identifier: GPL-2.0
> >> +# Copyright (C) 2019 ARM Limited
> > 
> > Change of copyright?  This isn't pure Arm IP upstream IIUC.
> > 
> > Maybe just drop it: Makefiles don't usually contain significant IP, so
> > many have no copyright message anyway.
> > 
> Right. I'll drop.
> >> -# ARCH can be overridden by the user for cross compiling
> >> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
> >> +# When ARCH not overridden for crosscompiling, lookup machine
> >> +ARCH ?= $(shell uname -m)
> >> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
> >>  
> >> -ifneq (,$(filter $(ARCH),aarch64 arm64))
> >> -TEST_GEN_PROGS := tags_test
> >> -TEST_PROGS := run_tags_test.sh
> >> +ifeq ("x$(ARCH)", "xarm64")
> >> +SUBDIRS := tags
> >> +else
> >> +SUBDIRS :=
> >>  endif
> >>  
> >> -include ../lib.mk
> >> +CFLAGS := -Wall -O2 -g
> >> +
> >> +# A proper top_srcdir is needed by KSFT(lib.mk)
> >> +top_srcdir = ../../../../..
> >> +
> >> +# Additional include paths needed by kselftest.h and local headers
> >> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
> >> +
> >> +# Guessing where the Kernel headers could have been installed
> >> +# depending on ENV config
> >> +ifeq ($(KBUILD_OUTPUT),)
> >> +khdr_dir = $(top_srcdir)/usr/include
> >> +else
> >> +# the KSFT preferred location when KBUILD_OUTPUT is set
> >> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
> >> +endif
> > 
> > Looking at this, can we just pass the directory in from the toplevel
> > "all" rule instead of guessing?
> > 
> Do you mean toplevel in KSFT ?
> I think it's how should be done at the end, but I was trying to keep this series on
> arm64/ lands only. (also maybe I'm missing something obvious in KSFT handling of this
> situation....even though many other KSFT use built CFLAGS like: -I../../../usr/include
> or similar)
> 
> > Maybe don't churn this for now though.  It's something that could be
> > looked at later.
> > 
> 
> Ok. I'll leave here and fix it to avoid relative paths...which could be problematic
> when exported to lower level Makefiles.
> 
> Cheers
> 
> Cristian

Sounds reasonable

Cheers
---Dave
Cristian Marussi Sept. 5, 2019, 5:57 p.m. UTC | #6
Hi Amit

On 03/09/2019 10:26, Amit Kachhap wrote:
> 
> Hi Cristian,
> 
> On 9/2/19 4:59 PM, Cristian Marussi wrote:
>> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
>> framework; keep these new arm64 KSFT testcases separated into distinct
>> subdirs inside tools/testing/selftests/arm64/ depending on the specific
>> subsystem targeted.
>>
>> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
>> location of Kernel headers as installed by KSFT framework.
>>
>> Merge with
>>
>> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
>> 		     tagged pointers to kernel")
>>
>> while moving such KSFT tags tests inside their own subdirectory
>> (arm64/tags).
>>
>> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
>> ---
>> v4 --> v5
>> - rebased on arm64/for-next/core
>> - merged this patch with KSFT arm64 tags patch, while moving the latter
>>    into its own subdir
>> - moved kernel header includes search mechanism from KSFT arm64
>>    SIGNAL Makefile
> This approach breaks the compilation of individual test cases which need 
> to export includes individually.
> 
> make -C tools/testing/selftests/arm64/signal
> 
> ../../lib.mk:25: ../../../../scripts/subarch.include: No such file or 
> directory
> Makefile:25: warning: overriding recipe for target 'clean'
> ../../lib.mk:123: warning: ignoring old recipe for target 'clean'
> make: *** No rule to make target '../../../../scripts/subarch.include'. 
> Stop.
> 
> However tags test works well,
> make -C tools/testing/selftests/arm64/tags
> 
> aarch64-none-linux-gnu-gcc     tags_test.c  -o 
> /home/amikac01/work/MTE_WORK/linux-server/linux/tools/testing/selftests/arm64/tags/tags_test
> 
> 
> Thanks,
> Amit Daniel
> 

So at the end I think I'll opt for the following in V6 regarding the issue of being able to build specific
KSFT arm64 subsystems while properly searching kernel headers (and keeping compatible with the KSFT
framework completely):

- only arm64 toplevel KSFT Makefile searches for the kernel headers location for all and propagates down the info

- you can also now optionally specify which arm64 subsystem to build (to avoid have to build, say, all of signal/
  if you are not interested into....a sort of standalone mode without all the burden of the old standalone mode)

So you can issue:

$ make TARGETS=arm64 kselftest

or similarly:

$ make -C tools/testing/selftests TARGETS=arm64 \
                INSTALL_PATH=<your-installation-path> install

or select subsystems:

$ make -C tools/testing/selftests TARGETS=arm64 SUBTARGETS="tags signal" \
                INSTALL_PATH=<your-installation-path> install

with all of the above looking for the K headers in the proper place and without
duplicating the search code in multiple places. (bugs apart :D)

Thanks

Cristian

>> - export proper top_srcdir ENV for lib.mk
>> v3 --> v4
>> - comment reword
>> - simplified documentation in README
>> - dropped README about standalone
>> ---
>>   tools/testing/selftests/Makefile              |  1 +
>>   tools/testing/selftests/arm64/Makefile        | 70 +++++++++++++++++--
>>   tools/testing/selftests/arm64/README          | 20 ++++++
>>   tools/testing/selftests/arm64/tags/Makefile   | 10 +++
>>   .../arm64/{ => tags}/run_tags_test.sh         |  0
>>   .../selftests/arm64/{ => tags}/tags_test.c    |  0
>>   6 files changed, 95 insertions(+), 6 deletions(-)
>>   create mode 100644 tools/testing/selftests/arm64/README
>>   create mode 100644 tools/testing/selftests/arm64/tags/Makefile
>>   rename tools/testing/selftests/arm64/{ => tags}/run_tags_test.sh (100%)
>>   rename tools/testing/selftests/arm64/{ => tags}/tags_test.c (100%)
>>
>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>> index 25b43a8c2b15..1722dae9381a 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -1,5 +1,6 @@
>>   # SPDX-License-Identifier: GPL-2.0
>>   TARGETS = android
>> +TARGETS += arm64
>>   TARGETS += bpf
>>   TARGETS += breakpoints
>>   TARGETS += capabilities
>> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
>> index a61b2e743e99..5dbb0ffdfc9a 100644
>> --- a/tools/testing/selftests/arm64/Makefile
>> +++ b/tools/testing/selftests/arm64/Makefile
>> @@ -1,11 +1,69 @@
>>   # SPDX-License-Identifier: GPL-2.0
>> +# Copyright (C) 2019 ARM Limited
>>   
>> -# ARCH can be overridden by the user for cross compiling
>> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>> +# When ARCH not overridden for crosscompiling, lookup machine
>> +ARCH ?= $(shell uname -m)
>> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>>   
>> -ifneq (,$(filter $(ARCH),aarch64 arm64))
>> -TEST_GEN_PROGS := tags_test
>> -TEST_PROGS := run_tags_test.sh
>> +ifeq ("x$(ARCH)", "xarm64")
>> +SUBDIRS := tags
>> +else
>> +SUBDIRS :=
>>   endif
>>   
>> -include ../lib.mk
>> +CFLAGS := -Wall -O2 -g
>> +
>> +# A proper top_srcdir is needed by KSFT(lib.mk)
>> +top_srcdir = ../../../../..
>> +
>> +# Additional include paths needed by kselftest.h and local headers
>> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
>> +
>> +# Guessing where the Kernel headers could have been installed
>> +# depending on ENV config
>> +ifeq ($(KBUILD_OUTPUT),)
>> +khdr_dir = $(top_srcdir)/usr/include
>> +else
>> +# the KSFT preferred location when KBUILD_OUTPUT is set
>> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
>> +endif
>> +
>> +CFLAGS += -I$(khdr_dir)
>> +
>> +export CC
>> +export CFLAGS
>> +export top_srcdir
>> +
>> +all:
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		mkdir -p $$BUILD_TARGET;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +install: all
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +run_tests: all
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +# Avoid any output on non arm64 on emit_tests
>> +emit_tests: all
>> +	@for DIR in $(SUBDIRS); do				\
>> +		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
>> +		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
>> +	done
>> +
>> +clean:
>> +	@for DIR in $(SUBDIRS); 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/arm64/README b/tools/testing/selftests/arm64/README
>> new file mode 100644
>> index 000000000000..aca892e62a6c
>> --- /dev/null
>> +++ b/tools/testing/selftests/arm64/README
>> @@ -0,0 +1,20 @@
>> +KSelfTest ARM64
>> +===============
>> +
>> +- These tests are arm64 specific and so not built or run but just skipped
>> +  completely when env-variable ARCH is found to be different than 'arm64'
>> +  and `uname -m` reports other than 'aarch64'.
>> +
>> +- Holding true the above, ARM64 KSFT tests can be run within the KSelfTest
>> +  framework using standard Linux top-level-makefile targets:
>> +
>> +      $ make TARGETS=arm64 kselftest-clean
>> +      $ make TARGETS=arm64 kselftest
>> +
>> +      or
>> +
>> +      $ make -C tools/testing/selftests TARGETS=arm64 \
>> +		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/arm64/tags/Makefile b/tools/testing/selftests/arm64/tags/Makefile
>> new file mode 100644
>> index 000000000000..76205533135b
>> --- /dev/null
>> +++ b/tools/testing/selftests/arm64/tags/Makefile
>> @@ -0,0 +1,10 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +# ARCH can be overridden by the user for cross compiling
>> +ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>> +
>> +ifneq (,$(filter $(ARCH),aarch64 arm64))
>> +TEST_GEN_PROGS := tags_test
>> +TEST_PROGS := run_tags_test.sh
>> +endif
>> +
>> +include ../../lib.mk
>> diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/tags/run_tags_test.sh
>> similarity index 100%
>> rename from tools/testing/selftests/arm64/run_tags_test.sh
>> rename to tools/testing/selftests/arm64/tags/run_tags_test.sh
>> diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c
>> similarity index 100%
>> rename from tools/testing/selftests/arm64/tags_test.c
>> rename to tools/testing/selftests/arm64/tags/tags_test.c
>>
Amit Daniel Kachhap Sept. 9, 2019, 12:42 p.m. UTC | #7
Hi,

On 9/5/19 11:27 PM, Cristian Marussi wrote:
> Hi Amit
>
> On 03/09/2019 10:26, Amit Kachhap wrote:
>>
>> Hi Cristian,
>>
>> On 9/2/19 4:59 PM, Cristian Marussi wrote:
>>> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
>>> framework; keep these new arm64 KSFT testcases separated into distinct
>>> subdirs inside tools/testing/selftests/arm64/ depending on the specific
>>> subsystem targeted.
>>>
>>> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
>>> location of Kernel headers as installed by KSFT framework.
>>>
>>> Merge with
>>>
>>> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
>>>                  tagged pointers to kernel")
>>>
>>> while moving such KSFT tags tests inside their own subdirectory
>>> (arm64/tags).
>>>
>>> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
>>> ---
>>> v4 --> v5
>>> - rebased on arm64/for-next/core
>>> - merged this patch with KSFT arm64 tags patch, while moving the latter
>>>     into its own subdir
>>> - moved kernel header includes search mechanism from KSFT arm64
>>>     SIGNAL Makefile
>> This approach breaks the compilation of individual test cases which need
>> to export includes individually.
>>
>> make -C tools/testing/selftests/arm64/signal
>>
>> ../../lib.mk:25: ../../../../scripts/subarch.include: No such file or
>> directory
>> Makefile:25: warning: overriding recipe for target 'clean'
>> ../../lib.mk:123: warning: ignoring old recipe for target 'clean'
>> make: *** No rule to make target '../../../../scripts/subarch.include'.
>> Stop.
>>
>> However tags test works well,
>> make -C tools/testing/selftests/arm64/tags
>>
>> aarch64-none-linux-gnu-gcc     tags_test.c  -o
>> /home/amikac01/work/MTE_WORK/linux-server/linux/tools/testing/selftests/arm64/tags/tags_test
>>
>>
>> Thanks,
>> Amit Daniel
>>
>
> So at the end I think I'll opt for the following in V6 regarding the issue of being able to build specific
> KSFT arm64 subsystems while properly searching kernel headers (and keeping compatible with the KSFT
> framework completely):
>
> - only arm64 toplevel KSFT Makefile searches for the kernel headers location for all and propagates down the info
>
> - you can also now optionally specify which arm64 subsystem to build (to avoid have to build, say, all of signal/
>    if you are not interested into....a sort of standalone mode without all the burden of the old standalone mode)
ok.
>
> So you can issue:
>
> $ make TARGETS=arm64 kselftest
>
> or similarly:
>
> $ make -C tools/testing/selftests TARGETS=arm64 \
>                  INSTALL_PATH=<your-installation-path> install
>
> or select subsystems:
>
> $ make -C tools/testing/selftests TARGETS=arm64 SUBTARGETS="tags signal" \
>                  INSTALL_PATH=<your-installation-path> install
This option will be useful as it is better to compile just one subtarget
in development phase.

Thanks,
Amit
>
> with all of the above looking for the K headers in the proper place and without
> duplicating the search code in multiple places. (bugs apart :D)
>
> Thanks
>
> Cristian
>
>>> - export proper top_srcdir ENV for lib.mk
>>> v3 --> v4
>>> - comment reword
>>> - simplified documentation in README
>>> - dropped README about standalone
>>> ---
>>>    tools/testing/selftests/Makefile              |  1 +
>>>    tools/testing/selftests/arm64/Makefile        | 70 +++++++++++++++++--
>>>    tools/testing/selftests/arm64/README          | 20 ++++++
>>>    tools/testing/selftests/arm64/tags/Makefile   | 10 +++
>>>    .../arm64/{ => tags}/run_tags_test.sh         |  0
>>>    .../selftests/arm64/{ => tags}/tags_test.c    |  0
>>>    6 files changed, 95 insertions(+), 6 deletions(-)
>>>    create mode 100644 tools/testing/selftests/arm64/README
>>>    create mode 100644 tools/testing/selftests/arm64/tags/Makefile
>>>    rename tools/testing/selftests/arm64/{ => tags}/run_tags_test.sh (100%)
>>>    rename tools/testing/selftests/arm64/{ => tags}/tags_test.c (100%)
>>>
>>> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
>>> index 25b43a8c2b15..1722dae9381a 100644
>>> --- a/tools/testing/selftests/Makefile
>>> +++ b/tools/testing/selftests/Makefile
>>> @@ -1,5 +1,6 @@
>>>    # SPDX-License-Identifier: GPL-2.0
>>>    TARGETS = android
>>> +TARGETS += arm64
>>>    TARGETS += bpf
>>>    TARGETS += breakpoints
>>>    TARGETS += capabilities
>>> diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
>>> index a61b2e743e99..5dbb0ffdfc9a 100644
>>> --- a/tools/testing/selftests/arm64/Makefile
>>> +++ b/tools/testing/selftests/arm64/Makefile
>>> @@ -1,11 +1,69 @@
>>>    # SPDX-License-Identifier: GPL-2.0
>>> +# Copyright (C) 2019 ARM Limited
>>>
>>> -# ARCH can be overridden by the user for cross compiling
>>> -ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>>> +# When ARCH not overridden for crosscompiling, lookup machine
>>> +ARCH ?= $(shell uname -m)
>>> +ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
>>>
>>> -ifneq (,$(filter $(ARCH),aarch64 arm64))
>>> -TEST_GEN_PROGS := tags_test
>>> -TEST_PROGS := run_tags_test.sh
>>> +ifeq ("x$(ARCH)", "xarm64")
>>> +SUBDIRS := tags
>>> +else
>>> +SUBDIRS :=
>>>    endif
>>>
>>> -include ../lib.mk
>>> +CFLAGS := -Wall -O2 -g
>>> +
>>> +# A proper top_srcdir is needed by KSFT(lib.mk)
>>> +top_srcdir = ../../../../..
>>> +
>>> +# Additional include paths needed by kselftest.h and local headers
>>> +CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
>>> +
>>> +# Guessing where the Kernel headers could have been installed
>>> +# depending on ENV config
>>> +ifeq ($(KBUILD_OUTPUT),)
>>> +khdr_dir = $(top_srcdir)/usr/include
>>> +else
>>> +# the KSFT preferred location when KBUILD_OUTPUT is set
>>> +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
>>> +endif
>>> +
>>> +CFLAGS += -I$(khdr_dir)
>>> +
>>> +export CC
>>> +export CFLAGS
>>> +export top_srcdir
>>> +
>>> +all:
>>> +   @for DIR in $(SUBDIRS); do                              \
>>> +           BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
>>> +           mkdir -p $$BUILD_TARGET;                        \
>>> +           make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
>>> +   done
>>> +
>>> +install: all
>>> +   @for DIR in $(SUBDIRS); do                              \
>>> +           BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
>>> +           make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
>>> +   done
>>> +
>>> +run_tests: all
>>> +   @for DIR in $(SUBDIRS); do                              \
>>> +           BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
>>> +           make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
>>> +   done
>>> +
>>> +# Avoid any output on non arm64 on emit_tests
>>> +emit_tests: all
>>> +   @for DIR in $(SUBDIRS); do                              \
>>> +           BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
>>> +           make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
>>> +   done
>>> +
>>> +clean:
>>> +   @for DIR in $(SUBDIRS); 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/arm64/README b/tools/testing/selftests/arm64/README
>>> new file mode 100644
>>> index 000000000000..aca892e62a6c
>>> --- /dev/null
>>> +++ b/tools/testing/selftests/arm64/README
>>> @@ -0,0 +1,20 @@
>>> +KSelfTest ARM64
>>> +===============
>>> +
>>> +- These tests are arm64 specific and so not built or run but just skipped
>>> +  completely when env-variable ARCH is found to be different than 'arm64'
>>> +  and `uname -m` reports other than 'aarch64'.
>>> +
>>> +- Holding true the above, ARM64 KSFT tests can be run within the KSelfTest
>>> +  framework using standard Linux top-level-makefile targets:
>>> +
>>> +      $ make TARGETS=arm64 kselftest-clean
>>> +      $ make TARGETS=arm64 kselftest
>>> +
>>> +      or
>>> +
>>> +      $ make -C tools/testing/selftests TARGETS=arm64 \
>>> +           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/arm64/tags/Makefile b/tools/testing/selftests/arm64/tags/Makefile
>>> new file mode 100644
>>> index 000000000000..76205533135b
>>> --- /dev/null
>>> +++ b/tools/testing/selftests/arm64/tags/Makefile
>>> @@ -0,0 +1,10 @@
>>> +# SPDX-License-Identifier: GPL-2.0
>>> +# ARCH can be overridden by the user for cross compiling
>>> +ARCH ?= $(shell uname -m 2>/dev/null || echo not)
>>> +
>>> +ifneq (,$(filter $(ARCH),aarch64 arm64))
>>> +TEST_GEN_PROGS := tags_test
>>> +TEST_PROGS := run_tags_test.sh
>>> +endif
>>> +
>>> +include ../../lib.mk
>>> diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/tags/run_tags_test.sh
>>> similarity index 100%
>>> rename from tools/testing/selftests/arm64/run_tags_test.sh
>>> rename to tools/testing/selftests/arm64/tags/run_tags_test.sh
>>> diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c
>>> similarity index 100%
>>> rename from tools/testing/selftests/arm64/tags_test.c
>>> rename to tools/testing/selftests/arm64/tags/tags_test.c
>>>
>
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Dave Martin Sept. 16, 2019, 11:41 a.m. UTC | #8
On Mon, Sep 09, 2019 at 12:42:06PM +0000, Amit Kachhap wrote:
> Hi,
> 
> On 9/5/19 11:27 PM, Cristian Marussi wrote:
> > Hi Amit
> >
> > On 03/09/2019 10:26, Amit Kachhap wrote:
> >>
> >> Hi Cristian,
> >>
> >> On 9/2/19 4:59 PM, Cristian Marussi wrote:
> >>> Add a new arm64-specific empty subsystem amongst TARGETS of KSFT build
> >>> framework; keep these new arm64 KSFT testcases separated into distinct
> >>> subdirs inside tools/testing/selftests/arm64/ depending on the specific
> >>> subsystem targeted.
> >>>
> >>> Add into toplevel arm64 KSFT Makefile a mechanism to guess the effective
> >>> location of Kernel headers as installed by KSFT framework.
> >>>
> >>> Merge with
> >>>
> >>> commit 9ce1263033cd ("selftests, arm64: add a selftest for passing
> >>>                  tagged pointers to kernel")
> >>>
> >>> while moving such KSFT tags tests inside their own subdirectory
> >>> (arm64/tags).
> >>>
> >>> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> >>> ---
> >>> v4 --> v5
> >>> - rebased on arm64/for-next/core
> >>> - merged this patch with KSFT arm64 tags patch, while moving the latter
> >>>     into its own subdir
> >>> - moved kernel header includes search mechanism from KSFT arm64
> >>>     SIGNAL Makefile
> >> This approach breaks the compilation of individual test cases which need
> >> to export includes individually.
> >>
> >> make -C tools/testing/selftests/arm64/signal
> >>
> >> ../../lib.mk:25: ../../../../scripts/subarch.include: No such file or
> >> directory
> >> Makefile:25: warning: overriding recipe for target 'clean'
> >> ../../lib.mk:123: warning: ignoring old recipe for target 'clean'
> >> make: *** No rule to make target '../../../../scripts/subarch.include'.
> >> Stop.
> >>
> >> However tags test works well,
> >> make -C tools/testing/selftests/arm64/tags
> >>
> >> aarch64-none-linux-gnu-gcc     tags_test.c  -o
> >> /home/amikac01/work/MTE_WORK/linux-server/linux/tools/testing/selftests/arm64/tags/tags_test
> >>
> >>
> >> Thanks,
> >> Amit Daniel
> >>
> >
> > So at the end I think I'll opt for the following in V6 regarding the issue of being able to build specific
> > KSFT arm64 subsystems while properly searching kernel headers (and keeping compatible with the KSFT
> > framework completely):
> >
> > - only arm64 toplevel KSFT Makefile searches for the kernel headers location for all and propagates down the info
> >
> > - you can also now optionally specify which arm64 subsystem to build (to avoid have to build, say, all of signal/
> >    if you are not interested into....a sort of standalone mode without all the burden of the old standalone mode)
> ok.
> >
> > So you can issue:
> >
> > $ make TARGETS=arm64 kselftest
> >
> > or similarly:
> >
> > $ make -C tools/testing/selftests TARGETS=arm64 \
> >                  INSTALL_PATH=<your-installation-path> install
> >
> > or select subsystems:
> >
> > $ make -C tools/testing/selftests TARGETS=arm64 SUBTARGETS="tags signal" \
> >                  INSTALL_PATH=<your-installation-path> install
> This option will be useful as it is better to compile just one subtarget
> in development phase.

Agreed, this seems a reasonable approach.

[...]

Cheers
---Dave
diff mbox series

Patch

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 25b43a8c2b15..1722dae9381a 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -1,5 +1,6 @@ 
 # SPDX-License-Identifier: GPL-2.0
 TARGETS = android
+TARGETS += arm64
 TARGETS += bpf
 TARGETS += breakpoints
 TARGETS += capabilities
diff --git a/tools/testing/selftests/arm64/Makefile b/tools/testing/selftests/arm64/Makefile
index a61b2e743e99..5dbb0ffdfc9a 100644
--- a/tools/testing/selftests/arm64/Makefile
+++ b/tools/testing/selftests/arm64/Makefile
@@ -1,11 +1,69 @@ 
 # SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2019 ARM Limited
 
-# ARCH can be overridden by the user for cross compiling
-ARCH ?= $(shell uname -m 2>/dev/null || echo not)
+# When ARCH not overridden for crosscompiling, lookup machine
+ARCH ?= $(shell uname -m)
+ARCH := $(shell echo $(ARCH) | sed -e s/aarch64/arm64/)
 
-ifneq (,$(filter $(ARCH),aarch64 arm64))
-TEST_GEN_PROGS := tags_test
-TEST_PROGS := run_tags_test.sh
+ifeq ("x$(ARCH)", "xarm64")
+SUBDIRS := tags
+else
+SUBDIRS :=
 endif
 
-include ../lib.mk
+CFLAGS := -Wall -O2 -g
+
+# A proper top_srcdir is needed by KSFT(lib.mk)
+top_srcdir = ../../../../..
+
+# Additional include paths needed by kselftest.h and local headers
+CFLAGS += -I$(top_srcdir)/tools/testing/selftests/
+
+# Guessing where the Kernel headers could have been installed
+# depending on ENV config
+ifeq ($(KBUILD_OUTPUT),)
+khdr_dir = $(top_srcdir)/usr/include
+else
+# the KSFT preferred location when KBUILD_OUTPUT is set
+khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include
+endif
+
+CFLAGS += -I$(khdr_dir)
+
+export CC
+export CFLAGS
+export top_srcdir
+
+all:
+	@for DIR in $(SUBDIRS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		mkdir -p $$BUILD_TARGET;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+install: all
+	@for DIR in $(SUBDIRS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+run_tests: all
+	@for DIR in $(SUBDIRS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+# Avoid any output on non arm64 on emit_tests
+emit_tests: all
+	@for DIR in $(SUBDIRS); do				\
+		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
+		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
+	done
+
+clean:
+	@for DIR in $(SUBDIRS); 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/arm64/README b/tools/testing/selftests/arm64/README
new file mode 100644
index 000000000000..aca892e62a6c
--- /dev/null
+++ b/tools/testing/selftests/arm64/README
@@ -0,0 +1,20 @@ 
+KSelfTest ARM64
+===============
+
+- These tests are arm64 specific and so not built or run but just skipped
+  completely when env-variable ARCH is found to be different than 'arm64'
+  and `uname -m` reports other than 'aarch64'.
+
+- Holding true the above, ARM64 KSFT tests can be run within the KSelfTest
+  framework using standard Linux top-level-makefile targets:
+
+      $ make TARGETS=arm64 kselftest-clean
+      $ make TARGETS=arm64 kselftest
+
+      or
+
+      $ make -C tools/testing/selftests TARGETS=arm64 \
+		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/arm64/tags/Makefile b/tools/testing/selftests/arm64/tags/Makefile
new file mode 100644
index 000000000000..76205533135b
--- /dev/null
+++ b/tools/testing/selftests/arm64/tags/Makefile
@@ -0,0 +1,10 @@ 
+# SPDX-License-Identifier: GPL-2.0
+# ARCH can be overridden by the user for cross compiling
+ARCH ?= $(shell uname -m 2>/dev/null || echo not)
+
+ifneq (,$(filter $(ARCH),aarch64 arm64))
+TEST_GEN_PROGS := tags_test
+TEST_PROGS := run_tags_test.sh
+endif
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/tags/run_tags_test.sh
similarity index 100%
rename from tools/testing/selftests/arm64/run_tags_test.sh
rename to tools/testing/selftests/arm64/tags/run_tags_test.sh
diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c
similarity index 100%
rename from tools/testing/selftests/arm64/tags_test.c
rename to tools/testing/selftests/arm64/tags/tags_test.c