Commit d3835bb8fa6758b4f38da3741e206192a6340f90

Authored by Breno Leitao
Committed by Greg Kroah-Hartman
1 parent 3e59ed2e31

powerpc/selftests: Wait all threads to join

[ 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>

Showing 1 changed file with 17 additions and 10 deletions Side-by-side Diff

tools/testing/selftests/powerpc/tm/tm-tmspr.c
... ... @@ -98,7 +98,7 @@
98 98  
99 99 int test_tmspr()
100 100 {
101   - pthread_t thread;
  101 + pthread_t *thread;
102 102 int thread_num;
103 103 unsigned long i;
104 104  
105 105  
106 106  
107 107  
108 108  
... ... @@ -107,21 +107,28 @@
107 107 /* To cause some context switching */
108 108 thread_num = 10 * sysconf(_SC_NPROCESSORS_ONLN);
109 109  
  110 + thread = malloc(thread_num * sizeof(pthread_t));
  111 + if (thread == NULL)
  112 + return EXIT_FAILURE;
  113 +
110 114 /* Test TFIAR and TFHAR */
111   - for (i = 0 ; i < thread_num ; i += 2){
112   - if (pthread_create(&thread, NULL, (void*)tfiar_tfhar, (void *)i))
  115 + for (i = 0; i < thread_num; i += 2) {
  116 + if (pthread_create(&thread[i], NULL, (void *)tfiar_tfhar,
  117 + (void *)i))
113 118 return EXIT_FAILURE;
114 119 }
115   - if (pthread_join(thread, NULL) != 0)
116   - return EXIT_FAILURE;
117   -
118 120 /* Test TEXASR */
119   - for (i = 0 ; i < thread_num ; i++){
120   - if (pthread_create(&thread, NULL, (void*)texasr, (void *)i))
  121 + for (i = 1; i < thread_num; i += 2) {
  122 + if (pthread_create(&thread[i], NULL, (void *)texasr, (void *)i))
121 123 return EXIT_FAILURE;
122 124 }
123   - if (pthread_join(thread, NULL) != 0)
124   - return EXIT_FAILURE;
  125 +
  126 + for (i = 0; i < thread_num; i++) {
  127 + if (pthread_join(thread[i], NULL) != 0)
  128 + return EXIT_FAILURE;
  129 + }
  130 +
  131 + free(thread);
125 132  
126 133 if (passed)
127 134 return 0;