Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so |
| 2 | // RUN: %clangxx_asan -fsanitize-coverage=func %s %ld_flags_rpath_exe -o %t |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 3 | // RUN: rm -rf %T/coverage && mkdir -p %T/coverage && cd %T/coverage |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 4 | // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-main |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 5 | // RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 6 | // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 7 | // RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 8 | // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 9 | // RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 10 | // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 11 | // RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 |
| 12 | // RUN: %sancov print `ls *coverage.*sancov | grep '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1 |
| 13 | // RUN: %sancov merge `ls *coverage.*sancov | grep -v '.so'` > merged-cov |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 14 | // RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 15 | // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report |
| 16 | // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 17 | // RUN: rm -r %T/coverage |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 18 | // |
| 19 | // https://code.google.com/p/address-sanitizer/issues/detail?id=263 |
| 20 | // XFAIL: android |
| 21 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 22 | #include <sanitizer/coverage_interface.h> |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 23 | #include <assert.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | #include <unistd.h> |
| 27 | |
| 28 | #ifdef SHARED |
| 29 | void bar() { printf("bar\n"); } |
| 30 | #else |
| 31 | __attribute__((noinline)) |
| 32 | void foo() { printf("foo\n"); } |
| 33 | extern void bar(); |
| 34 | |
| 35 | int G[4]; |
| 36 | |
| 37 | int main(int argc, char **argv) { |
| 38 | fprintf(stderr, "PID: %d\n", getpid()); |
| 39 | for (int i = 1; i < argc; i++) { |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 40 | if (!strcmp(argv[i], "foo")) { |
| 41 | uintptr_t old_coverage = __sanitizer_get_total_unique_coverage(); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 42 | foo(); |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 43 | uintptr_t new_coverage = __sanitizer_get_total_unique_coverage(); |
| 44 | assert(new_coverage > old_coverage); |
| 45 | } |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 46 | if (!strcmp(argv[i], "bar")) |
| 47 | bar(); |
| 48 | } |
| 49 | if (argc == 5) { |
| 50 | static volatile char *zero = 0; |
| 51 | *zero = 0; // SEGV if argc == 5. |
| 52 | } |
| 53 | return G[argc]; // Buffer overflow if argc >= 4. |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | // CHECK-main: PID: [[PID:[0-9]+]] |
| 58 | // CHECK-main: [[PID]].sancov: 1 PCs written |
| 59 | // CHECK-main-NOT: .so.[[PID]] |
| 60 | // |
| 61 | // CHECK-foo: PID: [[PID:[0-9]+]] |
| 62 | // CHECK-foo: [[PID]].sancov: 2 PCs written |
| 63 | // CHECK-foo-NOT: .so.[[PID]] |
| 64 | // |
| 65 | // CHECK-bar: PID: [[PID:[0-9]+]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 66 | // CHECK-bar: .so.[[PID]].sancov: 1 PCs written |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 67 | // CHECK-bar: [[PID]].sancov: 1 PCs written |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 68 | // |
| 69 | // CHECK-foo-bar: PID: [[PID:[0-9]+]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 70 | // CHECK-foo-bar: so.[[PID]].sancov: 1 PCs written |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 71 | // CHECK-foo-bar: [[PID]].sancov: 2 PCs written |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 72 | // |
| 73 | // CHECK-report: AddressSanitizer: global-buffer-overflow |
| 74 | // CHECK-report: PCs written |
| 75 | // |
| 76 | // CHECK-segv: AddressSanitizer: SEGV |
| 77 | // CHECK-segv: PCs written |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 78 | // |
| 79 | // CHECK-SANCOV1: 1 PCs total |
| 80 | // CHECK-SANCOV2: 2 PCs total |