1 /* Copyright (c) 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc.
2    Use is subject to license terms.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */
16 
17 #include <my_global.h>
18 #include <my_sys.h>
19 #include <tap.h>
20 
21 volatile uint32 bad;
22 pthread_mutex_t mutex;
23 
24 void do_tests();
25 
test_concurrently(const char * test,pthread_handler handler,int n,int m)26 void test_concurrently(const char *test, pthread_handler handler, int n, int m)
27 {
28   pthread_t *threads= malloc(n * sizeof(pthread_t));
29   int i;
30   ulonglong now= my_interval_timer();
31 
32   assert(threads);
33   bad= 0;
34 
35   diag("Testing %s with %d threads, %d iterations... ", test, n, m);
36   for (i= 0; i < n; i++)
37   {
38     if (pthread_create(&threads[i], 0, handler, &m) != 0)
39     {
40       diag("Could not create thread");
41       abort();
42     }
43   }
44 
45   for (i= 0; i < n; i++)
46     pthread_join(threads[i], 0);
47 
48   now= my_interval_timer() - now;
49   free(threads);
50   ok(!bad, "tested %s in %g secs (%d)", test, ((double)now)/1e9, bad);
51 }
52 
main(int argc,char ** argv)53 int main(int argc __attribute__((unused)), char **argv)
54 {
55   MY_INIT(argv[0]);
56 
57   if (argv[1] && *argv[1])
58     DBUG_SET_INITIAL(argv[1]);
59 
60   pthread_mutex_init(&mutex, 0);
61 
62 #define CYCLES 30000
63 #define THREADS 30
64 
65   diag("N CPUs: %d", my_getncpus());
66 
67   do_tests();
68 
69   pthread_mutex_destroy(&mutex);
70   my_end(0);
71   return exit_status();
72 }
73 
74