summaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/shell/pipe_test.sh
blob: d4c8005ce9b96bfdef290c671f20ae7451186b0f (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# perf pipe recording and injection test
# SPDX-License-Identifier: GPL-2.0

shelldir=$(dirname "$0")
# shellcheck source=lib/perf_has_symbol.sh
. "${shelldir}"/lib/perf_has_symbol.sh

sym="noploop"

skip_test_missing_symbol ${sym}

data=$(mktemp /tmp/perf.data.XXXXXX)
data2=$(mktemp /tmp/perf.data2.XXXXXX)
prog="perf test -w noploop"
err=0

set -e

cleanup() {
  rm -rf "${data}"
  rm -rf "${data}".old
  rm -rf "${data2}"
  rm -rf "${data2}".old

  trap - EXIT TERM INT
}

trap_cleanup() {
  echo "Unexpected signal in ${FUNCNAME[1]}"
  cleanup
  exit 1
}
trap trap_cleanup EXIT TERM INT

test_record_report() {
  echo
  echo "Record+report pipe test"

  task="perf"
  if ! perf record -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task}
  then
    echo "Record+report pipe test [Failed - cannot find the test file in the perf report #1]"
    err=1
    return
  fi

  if ! perf record -g -e task-clock:u -o - ${prog} | perf report -i - --task | grep -q ${task}
  then
    echo "Record+report pipe test [Failed - cannot find the test file in the perf report #2]"
    err=1
    return
  fi

  perf record -g -e task-clock:u -o - ${prog} > ${data}
  if ! perf report -i ${data} --task | grep -q ${task}
  then
    echo "Record+report pipe test [Failed - cannot find the test file in the perf report #3]"
    err=1
    return
  fi

  echo "Record+report pipe test [Success]"
}

test_inject_bids() {
  inject_opt=$1

  echo
  echo "Inject ${inject_opt} build-ids test"

  if ! perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt}| perf report -i - | grep -q ${sym}
  then
    echo "Inject build-ids test [Failed - cannot find noploop function in pipe #1]"
    err=1
    return
  fi

  if ! perf record -g -e task-clock:u -o - ${prog} | perf inject ${inject_opt} | perf report -i - | grep -q ${sym}
  then
    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #2]"
    err=1
    return
  fi

  perf record -e task-clock:u -o - ${prog} | perf inject ${inject_opt} -o ${data}
  if ! perf report -i ${data} | grep -q ${sym}; then
    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #3]"
    err=1
    return
  fi

  perf record -e task-clock:u -o ${data} ${prog}
  if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then
    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #4]"
    err=1
    return
  fi

  perf record -e task-clock:u -o - ${prog} > ${data}
  if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q ${sym}; then
    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #5]"
    err=1
    return
  fi

  perf record -e task-clock:u -o - ${prog} > ${data}
  perf inject ${inject_opt} -i ${data} -o ${data2}
  if ! perf report -i ${data2} | grep -q ${sym}; then
    echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploop function in pipe #6]"
    err=1
    return
  fi

  echo "Inject ${inject_opt} build-ids test [Success]"
}

test_record_report
test_inject_bids -B
test_inject_bids -b
test_inject_bids --buildid-all
test_inject_bids --mmap2-buildid-all

cleanup
exit $err