• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Test for direct coverage writing with dlopen.
2 
3 // Test normal exit, coverage level 1.
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
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
12 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
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
17 // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK1 %s
18 
19 
20 // Test sudden death, coverage level 1.
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
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
29 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
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
34 // RUN: %sancov print *.sancov |& FileCheck --check-prefix=CHECK1 %s
35 
36 
37 // Test normal exit, coverage level 2.
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
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
46 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
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.
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
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
63 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
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.
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
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
80 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
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.
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
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
97 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
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
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" {
bar()113 void bar() {
114   printf("bar\n");
115 #ifdef KILL
116   kill(getpid(), SIGKILL);
117 #endif
118 }
119 }
120 #else
121 
122 volatile int sink;
123 
main(int argc,char ** argv)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);
129 
130   if (argc == 0)
131     sink = 0;
132 
133   void (*bar1)() = (void (*)())dlsym(handle1, "bar");
134   assert(bar1);
135   bar1();
136 
137   return 0;
138 }
139 #endif
140 
141 // CHECK1: 2 PCs total
142 // CHECK2: 4 PCs total
143 // CHECK3: 5 PCs total
144