1 // Test for direct coverage writing with dlopen. 2 3 // Test normal exit. 4 // RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC 5 // RUN: %clangxx_asan -mllvm -asan-coverage=1 -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: ASAN_OPTIONS=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 %s 18 19 20 // Test sudden death. 21 // RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC 22 // RUN: %clangxx_asan -mllvm -asan-coverage=1 -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: ASAN_OPTIONS=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 %s 35 36 #include <assert.h> 37 #include <dlfcn.h> 38 #include <stdio.h> 39 #include <unistd.h> 40 #include <sys/types.h> 41 #include <signal.h> 42 43 #ifdef SHARED 44 extern "C" { bar()45void bar() { 46 printf("bar\n"); 47 #ifdef KILL 48 kill(getpid(), SIGKILL); 49 #endif 50 } 51 } 52 #else 53 main(int argc,char ** argv)54int main(int argc, char **argv) { 55 fprintf(stderr, "PID: %d\n", getpid()); 56 void *handle1 = 57 dlopen(SO_DIR "/libcoverage_android_test_1.so", RTLD_LAZY); 58 assert(handle1); 59 void (*bar1)() = (void (*)())dlsym(handle1, "bar"); 60 assert(bar1); 61 bar1(); 62 63 return 0; 64 } 65 #endif 66 67 // CHECK: 2 PCs total 68