kselftest: arm64: extend toplevel skeleton Makefile
authorCristian Marussi <cristian.marussi@arm.com>
Fri, 25 Oct 2019 17:57:06 +0000 (18:57 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 8 Nov 2019 11:10:30 +0000 (11:10 +0000)
Modify KSFT arm64 toplevel Makefile to maintain arm64 kselftests organized
by subsystem, keeping them into distinct subdirectories under arm64 custom
KSFT directory: tools/testing/selftests/arm64/

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

Fit existing arm64 tags kselftest into this new schema moving them into
their own subdirectory (arm64/tags).

Reviewed-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
tools/testing/selftests/Makefile
tools/testing/selftests/arm64/.gitignore [deleted file]
tools/testing/selftests/arm64/Makefile
tools/testing/selftests/arm64/README [new file with mode: 0644]
tools/testing/selftests/arm64/run_tags_test.sh [deleted file]
tools/testing/selftests/arm64/tags/.gitignore [new file with mode: 0644]
tools/testing/selftests/arm64/tags/Makefile [new file with mode: 0644]
tools/testing/selftests/arm64/tags/run_tags_test.sh [new file with mode: 0755]
tools/testing/selftests/arm64/tags/tags_test.c [new file with mode: 0644]
tools/testing/selftests/arm64/tags_test.c [deleted file]

index 4cdbae6f4e61b39083182bcece354a7e381ac6a8..a740198e07d7f471bf298b804ae9e0e7e985e8a9 100644 (file)
@@ -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/.gitignore b/tools/testing/selftests/arm64/.gitignore
deleted file mode 100644 (file)
index e8fae8d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-tags_test
index f9f79fb272f016e3259b20f94492d5adc21672b8..cd27ca6892242e1b052afaeb4d99cb6b8a4b1df8 100644 (file)
@@ -1,12 +1,66 @@
 # SPDX-License-Identifier: GPL-2.0
 
-# ARCH can be overridden by the user for cross compiling
+# When ARCH not overridden for crosscompiling, lookup machine
 ARCH ?= $(shell uname -m 2>/dev/null || echo not)
 
 ifneq (,$(filter $(ARCH),aarch64 arm64))
-CFLAGS += -I../../../../usr/include/
-TEST_GEN_PROGS := tags_test
-TEST_PROGS := run_tags_test.sh
+ARM64_SUBTARGETS ?= tags
+else
+ARM64_SUBTARGETS :=
 endif
 
-include ../lib.mk
+CFLAGS := -Wall -O2 -g
+
+# 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/
+
+# 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 CFLAGS
+export top_srcdir
+
+all:
+       @for DIR in $(ARM64_SUBTARGETS); do                             \
+               BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
+               mkdir -p $$BUILD_TARGET;                        \
+               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
+       done
+
+install: all
+       @for DIR in $(ARM64_SUBTARGETS); do                             \
+               BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
+               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
+       done
+
+run_tests: all
+       @for DIR in $(ARM64_SUBTARGETS); 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 $(ARM64_SUBTARGETS); do                             \
+               BUILD_TARGET=$(OUTPUT)/$$DIR;                   \
+               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;         \
+       done
+
+clean:
+       @for DIR in $(ARM64_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/arm64/README b/tools/testing/selftests/arm64/README
new file mode 100644 (file)
index 0000000..a1badd8
--- /dev/null
@@ -0,0 +1,25 @@
+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
+
+      or, alternatively, only specific arm64/ subtargets can be picked:
+
+      $ make -C tools/testing/selftests TARGETS=arm64 ARM64_SUBTARGETS="tags 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/arm64/run_tags_test.sh b/tools/testing/selftests/arm64/run_tags_test.sh
deleted file mode 100755 (executable)
index 745f113..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0
-
-echo "--------------------"
-echo "running tags test"
-echo "--------------------"
-./tags_test
-if [ $? -ne 0 ]; then
-       echo "[FAIL]"
-else
-       echo "[PASS]"
-fi
diff --git a/tools/testing/selftests/arm64/tags/.gitignore b/tools/testing/selftests/arm64/tags/.gitignore
new file mode 100644 (file)
index 0000000..e8fae8d
--- /dev/null
@@ -0,0 +1 @@
+tags_test
diff --git a/tools/testing/selftests/arm64/tags/Makefile b/tools/testing/selftests/arm64/tags/Makefile
new file mode 100644 (file)
index 0000000..41cb750
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+CFLAGS += -I../../../../../usr/include/
+TEST_GEN_PROGS := tags_test
+TEST_PROGS := run_tags_test.sh
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/arm64/tags/run_tags_test.sh b/tools/testing/selftests/arm64/tags/run_tags_test.sh
new file mode 100755 (executable)
index 0000000..745f113
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+echo "--------------------"
+echo "running tags test"
+echo "--------------------"
+./tags_test
+if [ $? -ne 0 ]; then
+       echo "[FAIL]"
+else
+       echo "[PASS]"
+fi
diff --git a/tools/testing/selftests/arm64/tags/tags_test.c b/tools/testing/selftests/arm64/tags/tags_test.c
new file mode 100644 (file)
index 0000000..5701163
--- /dev/null
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/prctl.h>
+#include <sys/utsname.h>
+
+#define SHIFT_TAG(tag)         ((uint64_t)(tag) << 56)
+#define SET_TAG(ptr, tag)      (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
+                                       SHIFT_TAG(tag))
+
+int main(void)
+{
+       static int tbi_enabled = 0;
+       unsigned long tag = 0;
+       struct utsname *ptr;
+       int err;
+
+       if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
+               tbi_enabled = 1;
+       ptr = (struct utsname *)malloc(sizeof(*ptr));
+       if (tbi_enabled)
+               tag = 0x42;
+       ptr = (struct utsname *)SET_TAG(ptr, tag);
+       err = uname(ptr);
+       free(ptr);
+
+       return err;
+}
diff --git a/tools/testing/selftests/arm64/tags_test.c b/tools/testing/selftests/arm64/tags_test.c
deleted file mode 100644 (file)
index 5701163..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <sys/prctl.h>
-#include <sys/utsname.h>
-
-#define SHIFT_TAG(tag)         ((uint64_t)(tag) << 56)
-#define SET_TAG(ptr, tag)      (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \
-                                       SHIFT_TAG(tag))
-
-int main(void)
-{
-       static int tbi_enabled = 0;
-       unsigned long tag = 0;
-       struct utsname *ptr;
-       int err;
-
-       if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == 0)
-               tbi_enabled = 1;
-       ptr = (struct utsname *)malloc(sizeof(*ptr));
-       if (tbi_enabled)
-               tag = 0x42;
-       ptr = (struct utsname *)SET_TAG(ptr, tag);
-       err = uname(ptr);
-       free(ptr);
-
-       return err;
-}