]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/profile/instrprof-merging.cpp
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / profile / instrprof-merging.cpp
1 // 1) Compile shared code into different object files and into an executable.
2
3 // RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v1.o -D_VERSION_1
4 // RUN: %clangxx_profgen -fcoverage-mapping %s -c -o %t.v2.o -D_VERSION_2
5 // RUN: %clangxx_profgen -fcoverage-mapping %t.v1.o %t.v2.o -o %t.exe
6
7 // 2) Collect profile data.
8
9 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.exe
10 // RUN: llvm-profdata merge %t.profraw -o %t.profdata
11
12 // 3) Generate coverage reports from the different object files and the exe.
13
14 // RUN: llvm-cov show %t.v1.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V1-ONLY
15 // RUN: llvm-cov show %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V2,V2-ONLY
16 // RUN: llvm-cov show %t.v1.o -object %t.v2.o -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
17 // RUN: llvm-cov show %t.exe -instr-profile=%t.profdata | FileCheck %s -check-prefixes=V1,V2
18
19 // 4) Verify that coverage reporting on the aggregate coverage mapping shows
20 //    hits for all code. (We used to arbitrarily pick a mapping from one binary
21 //    and prefer it over others.) When only limited coverage information is
22 //    available (just from one binary), don't try to guess any region counts.
23
24 struct A {
25   A() {}    // V1: [[@LINE]]{{ *}}|{{ *}}1
26             // V1-ONLY: [[@LINE+1]]{{ *}}|{{ *}}|
27   A(int) {} // V2-ONLY: [[@LINE-2]]{{ *}}|{{ *}}|
28             // V2: [[@LINE-1]]{{ *}}|{{ *}}1
29 };
30
31 #ifdef _VERSION_1
32
33 void foo();
34
35 void bar() {
36   A x;      // V1: [[@LINE]]{{ *}}|{{ *}}1
37 }
38
39 int main() {
40   foo();    // V1: [[@LINE]]{{ *}}|{{ *}}1
41   bar();
42   return 0;
43 }
44
45 #endif // _VERSION_1
46
47 #ifdef _VERSION_2
48
49 void foo() {
50   A x{0};   // V2: [[@LINE]]{{ *}}|{{ *}}1
51 }
52
53 #endif // _VERSION_2