[compiler-rt] r212474 - [Sanitizer] Move test for malloc/free hooks under test/sanitizer_common

Alexey Samsonov vonosmas at gmail.com
Mon Jul 7 11:47:30 PDT 2014


Author: samsonov
Date: Mon Jul  7 13:47:29 2014
New Revision: 212474

URL: http://llvm.org/viewvc/llvm-project?rev=212474&view=rev
Log:
[Sanitizer] Move test for malloc/free hooks under test/sanitizer_common

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc
      - copied, changed from r212469, compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc
Removed:
    compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc
    compiler-rt/trunk/test/msan/malloc_hook.cc
    compiler-rt/trunk/test/tsan/malloc_hook.cc

Removed: compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc?rev=212473&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc (removed)
@@ -1,39 +0,0 @@
-// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-
-// Malloc/free hooks are not supported on Windows.
-// XFAIL: win32
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <sanitizer/allocator_interface.h>
-
-extern "C" {
-const volatile void *global_ptr;
-
-// Note: avoid calling functions that allocate memory in malloc/free
-// to avoid infinite recursion.
-void __sanitizer_malloc_hook(const volatile void *ptr, size_t sz) {
-  if (__sanitizer_get_ownership(ptr)) {
-    write(1, "MallocHook\n", sizeof("MallocHook\n"));
-    global_ptr = ptr;
-  }
-}
-void __sanitizer_free_hook(const volatile void *ptr) {
-  if (__sanitizer_get_ownership(ptr) && ptr == global_ptr)
-    write(1, "FreeHook\n", sizeof("FreeHook\n"));
-}
-}  // extern "C"
-
-int main() {
-  volatile int *x = new int;
-  // CHECK: MallocHook
-  // Check that malloc hook was called with correct argument.
-  if (global_ptr != (void*)x) {
-    _exit(1);
-  }
-  *x = 0;
-  delete x;
-  // CHECK: FreeHook
-  return 0;
-}

Removed: compiler-rt/trunk/test/msan/malloc_hook.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/malloc_hook.cc?rev=212473&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/malloc_hook.cc (original)
+++ compiler-rt/trunk/test/msan/malloc_hook.cc (removed)
@@ -1,36 +0,0 @@
-// RUN: %clangxx_msan -O2 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-#include <stdlib.h>
-#include <unistd.h>
-#include <sanitizer/allocator_interface.h>
-
-extern "C" {
-
-const volatile void *global_ptr;
-
-// Note: avoid calling functions that allocate memory in malloc/free
-// to avoid infinite recursion.
-void __sanitizer_malloc_hook(const volatile void *ptr, size_t sz) {
-  if (__sanitizer_get_ownership(ptr)) {
-    write(1, "MallocHook\n", sizeof("MallocHook\n"));
-    global_ptr = ptr;
-  }
-}
-void __sanitizer_free_hook(const volatile void *ptr) {
-  if (__sanitizer_get_ownership(ptr) && ptr == global_ptr)
-    write(1, "FreeHook\n", sizeof("FreeHook\n"));
-}
-}  // extern "C"
-
-int main() {
-  volatile int *x = new int;
-  // CHECK: MallocHook
-  // Check that malloc hook was called with correct argument.
-  if (global_ptr != (void*)x) {
-    _exit(1);
-  }
-  *x = 0;
-  delete x;
-  // CHECK: FreeHook
-  return 0;
-}

Copied: compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc (from r212469, compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc?p2=compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc&p1=compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc&r1=212469&r2=212474&rev=212474&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/malloc_hook.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/malloc_hook.cc Mon Jul  7 13:47:29 2014
@@ -1,8 +1,7 @@
-// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
 
-// Malloc/free hooks are not supported on Windows.
-// XFAIL: win32
+// Malloc/free hooks are not supported on Windows and doesn't work in LSan.
+// XFAIL: win32, lsan
 
 #include <stdlib.h>
 #include <unistd.h>

Removed: compiler-rt/trunk/test/tsan/malloc_hook.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/malloc_hook.cc?rev=212473&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/malloc_hook.cc (original)
+++ compiler-rt/trunk/test/tsan/malloc_hook.cc (removed)
@@ -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





More information about the llvm-commits mailing list