1// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
2// RUN: %clangxx_asan -fsanitize-coverage=func,trace-pc-guard %s %ld_flags_rpath_exe -o %t
3// RUN: rm -rf %t-dir && mkdir -p %t-dir && cd %t-dir
4// RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s
5//
6// UNSUPPORTED: ios
7
8#include <stdio.h>
9
10#include <sanitizer/coverage_interface.h>
11
12#ifdef SHARED
13void bar1() { printf("bar1\n"); }
14void bar2() { printf("bar2\n"); }
15#else
16__attribute__((noinline)) void foo1() { printf(format: "foo1\n"); }
17__attribute__((noinline)) void foo2() { printf(format: "foo2\n"); }
18void bar1();
19void bar2();
20
21int main(int argc, char **argv) {
22 fprintf(stderr, format: "RESET\n");
23 __sanitizer_cov_reset();
24 foo1();
25 foo2();
26 bar1();
27 bar2();
28 __sanitizer_cov_dump();
29// CHECK: RESET
30// CHECK-DAG: SanitizerCoverage: ./coverage-reset.cpp{{.*}}.sancov: 2 PCs written
31// CHECK-DAG: SanitizerCoverage: ./libcoverage-reset.cpp{{.*}}.sancov: 2 PCs written
32
33 fprintf(stderr, format: "RESET\n");
34 __sanitizer_cov_reset();
35 foo1();
36 bar1();
37 __sanitizer_cov_dump();
38// CHECK: RESET
39// CHECK-DAG: SanitizerCoverage: ./coverage-reset.cpp{{.*}}.sancov: 1 PCs written
40// CHECK-DAG: SanitizerCoverage: ./libcoverage-reset.cpp{{.*}}.sancov: 1 PCs written
41
42 fprintf(stderr, format: "RESET\n");
43 __sanitizer_cov_reset();
44 foo1();
45 foo2();
46 __sanitizer_cov_dump();
47// CHECK: RESET
48// CHECK: SanitizerCoverage: ./coverage-reset.cpp{{.*}}.sancov: 2 PCs written
49
50 fprintf(stderr, format: "RESET\n");
51 __sanitizer_cov_reset();
52 bar1();
53 bar2();
54 __sanitizer_cov_dump();
55// CHECK: RESET
56// CHECK: SanitizerCoverage: ./libcoverage-reset.cpp{{.*}}.sancov: 2 PCs written
57
58 fprintf(stderr, format: "RESET\n");
59 __sanitizer_cov_reset();
60// CHECK: RESET
61
62 bar2();
63// CHECK: SanitizerCoverage: ./libcoverage-reset.cpp{{.*}}.sancov: 1 PCs written
64}
65#endif
66

source code of compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp