[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / test / tools / llvm-cov / branch-showBranchPercentage.c
bloba649462116a08e302e078e523b141e802d4f44b6
1 // Test visualization of branch taken percentages
3 // RUN: llvm-profdata merge %S/Inputs/branch-showBranchPercentage.proftext -o %t.profdata
4 // RUN: llvm-cov show --show-branches=percent %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
6 #include <stdio.h>
7 #include <stdlib.h>
9 extern void __llvm_profile_write_file(void);
11 int main(int argc, char *argv[])
13 int i = 0;
14 if (argc < 3) // CHECK: Branch ([[@LINE]]:7): [True: 16.67%, False: 83.33%]
16 __llvm_profile_write_file();
17 return 0;
20 int a = atoi(argv[1]);
21 int b = atoi(argv[2]);
23 // CHECK: Branch ([[@LINE+4]]:8): [True: 20.00%, False: 80.00%]
24 // CHECK: Branch ([[@LINE+3]]:18): [True: 0.00%, False: 100.00%]
25 // CHECK: Branch ([[@LINE+2]]:29): [True: 0.00%, False: 100.00%]
26 // CHECK: Branch ([[@LINE+1]]:40): [True: 40.00%, False: 60.00%]
27 if ((a == 0 && b == 2) || b == 34 || a == b)
28 printf("case1\n");
30 b = (a != 0 || a == 2) ? b : b+2; // CHECK: Branch ([[@LINE]]:8): [True: 80.00%, False: 20.00%]
31 // CHECK: Branch ([[@LINE-1]]:18): [True: 0.00%, False: 100.00%]
32 b = (a != 0 && a == 1); // CHECK: Branch ([[@LINE]]:8): [True: 80.00%, False: 20.00%]
33 // CHECK: Branch ([[@LINE-1]]:18): [True: 25.00%, False: 75.00%]
34 for (i = 0; i < b; i++) { a = 2 + b + b; }
35 // CHECK: Branch ([[@LINE-1]]:15): [True: 16.67%, False: 83.33%]
37 b = a;
39 switch (a)
41 case 0: // CHECK: Branch ([[@LINE]]:5): [True: 20.00%, False: 80.00%]
42 printf("case0\n");
43 case 2: // CHECK: Branch ([[@LINE]]:5): [True: 20.00%, False: 80.00%]
44 printf("case2\n");
45 case 3: // CHECK: Branch ([[@LINE]]:5): [True: 0.00%, False: 100.00%]
46 printf("case3\n");
47 default: break; // CHECK: Branch ([[@LINE]]:5): [True: 60.00%, False: 40.00%]
50 i = 0;
51 do {
52 printf("loop\n");
53 } while (i++ < 10); // CHECK: Branch ([[@LINE]]:12): [True: 90.91%, False: 9.09%]
55 __llvm_profile_write_file();
57 return b;
59 // RUN: llvm-profdata merge %S/Inputs/branch-showBranchPercentage.proftext -o %t.profdata
60 // RUN: llvm-cov show --show-branches=percent %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s -format html -o %t.html.dir
62 // Test html output.
63 // RUN: FileCheck -check-prefix=HTML -input-file=%t.html.dir/coverage/tmp/branch-showBranchPercentage.c.html %s
64 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}16.67%,{{.*}}83.33%]
65 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}20.00%,{{.*}}80.00%]
66 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}0.00%,{{.*}}100.00%]
67 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}0.00%,{{.*}}100.00%]
68 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}40.00%,{{.*}}60.00%]
69 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}80.00%,{{.*}}20.00%]
70 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}0.00%,{{.*}}100.00%]
71 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}80.00%,{{.*}}20.00%]
72 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}25.00%,{{.*}}75.00%]
73 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}16.67%,{{.*}}83.33%]
74 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}20.00%,{{.*}}80.00%]
75 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}20.00%,{{.*}}80.00%]
76 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}0.00%,{{.*}}100.00%]
77 // HTML: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>{{.*}}60.00%,{{.*}}40.00%]