summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
authorYury Gribov <y.gribov@samsung.com>2015-11-11 11:59:38 +0000
committerYury Gribov <y.gribov@samsung.com>2015-11-11 11:59:38 +0000
commit468d955b986346ab75feffe1347bca46a0d01ed9 (patch)
tree4985bb9bbb55c5d7d05dd71e30b00e667ad61c85 /compiler-rt/test
parent12982a816c4be8702202cfcf5c3a83a29f70b5b9 (diff)
downloadbcm5719-llvm-468d955b986346ab75feffe1347bca46a0d01ed9.tar.gz
bcm5719-llvm-468d955b986346ab75feffe1347bca46a0d01ed9.zip
[ASan] Enable optional ASan recovery.
Differential Revision: http://reviews.llvm.org/D12318 llvm-svn: 252723
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.c12
-rw-r--r--compiler-rt/test/asan/TestCases/Linux/halt_on_error-torture.cc79
-rw-r--r--compiler-rt/test/asan/TestCases/Linux/interface_symbols_linux.c12
-rw-r--r--compiler-rt/test/asan/TestCases/halt_on_error-1.c29
4 files changed, 132 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.c b/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.c
index 9bd32869c9e..ed5779ebe22 100644
--- a/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.c
+++ b/compiler-rt/test/asan/TestCases/Darwin/interface_symbols_darwin.c
@@ -29,6 +29,18 @@
// RUN: echo __asan_report_store16 >> %t.interface
// RUN: echo __asan_report_load_n >> %t.interface
// RUN: echo __asan_report_store_n >> %t.interface
+// RUN: echo __asan_report_load1_noabort >> %t.interface
+// RUN: echo __asan_report_load2_noabort >> %t.interface
+// RUN: echo __asan_report_load4_noabort >> %t.interface
+// RUN: echo __asan_report_load8_noabort >> %t.interface
+// RUN: echo __asan_report_load16_noabort >> %t.interface
+// RUN: echo __asan_report_store1_noabort >> %t.interface
+// RUN: echo __asan_report_store2_noabort >> %t.interface
+// RUN: echo __asan_report_store4_noabort >> %t.interface
+// RUN: echo __asan_report_store8_noabort >> %t.interface
+// RUN: echo __asan_report_store16_noabort >> %t.interface
+// RUN: echo __asan_report_load_n_noabort >> %t.interface
+// RUN: echo __asan_report_store_n_noabort >> %t.interface
// RUN: echo __asan_report_exp_load1 >> %t.interface
// RUN: echo __asan_report_exp_load2 >> %t.interface
// RUN: echo __asan_report_exp_load4 >> %t.interface
diff --git a/compiler-rt/test/asan/TestCases/Linux/halt_on_error-torture.cc b/compiler-rt/test/asan/TestCases/Linux/halt_on_error-torture.cc
new file mode 100644
index 00000000000..6b100d7a060
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Linux/halt_on_error-torture.cc
@@ -0,0 +1,79 @@
+// Stress test recovery mode with many threads.
+//
+// RUN: %clangxx_asan -fsanitize-recover=address %s -o %t
+//
+// RUN: env ASAN_OPTIONS=halt_on_error=false:max_errors=1000 %run %t 1 10 >1.txt 2>&1
+// RUN: FileCheck %s < 1.txt
+// RUN: [ $(wc -l < 1.txt) -gt 1 ]
+//
+// RUN: env ASAN_OPTIONS=halt_on_error=false:max_errors=1000 %run %t 10 20 >10.txt 2>&1
+// RUN: FileCheck %s < 10.txt
+// This one is racy although very unlikely to fail:
+// RUN: [ $(wc -l < 10.txt) -gt 1 ]
+// Collisions are highly unlikely but still possible so we need the alternative:
+// RUN: FileCheck --check-prefix=CHECK-COLLISION %s < 1.txt || FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt
+//
+// REQUIRES: stable-runtime
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <time.h>
+
+#include <sanitizer/asan_interface.h>
+
+size_t nthreads = 10;
+size_t niter = 10;
+
+void *run(void *arg) {
+ unsigned seed = (unsigned)(size_t)arg;
+
+ volatile char tmp[2];
+ __asan_poison_memory_region(&tmp, sizeof(tmp));
+
+ for (size_t i = 0; i < niter; ++i) {
+ struct timespec delay = { 0, rand_r(&seed) * 1000000 };
+ nanosleep(&delay, 0);
+
+ // Expect error collisions here
+ // CHECK: AddressSanitizer: use-after-poison
+ volatile int idx = 0;
+ tmp[idx] = 0;
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ if (argc != 3) {
+ fprintf(stderr, "Syntax: %s nthreads niter\n", argv[0]);
+ exit(1);
+ }
+
+ nthreads = (size_t)strtoul(argv[1], 0, 0);
+ niter = (size_t)strtoul(argv[2], 0, 0);
+
+ pthread_t *tids = new pthread_t[nthreads];
+
+ for (size_t i = 0; i < nthreads; ++i) {
+ if (0 != pthread_create(&tids[i], 0, run, (void *)i)) {
+ fprintf(stderr, "Failed to create thread\n");
+ exit(1);
+ }
+ }
+
+ for (size_t i = 0; i < nthreads; ++i) {
+ if (0 != pthread_join(tids[i], 0)) {
+ fprintf(stderr, "Failed to join thread\n");
+ exit(1);
+ }
+ }
+
+ // CHECK-COLLISION: AddressSanitizer: nested bug in the same thread, aborting
+ // CHECK-NO-COLLISION: All threads terminated
+ printf("All threads terminated\n");
+
+ delete [] tids;
+
+ return 0;
+}
diff --git a/compiler-rt/test/asan/TestCases/Linux/interface_symbols_linux.c b/compiler-rt/test/asan/TestCases/Linux/interface_symbols_linux.c
index beb44bdc0b0..971feb5dc09 100644
--- a/compiler-rt/test/asan/TestCases/Linux/interface_symbols_linux.c
+++ b/compiler-rt/test/asan/TestCases/Linux/interface_symbols_linux.c
@@ -24,6 +24,18 @@
// RUN: echo __asan_report_store16 >> %t.interface
// RUN: echo __asan_report_load_n >> %t.interface
// RUN: echo __asan_report_store_n >> %t.interface
+// RUN: echo __asan_report_load1_noabort >> %t.interface
+// RUN: echo __asan_report_load2_noabort >> %t.interface
+// RUN: echo __asan_report_load4_noabort >> %t.interface
+// RUN: echo __asan_report_load8_noabort >> %t.interface
+// RUN: echo __asan_report_load16_noabort >> %t.interface
+// RUN: echo __asan_report_store1_noabort >> %t.interface
+// RUN: echo __asan_report_store2_noabort >> %t.interface
+// RUN: echo __asan_report_store4_noabort >> %t.interface
+// RUN: echo __asan_report_store8_noabort >> %t.interface
+// RUN: echo __asan_report_store16_noabort >> %t.interface
+// RUN: echo __asan_report_load_n_noabort >> %t.interface
+// RUN: echo __asan_report_store_n_noabort >> %t.interface
// RUN: echo __asan_report_exp_load1 >> %t.interface
// RUN: echo __asan_report_exp_load2 >> %t.interface
// RUN: echo __asan_report_exp_load4 >> %t.interface
diff --git a/compiler-rt/test/asan/TestCases/halt_on_error-1.c b/compiler-rt/test/asan/TestCases/halt_on_error-1.c
new file mode 100644
index 00000000000..90a907c39e7
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/halt_on_error-1.c
@@ -0,0 +1,29 @@
+// Test recovery mode.
+//
+// RUN: %clang_asan -fsanitize-recover=address %s -o %t
+//
+// RUN: env not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:halt_on_error=true not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER
+
+#include <string.h>
+
+volatile int ten = 10;
+
+int main() {
+ char x[10];
+ // CHECK: WRITE of size 11
+ // CHECK-RECOVER: WRITE of size 11
+ memset(x, 0, 11);
+ // CHECK-NOT: READ of size 1
+ // CHECK-RECOVER: READ of size 1
+ volatile int res = x[ten];
+ // CHECK-NOT: WRITE of size 1
+ // CHECK-RECOVER: WRITE of size 1
+ x[ten] = res + 3;
+ // CHECK-NOT: READ of size 1
+ // CHECK-RECOVER: READ of size 1
+ res = x[ten];
+ return 0;
+}
+
OpenPOWER on IntegriCloud