blob: 21a98515f648d2ec642e0df66b116569b6e9091e [file] [log] [blame]
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07001// Test -fsanitize-coverage=trace-bb
Stephen Hines6d186232014-11-26 17:56:19 -08002//
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07003// RUN: %clangxx_asan -O1 -fsanitize-coverage=func,trace-bb %s -o %t
Stephen Hines6d186232014-11-26 17:56:19 -08004// RUN: rm -rf %T/coverage-tracing
Stephen Hines86277eb2015-03-23 12:06:32 -07005// RUN: mkdir %T/coverage-tracing
6// RUN: cd %T/coverage-tracing
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07007// 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 Hines86277eb2015-03-23 12:06:32 -070015// 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 Hines6d186232014-11-26 17:56:19 -080025// RUN: rm -rf %T/coverage-tracing
26//
27// REQUIRES: asan-64-bits
28
Stephen Hines86277eb2015-03-23 12:06:32 -070029#include <stdlib.h>
Stephen Hines6d186232014-11-26 17:56:19 -080030volatile int sink;
Stephen Hines86277eb2015-03-23 12:06:32 -070031__attribute__((noinline)) void foo() { sink++; }
32__attribute__((noinline)) void bar() { sink++; }
33
Stephen Hines6d186232014-11-26 17:56:19 -080034int main(int argc, char **argv) {
Stephen Hines86277eb2015-03-23 12:06:32 -070035 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 Hines6d186232014-11-26 17:56:19 -080043}
44
Stephen Hines86277eb2015-03-23 12:06:32 -070045// 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