selftests/powerpc: Skip vmx/vsx/tar/etc tests on older CPUs
authorMichael Ellerman <mpe@ellerman.id.au>
Mon, 3 Aug 2020 02:07:19 +0000 (12:07 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 3 Aug 2020 12:12:41 +0000 (22:12 +1000)
Some of our tests use VSX or newer VMX instructions, so need to be
skipped on older CPUs to avoid SIGILL'ing.

Similarly TAR was added in v2.07, and the PMU event used in the stcx
fail test only works on Power8 or later.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200803020719.96114-1-mpe@ellerman.id.au
tools/testing/selftests/powerpc/math/Makefile
tools/testing/selftests/powerpc/math/vmx_preempt.c
tools/testing/selftests/powerpc/math/vmx_signal.c
tools/testing/selftests/powerpc/math/vmx_syscall.c
tools/testing/selftests/powerpc/math/vsx_preempt.c
tools/testing/selftests/powerpc/pmu/count_stcx_fail.c
tools/testing/selftests/powerpc/ptrace/ptrace-tar.c
tools/testing/selftests/powerpc/ptrace/ptrace-vsx.c
tools/testing/selftests/powerpc/stringloops/Makefile
tools/testing/selftests/powerpc/stringloops/memcmp.c

index 4e2049d..fcc91c2 100644 (file)
@@ -11,9 +11,9 @@ $(OUTPUT)/fpu_syscall: fpu_asm.S
 $(OUTPUT)/fpu_preempt: fpu_asm.S
 $(OUTPUT)/fpu_signal:  fpu_asm.S
 
-$(OUTPUT)/vmx_syscall: vmx_asm.S
-$(OUTPUT)/vmx_preempt: vmx_asm.S
-$(OUTPUT)/vmx_signal: vmx_asm.S
+$(OUTPUT)/vmx_syscall: vmx_asm.S ../utils.c
+$(OUTPUT)/vmx_preempt: vmx_asm.S ../utils.c
+$(OUTPUT)/vmx_signal: vmx_asm.S ../utils.c
 
 $(OUTPUT)/vsx_preempt: CFLAGS += -mvsx
-$(OUTPUT)/vsx_preempt: vsx_asm.S
+$(OUTPUT)/vsx_preempt: vsx_asm.S ../utils.c
index 2e059f1..6761d6c 100644 (file)
@@ -57,6 +57,9 @@ int test_preempt_vmx(void)
        int i, rc, threads;
        pthread_t *tids;
 
+       // vcmpequd used in vmx_asm.S is v2.07
+       SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
+
        threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
        tids = malloc(threads * sizeof(pthread_t));
        FAIL_IF(!tids);
index 785a48e..b340a5c 100644 (file)
@@ -96,6 +96,9 @@ int test_signal_vmx(void)
        void *rc_p;
        pthread_t *tids;
 
+       // vcmpequd used in vmx_asm.S is v2.07
+       SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
+
        threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
        tids = malloc(threads * sizeof(pthread_t));
        FAIL_IF(!tids);
index 9ee293c..03c78df 100644 (file)
@@ -49,9 +49,14 @@ int test_vmx_syscall(void)
         * Setup an environment with much context switching
         */
        pid_t pid2;
-       pid_t pid = fork();
+       pid_t pid;
        int ret;
        int child_ret;
+
+       // vcmpequd used in vmx_asm.S is v2.07
+       SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
+
+       pid = fork();
        FAIL_IF(pid == -1);
 
        pid2 = fork();
index 63de9c6..d1601bb 100644 (file)
@@ -92,6 +92,8 @@ int test_preempt_vsx(void)
        int i, rc, threads;
        pthread_t *tids;
 
+       SKIP_IF(!have_hwcap(PPC_FEATURE_HAS_VSX));
+
        threads = sysconf(_SC_NPROCESSORS_ONLN) * THREAD_FACTOR;
        tids = malloc(threads * sizeof(pthread_t));
        FAIL_IF(!tids);
index 7b4ac45..2980abc 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <sys/prctl.h>
+#include <asm/cputable.h>
 
 #include "event.h"
 #include "utils.h"
@@ -104,6 +105,9 @@ static int test_body(void)
        struct event events[3];
        u64 overhead;
 
+       // The STCX_FAIL event we use works on Power8 or later
+       SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
+
        setup_event(&events[0], PERF_COUNT_HW_INSTRUCTIONS, PERF_TYPE_HARDWARE, "instructions");
        setup_event(&events[1], PERF_COUNT_HW_CPU_CYCLES, PERF_TYPE_HARDWARE, "cycles");
        setup_event(&events[2], PM_STCX_FAIL, PERF_TYPE_RAW, "stcx_fail");
index 58cb1a8..4436ca9 100644 (file)
@@ -78,6 +78,9 @@ int ptrace_tar(void)
        pid_t pid;
        int ret, status;
 
+       // TAR was added in v2.07
+       SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
+
        shm_id = shmget(IPC_PRIVATE, sizeof(int) * 3, 0777|IPC_CREAT);
        pid = fork();
        if (pid < 0) {
index c4fe0e8..cb9875f 100644 (file)
@@ -61,6 +61,8 @@ int ptrace_vsx(void)
        pid_t pid;
        int ret, status, i;
 
+       SKIP_IF(!have_hwcap(PPC_FEATURE_HAS_VSX));
+
        shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
 
        for (i = 0; i < VEC_MAX; i++)
index 7fc0623..9c39f55 100644 (file)
@@ -8,7 +8,7 @@ build_32bit = $(shell if ($(CC) $(CFLAGS) -m32 -o /dev/null memcmp.c >/dev/null
 
 TEST_GEN_PROGS := memcmp_64 strlen
 
-$(OUTPUT)/memcmp_64: memcmp.c
+$(OUTPUT)/memcmp_64: memcmp.c ../utils.c
 $(OUTPUT)/memcmp_64: CFLAGS += -m64 -maltivec
 
 ifeq ($(build_32bit),1)
index e4605ca..979df3d 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <sys/mman.h>
 #include <time.h>
+#include <asm/cputable.h>
 #include "utils.h"
 
 #define SIZE 256
@@ -151,6 +152,11 @@ static int testcase(bool islarge)
 
 static int testcases(void)
 {
+#ifdef __powerpc64__
+       // vcmpequd used in memcmp_64.S is v2.07
+       SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07));
+#endif
+
        testcase(0);
        testcase(1);
        return 0;