Move ASan lit-tests under test/asan
[blocksruntime.git] / test / asan / TestCases / Linux / coverage.cc
blob449e1c4469003e520f5f721fa6d3936110d68efc
1 // RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSHARED %s -shared -o %t.so -fPIC
2 // RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t -Wl,-R. %t.so
3 // RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
4 // RUN: %t 2>&1 | FileCheck %s --check-prefix=CHECK-main
5 // RUN: %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo
6 // RUN: %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar
7 // RUN: %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar
8 // RUN: not %t foo bar 1 2 2>&1 | FileCheck %s --check-prefix=CHECK-report
9 //
10 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
11 // XFAIL: android
13 #include <stdio.h>
14 #include <string.h>
15 #include <unistd.h>
17 #ifdef SHARED
18 void bar() { printf("bar\n"); }
19 #else
20 __attribute__((noinline))
21 void foo() { printf("foo\n"); }
22 extern void bar();
24 int G[4];
26 int main(int argc, char **argv) {
27 fprintf(stderr, "PID: %d\n", getpid());
28 for (int i = 1; i < argc; i++) {
29 if (!strcmp(argv[i], "foo"))
30 foo();
31 if (!strcmp(argv[i], "bar"))
32 bar();
34 return G[argc]; // Buffer overflow if argc >= 4.
36 #endif
38 // CHECK-main: PID: [[PID:[0-9]+]]
39 // CHECK-main: [[PID]].sancov: 1 PCs written
40 // CHECK-main-NOT: .so.[[PID]]
42 // CHECK-foo: PID: [[PID:[0-9]+]]
43 // CHECK-foo: [[PID]].sancov: 2 PCs written
44 // CHECK-foo-NOT: .so.[[PID]]
46 // CHECK-bar: PID: [[PID:[0-9]+]]
47 // CHECK-bar: [[PID]].sancov: 1 PCs written
48 // CHECK-bar: .so.[[PID]].sancov: 1 PCs written
50 // CHECK-foo-bar: PID: [[PID:[0-9]+]]
51 // CHECK-foo-bar: [[PID]].sancov: 2 PCs written
52 // CHECK-foo-bar: so.[[PID]].sancov: 1 PCs written
54 // CHECK-report: AddressSanitizer: global-buffer-overflow
55 // CHECK-report: PCs written