xref: /aosp_15_r20/external/compiler-rt/test/profile/instrprof-shared.test (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot"""
2*7c3d14c8STreehugger RobotThis test produces three shared libraries:
3*7c3d14c8STreehugger Robot
4*7c3d14c8STreehugger Robot1. libt-instr.so is instrumented
5*7c3d14c8STreehugger Robot2. libt-no-instr1.so is not instrumented
6*7c3d14c8STreehugger Robot3. libt-no-instr2.so is built with profile rt linked in (via -u<hook>), but the object file is built
7*7c3d14c8STreehugger Robot   with instrumentation turned off.
8*7c3d14c8STreehugger Robot
9*7c3d14c8STreehugger RobotAfter the libraries are built, the main program is then built with/without instrumentation and linked
10*7c3d14c8STreehugger Robotagainst 3 libraries above.
11*7c3d14c8STreehugger Robot
12*7c3d14c8STreehugger RobotThe test is to verify that programs linked against these shared objects with and without instrumentation
13*7c3d14c8STreehugger Robotenabled behave as expected.
14*7c3d14c8STreehugger Robot"""
15*7c3d14c8STreehugger Robot
16*7c3d14c8STreehugger RobotRUN: mkdir -p %t.d
17*7c3d14c8STreehugger RobotRUN: %clang_profgen -o %t.d/libt-instr.so -fPIC -shared %S/Inputs/instrprof-shared-lib.c
18*7c3d14c8STreehugger RobotRUN: %clang -o %t.d/libt-no-instr1.so -fPIC -shared %S/Inputs/instrprof-shared-lib.c
19*7c3d14c8STreehugger RobotRUN: %clang -c -o %t.d/instrprof-shared-lib-no-instr2.o -fPIC  %S/Inputs/instrprof-shared-lib.c
20*7c3d14c8STreehugger RobotRUN: %clang_profgen -o %t.d/libt-no-instr2.so -fPIC -shared %t.d/instrprof-shared-lib-no-instr2.o
21*7c3d14c8STreehugger Robot
22*7c3d14c8STreehugger RobotRUN: %clang_profgen -o %t-instr-instr -L%t.d -rpath %t.d -lt-instr  %S/Inputs/instrprof-shared-main.c
23*7c3d14c8STreehugger RobotRUN: %clang_profgen -o %t-instr-no-instr1 -L%t.d -rpath %t.d -lt-no-instr1  %S/Inputs/instrprof-shared-main.c
24*7c3d14c8STreehugger RobotRUN: %clang_profgen -o %t-instr-no-instr2 -L%t.d -rpath %t.d -lt-no-instr2  %S/Inputs/instrprof-shared-main.c
25*7c3d14c8STreehugger RobotRUN: %clang -o %t-no-instr1-instr -L%t.d -rpath %t.d -lt-instr  %S/Inputs/instrprof-shared-main.c
26*7c3d14c8STreehugger RobotRUN: %clang -o %t-no-instr1-no-instr1 -L%t.d -rpath %t.d -lt-no-instr1  %S/Inputs/instrprof-shared-main.c
27*7c3d14c8STreehugger RobotRUN: %clang -o %t-no-instr1-no-instr2 -L%t.d -rpath %t.d -lt-no-instr2  %S/Inputs/instrprof-shared-main.c
28*7c3d14c8STreehugger RobotRUN: %clang -c -o %t.d/instrprof-shared-main-no-instr2.o  %S/Inputs/instrprof-shared-main.c
29*7c3d14c8STreehugger RobotRUN: %clang -o %t-no-instr2-instr -L%t.d -rpath %t.d -lt-instr  %t.d/instrprof-shared-main-no-instr2.o
30*7c3d14c8STreehugger RobotRUN: %clang -o %t-no-instr2-no-instr1 -L%t.d -rpath %t.d -lt-no-instr1  %t.d/instrprof-shared-main-no-instr2.o
31*7c3d14c8STreehugger RobotRUN: %clang -o %t-no-instr2-no-instr2 -L%t.d -rpath %t.d -lt-no-instr2  %t.d/instrprof-shared-main-no-instr2.o
32*7c3d14c8STreehugger Robot
33*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-instr-instr.profraw %run %t-instr-instr
34*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-instr-no-instr1.profraw %run %t-instr-no-instr1
35*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-instr-no-instr2.profraw %run %t-instr-no-instr2
36*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-no-instr1-instr.profraw %run %t-no-instr1-instr
37*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-no-instr2-instr.profraw %run %t-no-instr2-instr
38*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-no-instr1-no-instr1.profraw %run %t-no-instr1-no-instr1
39*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-no-instr1-no-instr2.profraw %run %t-no-instr1-no-instr2
40*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-no-instr2-no-instr1.profraw %run %t-no-instr2-no-instr1
41*7c3d14c8STreehugger RobotRUN: env LLVM_PROFILE_FILE=%t-no-instr2-no-instr2.profraw %run %t-no-instr2-no-instr2
42*7c3d14c8STreehugger Robot
43*7c3d14c8STreehugger RobotRUN: llvm-profdata merge -o %t-instr-instr.profdata %t-instr-instr.profraw
44*7c3d14c8STreehugger RobotRUN: llvm-profdata merge -o %t-instr-no-instr1.profdata %t-instr-no-instr1.profraw
45*7c3d14c8STreehugger RobotRUN: llvm-profdata merge -o %t-instr-no-instr2.profdata %t-instr-no-instr2.profraw
46*7c3d14c8STreehugger RobotRUN: llvm-profdata merge -o %t-no-instr1-instr.profdata %t-no-instr1-instr.profraw
47*7c3d14c8STreehugger RobotRUN: llvm-profdata merge -o %t-no-instr2-instr.profdata %t-no-instr2-instr.profraw
48*7c3d14c8STreehugger Robot
49*7c3d14c8STreehugger RobotRUN: not llvm-profdata merge -o %t-no-instr1-no-instr1.profdata %t-no-instr1-no-instr1.profraw 2>&1 | FileCheck %s --check-prefix=MISSING-FILE
50*7c3d14c8STreehugger RobotRUN: not llvm-profdata merge -o %t-no-instr2-no-instr1.profdata %t-no-instr2-no-instr1.profraw 2>&1 | FileCheck %s --check-prefix=MISSING-FILE
51*7c3d14c8STreehugger RobotMISSING-FILE: profraw
52*7c3d14c8STreehugger Robot
53*7c3d14c8STreehugger RobotRUN: llvm-profdata show -counts --function main %t-instr-instr.profdata | grep -v 'Total\|Maximum' > %t-main-1
54*7c3d14c8STreehugger RobotRUN: llvm-profdata show -counts --function main %t-instr-no-instr1.profdata | grep -v 'Total\|Maximum' > %t-main-2
55*7c3d14c8STreehugger RobotRUN: llvm-profdata show -counts --function main %t-instr-no-instr2.profdata | grep -v 'Total\|Maximum' > %t-main-3
56*7c3d14c8STreehugger RobotRUN: llvm-profdata show -counts --function foo %t-instr-instr.profdata | grep -v 'Total\|Maximum' > %t-foo-1
57*7c3d14c8STreehugger RobotRUN: llvm-profdata show -counts --function foo %t-no-instr1-instr.profdata | grep -v 'Total\|Maximum' > %t-foo-2
58*7c3d14c8STreehugger RobotRUN: llvm-profdata show -counts --function foo %t-no-instr2-instr.profdata | grep -v 'Total\|Maximum'  > %t-foo-3
59*7c3d14c8STreehugger Robot
60*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-instr-instr.profdata -o %t-main-instr-instr.ll -S -emit-llvm %S/Inputs/instrprof-shared-main.c
61*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-instr-no-instr1.profdata -o %t-main-instr-no-instr1.ll -S -emit-llvm %S/Inputs/instrprof-shared-main.c
62*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-instr-no-instr2.profdata -o %t-main-instr-no-instr2.ll -S -emit-llvm %S/Inputs/instrprof-shared-main.c
63*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-instr-instr.profdata -o %t-lib-instr-instr.ll -S -emit-llvm %S/Inputs/instrprof-shared-lib.c
64*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-no-instr1-instr.profdata -o %t-lib-no-instr1-instr.ll -S -emit-llvm %S/Inputs/instrprof-shared-lib.c
65*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-no-instr2-instr.profdata -o %t-lib-no-instr2-instr.ll -S -emit-llvm %S/Inputs/instrprof-shared-lib.c
66*7c3d14c8STreehugger RobotRUN: %clang_profuse=%t-instr-instr.profdata -o %t-lib-instr-instr.ll -S -emit-llvm %S/Inputs/instrprof-shared-lib.c
67*7c3d14c8STreehugger Robot
68*7c3d14c8STreehugger RobotRUN: diff %t-main-instr-no-instr1.ll %t-main-instr-no-instr2.ll
69*7c3d14c8STreehugger RobotRUN: diff %t-lib-no-instr1-instr.ll %t-lib-no-instr2-instr.ll
70*7c3d14c8STreehugger Robot
71*7c3d14c8STreehugger RobotRUN: diff %t-main-1 %t-main-2
72*7c3d14c8STreehugger RobotRUN: diff %t-main-1 %t-main-3
73*7c3d14c8STreehugger RobotRUN: diff %t-foo-1 %t-foo-2
74*7c3d14c8STreehugger RobotRUN: diff %t-foo-1 %t-foo-3
75*7c3d14c8STreehugger Robot
76