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