| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdint.h> |
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
#include "vtv_utils.h" |
| 7 |
#include "vtv_rts.h" |
| 8 |
|
| 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 */ |
| 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 40000 |
| 17 |
#define ELEMENTS_PER_MAP 100 |
| 18 |
#define NUM_REPEATS 1 |
| 19 |
|
| 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]; |
| 24 |
|
| 25 |
/* This variable has to be put in rel.ro */ |
| 26 |
void * maps[NUM_MAPS] VTV_PROTECTED_VAR; |
| 27 |
|
| 28 |
struct fake_vt { |
| 29 |
void * fake_vfp [4]; |
| 30 |
}; |
| 31 |
void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP]; |
| 32 |
|
| 33 |
|
| 34 |
void |
| 35 |
generate_names (void) |
| 36 |
{ |
| 37 |
int i; |
| 38 |
|
| 39 |
for (i = 0; i < NUM_MAPS; ++i) |
| 40 |
{ |
| 41 |
fake_names[i] = (char *) malloc (9 * sizeof (char)); |
| 42 |
snprintf (fake_names[i], 9, "name%d", i); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
static uint32_t |
| 47 |
vtv_string_hash(const char *in) |
| 48 |
{ |
| 49 |
const char *s = in; |
| 50 |
uint32_t h = 0; |
| 51 |
|
| 52 |
for ( ; *s; ++s) |
| 53 |
h = 5 * h + *s; |
| 54 |
return h; |
| 55 |
} |
| 56 |
|
| 57 |
int main() |
| 58 |
{ |
| 59 |
__VLTChangePermission(__VLTP_READ_WRITE); |
| 60 |
|
| 61 |
generate_names(); |
| 62 |
|
| 63 |
for (int k = 0; k < NUM_REPEATS; k++) |
| 64 |
{ |
| 65 |
int curr_fake_vt = 0; |
| 66 |
for (int i = 0; i < NUM_MAPS; i++) |
| 67 |
{ |
| 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]; |
| 72 |
|
| 73 |
*value_ptr = len1; |
| 74 |
value_ptr++; |
| 75 |
*value_ptr = hash_value; |
| 76 |
|
| 77 |
memcpy ((char *) key_buffer + KEY_TYPE_FIXED_SIZE, fake_names[i], |
| 78 |
len1); |
| 79 |
|
| 80 |
|
| 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++) |
| 89 |
{ |
| 90 |
temp_array[j] = &fake_vts[curr_fake_vt]; |
| 91 |
curr_fake_vt++; |
| 92 |
} |
| 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 |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
__VLTChangePermission(__VLTP_READ_ONLY); |
| 104 |
|
| 105 |
return 0; |
| 106 |
} |