summaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/shell/pipe_test.sh
blob: 1b32b4f2839114395ce07bb87c9dfa126ac40740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# perf pipe recording and injection test
# SPDX-License-Identifier: GPL-2.0

# skip if there's no compiler
if ! [ -x "$(command -v cc)" ]; then
	echo "failed: no compiler, install gcc"
	exit 2
fi

file=$(mktemp /tmp/test.file.XXXXXX)
data=$(mktemp /tmp/perf.data.XXXXXX)

cat <<EOF | cc -o ${file} -x c -
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

volatile int done;

void sigalrm(int sig) {
	done = 1;
}

__attribute__((noinline)) void noploop(void) {
	while (!done)
		continue;
}

int main(int argc, char *argv[]) {
	int sec = 1;

	if (argc > 1)
		sec = atoi(argv[1]);

	signal(SIGALRM, sigalrm);
	alarm(sec);

	noploop();
	return 0;
}
EOF


if ! perf record -e task-clock:u -o - ${file} | perf report -i - --task | grep test.file; then
	echo "cannot find the test file in the perf report"
	exit 1
fi

if ! perf record -e task-clock:u -o - ${file} | perf inject -b | perf report -i - | grep noploop; then
	echo "cannot find noploop function in pipe #1"
	exit 1
fi

perf record -e task-clock:u -o - ${file} | perf inject -b -o ${data}
if ! perf report -i ${data} | grep noploop; then
	echo "cannot find noploop function in pipe #2"
	exit 1
fi

perf record -e task-clock:u -o ${data} ${file}
if ! perf inject -b -i ${data} | perf report -i - | grep noploop; then
	echo "cannot find noploop function in pipe #3"
	exit 1
fi


rm -f ${file} ${data} ${data}.old
exit 0