xref: /linux/tools/perf/tests/shell/drm_pmu.sh (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
1#!/bin/bash
2# DRM PMU
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7output=$(mktemp /tmp/perf.drm_pmu.XXXXXX.txt)
8
9cleanup() {
10  rm -f "${output}"
11
12  trap - EXIT TERM INT
13}
14
15trap_cleanup() {
16  echo "Unexpected signal in ${FUNCNAME[1]}"
17  cleanup
18  exit 1
19}
20trap trap_cleanup EXIT TERM INT
21
22# Array to store file descriptors and device names
23declare -A device_fds
24
25# Open all devices and store file descriptors. Opening the device will create a
26# /proc/$$/fdinfo file containing the DRM statistics.
27fd_count=3 # Start with file descriptor 3
28for device in /dev/dri/*
29do
30  if [[ ! -c "$device" ]]
31  then
32    continue
33  fi
34  major=$(stat -c "%Hr" "$device")
35  if [[ "$major" != 226 ]]
36  then
37    continue
38  fi
39  echo "Opening $device"
40  eval "exec $fd_count<\"$device\""
41  echo "fdinfo for: $device (FD: $fd_count)"
42  cat "/proc/$$/fdinfo/$fd_count"
43  echo
44  device_fds["$device"]="$fd_count"
45  fd_count=$((fd_count + 1))
46done
47
48if [[ ${#device_fds[@]} -eq 0 ]]
49then
50  echo "No DRM devices found [Skip]"
51  cleanup
52  exit 2
53fi
54
55# For each DRM event
56err=0
57for p in $(perf list --raw-dump drm-)
58do
59  echo -n "Testing perf stat of $p. "
60  perf stat -e "$p" --pid=$$ true > "$output" 2>&1
61  if ! grep -q "$p" "$output"
62  then
63    echo "Missing DRM event in: [Failed]"
64    cat "$output"
65    err=1
66  else
67    echo "[OK]"
68  fi
69done
70
71# Close all file descriptors
72for fd in "${device_fds[@]}"; do
73  eval "exec $fd<&-"
74done
75
76# Finished
77cleanup
78exit $err
79