xref: /linux/tools/perf/tests/shell/header.sh (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
1#!/bin/bash
2# perf header tests
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7err=0
8perfdata=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX)
9script_output=$(mktemp /tmp/__perf_test_header.perf.data.XXXXX.script)
10
11cleanup() {
12  rm -f "${perfdata}"
13  rm -f "${perfdata}".old
14  rm -f "${script_output}"
15
16  trap - EXIT TERM INT
17}
18
19trap_cleanup() {
20  echo "Unexpected signal in ${FUNCNAME[1]}"
21  cleanup
22  exit 1
23}
24trap trap_cleanup EXIT TERM INT
25
26check_header_output() {
27  declare -a fields=(
28    "captured"
29    "hostname"
30    "os release"
31    "arch"
32    "cpuid"
33    "nrcpus"
34    "event"
35    "cmdline"
36    "perf version"
37    "sibling (cores|dies|threads)"
38    "sibling threads"
39    "total memory"
40  )
41  for i in "${fields[@]}"
42  do
43    if ! grep -q -E "$i" "${script_output}"
44    then
45      echo "Failed to find expected $i in output"
46      err=1
47    fi
48  done
49}
50
51test_file() {
52  echo "Test perf header file"
53
54  perf record -o "${perfdata}" -- perf test -w noploop
55  perf report --header-only -I -i "${perfdata}" > "${script_output}"
56  check_header_output
57
58  echo "Test perf header file [Done]"
59}
60
61test_pipe() {
62  echo "Test perf header pipe"
63
64  perf record -o - -- perf test -w noploop | perf report --header-only -I -i - > "${script_output}"
65  check_header_output
66
67  echo "Test perf header pipe [Done]"
68}
69
70test_file
71test_pipe
72
73cleanup
74exit $err
75