Merge tag 'hyperv-fixes-signed-20211007' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / tools / perf / tests / shell / pipe_test.sh
1 #!/bin/sh
2 # perf pipe recording and injection test
3 # SPDX-License-Identifier: GPL-2.0
4
5 # skip if there's no compiler
6 if ! [ -x "$(command -v cc)" ]; then
7         echo "failed: no compiler, install gcc"
8         exit 2
9 fi
10
11 file=$(mktemp /tmp/test.file.XXXXXX)
12 data=$(mktemp /tmp/perf.data.XXXXXX)
13
14 cat <<EOF | cc -o ${file} -x c -
15 #include <signal.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18
19 volatile int done;
20
21 void sigalrm(int sig) {
22         done = 1;
23 }
24
25 __attribute__((noinline)) void noploop(void) {
26         while (!done)
27                 continue;
28 }
29
30 int main(int argc, char *argv[]) {
31         int sec = 1;
32
33         if (argc > 1)
34                 sec = atoi(argv[1]);
35
36         signal(SIGALRM, sigalrm);
37         alarm(sec);
38
39         noploop();
40         return 0;
41 }
42 EOF
43
44
45 if ! perf record -e task-clock:u -o - ${file} | perf report -i - --task | grep test.file; then
46         echo "cannot find the test file in the perf report"
47         exit 1
48 fi
49
50 if ! perf record -e task-clock:u -o - ${file} | perf inject -b | perf report -i - | grep noploop; then
51         echo "cannot find noploop function in pipe #1"
52         exit 1
53 fi
54
55 perf record -e task-clock:u -o - ${file} | perf inject -b -o ${data}
56 if ! perf report -i ${data} | grep noploop; then
57         echo "cannot find noploop function in pipe #2"
58         exit 1
59 fi
60
61 perf record -e task-clock:u -o ${data} ${file}
62 if ! perf inject -b -i ${data} | perf report -i - | grep noploop; then
63         echo "cannot find noploop function in pipe #3"
64         exit 1
65 fi
66
67
68 rm -f ${file} ${data} ${data}.old
69 exit 0