aboutsummaryrefslogtreecommitdiff
path: root/test/sanitizer_common/TestCases/Posix
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:45:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:45:36 +0000
commit6f08730ec5f639f05f2f15354171e4a3c9af9dc1 (patch)
tree7374e9d4448083010ada98d17976199c7e945d47 /test/sanitizer_common/TestCases/Posix
parentc003a57e2e4a1ad9be0338806bc1038b6987155f (diff)
downloadsrc-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.tar.gz
src-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.zip
Vendor import of compiler-rt release_39 branch r276489:vendor/compiler-rt/compiler-rt-release_39-r276489
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=303235 svn path=/vendor/compiler-rt/compiler-rt-release_39-r276489/; revision=303236; tag=vendor/compiler-rt/compiler-rt-release_39-r276489
Diffstat (limited to 'test/sanitizer_common/TestCases/Posix')
-rw-r--r--test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc61
-rw-r--r--test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc40
-rw-r--r--test/sanitizer_common/TestCases/Posix/getpass.cc37
-rw-r--r--test/sanitizer_common/TestCases/Posix/lit.local.cfg2
-rw-r--r--test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc40
-rw-r--r--test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc37
6 files changed, 155 insertions, 62 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc b/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc
deleted file mode 100644
index 36d4df567ee7..000000000000
--- a/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-// RUN: %clangxx -g %s -o %t
-// RUN: %env_tool_opts=decorate_proc_maps=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%tool_name
-// REQUIRES: stable-runtime
-#include <errno.h>
-#include <fcntl.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-bool CopyFdToFd(int in_fd, int out_fd) {
- const size_t kBufSize = 0x10000;
- static char buf[kBufSize];
- while (true) {
- ssize_t got = read(in_fd, buf, kBufSize);
- if (got > 0) {
- write(out_fd, buf, got);
- } else if (got == 0) {
- break;
- } else if (errno != EAGAIN || errno != EWOULDBLOCK || errno != EINTR) {
- fprintf(stderr, "error reading file, errno %d\n", errno);
- return false;
- }
- }
- return true;
-}
-
-void *ThreadFn(void *arg) {
- (void)arg;
- int fd = open("/proc/self/maps", O_RDONLY);
- bool res = CopyFdToFd(fd, 2);
- close(fd);
- return (void *)!res;
-}
-
-int main(void) {
- pthread_t t;
- void *res;
- pthread_create(&t, 0, ThreadFn, 0);
- pthread_join(t, &res);
- return (int)(size_t)res;
-}
-
-// CHECK-asan: rw-p {{.*}} [low shadow]
-// CHECK-asan: ---p {{.*}} [shadow gap]
-// CHECK-asan: rw-p {{.*}} [high shadow]
-
-// CHECK-msan: ---p {{.*}} [invalid]
-// CHECK-msan: rw-p {{.*}} [shadow{{.*}}]
-// CHECK-msan: ---p {{.*}} [origin{{.*}}]
-
-// CHECK-tsan: rw-p {{.*}} [shadow]
-// CHECK-tsan: rw-p {{.*}} [meta shadow]
-// CHECK-tsan: rw-p {{.*}} [trace 0]
-// CHECK-tsan: rw-p {{.*}} [trace header 0]
-// CHECK-tsan: rw-p {{.*}} [trace 1]
-// CHECK-tsan: rw-p {{.*}} [trace header 1]
-
-// Nothing interesting with standalone LSan.
-// CHECK-lsan: decorate_proc_maps
diff --git a/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc b/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc
new file mode 100644
index 000000000000..88d41b6d5fea
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc
@@ -0,0 +1,40 @@
+// Test dedup_token_length
+// RUN: %clangxx -O0 %s -o %t
+// RUN: env %tool_options='abort_on_error=0' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: env %tool_options='abort_on_error=0, dedup_token_length=0' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: env %tool_options='abort_on_error=0, dedup_token_length=1' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: env %tool_options='abort_on_error=0, dedup_token_length=2' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: env %tool_options='abort_on_error=0, dedup_token_length=3' not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+// REQUIRES: stable-runtime
+// FIXME: implement SEGV handler in other sanitizers, not just asan.
+// XFAIL: msan
+// XFAIL: lsan
+// XFAIL: tsan
+
+volatile int *null = 0;
+
+namespace Xyz {
+ template<class A, class B> void Abc() {
+ *null = 0;
+ }
+}
+
+extern "C" void bar() {
+ Xyz::Abc<int, int>();
+}
+
+void FOO() {
+ bar();
+}
+
+int main(int argc, char **argv) {
+ FOO();
+}
+
+// CHECK0-NOT: DEDUP_TOKEN:
+// CHECK1: DEDUP_TOKEN: void Xyz::Abc<int, int>()
+// CHECK1-NOT: bar
+// CHECK2: DEDUP_TOKEN: void Xyz::Abc<int, int>()--bar
+// CHECK2-NOT: FOO
+// CHECK3: DEDUP_TOKEN: void Xyz::Abc<int, int>()--bar--FOO()
diff --git a/test/sanitizer_common/TestCases/Posix/getpass.cc b/test/sanitizer_common/TestCases/Posix/getpass.cc
new file mode 100644
index 000000000000..251f9119d682
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/getpass.cc
@@ -0,0 +1,37 @@
+// RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t | FileCheck %s
+// REQUIRES: stable-runtime
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#if __linux__
+#include <pty.h>
+#else
+#include <util.h>
+#endif
+
+int
+main (int argc, char** argv)
+{
+ int master;
+ int pid = forkpty(&master, NULL, NULL, NULL);
+
+ if(pid == -1) {
+ fprintf(stderr, "forkpty failed\n");
+ return 1;
+ } else if (pid > 0) {
+ char buf[1024];
+ int res = read(master, buf, sizeof(buf));
+ write(1, buf, res);
+ write(master, "password\n", 9);
+ while ((res = read(master, buf, sizeof(buf))) > 0) write(1, buf, res);
+ } else {
+ char *s = getpass("prompt");
+ assert(strcmp(s, "password") == 0);
+ write(1, "done\n", 5);
+ }
+ return 0;
+}
+
+// CHECK: prompt
+// CHECK: done
diff --git a/test/sanitizer_common/TestCases/Posix/lit.local.cfg b/test/sanitizer_common/TestCases/Posix/lit.local.cfg
index a6d96d3054cf..60a9460820a6 100644
--- a/test/sanitizer_common/TestCases/Posix/lit.local.cfg
+++ b/test/sanitizer_common/TestCases/Posix/lit.local.cfg
@@ -5,5 +5,5 @@ def getRoot(config):
root = getRoot(config)
-if root.host_os in ['Windows', 'Darwin']:
+if root.host_os in ['Windows']:
config.unsupported = True
diff --git a/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc b/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc
new file mode 100644
index 000000000000..fdb68c0cdea5
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc
@@ -0,0 +1,40 @@
+// RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: stable-runtime
+
+#include <sanitizer/common_interface_defs.h>
+#include <stdio.h>
+
+volatile char *zero = 0;
+
+void Death() {
+ fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
+}
+// CHECK: DEATH CALLBACK EXECUTED
+
+char global;
+volatile char *sink;
+
+__attribute__((noinline))
+void MaybeInit(int *uninitialized) {
+ if (zero)
+ *uninitialized = 1;
+}
+
+__attribute__((noinline))
+void Leak() {
+ sink = new char[100]; // trigger lsan report.
+}
+
+int main(int argc, char **argv) {
+ int uninitialized;
+ __sanitizer_set_death_callback(Death);
+ MaybeInit(&uninitialized);
+ if (uninitialized) // trigger msan report.
+ global = 77;
+ sink = new char[100];
+ delete[] sink;
+ global = sink[0]; // use-after-free: trigger asan/tsan report.
+ Leak();
+ sink = 0;
+}
diff --git a/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc b/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
new file mode 100644
index 000000000000..af7eea1d7de2
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
@@ -0,0 +1,37 @@
+// Test __sanitizer_set_report_fd:
+// RUN: %clangxx -O2 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: not %run %t stdout | FileCheck %s
+// RUN: not %run %t %t-out && FileCheck < %t-out %s
+
+// REQUIRES: stable-runtime
+// FIXME: implement SEGV handler in other sanitizers, not just asan.
+// XFAIL: msan
+// XFAIL: lsan
+// XFAIL: tsan
+
+#include <sanitizer/common_interface_defs.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <assert.h>
+
+volatile int *null = 0;
+
+int main(int argc, char **argv) {
+ if (argc == 2) {
+ if (!strcmp(argv[1], "stdout")) {
+ __sanitizer_set_report_fd(reinterpret_cast<void*>(1));
+ } else {
+ int fd = open(argv[1], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
+ assert(fd > 0);
+ __sanitizer_set_report_fd(reinterpret_cast<void*>(fd));
+ }
+ }
+ *null = 0;
+}
+
+// CHECK: ERROR: {{.*}} SEGV on unknown address