xref: /linux/tools/perf/tests/shell/pipe_test.sh (revision 61f87151839b9767a06be93b99f1fc324147a0d3)
1#!/bin/bash
2# perf pipe recording and injection test
3# SPDX-License-Identifier: GPL-2.0
4
5shelldir=$(dirname "$0")
6# shellcheck source=lib/perf_has_symbol.sh
7. "${shelldir}"/lib/perf_has_symbol.sh
8
9sym="noploop"
10
11skip_test_missing_symbol ${sym}
12
13data=$(mktemp /tmp/perf.data.XXXXXX)
14prog="perf test -w noploop"
15err=0
16
17set -e
18
19cleanup() {
20  rm -rf "${data}"
21  rm -rf "${data}".old
22
23  trap - EXIT TERM INT
24}
25
26trap_cleanup() {
27  echo "Unexpected signal in ${FUNCNAME[1]}"
28  cleanup
29  exit 1
30}
31trap trap_cleanup EXIT TERM INT
32
33test_record_report() {
34  echo
35  echo "Record+report pipe test"
36
37  task="perf"
38  if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task}
39  then
40    echo "Record+report pipe test [Failed - cannot find the test file in the perf report #1]"
41    err=1
42    return
43  fi
44
45  if ! perf record -g -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task}
46  then
47    echo "Record+report pipe test [Failed - cannot find the test file in the perf report #2]"
48    err=1
49    return
50  fi
51
52  echo "Record+report pipe test [Success]"
53}
54
55test_inject_bids() {
56  inject_opt=$1
57
58  echo
59  echo "Inject ${inject_opt} build-ids test"
60
61  if ! perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt}| perf report -i - | grep -q ${sym}
62  then
63    echo "Inject build-ids test [Failed - cannot find noploop function in pipe #1]"
64    err=1
65    return
66  fi
67
68  if ! perf record -g -e task-clock:u -o - ${prog} | perf inject ${inject_opt} | perf report -i - | grep -q ${sym}
69  then
70    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #2]"
71    err=1
72    return
73  fi
74
75  perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt} -o ${data}
76  if ! perf report -i ${data} | grep -q ${sym}; then
77    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #3]"
78    err=1
79    return
80  fi
81
82  perf record -e task-clock:u -o ${data} ${prog}
83  if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then
84    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #4]"
85    err=1
86    return
87  fi
88
89  echo "Inject ${inject_opt} build-ids test [Success]"
90}
91
92test_record_report
93test_inject_bids -b
94test_inject_bids --buildid-all
95
96cleanup
97exit $err
98
99