brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 634240c Raw
67 lines · c
1/* Checks that BOLT correctly handles instrumentation of indirect calls2 * 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>9 10int foo(int x) { return x + 1; }11 12int bar(int (*fn)(int), int val) { return fn(val); }13 14void sigHandler(int signum) { bar(foo, 3); }15 16int 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);32    }33    printf("[child]\n");34  }35  return 0;36}37 38/*39REQUIRES: system-linux,bolt-runtime,lit-max-individual-test-time40 41RUN: %clang %cflags -D_GNU_SOURCE %s -o %t.exe -Wl,-q -pie -fpie42 43RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \44RUN:   --instrumentation-wait-forks=1 --conservative-instrumentation \45RUN:   -o %t.instrumented_conservative46 47# Instrumented program needs to finish returning zero48RUN: %t.instrumented_conservative | FileCheck %s -check-prefix=CHECK-OUTPUT49 50RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \51RUN:   --instrumentation-wait-forks=1 \52RUN:   -o %t.instrumented53 54# Instrumented program needs to finish returning zero55RUN: %t.instrumented | FileCheck %s -check-prefix=CHECK-OUTPUT56 57# Test that the instrumented data makes sense58RUN:  llvm-bolt %t.exe -o %t.bolted --data %t.fdata \59RUN:    --reorder-blocks=ext-tsp --reorder-functions=hfsort+ \60RUN:    --print-only=interp --print-finalized61 62RUN: %t.bolted | FileCheck %s -check-prefix=CHECK-OUTPUT63 64CHECK-OUTPUT: [child]65CHECK-OUTPUT: [parent]66*/67