xref: /linux/tools/perf/tests/shell/diff.sh (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
1#!/bin/sh
2# perf diff tests
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7err=0
8perfdata1=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
9perfdata2=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
10perfdata3=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
11testprog="perf test -w thloop"
12
13shelldir=$(dirname "$0")
14# shellcheck source=lib/perf_has_symbol.sh
15. "${shelldir}"/lib/perf_has_symbol.sh
16
17testsym="test_loop"
18
19skip_test_missing_symbol ${testsym}
20
21cleanup() {
22  rm -rf "${perfdata1}"
23  rm -rf "${perfdata1}".old
24  rm -rf "${perfdata2}"
25  rm -rf "${perfdata2}".old
26  rm -rf "${perfdata3}"
27  rm -rf "${perfdata3}".old
28
29  trap - EXIT TERM INT
30}
31
32trap_cleanup() {
33  cleanup
34  exit 1
35}
36trap trap_cleanup EXIT TERM INT
37
38make_data() {
39  file="$1"
40  if ! perf record -o "${file}" ${testprog} 2> /dev/null
41  then
42    echo "Workload record [Failed record]"
43    echo 1
44    return
45  fi
46  if ! perf report -i "${file}" -q | grep -q "${testsym}"
47  then
48    echo "Workload record [Failed missing output]"
49    echo 1
50    return
51  fi
52  echo 0
53}
54
55test_two_files() {
56  echo "Basic two file diff test"
57  err=$(make_data "${perfdata1}")
58  if [ $err != 0 ]
59  then
60    return
61  fi
62  err=$(make_data "${perfdata2}")
63  if [ $err != 0 ]
64  then
65    return
66  fi
67
68  if ! perf diff "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
69  then
70    echo "Basic two file diff test [Failed diff]"
71    err=1
72    return
73  fi
74  echo "Basic two file diff test [Success]"
75}
76
77test_three_files() {
78  echo "Basic three file diff test"
79  err=$(make_data "${perfdata1}")
80  if [ $err != 0 ]
81  then
82    return
83  fi
84  err=$(make_data "${perfdata2}")
85  if [ $err != 0 ]
86  then
87    return
88  fi
89  err=$(make_data "${perfdata3}")
90  if [ $err != 0 ]
91  then
92    return
93  fi
94
95  if ! perf diff "${perfdata1}" "${perfdata2}" "${perfdata3}" | grep -q "${testsym}"
96  then
97    echo "Basic three file diff test [Failed diff]"
98    err=1
99    return
100  fi
101  echo "Basic three file diff test [Success]"
102}
103
104test_two_files
105test_three_files
106
107cleanup
108exit $err
109