diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2015-01-21 13:50:02 +0000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2015-01-21 13:50:02 +0000 |
| commit | 3ab6b2347e8d940b0687fb693c861c68d1e50998 (patch) | |
| tree | f09bef7d67646f964ad364f8d43a027ce82bd419 /compiler-rt/test/tsan/load_shared_lib.cc | |
| parent | 79ca0fd1a02132ef3d85aacbfc4ab5eab5911c08 (diff) | |
| download | bcm5719-llvm-3ab6b2347e8d940b0687fb693c861c68d1e50998.tar.gz bcm5719-llvm-3ab6b2347e8d940b0687fb693c861c68d1e50998.zip | |
tsan: remove sleeps from tests
Even sleep(1) lead to episodical flakes on some machines.
Use an invisible by tsan barrier to enforce required execution order instead.
This makes the tests deterministic and faster.
llvm-svn: 226659
Diffstat (limited to 'compiler-rt/test/tsan/load_shared_lib.cc')
| -rw-r--r-- | compiler-rt/test/tsan/load_shared_lib.cc | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/compiler-rt/test/tsan/load_shared_lib.cc b/compiler-rt/test/tsan/load_shared_lib.cc index a27dc1cc6ff..b7934b82df7 100644 --- a/compiler-rt/test/tsan/load_shared_lib.cc +++ b/compiler-rt/test/tsan/load_shared_lib.cc @@ -7,35 +7,39 @@ #ifdef BUILD_SO -#include <stddef.h> -#include <unistd.h> +#include "test.h" int GLOB_SHARED = 0; extern "C" +void init_so() { + barrier_init(&barrier, 2); +} + +extern "C" void *write_from_so(void *unused) { - if (unused) - sleep(1); + if (unused == 0) + barrier_wait(&barrier); GLOB_SHARED++; + if (unused != 0) + barrier_wait(&barrier); return NULL; } #else // BUILD_SO +#include "test.h" #include <dlfcn.h> -#include <pthread.h> -#include <stdio.h> -#include <stddef.h> -#include <unistd.h> - #include <string> int GLOB = 0; void *write_glob(void *unused) { - if (unused) - sleep(1); + if (unused == 0) + barrier_wait(&barrier); GLOB++; + if (unused != 0) + barrier_wait(&barrier); return NULL; } @@ -48,6 +52,7 @@ void race_two_threads(void *(*access_callback)(void *unused)) { } int main(int argc, char *argv[]) { + barrier_init(&barrier, 2); std::string path = std::string(argv[0]) + std::string("-so.so"); race_two_threads(write_glob); // CHECK: write_glob @@ -56,6 +61,9 @@ int main(int argc, char *argv[]) { printf("error in dlopen(): %s\n", dlerror()); return 1; } + void (*init_so)(); + *(void **)&init_so = dlsym(lib, "init_so"); + init_so(); void *(*write_from_so)(void *unused); *(void **)&write_from_so = dlsym(lib, "write_from_so"); race_two_threads(write_from_so); |

