1 | // Tests trace pc guard coverage collection. |
2 | |
3 | // REQUIRES: has_sancovcc |
4 | // UNSUPPORTED: ubsan,target={{(powerpc64|s390x|thumb).*}} |
5 | // XFAIL: tsan,darwin |
6 | // XFAIL: android && asan |
7 | |
8 | // RUN: DIR=%t_workdir |
9 | // RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard" |
10 | // RUN: rm -rf $DIR |
11 | // RUN: mkdir -p $DIR |
12 | // RUN: cd $DIR |
13 | // RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC |
14 | // RUN: %clangxx -DSHARED2 $CLANG_ARGS -shared %s -o %t_2.so -fPIC |
15 | // RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.so |
16 | // RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s |
17 | // RUN: %sancovcc -covered-functions -strip_path_prefix=TestCases/ *.sancov \ |
18 | // RUN: %t %t_1.so %t_2.so 2>&1 | \ |
19 | // RUN: FileCheck --check-prefix=CHECK-SANCOV %s |
20 | // RUN: rm -rf $DIR |
21 | |
22 | #include <stdio.h> |
23 | |
24 | extern "C" { |
25 | int bar(); |
26 | int baz(); |
27 | } |
28 | |
29 | #ifdef MAIN |
30 | |
31 | int foo() { |
32 | fprintf(stderr, "foo\n" ); |
33 | return 1; |
34 | } |
35 | |
36 | int main() { |
37 | fprintf(stderr, "main\n" ); |
38 | foo(); |
39 | bar(); |
40 | baz(); |
41 | } |
42 | |
43 | #endif // MAIN |
44 | |
45 | extern "C" { |
46 | |
47 | #ifdef SHARED1 |
48 | int bar() { |
49 | fprintf(stderr, "bar\n" ); |
50 | return 1; |
51 | } |
52 | #endif |
53 | |
54 | #ifdef SHARED2 |
55 | int baz() { |
56 | fprintf(stderr, "baz\n" ); |
57 | return 1; |
58 | } |
59 | #endif |
60 | |
61 | } // extern "C" |
62 | |
63 | // CHECK: main |
64 | // CHECK-NEXT: foo |
65 | // CHECK-NEXT: bar |
66 | // CHECK-NEXT: baz |
67 | // CHECK-DAG: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard-dso.{{.*}}.sancov: 2 PCs written |
68 | // CHECK-DAG: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard-dso.{{.*}}_2.so.{{.*}}.sancov: 1 PCs written |
69 | // CHECK-DAG: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard-dso.{{.*}}_1.so.{{.*}}.sancov: 1 PCs written |
70 | // |
71 | // CHECK-SANCOV: Ignoring {{.*}}_1.so and its coverage because __sanitizer_cov* functions were not found. |
72 | // CHECK-SANCOV: Ignoring {{.*}}_2.so and its coverage because __sanitizer_cov* functions were not found. |
73 | // CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cpp:[[@LINE-42]] foo |
74 | // CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard-dso.cpp:[[@LINE-38]] main |
75 | |