]> git.ipfire.org Git - thirdparty/gcc.git/blob - libvtv/testsuite/register_pair_mt.cc
Commit the vtable verification feature.
[thirdparty/gcc.git] / libvtv / testsuite / register_pair_mt.cc
1 #include "vtv_utils.h"
2 #include "vtv_rts.h"
3 #include "pthread.h"
4 #include <stdio.h>
5
6
7 /* Multi-threaded test for calls to RegisterPair */
8
9 /* This configuration will test mostly inserting of elements that are already inserted since
10 the number of repeats is 10 */
11
12 /* This test case may fail depending on the system configuration.
13 Check the value of /proc/sys/vm/max_map_count and fix by doing
14 Ex: sudo sh -c "echo 131060 > /proc/sys/vm/max_map_count" */
15
16 #define NUM_MAPS 200
17 #define ELEMENTS_PER_MAP 100
18 #define NUM_REPEATS 10
19
20 #define NUM_THREADS 9
21
22 /* This variable has to be put in rel.ro */
23 void * volatile maps[NUM_MAPS] VTV_PROTECTED_VAR;
24
25 struct fake_vt {
26 void * fake_vfp [4];
27 };
28 void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP];
29
30 volatile int current_map = -1;
31 volatile int threads_completed_it = 0;
32
33 void * do_register_pairs(void *)
34 {
35 for (int k = 0; k < NUM_REPEATS; k++)
36 {
37 int curr_fake_vt = 0;
38 for (int i = 0; i < NUM_MAPS; i++)
39 {
40 while (current_map < (k*NUM_MAPS + i))
41 ;
42
43 __VLTChangePermission(__VLTP_READ_WRITE);
44
45 for (int j = 0; j < ELEMENTS_PER_MAP; j++)
46 {
47 #ifdef VTV_DEBUG
48 __VLTRegisterPair((void **) &maps[i], &fake_vts[curr_fake_vt], 0, 0, 0, 0);
49 #else
50 __VLTRegisterPair((void **) &maps[i], &fake_vts[curr_fake_vt]);
51 #endif
52 __VLTVerifyVtablePointer((void **) &maps[i], &fake_vts[curr_fake_vt]);
53 curr_fake_vt++;
54 }
55
56 __VLTChangePermission(__VLTP_READ_ONLY);
57
58 int old_value;
59 do {
60 old_value = threads_completed_it;
61 } while (!__sync_bool_compare_and_swap(&threads_completed_it, old_value, old_value + 1));
62
63 if (old_value == (NUM_THREADS - 1)) // Only one thread will do this.
64 {
65 threads_completed_it = 0;
66 printf("%c%d", 13, current_map + 1);
67 fflush(stdout);
68 current_map++;
69 }
70 }
71 }
72
73 return NULL;
74 }
75
76
77 int main()
78 {
79 pthread_t thread_ids[NUM_THREADS];
80
81 for (int t = 0; t < NUM_THREADS; t++ )
82 if (pthread_create(&thread_ids[t], NULL, do_register_pairs, NULL) != 0)
83 {
84 printf("failed pthread_create\n");
85 exit(1);
86 }
87
88 current_map = 0; // start the work on the other threads
89
90 for (int t = 0; t < NUM_THREADS; t++)
91 if (pthread_join(thread_ids[t], NULL) != 0)
92 {
93 printf("failed pthread_join\n");
94 exit(2);
95 }
96
97 printf("\n");
98
99
100
101 return 0;
102 }