2015-02-06 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libvtv / testsuite / libvtv.cc / register_set_pair_inserts.cc
blob297e875679776f81061c14f5bbc763035dc7d3ee
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <stdint.h>
4 #include <string.h>
6 #include "vtv_utils.h"
7 #include "vtv_rts.h"
9 /* This configuration will test mostly inserting of new elements since
10 the number of repeats is 1. It should also do a lot of rehashing */
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" */
16 #define NUM_MAPS 40000
17 #define ELEMENTS_PER_MAP 100
18 #define NUM_REPEATS 1
20 #define KEY_TYPE_FIXED_SIZE 8
21 void *key_buffer = malloc (17);
22 typedef char * name_string;
23 name_string fake_names[NUM_MAPS];
25 /* This variable has to be put in rel.ro */
26 void * maps[NUM_MAPS] VTV_PROTECTED_VAR;
28 struct fake_vt {
29 void * fake_vfp [4];
31 void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP];
34 void
35 generate_names (void)
37 int i;
39 for (i = 0; i < NUM_MAPS; ++i)
41 fake_names[i] = (char *) malloc (9 * sizeof (char));
42 snprintf (fake_names[i], 9, "name%d", i);
46 static uint32_t
47 vtv_string_hash(const char *in)
49 const char *s = in;
50 uint32_t h = 0;
52 for ( ; *s; ++s)
53 h = 5 * h + *s;
54 return h;
57 int main()
59 __VLTChangePermission(__VLTP_READ_WRITE);
61 generate_names();
63 for (int k = 0; k < NUM_REPEATS; k++)
65 int curr_fake_vt = 0;
66 for (int i = 0; i < NUM_MAPS; i++)
68 uint32_t *value_ptr = (uint32_t *) key_buffer;
69 uint32_t len1 = strlen (fake_names[i]);
70 uint32_t hash_value = vtv_string_hash (fake_names[i]);
71 void *temp_array[ELEMENTS_PER_MAP];
73 *value_ptr = len1;
74 value_ptr++;
75 *value_ptr = hash_value;
77 memcpy ((char *) key_buffer + KEY_TYPE_FIXED_SIZE, fake_names[i],
78 len1);
81 #ifdef VTV_DEBUG
82 __VLTRegisterPairDebug (&maps[i], (char *) key_buffer, 128,
83 &fake_vts[curr_fake_vt], "", "");
84 #else
85 __VLTRegisterPair (&maps[i], (char *) key_buffer, 128,
86 &fake_vts[curr_fake_vt]);
87 #endif
88 for (int j = 0; j < ELEMENTS_PER_MAP; j++)
90 temp_array[j] = &fake_vts[curr_fake_vt];
91 curr_fake_vt++;
93 #ifdef VTV_DEBUG
94 __VLTRegisterSetDebug (&maps[i], (char *) key_buffer, 128, 100,
95 (void **) &temp_array);
96 #else
97 __VLTRegisterSet (&maps[i], (char *) key_buffer, 128, 100,
98 (void **) &temp_array);
99 #endif
103 __VLTChangePermission(__VLTP_READ_ONLY);
105 return 0;