selftests/powerpc: Fix TM tests when CPU 0 is offline
authorMichael Ellerman <mpe@ellerman.id.au>
Thu, 13 Aug 2020 01:34:43 +0000 (11:34 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 8 Sep 2020 12:23:42 +0000 (22:23 +1000)
Several of the TM tests fail spuriously if CPU 0 is offline, because
they blindly try to affinitise to CPU 0.

Fix them by picking any online CPU and using that instead.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200813013445.686464-1-mpe@ellerman.id.au
tools/testing/selftests/powerpc/tm/tm-poison.c
tools/testing/selftests/powerpc/tm/tm-trap.c
tools/testing/selftests/powerpc/tm/tm-unavailable.c

index 9775584..29e5f26 100644 (file)
@@ -26,7 +26,7 @@
 
 int tm_poison_test(void)
 {
-       int pid;
+       int cpu, pid;
        cpu_set_t cpuset;
        uint64_t poison = 0xdeadbeefc0dec0fe;
        uint64_t unknown = 0;
@@ -35,10 +35,13 @@ int tm_poison_test(void)
 
        SKIP_IF(!have_htm());
 
-       /* Attach both Child and Parent to CPU 0 */
+       cpu = pick_online_cpu();
+       FAIL_IF(cpu < 0);
+
+       // Attach both Child and Parent to the same CPU
        CPU_ZERO(&cpuset);
-       CPU_SET(0, &cpuset);
-       sched_setaffinity(0, sizeof(cpuset), &cpuset);
+       CPU_SET(cpu, &cpuset);
+       FAIL_IF(sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0);
 
        pid = fork();
        if (!pid) {
index 601f0c1..c75960a 100644 (file)
@@ -247,8 +247,7 @@ void *pong(void *not_used)
 int tm_trap_test(void)
 {
        uint16_t k = 1;
-
-       int rc;
+       int cpu, rc;
 
        pthread_attr_t attr;
        cpu_set_t cpuset;
@@ -267,9 +266,12 @@ int tm_trap_test(void)
        usr1_sa.sa_sigaction = usr1_signal_handler;
        sigaction(SIGUSR1, &usr1_sa, NULL);
 
-       /* Set only CPU 0 in the mask. Both threads will be bound to cpu 0. */
+       cpu = pick_online_cpu();
+       FAIL_IF(cpu < 0);
+
+       // Set only one CPU in the mask. Both threads will be bound to that CPU.
        CPU_ZERO(&cpuset);
-       CPU_SET(0, &cpuset);
+       CPU_SET(cpu, &cpuset);
 
        /* Init pthread attribute */
        rc = pthread_attr_init(&attr);
index 2ca2fcc..a1348a5 100644 (file)
@@ -338,16 +338,19 @@ void test_fp_vec(int fp, int vec, pthread_attr_t *attr)
 
 int tm_unavailable_test(void)
 {
-       int rc, exception; /* FP = 0, VEC = 1, VSX = 2 */
+       int cpu, rc, exception; /* FP = 0, VEC = 1, VSX = 2 */
        pthread_t t1;
        pthread_attr_t attr;
        cpu_set_t cpuset;
 
        SKIP_IF(!have_htm());
 
-       /* Set only CPU 0 in the mask. Both threads will be bound to CPU 0. */
+       cpu = pick_online_cpu();
+       FAIL_IF(cpu < 0);
+
+       // Set only one CPU in the mask. Both threads will be bound to that CPU.
        CPU_ZERO(&cpuset);
-       CPU_SET(0, &cpuset);
+       CPU_SET(cpu, &cpuset);
 
        /* Init pthread attribute. */
        rc = pthread_attr_init(&attr);