summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Kutuzov <vkutuzov@accesssoftek.com>2014-12-11 17:42:29 +0000
committerViktor Kutuzov <vkutuzov@accesssoftek.com>2014-12-11 17:42:29 +0000
commit289734dae9b04790f6ccf9c14575bc2e0e27d725 (patch)
tree8b67e3fcf4ab542854de272c1d7c6f8930bcab64
parent97eeb3d1205e6d95cc75edcf5ee21d40de74ddc9 (diff)
[Tsan] Fix the signal_recursive.cc test to pass on systems with high loads
Differential Revision: http://reviews.llvm.org/D6504 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224030 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/tsan/process_sleep.h7
-rw-r--r--test/tsan/signal_recursive.cc27
2 files changed, 21 insertions, 13 deletions
diff --git a/test/tsan/process_sleep.h b/test/tsan/process_sleep.h
new file mode 100644
index 000000000..5938a42bf
--- /dev/null
+++ b/test/tsan/process_sleep.h
@@ -0,0 +1,7 @@
+#include <time.h>
+
+static void process_sleep(int sec) {
+ clock_t beg = clock();
+ while((clock() - beg) / CLOCKS_PER_SEC < sec)
+ usleep(100);
+}
diff --git a/test/tsan/signal_recursive.cc b/test/tsan/signal_recursive.cc
index d92ba9741..bbb680758 100644
--- a/test/tsan/signal_recursive.cc
+++ b/test/tsan/signal_recursive.cc
@@ -11,6 +11,8 @@
#include <stdlib.h>
#include <stdio.h>
+#include "process_sleep.h"
+
static const int kSigSuspend = SIGUSR1;
static const int kSigRestart = SIGUSR2;
static sigset_t g_suspend_handler_mask;
@@ -59,33 +61,30 @@ static void RestartHandler(int sig) {
}
static void StopWorld(pthread_t thread) {
- int result = pthread_kill(thread, kSigSuspend);
- if (result != 0)
+ if (pthread_kill(thread, kSigSuspend) != 0)
fail("pthread_kill failed");
- while ((result = sem_wait(&g_thread_suspend_ack_sem)) != 0) {
- if (result != EINTR) {
+ while (sem_wait(&g_thread_suspend_ack_sem) != 0) {
+ if (errno != EINTR)
fail("sem_wait failed");
- }
}
}
static void StartWorld(pthread_t thread) {
- int result = pthread_kill(thread, kSigRestart);
- if (result != 0)
+ if (pthread_kill(thread, kSigRestart) != 0)
fail("pthread_kill failed");
- while ((result = sem_wait(&g_thread_suspend_ack_sem)) != 0) {
- if (result != EINTR) {
+ while (sem_wait(&g_thread_suspend_ack_sem) != 0) {
+ if (errno != EINTR)
fail("sem_wait failed");
- }
}
}
static void CollectGarbage(pthread_t thread) {
StopWorld(thread);
// Walk stacks
- StartWorld(thread);
+ process_sleep(1);
+ StartWorld(thread);
}
static void Init() {
@@ -118,9 +117,11 @@ void* BusyThread(void *arg) {
int main(int argc, const char *argv[]) {
Init();
pthread_t busy_thread;
- pthread_create(&busy_thread, NULL, &BusyThread, NULL);
+ if (pthread_create(&busy_thread, NULL, &BusyThread, NULL) != 0)
+ fail("pthread_create failed");
CollectGarbage(busy_thread);
- pthread_join(busy_thread, 0);
+ if (pthread_join(busy_thread, 0) != 0)
+ fail("pthread_join failed");
fprintf(stderr, "DONE\n");
return 0;
}