Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 1 | // Test for direct coverage writing with dlopen at coverage level 1 to 3. |
| 2 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 3 | // RUN: %clangxx_asan -fsanitize-coverage=func -DSHARED %s -shared -o %dynamiclib -fPIC |
| 4 | // RUN: %clangxx_asan -fsanitize-coverage=func %s %libdl -o %t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | |
| 6 | // RUN: rm -rf %T/coverage-direct |
| 7 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 8 | // RUN: mkdir -p %T/coverage-direct/normal |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 9 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 10 | // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 11 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 12 | // RUN: mkdir -p %T/coverage-direct/direct |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 13 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 14 | // RUN: cd %T/coverage-direct/direct |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 20 | |
| 21 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 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 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 24 | |
| 25 | // RUN: rm -rf %T/coverage-direct |
| 26 | |
| 27 | // RUN: mkdir -p %T/coverage-direct/normal |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 28 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 29 | // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt |
| 30 | |
| 31 | // RUN: mkdir -p %T/coverage-direct/direct |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 32 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 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 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 43 | |
| 44 | // RUN: rm -rf %T/coverage-direct |
| 45 | |
| 46 | // RUN: mkdir -p %T/coverage-direct/normal |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 47 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 48 | // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt |
| 49 | |
| 50 | // RUN: mkdir -p %T/coverage-direct/direct |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 51 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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" { |
| 68 | void bar() { printf("bar\n"); } |
| 69 | } |
| 70 | #else |
| 71 | |
| 72 | int main(int argc, char **argv) { |
| 73 | fprintf(stderr, "PID: %d\n", getpid()); |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 74 | assert(argc > 1); |
| 75 | void *handle1 = dlopen(argv[1], RTLD_LAZY); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 76 | assert(handle1); |
| 77 | void (*bar1)() = (void (*)())dlsym(handle1, "bar"); |
| 78 | assert(bar1); |
| 79 | bar1(); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | #endif |