aboutsummaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-02-22 22:43:40 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-02-22 22:43:40 +0000
commitcd2dd3df15523e2be8d2bbace27641d6ac9fa40d (patch)
treefbdacaec253cc5ceee88cb44de5545fa32c8bd67 /test/asan
parent476c4db3dc56bee43df384704c75ccc71cfa7a1d (diff)
downloadsrc-cd2dd3df15523e2be8d2bbace27641d6ac9fa40d.tar.gz
src-cd2dd3df15523e2be8d2bbace27641d6ac9fa40d.zip
Import compiler-rt trunk r230183.vendor/compiler-rt/compiler-rt-r230183
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=279192 svn path=/vendor/compiler-rt/compiler-rt-r230183/; revision=279193; tag=vendor/compiler-rt/compiler-rt-r230183
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/CMakeLists.txt6
-rw-r--r--test/asan/TestCases/Windows/dll_host.cc7
-rw-r--r--test/asan/TestCases/Windows/globals_multiple_dlls.cc51
-rw-r--r--test/asan/TestCases/Windows/oom.cc12
-rw-r--r--test/asan/TestCases/Windows/symbols_path.cc22
-rw-r--r--test/asan/TestCases/dlclose-test.cc7
-rw-r--r--test/asan/TestCases/gc-test.cc6
-rw-r--r--test/asan/lit.cfg8
8 files changed, 112 insertions, 7 deletions
diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt
index 0c46ef7e6e31..e1b81264604d 100644
--- a/test/asan/CMakeLists.txt
+++ b/test/asan/CMakeLists.txt
@@ -55,11 +55,7 @@ foreach(arch ${ASAN_SUPPORTED_ARCH})
endforeach()
set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(COMPILER_RT_STANDALONE_BUILD)
- add_executable(FileCheck IMPORTED GLOBAL)
- set_property(TARGET FileCheck PROPERTY IMPORTED_LOCATION ${LLVM_TOOLS_BINARY_DIR}/FileCheck)
- list(APPEND ASAN_TEST_DEPS FileCheck)
-else()
+if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND ASAN_TEST_DEPS asan)
endif()
set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
diff --git a/test/asan/TestCases/Windows/dll_host.cc b/test/asan/TestCases/Windows/dll_host.cc
index d3b4c149d009..71721fe29e88 100644
--- a/test/asan/TestCases/Windows/dll_host.cc
+++ b/test/asan/TestCases/Windows/dll_host.cc
@@ -6,9 +6,14 @@
//
// Get the list of ASan wrappers exported by the main module RTL:
// RUN: dumpbin /EXPORTS %t | grep -o "__asan_wrap[^ ]*" | grep -v @ | sort | uniq > %t.exported_wrappers
+// FIXME: we should really check the other __asan exports too.
+// RUN: dumpbin /EXPORTS %t | grep -o "__sanitizer_[^ ]*" | grep -v @ | sort | uniq >> %t.exported_wrappers
//
// Get the list of ASan wrappers imported by the DLL RTL:
-// RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed "s/.*(\(.*\)).*/__asan_wrap_\1/" | sort | uniq > %t.dll_imports
+// [BEWARE: be really careful with the sed commands, as this test can be run
+// from different environemnts with different shells and seds]
+// RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed -e s/.*(/__asan_wrap_/ | sed -e s/).*// | sort | uniq > %t.dll_imports
+// RUN: grep "^INTERFACE_FUNCTION.*sanitizer" %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed -e s/.*(// | sed -e s/).*// | sort | uniq >> %t.dll_imports
//
// Now make sure the DLL thunk imports everything:
// RUN: echo
diff --git a/test/asan/TestCases/Windows/globals_multiple_dlls.cc b/test/asan/TestCases/Windows/globals_multiple_dlls.cc
new file mode 100644
index 000000000000..634e5782796c
--- /dev/null
+++ b/test/asan/TestCases/Windows/globals_multiple_dlls.cc
@@ -0,0 +1,51 @@
+// Make sure everything works even if the main module doesn't have any stack
+// variables, thus doesn't explicitly reference any symbol exported by the
+// runtime thunk.
+//
+// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe
+// RUN: env ASAN_OPTIONS=report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s
+
+#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+
+extern "C" {
+#if defined(EXE)
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ printf("Usage: %s [client].dll\n", argv[0]);
+ return 101;
+ }
+ const char *dll_name = argv[1];
+
+// CHECK: time to load DLL
+ printf("time to load DLL\n");
+ fflush(0);
+
+// On DLL load, the "in DLL\n" string is registered:
+// CHECK: Added Global{{.*}} size=19
+// CHECK: in DLL(reason=1)
+ HMODULE dll = LoadLibrary(dll_name);
+ if (dll == NULL)
+ return 3;
+
+// CHECK: in DLL(reason=0)
+// CHECK-NEXT: Removed Global{{.*}} size=19
+ if (!FreeLibrary(dll))
+ return 4;
+
+// CHECK: bye!
+ printf("bye!\n");
+ fflush(0);
+}
+#elif defined(DLL)
+BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
+ printf("in DLL(reason=%d)\n", (int)reason);
+ fflush(0);
+ return TRUE;
+}
+#else
+# error oops!
+#endif
+}
diff --git a/test/asan/TestCases/Windows/oom.cc b/test/asan/TestCases/Windows/oom.cc
new file mode 100644
index 000000000000..b24cddf17a97
--- /dev/null
+++ b/test/asan/TestCases/Windows/oom.cc
@@ -0,0 +1,12 @@
+// RUN: %clang_cl_asan -O0 %s -Fe%t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <malloc.h>
+
+int main() {
+ while (true) {
+ void *ptr = malloc(200 * 1024 * 1024); // 200MB
+ free(ptr);
+ }
+// CHECK: failed to allocate
+}
diff --git a/test/asan/TestCases/Windows/symbols_path.cc b/test/asan/TestCases/Windows/symbols_path.cc
new file mode 100644
index 000000000000..3c69f8861d78
--- /dev/null
+++ b/test/asan/TestCases/Windows/symbols_path.cc
@@ -0,0 +1,22 @@
+// Make sure symbolization works even if the path to the .exe file changes.
+// RUN: mkdir %t || true
+// RUN: %clang_cl_asan -O0 %s -Fe%t/symbols_path.exe
+// RUN: not %run %t/symbols_path.exe 2>&1 | FileCheck %s
+// RUN: mkdir %t2 || true
+// RUN: mv %t/* %t2
+// RUN: not %run %t2/symbols_path.exe 2>&1 | FileCheck %s
+
+#include <malloc.h>
+
+int main() {
+ char *buffer = (char*)malloc(42);
+ buffer[-1] = 42;
+// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 1 at [[ADDR]] thread T0
+// CHECK-NEXT: {{#0 .* main .*symbols_path.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 1 bytes to the left of 42-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK-NEXT: {{#0 .* malloc }}
+// CHECK-NEXT: {{#1 .* main .*symbols_path.cc}}:[[@LINE-8]]
+ free(buffer);
+}
diff --git a/test/asan/TestCases/dlclose-test.cc b/test/asan/TestCases/dlclose-test.cc
index 2d31aee5a32f..369abd3127cc 100644
--- a/test/asan/TestCases/dlclose-test.cc
+++ b/test/asan/TestCases/dlclose-test.cc
@@ -33,6 +33,13 @@
#include <string>
+#if defined(__FreeBSD__)
+// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before
+// that, it was never implemented. So just define it to zero.
+#undef MAP_NORESERVE
+#define MAP_NORESERVE 0
+#endif
+
using std::string;
typedef int *(fun_t)();
diff --git a/test/asan/TestCases/gc-test.cc b/test/asan/TestCases/gc-test.cc
index ffbea85b2650..4ffa51dd22d3 100644
--- a/test/asan/TestCases/gc-test.cc
+++ b/test/asan/TestCases/gc-test.cc
@@ -1,6 +1,9 @@
// RUN: %clangxx_asan %s -pthread -o %t
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: %clangxx_asan -O3 %s -pthread -o %t
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
// REQUIRES: stable-runtime
#include <assert.h>
@@ -9,6 +12,7 @@
#include <sanitizer/asan_interface.h>
static const int kNumThreads = 2;
+static const int kLeftRedzoneSize = sizeof(void *) * 4;
void *Thread(void *unused) {
void *fake_stack = __asan_get_current_fake_stack();
@@ -23,7 +27,7 @@ void *Thread(void *unused) {
assert(real_stack);
assert((char*)beg <= (char*)&var[0]);
assert((char*)end > (char*)&var[0]);
- for (int i = -32; i < 15; i++) {
+ for (int i = -kLeftRedzoneSize; i < 15; i++) {
void *beg1, *end1;
char *ptr = &var[0] + i;
void *real_stack1 =
diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg
index 8be7062614b3..a6f443cfb6a5 100644
--- a/test/asan/lit.cfg
+++ b/test/asan/lit.cfg
@@ -3,6 +3,8 @@
import os
import platform
+import lit.formats
+
def get_required_attr(config, attr_name):
attr_value = getattr(config, attr_name, None)
if attr_value == None:
@@ -15,6 +17,8 @@ def get_required_attr(config, attr_name):
def push_dynamic_library_lookup_path(config, new_path):
if platform.system() == 'Windows':
dynamic_library_lookup_var = 'PATH'
+ elif platform.system() == 'Darwin':
+ dynamic_library_lookup_var = 'DYLD_LIBRARY_PATH'
else:
dynamic_library_lookup_var = 'LD_LIBRARY_PATH'
@@ -25,6 +29,10 @@ def push_dynamic_library_lookup_path(config, new_path):
# Setup config name.
config.name = 'AddressSanitizer' + config.name_suffix
+# testFormat: The test format to use to interpret tests.
+external_bash = (not sys.platform in ['win32'])
+config.test_format = lit.formats.ShTest(external_bash)
+
# Setup source root.
config.test_source_root = os.path.dirname(__file__)