Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 1 | // Test -fsanitize-coverage=trace-bb |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 2 | // |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 3 | // RUN: %clangxx_asan -O1 -fsanitize-coverage=func,trace-bb %s -o %t |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 4 | // RUN: rm -rf %T/coverage-tracing |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 5 | // RUN: mkdir %T/coverage-tracing |
| 6 | // RUN: cd %T/coverage-tracing |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 7 | // RUN: A=x; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK1; mv trace-points.*.sancov $A.points |
| 8 | // RUN: A=f; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points |
| 9 | // RUN: A=b; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points |
| 10 | // RUN: A=bf; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points |
| 11 | // RUN: A=fb; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points |
| 12 | // RUN: A=ffb; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points |
| 13 | // RUN: A=fff; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points |
| 14 | // RUN: A=bbf; ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:verbosity=1 %run %t $A 100 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK301; mv trace-points.*.sancov $A.points |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 15 | // RUN: diff f.points fff.points |
| 16 | // RUN: diff bf.points fb.points |
| 17 | // RUN: diff bf.points ffb.points |
| 18 | // RUN: diff bf.points bbf.points |
| 19 | // RUN: not diff x.points f.points |
| 20 | // RUN: not diff x.points b.points |
| 21 | // RUN: not diff x.points bf.points |
| 22 | // RUN: not diff f.points b.points |
| 23 | // RUN: not diff f.points bf.points |
| 24 | // RUN: not diff b.points bf.points |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 25 | // RUN: rm -rf %T/coverage-tracing |
| 26 | // |
| 27 | // REQUIRES: asan-64-bits |
| 28 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 29 | #include <stdlib.h> |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 30 | volatile int sink; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 31 | __attribute__((noinline)) void foo() { sink++; } |
| 32 | __attribute__((noinline)) void bar() { sink++; } |
| 33 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 34 | int main(int argc, char **argv) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 35 | if (argc != 3) return 0; |
| 36 | int n = strtol(argv[2], 0, 10); |
| 37 | while (n-- > 0) { |
| 38 | for (int i = 0; argv[1][i]; i++) { |
| 39 | if (argv[1][i] == 'f') foo(); |
| 40 | else if (argv[1][i] == 'b') bar(); |
| 41 | } |
| 42 | } |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 45 | // CHECK: CovDump: Trace: 3 PCs written |
| 46 | // CHECK1: CovDump: Trace: 1 Events written |
| 47 | // CHECK2: CovDump: Trace: 2 Events written |
| 48 | // CHECK3: CovDump: Trace: 3 Events written |
| 49 | // CHECK4: CovDump: Trace: 4 Events written |
| 50 | // CHECK301: CovDump: Trace: 301 Events written |