diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libvtv/testsuite/libvtv.mt.cc | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libvtv/testsuite/libvtv.mt.cc')
3 files changed, 382 insertions, 0 deletions
diff --git a/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/mt.exp b/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/mt.exp new file mode 100644 index 000000000..e2ee43577 --- /dev/null +++ b/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/mt.exp @@ -0,0 +1,68 @@ +load_lib libvtv-dg.exp +load_gcc_lib gcc-dg.exp + +global VTV_FLAGS +set VTV_FLAGS [list {-O0} {-O2}] + +libvtv_init c++ + +set shlib_ext [get_shlib_extension] +set lang_link_flags "-shared-libgcc -lstdc++" +set lang_test_file_found 0 +set lang_library_path "../libstdc++-v3/src/.libs" + +dg-init + +set blddir [lookfor_file [get_multilibs] libvtv] + +# Find the correct libstdc++ library to use. + +if { $blddir != "" } { + # Look for a static libstdc++ first. + if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] { + set lang_test_file "${lang_library_path}/libstdc++.a" + set lang_test_file_found 1 + # We may have a shared only build, so look for a shared libstdc++. + } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] { + set lang_test_file "${lang_library_path}/libstdc++.${shlib_ext}" + set lang_test_file_found 1 + } else { + puts "looking for ${blddir}/${lang_library_path}/libstdc++.${shlib_ext}" + puts "No libstdc++ library found, will not execute c++ tests" + } +} elseif { [info exists GXX_UNDER_TEST] } { + set lang_test_file_found 1 + # Needs to exist for libvtv.exp. + set lang_test_file "" +} else { + puts "GXX_UNDER_TEST not defined, will not execute c++ tests" +} + + +global srcdir + +if { $lang_test_file_found } { + # Set the path for finding libstdc++. + if { $blddir != "" } { + set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}" + } else { + set ld_library_path "$always_ld_library_path" + } + append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST] + set_ld_library_path_env_vars + + # Make sure we can find the libstdc++ header files. + set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags" + if { [file exists $flags_file] } { + set libstdcxx_includes [exec sh $flags_file --build-includes] + } else { + set libstdcxx_includes "" + } + + # Run the tests with -fvtable-verify=std + foreach flags $VTV_FLAGS { + foreach srcfile [lsort [glob -nocomplain ${srcdir}/libvtv.mt.cc/*.cc]] { + dg-runtest $srcfile "$flags -fvtable-verify=std -lpthread" $libstdcxx_includes + } + } +} diff --git a/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc b/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc new file mode 100644 index 000000000..6df197343 --- /dev/null +++ b/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/register_set_pair_inserts_mt.cc @@ -0,0 +1,156 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include "vtv_utils.h" +#include "vtv_rts.h" +#include "pthread.h" + + +/* Multi-threaded test for calls to RegisterPair */ + +/* This configuration will test mostly inserting of new elements since + the number of repeats is 1. It should also do a lot of rehashing */ + +/* This test case may fail depending on the system configuration. + Check the value of /proc/sys/vm/max_map_count and fix by doing + Ex: sudo sh -c "echo 131060 > /proc/sys/vm/max_map_count" */ + +#define NUM_MAPS 2000 +#define ELEMENTS_PER_MAP 100 +#define NUM_REPEATS 1 + +#define NUM_THREADS 9 + +#define KEY_TYPE_FIXED_SIZE 8 +void *key_buffer = malloc (17); +typedef char * name_string; +name_string fake_names[NUM_MAPS]; + +/* This variable has to be put in rel.ro */ +void * volatile maps[NUM_MAPS] VTV_PROTECTED_VAR; + +struct fake_vt { + void * fake_vfp [4]; +}; +void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP]; + +volatile int current_map = -1; +volatile int threads_completed_it = 0; + +void +generate_names (void) +{ + int i; + + for (i = 0; i < NUM_MAPS; ++i) + { + fake_names[i] = (char *) malloc (9 * sizeof (char)); + snprintf (fake_names[i], 9, "name%d", i); + } +} + +static uint32_t +vtv_string_hash(const char *in) +{ + const char *s = in; + uint32_t h = 0; + + for ( ; *s; ++s) + h = 5 * h + *s; + return h; +} + +void * do_register_pairs(void *) +{ + for (int k = 0; k < NUM_REPEATS; k++) + { + int curr_fake_vt = 0; + for (int i = 0; i < NUM_MAPS; i++) + { + uint32_t *value_ptr = (uint32_t *) key_buffer; + uint32_t len1 = strlen (fake_names[i]); + uint32_t hash_value = vtv_string_hash (fake_names[i]); + void *temp_array[ELEMENTS_PER_MAP]; + + while (current_map < (k*NUM_MAPS + i)) + ; + + __VLTChangePermission(__VLTP_READ_WRITE); + + *value_ptr = len1; + value_ptr++; + *value_ptr = hash_value; + + memcpy ((char *) key_buffer + KEY_TYPE_FIXED_SIZE, fake_names[i], + len1); + + +#ifdef VTV_DEBUG + __VLTRegisterPairDebug ((void **) &maps[i], (char *) key_buffer, 128, + &fake_vts[curr_fake_vt], "", ""); +#else + __VLTRegisterPair ((void **) &maps[i], (char *) key_buffer, 128, + &fake_vts[curr_fake_vt]); +#endif + for (int j = 0; j < ELEMENTS_PER_MAP; j++) + { + temp_array[j] = &fake_vts[curr_fake_vt]; + curr_fake_vt++; + } + +#ifdef VTV_DEBUG + __VLTRegisterSetDebug ((void **) &maps[i], (char *) key_buffer, 128, 100, + (void **) &temp_array); +#else + __VLTRegisterSet ((void **) &maps[i], (char *) key_buffer, 128, 100, + (void **) &temp_array); +#endif + __VLTChangePermission(__VLTP_READ_ONLY); + + int old_value; + do { + old_value = threads_completed_it; + } while (!__sync_bool_compare_and_swap(&threads_completed_it, old_value, old_value + 1)); + + if (old_value == (NUM_THREADS - 1)) // Only one thread will do this. + { + threads_completed_it = 0; + printf("%c%d", 13, current_map + 1); + fflush(stdout); + current_map++; + } + } + } + + return NULL; +} + + +int main() +{ + pthread_t thread_ids[NUM_THREADS]; + + generate_names(); + + for (int t = 0; t < NUM_THREADS; t++ ) + if (pthread_create(&thread_ids[t], NULL, do_register_pairs, NULL) != 0) + { + printf("failed pthread_create\n"); + exit(1); + } + + current_map = 0; // start the work on the other threads + + for (int t = 0; t < NUM_THREADS; t++) + if (pthread_join(thread_ids[t], NULL) != 0) + { + printf("failed pthread_join\n"); + exit(2); + } + + printf("\n"); + + return 0; +} diff --git a/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc b/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc new file mode 100644 index 000000000..1d480a1e3 --- /dev/null +++ b/gcc-4.9/libvtv/testsuite/libvtv.mt.cc/register_set_pair_mt.cc @@ -0,0 +1,158 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include "vtv_utils.h" +#include "vtv_rts.h" +#include "pthread.h" + + +/* Multi-threaded test for calls to RegisterPair */ + +/* This configuration will test mostly inserting of elements that are already inserted since + the number of repeats is 10 */ + +/* This test case may fail depending on the system configuration. + Check the value of /proc/sys/vm/max_map_count and fix by doing + Ex: sudo sh -c "echo 131060 > /proc/sys/vm/max_map_count" */ + +#define NUM_MAPS 200 +#define ELEMENTS_PER_MAP 100 +#define NUM_REPEATS 10 + +#define NUM_THREADS 9 + +#define KEY_TYPE_FIXED_SIZE 8 +void *key_buffer = malloc (17); +typedef char * name_string; +name_string fake_names[NUM_MAPS]; + +/* This variable has to be put in rel.ro */ +void * volatile maps[NUM_MAPS] VTV_PROTECTED_VAR; + +struct fake_vt { + void * fake_vfp [4]; +}; +void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP]; + +volatile int current_map = -1; +volatile int threads_completed_it = 0; + +void +generate_names (void) +{ + int i; + + for (i = 0; i < NUM_MAPS; ++i) + { + fake_names[i] = (char *) malloc (9 * sizeof (char)); + snprintf (fake_names[i], 9, "name%d", i); + } +} + +static uint32_t +vtv_string_hash(const char *in) +{ + const char *s = in; + uint32_t h = 0; + + for ( ; *s; ++s) + h = 5 * h + *s; + return h; +} + +void * do_register_pairs(void *) +{ + for (int k = 0; k < NUM_REPEATS; k++) + { + int curr_fake_vt = 0; + for (int i = 0; i < NUM_MAPS; i++) + { + uint32_t *value_ptr = (uint32_t *) key_buffer; + uint32_t len1 = strlen (fake_names[i]); + uint32_t hash_value = vtv_string_hash (fake_names[i]); + void *temp_array[ELEMENTS_PER_MAP]; + + while (current_map < (k*NUM_MAPS + i)) + ; + + __VLTChangePermission(__VLTP_READ_WRITE); + + *value_ptr = len1; + value_ptr++; + *value_ptr = hash_value; + + memcpy ((char *) key_buffer + KEY_TYPE_FIXED_SIZE, fake_names[i], + len1); + + +#ifdef VTV_DEBUG + __VLTRegisterPairDebug ((void **) &maps[i], (char *) key_buffer, 128, + &fake_vts[curr_fake_vt], "", ""); +#else + __VLTRegisterPair ((void **) &maps[i], (char *) key_buffer, 128, + &fake_vts[curr_fake_vt]); +#endif + for (int j = 0; j < ELEMENTS_PER_MAP; j++) + { + temp_array[j] = &fake_vts[curr_fake_vt]; + curr_fake_vt++; + } + +#ifdef VTV_DEBUG + __VLTRegisterSetDebug ((void **) &maps[i], (char *) key_buffer, 128, 100, + (void **) &temp_array); +#else + __VLTRegisterSet ((void **) &maps[i], (char *) key_buffer, 128, 100, + (void **) &temp_array); +#endif + __VLTChangePermission(__VLTP_READ_ONLY); + + int old_value; + do { + old_value = threads_completed_it; + } while (!__sync_bool_compare_and_swap(&threads_completed_it, old_value, old_value + 1)); + + if (old_value == (NUM_THREADS - 1)) // Only one thread will do this. + { + threads_completed_it = 0; + printf("%c%d", 13, current_map + 1); + fflush(stdout); + current_map++; + } + } + } + + return NULL; +} + + +int main() +{ + pthread_t thread_ids[NUM_THREADS]; + + generate_names (); + + for (int t = 0; t < NUM_THREADS; t++ ) + if (pthread_create(&thread_ids[t], NULL, do_register_pairs, NULL) != 0) + { + printf("failed pthread_create\n"); + exit(1); + } + + current_map = 0; // start the work on the other threads + + for (int t = 0; t < NUM_THREADS; t++) + if (pthread_join(thread_ids[t], NULL) != 0) + { + printf("failed pthread_join\n"); + exit(2); + } + + printf("\n"); + + + + return 0; +} |