diff options
author | Alexey Samsonov <samsonov@google.com> | 2014-02-14 14:35:48 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2014-02-14 14:35:48 +0000 |
commit | e6a6183e9b8ecf7dec8808fa87577d5b574ca22e (patch) | |
tree | a6e5f3181f2e0c4ffc21f9648c5e9c873f34b330 /compiler-rt/test/tsan/load_shared_lib.cc | |
parent | 9f20d6703479a952465f7db0c2fbd70904c030c2 (diff) | |
download | bcm5719-llvm-e6a6183e9b8ecf7dec8808fa87577d5b574ca22e.tar.gz bcm5719-llvm-e6a6183e9b8ecf7dec8808fa87577d5b574ca22e.zip |
Move TSan lit-tests under test/tsan
llvm-svn: 201414
Diffstat (limited to 'compiler-rt/test/tsan/load_shared_lib.cc')
-rw-r--r-- | compiler-rt/test/tsan/load_shared_lib.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/load_shared_lib.cc b/compiler-rt/test/tsan/load_shared_lib.cc new file mode 100644 index 00000000000..d60cd5700a8 --- /dev/null +++ b/compiler-rt/test/tsan/load_shared_lib.cc @@ -0,0 +1,44 @@ +// Check that if the list of shared libraries changes between the two race +// reports, the second report occurring in a new shared library is still +// symbolized correctly. + +// RUN: %clangxx_tsan -O1 %p/SharedLibs/load_shared_lib-so.cc \ +// RUN: -fPIC -shared -o %t-so.so +// RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s + +#include <dlfcn.h> +#include <pthread.h> +#include <stdio.h> + +#include <string> + +int GLOB = 0; + +void *write_glob(void *unused) { + GLOB++; + return NULL; +} + +void race_two_threads(void *(*access_callback)(void *unused)) { + pthread_t t1, t2; + pthread_create(&t1, NULL, access_callback, NULL); + pthread_create(&t2, NULL, access_callback, NULL); + pthread_join(t1, NULL); + pthread_join(t2, NULL); +} + +int main(int argc, char *argv[]) { + std::string path = std::string(argv[0]) + std::string("-so.so"); + race_two_threads(write_glob); + // CHECK: write_glob + void *lib = dlopen(path.c_str(), RTLD_NOW); + if (!lib) { + printf("error in dlopen(): %s\n", dlerror()); + return 1; + } + void *(*write_from_so)(void *unused); + *(void **)&write_from_so = dlsym(lib, "write_from_so"); + race_two_threads(write_from_so); + // CHECK: write_from_so + return 0; +} |