1 // Test for direct coverage writing with dlopen at coverage level 1 to 3. 2 3 // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC 4 // RUN: %clangxx_asan -fsanitize-coverage=func %s %libdl -o %t 5 6 // RUN: rm -rf %T/coverage-direct 7 8 // RUN: mkdir -p %T/coverage-direct/normal 9 // RUN: %env_asan_opts=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib 10 // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt 11 12 // RUN: mkdir -p %T/coverage-direct/direct 13 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib 14 // RUN: cd %T/coverage-direct/direct 15 // RUN: %sancov rawunpack *.sancov.raw 16 // RUN: %sancov print *.sancov >out.txt 17 // RUN: cd ../.. 18 19 // RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt 20 21 22 // RUN: %clangxx_asan -fsanitize-coverage=bb -DSHARED %s -shared -o %dynamiclib -fPIC 23 // RUN: %clangxx_asan -fsanitize-coverage=bb -DSO_DIR=\"%T\" %s %libdl -o %t 24 25 // RUN: rm -rf %T/coverage-direct 26 27 // RUN: mkdir -p %T/coverage-direct/normal 28 // RUN: %env_asan_opts=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib 29 // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt 30 31 // RUN: mkdir -p %T/coverage-direct/direct 32 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib 33 // RUN: cd %T/coverage-direct/direct 34 // RUN: %sancov rawunpack *.sancov.raw 35 // RUN: %sancov print *.sancov >out.txt 36 // RUN: cd ../.. 37 38 // RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt 39 40 41 // RUN: %clangxx_asan -fsanitize-coverage=edge -DSHARED %s -shared -o %dynamiclib -fPIC 42 // RUN: %clangxx_asan -fsanitize-coverage=edge -DSO_DIR=\"%T\" %s %libdl -o %t 43 44 // RUN: rm -rf %T/coverage-direct 45 46 // RUN: mkdir -p %T/coverage-direct/normal 47 // RUN: %env_asan_opts=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib 48 // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt 49 50 // RUN: mkdir -p %T/coverage-direct/direct 51 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib 52 // RUN: cd %T/coverage-direct/direct 53 // RUN: %sancov rawunpack *.sancov.raw 54 // RUN: %sancov print *.sancov >out.txt 55 // RUN: cd ../.. 56 57 // RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt 58 59 // XFAIL: android 60 61 #include <assert.h> 62 #include <dlfcn.h> 63 #include <stdio.h> 64 #include <unistd.h> 65 66 #ifdef SHARED 67 extern "C" { bar()68void bar() { printf("bar\n"); } 69 } 70 #else 71 main(int argc,char ** argv)72int main(int argc, char **argv) { 73 fprintf(stderr, "PID: %d\n", getpid()); 74 assert(argc > 1); 75 void *handle1 = dlopen(argv[1], RTLD_LAZY); 76 assert(handle1); 77 void (*bar1)() = (void (*)())dlsym(handle1, "bar"); 78 assert(bar1); 79 bar1(); 80 81 return 0; 82 } 83 #endif 84