• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Test -fsanitize-coverage=trace-bb
2 //
3 // RUN: %clangxx_asan -O1 -fsanitize-coverage=func,trace-bb %s -o %t
4 // RUN: rm -rf   %T/coverage-tracing
5 // RUN: mkdir %T/coverage-tracing
6 // RUN: cd %T/coverage-tracing
7 // RUN:  A=x;   %env_asan_opts=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;   %env_asan_opts=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;   %env_asan_opts=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;  %env_asan_opts=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;  %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=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; %env_asan_opts=coverage=1:verbosity=1 %run %t $A 100 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK301; mv trace-points.*.sancov $A.points
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
25 // RUN: rm -rf   %T/coverage-tracing
26 //
27 // REQUIRES: asan-64-bits
28 // UNSUPPORTED: android
29 
30 #include <stdlib.h>
31 volatile int sink;
foo()32 __attribute__((noinline)) void foo() { sink++; }
bar()33 __attribute__((noinline)) void bar() { sink++; }
34 
main(int argc,char ** argv)35 int main(int argc, char **argv) {
36   if (argc != 3) return 0;
37   int n = strtol(argv[2], 0, 10);
38   while (n-- > 0) {
39     for (int i = 0; argv[1][i]; i++) {
40       if (argv[1][i] == 'f') foo();
41       else if (argv[1][i] == 'b') bar();
42     }
43   }
44 }
45 
46 // CHECK: CovDump: Trace: 3 PCs written
47 // CHECK1: CovDump: Trace: 1 Events written
48 // CHECK2: CovDump: Trace: 2 Events written
49 // CHECK3: CovDump: Trace: 3 Events written
50 // CHECK4: CovDump: Trace: 4 Events written
51 // CHECK301: CovDump: Trace: 301 Events written
52