xref: /linux/tools/perf/tests/shell/sched.sh (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
1#!/bin/bash
2# perf sched tests
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7if [ "$(id -u)" != 0 ]; then
8  echo "[Skip] No root permission"
9  exit 2
10fi
11
12err=0
13perfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX)
14PID1=0
15PID2=0
16
17cleanup() {
18  rm -f "${perfdata}"
19  rm -f "${perfdata}".old
20
21  trap - EXIT TERM INT
22}
23
24trap_cleanup() {
25  echo "Unexpected signal in ${FUNCNAME[1]}"
26  cleanup
27  exit 1
28}
29trap trap_cleanup EXIT TERM INT
30
31start_noploops() {
32  # Start two noploop workloads on CPU0 to trigger scheduling.
33  perf test -w noploop 10 &
34  PID1=$!
35  taskset -pc 0 $PID1
36  perf test -w noploop 10 &
37  PID2=$!
38  taskset -pc 0 $PID2
39
40  if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID1/status"
41  then
42    echo "Sched [Error taskset did not work for the 1st noploop ($PID1)]"
43    grep Cpus_allowed /proc/$PID1/status
44    err=1
45  fi
46
47  if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID2/status"
48  then
49    echo "Sched [Error taskset did not work for the 2nd noploop ($PID2)]"
50    grep Cpus_allowed /proc/$PID2/status
51    err=1
52  fi
53}
54
55cleanup_noploops() {
56  kill "$PID1" "$PID2"
57}
58
59test_sched_record() {
60  echo "Sched record"
61
62  start_noploops
63
64  perf sched record --no-inherit -o "${perfdata}" sleep 1
65
66  cleanup_noploops
67}
68
69test_sched_latency() {
70  echo "Sched latency"
71
72  if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop
73  then
74    echo "Sched latency [Failed missing output]"
75    err=1
76  fi
77}
78
79test_sched_script() {
80  echo "Sched script"
81
82  if ! perf sched script -i "${perfdata}" | grep -q perf-noploop
83  then
84    echo "Sched script [Failed missing output]"
85    err=1
86  fi
87}
88
89test_sched_map() {
90  echo "Sched map"
91
92  if ! perf sched map -i "${perfdata}" | grep -q perf-noploop
93  then
94    echo "Sched map [Failed missing output]"
95    err=1
96  fi
97}
98
99test_sched_timehist() {
100  echo "Sched timehist"
101
102  if ! perf sched timehist -i "${perfdata}" | grep -q perf-noploop
103  then
104    echo "Sched timehist [Failed missing output]"
105    err=1
106  fi
107}
108
109test_sched_record
110test_sched_latency
111test_sched_script
112test_sched_map
113test_sched_timehist
114
115cleanup
116exit $err
117