Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame^] | 1 | // Test for direct coverage writing enabled at activation time. |
| 2 | |
| 3 | // RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_activation_test_1.so -fPIC |
| 4 | // RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o |
| 5 | // RUN: %clangxx_asan -fsanitize-coverage=1 %t.o %libdl -o %t |
| 6 | |
| 7 | // RUN: rm -rf %T/coverage-direct-activation |
| 8 | |
| 9 | // RUN: mkdir -p %T/coverage-direct-activation/normal |
| 10 | // RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t |
| 11 | // RUN: %sancov print %T/coverage-direct-activation/normal/*.sancov >%T/coverage-direct-activation/normal/out.txt |
| 12 | |
| 13 | // RUN: mkdir -p %T/coverage-direct-activation/direct |
| 14 | // RUN: ASAN_OPTIONS=start_deactivated=1,coverage_direct=1,verbosity=1 \ |
| 15 | // RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t |
| 16 | // RUN: cd %T/coverage-direct-activation/direct |
| 17 | // RUN: %sancov rawunpack *.sancov.raw |
| 18 | // RUN: %sancov print *.sancov >out.txt |
| 19 | // RUN: cd ../.. |
| 20 | |
| 21 | // Test start_deactivated=1,coverage=1 in ASAN_OPTIONS. |
| 22 | |
| 23 | // RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct/out.txt |
| 24 | |
| 25 | // RUN: mkdir -p %T/coverage-direct-activation/direct2 |
| 26 | // RUN: ASAN_OPTIONS=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \ |
| 27 | // RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t |
| 28 | // RUN: cd %T/coverage-direct-activation/direct2 |
| 29 | // RUN: %sancov rawunpack *.sancov.raw |
| 30 | // RUN: %sancov print *.sancov >out.txt |
| 31 | // RUN: cd ../.. |
| 32 | |
| 33 | // RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct2/out.txt |
| 34 | |
| 35 | // XFAIL: android |
| 36 | |
| 37 | #include <assert.h> |
| 38 | #include <dlfcn.h> |
| 39 | #include <stdio.h> |
| 40 | #include <unistd.h> |
| 41 | |
| 42 | #ifdef SHARED |
| 43 | extern "C" { |
| 44 | void bar() { printf("bar\n"); } |
| 45 | } |
| 46 | #else |
| 47 | |
| 48 | int main(int argc, char **argv) { |
| 49 | fprintf(stderr, "PID: %d\n", getpid()); |
| 50 | void *handle1 = |
| 51 | dlopen(SO_DIR "/libcoverage_direct_activation_test_1.so", RTLD_LAZY); |
| 52 | assert(handle1); |
| 53 | void (*bar1)() = (void (*)())dlsym(handle1, "bar"); |
| 54 | assert(bar1); |
| 55 | bar1(); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | #endif |