Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // Test for direct coverage writing with dlopen. |
| 2 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 3 | // Test normal exit, coverage level 1. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 4 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC |
| 5 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSO_DIR=\"%device\" %s -o %t |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 6 | |
| 7 | // RUN: adb shell rm -rf %device/coverage-android |
| 8 | // RUN: rm -rf %T/coverage-android |
| 9 | |
| 10 | // RUN: adb shell mkdir -p %device/coverage-android/direct |
| 11 | // RUN: mkdir -p %T/coverage-android/direct |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 12 | // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 13 | // RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct |
| 14 | // RUN: ls; pwd |
| 15 | // RUN: cd %T/coverage-android/direct |
| 16 | // RUN: %sancov rawunpack *.sancov.raw |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 17 | // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK1 %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 18 | |
| 19 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 20 | // Test sudden death, coverage level 1. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 21 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC |
| 22 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSO_DIR=\"%device\" %s -o %t |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 23 | |
| 24 | // RUN: adb shell rm -rf %device/coverage-android-kill |
| 25 | // RUN: rm -rf %T/coverage-android-kill |
| 26 | |
| 27 | // RUN: adb shell mkdir -p %device/coverage-android-kill/direct |
| 28 | // RUN: mkdir -p %T/coverage-android-kill/direct |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 29 | // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 30 | // RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct |
| 31 | // RUN: ls; pwd |
| 32 | // RUN: cd %T/coverage-android-kill/direct |
| 33 | // RUN: %sancov rawunpack *.sancov.raw |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 34 | // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK1 %s |
| 35 | |
| 36 | |
| 37 | // Test normal exit, coverage level 2. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 38 | // RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC |
| 39 | // RUN: %clangxx_asan -fsanitize-coverage=bb -DSO_DIR=\"%device\" %s -o %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 40 | |
| 41 | // RUN: adb shell rm -rf %device/coverage-android |
| 42 | // RUN: rm -rf %T/coverage-android |
| 43 | |
| 44 | // RUN: adb shell mkdir -p %device/coverage-android/direct |
| 45 | // RUN: mkdir -p %T/coverage-android/direct |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 46 | // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 47 | // RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct |
| 48 | // RUN: ls; pwd |
| 49 | // RUN: cd %T/coverage-android/direct |
| 50 | // RUN: %sancov rawunpack *.sancov.raw |
| 51 | // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK2 %s |
| 52 | |
| 53 | |
| 54 | // Test sudden death, coverage level 2. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 55 | // RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC |
| 56 | // RUN: %clangxx_asan -fsanitize-coverage=bb -DSO_DIR=\"%device\" %s -o %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 57 | |
| 58 | // RUN: adb shell rm -rf %device/coverage-android-kill |
| 59 | // RUN: rm -rf %T/coverage-android-kill |
| 60 | |
| 61 | // RUN: adb shell mkdir -p %device/coverage-android-kill/direct |
| 62 | // RUN: mkdir -p %T/coverage-android-kill/direct |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 63 | // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 64 | // RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct |
| 65 | // RUN: ls; pwd |
| 66 | // RUN: cd %T/coverage-android-kill/direct |
| 67 | // RUN: %sancov rawunpack *.sancov.raw |
| 68 | // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK2 %s |
| 69 | |
| 70 | |
| 71 | // Test normal exit, coverage level 3. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 72 | // RUN: %clangxx_asan -fsanitize-coverage=edge -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC |
| 73 | // RUN: %clangxx_asan -fsanitize-coverage=edge -DSO_DIR=\"%device\" %s -o %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 74 | |
| 75 | // RUN: adb shell rm -rf %device/coverage-android |
| 76 | // RUN: rm -rf %T/coverage-android |
| 77 | |
| 78 | // RUN: adb shell mkdir -p %device/coverage-android/direct |
| 79 | // RUN: mkdir -p %T/coverage-android/direct |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 80 | // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 81 | // RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct |
| 82 | // RUN: ls; pwd |
| 83 | // RUN: cd %T/coverage-android/direct |
| 84 | // RUN: %sancov rawunpack *.sancov.raw |
| 85 | // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK3 %s |
| 86 | |
| 87 | |
| 88 | // Test sudden death, coverage level 3. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 89 | // RUN: %clangxx_asan -fsanitize-coverage=edge -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC |
| 90 | // RUN: %clangxx_asan -fsanitize-coverage=edge -DSO_DIR=\"%device\" %s -o %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 91 | |
| 92 | // RUN: adb shell rm -rf %device/coverage-android-kill |
| 93 | // RUN: rm -rf %T/coverage-android-kill |
| 94 | |
| 95 | // RUN: adb shell mkdir -p %device/coverage-android-kill/direct |
| 96 | // RUN: mkdir -p %T/coverage-android-kill/direct |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 97 | // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 98 | // RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct |
| 99 | // RUN: ls; pwd |
| 100 | // RUN: cd %T/coverage-android-kill/direct |
| 101 | // RUN: %sancov rawunpack *.sancov.raw |
| 102 | // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK3 %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 103 | |
| 104 | #include <assert.h> |
| 105 | #include <dlfcn.h> |
| 106 | #include <stdio.h> |
| 107 | #include <unistd.h> |
| 108 | #include <sys/types.h> |
| 109 | #include <signal.h> |
| 110 | |
| 111 | #ifdef SHARED |
| 112 | extern "C" { |
| 113 | void bar() { |
| 114 | printf("bar\n"); |
| 115 | #ifdef KILL |
| 116 | kill(getpid(), SIGKILL); |
| 117 | #endif |
| 118 | } |
| 119 | } |
| 120 | #else |
| 121 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 122 | volatile int sink; |
| 123 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 124 | int main(int argc, char **argv) { |
| 125 | fprintf(stderr, "PID: %d\n", getpid()); |
| 126 | void *handle1 = |
| 127 | dlopen(SO_DIR "/libcoverage_android_test_1.so", RTLD_LAZY); |
| 128 | assert(handle1); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 129 | |
| 130 | if (argc == 0) |
| 131 | sink = 0; |
| 132 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 133 | void (*bar1)() = (void (*)())dlsym(handle1, "bar"); |
| 134 | assert(bar1); |
| 135 | bar1(); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | #endif |
| 140 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 141 | // CHECK1: 2 PCs total |
| 142 | // CHECK2: 7 PCs total |
| 143 | // CHECK3: 8 PCs total |