xref: /llvm-project/compiler-rt/test/profile/Linux/coverage_test.cpp (revision f23fae29eb38b9e9d0c6195fa82a882167bd8abe)
180d4b898SXinliang David Li // RUN: %clang_profgen -fuse-ld=gold -O2 -fdata-sections -ffunction-sections -fcoverage-mapping -Wl,--gc-sections -o %t %s
2944cd4d3SXinliang David Li // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
3944cd4d3SXinliang David Li // RUN: llvm-profdata merge -o %t.profdata %t.profraw
4*f23fae29SFangrui Song // RUN: llvm-cov show %t -instr-profile %t.profdata 2>&1 | FileCheck %s
50fc35d0aSXinliang David Li // BFD linker older than 2.26 has a bug that per-func profile data will be wrongly garbage collected when GC is turned on. We only do end-to-end test here without GC:
680d4b898SXinliang David Li // RUN: %clang_profgen -O2  -fcoverage-mapping  -o %t.2 %s
70fc35d0aSXinliang David Li // RUN: env LLVM_PROFILE_FILE=%t.2.profraw %run %t.2
80fc35d0aSXinliang David Li // RUN: llvm-profdata merge -o %t.2.profdata %t.2.profraw
9*f23fae29SFangrui Song // RUN: llvm-cov show %t.2 -instr-profile %t.2.profdata 2>&1 | FileCheck %s
100fc35d0aSXinliang David Li // Check covmap is not garbage collected when GC is turned on with BFD linker. Due to the bug mentioned above, we can only
110fc35d0aSXinliang David Li // do the check with objdump:
1280d4b898SXinliang David Li // RUN: %clang_profgen -O2  -fcoverage-mapping -Wl,--gc-sections -o %t.3 %s
130fc35d0aSXinliang David Li // RUN: llvm-objdump -h %t.3 | FileCheck --check-prefix COVMAP %s
140fc35d0aSXinliang David Li // Check PIE option
1580d4b898SXinliang David Li // RUN: %clang_profgen -fuse-ld=gold -O2 -fdata-sections -ffunction-sections -fPIE -pie -fcoverage-mapping -Wl,--gc-sections -o %t.pie %s
16944cd4d3SXinliang David Li // RUN: env LLVM_PROFILE_FILE=%t.pie.profraw %run %t.pie
17944cd4d3SXinliang David Li // RUN: llvm-profdata merge -o %t.pie.profdata %t.pie.profraw
18*f23fae29SFangrui Song // RUN: llvm-cov show %t.pie -instr-profile %t.pie.profdata 2>&1 | FileCheck %s
19944cd4d3SXinliang David Li 
foo(bool cond)205e3c5e80SVedant Kumar void foo(bool cond) { // CHECK:  [[@LINE]]| 1|void foo(
215e3c5e80SVedant Kumar   if (cond) {         // CHECK:  [[@LINE]]| 1| if (cond) {
22648752abSVedant Kumar   }                   // CHECK:  [[@LINE]]| 0|  }
235e3c5e80SVedant Kumar }                     // CHECK:  [[@LINE]]| 1|}
bar()245e3c5e80SVedant Kumar void bar() {          // CHECK:  [[@LINE]]| 1|void bar() {
255e3c5e80SVedant Kumar }                     // CHECK:  [[@LINE]]| 1|}
func()265e3c5e80SVedant Kumar void func() {         // CHECK:  [[@LINE]]| 0|void func(
275e3c5e80SVedant Kumar }                     // CHECK:  [[@LINE]]| 0|}
main()285e3c5e80SVedant Kumar int main() {          // CHECK:  [[@LINE]]| 1|int main(
295e3c5e80SVedant Kumar   foo(false);         // CHECK:  [[@LINE]]| 1| foo(
305e3c5e80SVedant Kumar   bar();              // CHECK:  [[@LINE]]| 1|  bar(
315e3c5e80SVedant Kumar   return 0;           // CHECK:  [[@LINE]]| 1| return
325e3c5e80SVedant Kumar }                     // CHECK:  [[@LINE]]| 1|}
33944cd4d3SXinliang David Li 
340fc35d0aSXinliang David Li // COVMAP: __llvm_covmap {{.*}}
35944cd4d3SXinliang David Li 
36