blob: 5f2631605595ddab8135477d2e443502ccafa932 [file] [log] [blame]
Stephen Hines6a211c52014-07-21 00:49:56 -07001// Test for direct coverage writing with dlopen.
2
Stephen Hines86277eb2015-03-23 12:06:32 -07003// Test normal exit, coverage level 1.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07004// 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 Hines6a211c52014-07-21 00:49:56 -07006
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 Nainarcdce50b2015-07-01 12:26:56 -070012// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
Stephen Hines6a211c52014-07-21 00:49:56 -070013// 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 Hines86277eb2015-03-23 12:06:32 -070017// RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK1 %s
Stephen Hines6a211c52014-07-21 00:49:56 -070018
19
Stephen Hines86277eb2015-03-23 12:06:32 -070020// Test sudden death, coverage level 1.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070021// 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 Hines6a211c52014-07-21 00:49:56 -070023
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 Nainarcdce50b2015-07-01 12:26:56 -070029// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
Stephen Hines6a211c52014-07-21 00:49:56 -070030// 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 Hines86277eb2015-03-23 12:06:32 -070034// RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK1 %s
35
36
37// Test normal exit, coverage level 2.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070038// 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 Hines86277eb2015-03-23 12:06:32 -070040
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 Nainarcdce50b2015-07-01 12:26:56 -070046// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
Stephen Hines86277eb2015-03-23 12:06:32 -070047// 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 Nainarcdce50b2015-07-01 12:26:56 -070055// 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 Hines86277eb2015-03-23 12:06:32 -070057
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 Nainarcdce50b2015-07-01 12:26:56 -070063// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
Stephen Hines86277eb2015-03-23 12:06:32 -070064// 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 Nainarcdce50b2015-07-01 12:26:56 -070072// 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 Hines86277eb2015-03-23 12:06:32 -070074
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 Nainarcdce50b2015-07-01 12:26:56 -070080// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
Stephen Hines86277eb2015-03-23 12:06:32 -070081// 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 Nainarcdce50b2015-07-01 12:26:56 -070089// 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 Hines86277eb2015-03-23 12:06:32 -070091
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 Nainarcdce50b2015-07-01 12:26:56 -070097// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
Stephen Hines86277eb2015-03-23 12:06:32 -070098// 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 Hines6a211c52014-07-21 00:49:56 -0700103
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
112extern "C" {
113void bar() {
114 printf("bar\n");
115#ifdef KILL
116 kill(getpid(), SIGKILL);
117#endif
118}
119}
120#else
121
Stephen Hines86277eb2015-03-23 12:06:32 -0700122volatile int sink;
123
Stephen Hines6a211c52014-07-21 00:49:56 -0700124int 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 Hines86277eb2015-03-23 12:06:32 -0700129
130 if (argc == 0)
131 sink = 0;
132
Stephen Hines6a211c52014-07-21 00:49:56 -0700133 void (*bar1)() = (void (*)())dlsym(handle1, "bar");
134 assert(bar1);
135 bar1();
136
137 return 0;
138}
139#endif
140
Stephen Hines86277eb2015-03-23 12:06:32 -0700141// CHECK1: 2 PCs total
142// CHECK2: 7 PCs total
143// CHECK3: 8 PCs total