Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / bolt / test / runtime / X86 / instrumentation-indirect.c
blob5f02a6020c74bee5bb28e7be836d1116bf9fa6c0
1 /* Checks that BOLT correctly handles instrumentation of indirect calls
2 * including case with indirect calls in signals handlers.
3 */
4 #include <signal.h>
5 #include <stdio.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
8 #include <unistd.h>
10 int foo(int x) { return x + 1; }
12 int bar(int (*fn)(int), int val) { return fn(val); }
14 void sigHandler(int signum) { bar(foo, 3); }
16 int main(int argc, char **argv) {
17 long long i;
18 pid_t pid, wpid;
19 int wstatus;
20 signal(SIGUSR1, sigHandler);
21 pid = fork();
22 if (pid) {
23 do {
24 kill(pid, SIGUSR1);
25 usleep(0);
26 wpid = waitpid(pid, &wstatus, WNOHANG);
27 } while (wpid == 0);
28 printf("[parent]\n");
29 } else {
30 for (i = 0; i < 100000; i++) {
31 bar(foo, i % 10);
33 printf("[child]\n");
35 return 0;
39 REQUIRES: system-linux,bolt-runtime,lit-max-individual-test-time
41 RUN: %clang %cflags %s -o %t.exe -Wl,-q -pie -fpie
43 RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \
44 RUN: --instrumentation-wait-forks=1 --conservative-instrumentation \
45 RUN: -o %t.instrumented_conservative
47 # Instrumented program needs to finish returning zero
48 RUN: %t.instrumented_conservative | FileCheck %s -check-prefix=CHECK-OUTPUT
50 RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \
51 RUN: --instrumentation-wait-forks=1 \
52 RUN: -o %t.instrumented
54 # Instrumented program needs to finish returning zero
55 RUN: %t.instrumented | FileCheck %s -check-prefix=CHECK-OUTPUT
57 # Test that the instrumented data makes sense
58 RUN: llvm-bolt %t.exe -o %t.bolted --data %t.fdata \
59 RUN: --reorder-blocks=ext-tsp --reorder-functions=hfsort+ \
60 RUN: --print-only=interp --print-finalized
62 RUN: %t.bolted | FileCheck %s -check-prefix=CHECK-OUTPUT
64 CHECK-OUTPUT: [child]
65 CHECK-OUTPUT: [parent]