powerpc/selftests: Wait all threads to join
authorBreno Leitao <leitao@debian.org>
Tue, 31 Jul 2018 20:55:57 +0000 (17:55 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Nov 2018 08:24:04 +0000 (09:24 +0100)
[ Upstream commit 693b31b2fc1636f0aa7af53136d3b49f6ad9ff39 ]

Test tm-tmspr might exit before all threads stop executing, because it just
waits for the very last thread to join before proceeding/exiting.

This patch makes sure that all threads that were created will join before
proceeding/exiting.

This patch also guarantees that the amount of threads being created is equal
to thread_num.

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/testing/selftests/powerpc/tm/tm-tmspr.c

index 2bda81c7bf2377d7405137fa9b49ad53be742dc5..df1d7d4b1c89f7e0dbcb003f05f5969782403d59 100644 (file)
@@ -98,7 +98,7 @@ void texasr(void *in)
 
 int test_tmspr()
 {
-       pthread_t       thread;
+       pthread_t       *thread;
        int             thread_num;
        unsigned long   i;
 
@@ -107,21 +107,28 @@ int test_tmspr()
        /* To cause some context switching */
        thread_num = 10 * sysconf(_SC_NPROCESSORS_ONLN);
 
+       thread = malloc(thread_num * sizeof(pthread_t));
+       if (thread == NULL)
+               return EXIT_FAILURE;
+
        /* Test TFIAR and TFHAR */
-       for (i = 0 ; i < thread_num ; i += 2){
-               if (pthread_create(&thread, NULL, (void*)tfiar_tfhar, (void *)i))
+       for (i = 0; i < thread_num; i += 2) {
+               if (pthread_create(&thread[i], NULL, (void *)tfiar_tfhar,
+                                  (void *)i))
                        return EXIT_FAILURE;
        }
-       if (pthread_join(thread, NULL) != 0)
-               return EXIT_FAILURE;
-
        /* Test TEXASR */
-       for (i = 0 ; i < thread_num ; i++){
-               if (pthread_create(&thread, NULL, (void*)texasr, (void *)i))
+       for (i = 1; i < thread_num; i += 2) {
+               if (pthread_create(&thread[i], NULL, (void *)texasr, (void *)i))
                        return EXIT_FAILURE;
        }
-       if (pthread_join(thread, NULL) != 0)
-               return EXIT_FAILURE;
+
+       for (i = 0; i < thread_num; i++) {
+               if (pthread_join(thread[i], NULL) != 0)
+                       return EXIT_FAILURE;
+       }
+
+       free(thread);
 
        if (passed)
                return 0;