summaryrefslogtreecommitdiff
path: root/test/tsan
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-07-07 18:47:29 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-07-07 18:47:29 +0000
commite6282c9c2e73c165b72bc17cf2ba48defcec8e90 (patch)
tree5b496d709d1f150596335c8be2adc5d1abda0ade /test/tsan
parent2db2642b40971e50383ce64cd3587b18165f8988 (diff)
[Sanitizer] Move test for malloc/free hooks under test/sanitizer_common
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212474 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan')
-rw-r--r--test/tsan/malloc_hook.cc53
1 files changed, 0 insertions, 53 deletions
diff --git a/test/tsan/malloc_hook.cc b/test/tsan/malloc_hook.cc
deleted file mode 100644
index af4fb84f0..000000000
--- a/test/tsan/malloc_hook.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <sanitizer/allocator_interface.h>
-
-static int malloc_count;
-static int free_count;
-
-extern "C" {
-void __sanitizer_malloc_hook(const volatile void *ptr, size_t size) {
- (void)ptr;
- (void)size;
- __sync_fetch_and_add(&malloc_count, 1);
-}
-
-void __sanitizer_free_hook(const volatile void *ptr) {
- (void)ptr;
- __sync_fetch_and_add(&free_count, 1);
-}
-}
-
-void *Thread1(void *x) {
- ((int*)x)[0]++;
- return 0;
-}
-
-void *Thread2(void *x) {
- sleep(1);
- ((int*)x)[0]++;
- return 0;
-}
-
-int main() {
- int *x = new int;
- pthread_t t[2];
- pthread_create(&t[0], 0, Thread1, x);
- pthread_create(&t[1], 0, Thread2, x);
- pthread_join(t[0], 0);
- pthread_join(t[1], 0);
- delete x;
- if (malloc_count == 0 || free_count == 0) {
- fprintf(stderr, "FAILED %d %d\n", malloc_count, free_count);
- exit(1);
- }
- fprintf(stderr, "DONE\n");
-}
-
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK-NOT: FAILED
-// CHECK: DONE