Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 1 | // Test for direct coverage writing enabled at activation time. |
| 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 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 4 | // RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 5 | // RUN: %clangxx_asan -fsanitize-coverage=func %t.o %libdl -o %t |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 6 | |
| 7 | // RUN: rm -rf %T/coverage-direct-activation |
| 8 | |
| 9 | // RUN: mkdir -p %T/coverage-direct-activation/normal |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 10 | // RUN: %env_asan_opts=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 14 | // RUN: %env_asan_opts=start_deactivated=1,coverage_direct=1,verbosity=1 \ |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 15 | // RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 26 | // RUN: %env_asan_opts=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \ |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 27 | // RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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()); |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 50 | assert(argc > 1); |
| 51 | void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 52 | assert(handle1); |
| 53 | void (*bar1)() = (void (*)())dlsym(handle1, "bar"); |
| 54 | assert(bar1); |
| 55 | bar1(); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | #endif |