xref: /linux/tools/testing/selftests/cpufreq/main.sh (revision b24413180f5600bcb3bb70fbed5cf186b60864bd)
1e66d5b67SViresh Kumar#!/bin/bash
2*b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3e66d5b67SViresh Kumar
4e66d5b67SViresh Kumarsource cpu.sh
5e66d5b67SViresh Kumarsource cpufreq.sh
6e66d5b67SViresh Kumarsource governor.sh
76751faf3SViresh Kumarsource module.sh
81e4c2830SViresh Kumarsource special-tests.sh
9e66d5b67SViresh Kumar
10e66d5b67SViresh KumarFUNC=basic	# do basic tests by default
11e66d5b67SViresh KumarOUTFILE=cpufreq_selftest
12e66d5b67SViresh KumarSYSFS=
13e66d5b67SViresh KumarCPUROOT=
14e66d5b67SViresh KumarCPUFREQROOT=
15e66d5b67SViresh Kumar
16e66d5b67SViresh Kumarhelpme()
17e66d5b67SViresh Kumar{
186751faf3SViresh Kumar	printf "Usage: $0 [-h] [-todg args]
19e66d5b67SViresh Kumar	[-h <help>]
20e66d5b67SViresh Kumar	[-o <output-file-for-dump>]
21b03eaf8dSViresh Kumar	[-t <basic: Basic cpufreq testing
22b03eaf8dSViresh Kumar	     suspend: suspend/resume,
236751faf3SViresh Kumar	     hibernate: hibernate/resume,
241e4c2830SViresh Kumar	     modtest: test driver or governor modules. Only to be used with -d or -g options,
251e4c2830SViresh Kumar	     sptest1: Simple governor switch to produce lockdep.
261e4c2830SViresh Kumar	     sptest2: Concurrent governor switch to produce lockdep.
271e4c2830SViresh Kumar	     sptest3: Governor races, shuffle between governors quickly.
281e4c2830SViresh Kumar	     sptest4: CPU hotplugs with updates to cpufreq files.>]
296751faf3SViresh Kumar	[-d <driver's module name: only with \"-t modtest>\"]
306751faf3SViresh Kumar	[-g <governor's module name: only with \"-t modtest>\"]
31e66d5b67SViresh Kumar	\n"
32e66d5b67SViresh Kumar	exit 2
33e66d5b67SViresh Kumar}
34e66d5b67SViresh Kumar
35e66d5b67SViresh Kumarprerequisite()
36e66d5b67SViresh Kumar{
37e66d5b67SViresh Kumar	msg="skip all tests:"
38e66d5b67SViresh Kumar
39e66d5b67SViresh Kumar	if [ $UID != 0 ]; then
40e66d5b67SViresh Kumar		echo $msg must be run as root >&2
41e66d5b67SViresh Kumar		exit 2
42e66d5b67SViresh Kumar	fi
43e66d5b67SViresh Kumar
44e66d5b67SViresh Kumar	taskset -p 01 $$
45e66d5b67SViresh Kumar
46e66d5b67SViresh Kumar	SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
47e66d5b67SViresh Kumar
48e66d5b67SViresh Kumar	if [ ! -d "$SYSFS" ]; then
49e66d5b67SViresh Kumar		echo $msg sysfs is not mounted >&2
50e66d5b67SViresh Kumar		exit 2
51e66d5b67SViresh Kumar	fi
52e66d5b67SViresh Kumar
53e66d5b67SViresh Kumar	CPUROOT=$SYSFS/devices/system/cpu
54e66d5b67SViresh Kumar	CPUFREQROOT="$CPUROOT/cpufreq"
55e66d5b67SViresh Kumar
56e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
57e66d5b67SViresh Kumar		echo $msg cpus not available in sysfs >&2
58e66d5b67SViresh Kumar		exit 2
59e66d5b67SViresh Kumar	fi
60e66d5b67SViresh Kumar
61e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
62e66d5b67SViresh Kumar		echo $msg cpufreq directory not available in sysfs >&2
63e66d5b67SViresh Kumar		exit 2
64e66d5b67SViresh Kumar	fi
65e66d5b67SViresh Kumar}
66e66d5b67SViresh Kumar
67e66d5b67SViresh Kumarparse_arguments()
68e66d5b67SViresh Kumar{
696751faf3SViresh Kumar	while getopts ht:o:d:g: arg
70e66d5b67SViresh Kumar	do
71e66d5b67SViresh Kumar		case $arg in
72e66d5b67SViresh Kumar			h) # --help
73e66d5b67SViresh Kumar				helpme
74e66d5b67SViresh Kumar				;;
75e66d5b67SViresh Kumar
761e4c2830SViresh Kumar			t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
77e66d5b67SViresh Kumar				FUNC=$OPTARG
78e66d5b67SViresh Kumar				;;
79e66d5b67SViresh Kumar
80e66d5b67SViresh Kumar			o) # --output-file (Output file to store dumps)
81e66d5b67SViresh Kumar				OUTFILE=$OPTARG
82e66d5b67SViresh Kumar				;;
83e66d5b67SViresh Kumar
846751faf3SViresh Kumar			d) # --driver-mod-name (Name of the driver module)
856751faf3SViresh Kumar				DRIVER_MOD=$OPTARG
866751faf3SViresh Kumar				;;
876751faf3SViresh Kumar
886751faf3SViresh Kumar			g) # --governor-mod-name (Name of the governor module)
896751faf3SViresh Kumar				GOVERNOR_MOD=$OPTARG
906751faf3SViresh Kumar				;;
916751faf3SViresh Kumar
92e66d5b67SViresh Kumar			\?)
93e66d5b67SViresh Kumar				helpme
94e66d5b67SViresh Kumar				;;
95e66d5b67SViresh Kumar		esac
96e66d5b67SViresh Kumar	done
97e66d5b67SViresh Kumar}
98e66d5b67SViresh Kumar
99e66d5b67SViresh Kumardo_test()
100e66d5b67SViresh Kumar{
101e66d5b67SViresh Kumar	# Check if CPUs are managed by cpufreq or not
102e66d5b67SViresh Kumar	count=$(count_cpufreq_managed_cpus)
103e66d5b67SViresh Kumar
1046751faf3SViresh Kumar	if [ $count = 0 -a $FUNC != "modtest" ]; then
105e66d5b67SViresh Kumar		echo "No cpu is managed by cpufreq core, exiting"
106e66d5b67SViresh Kumar		exit 2;
107e66d5b67SViresh Kumar	fi
108e66d5b67SViresh Kumar
109e66d5b67SViresh Kumar	case "$FUNC" in
110e66d5b67SViresh Kumar		"basic")
111e66d5b67SViresh Kumar		cpufreq_basic_tests
112e66d5b67SViresh Kumar		;;
113e66d5b67SViresh Kumar
114b03eaf8dSViresh Kumar		"suspend")
115b03eaf8dSViresh Kumar		do_suspend "suspend" 1
116b03eaf8dSViresh Kumar		;;
117b03eaf8dSViresh Kumar
118b03eaf8dSViresh Kumar		"hibernate")
119b03eaf8dSViresh Kumar		do_suspend "hibernate" 1
120b03eaf8dSViresh Kumar		;;
121b03eaf8dSViresh Kumar
1226751faf3SViresh Kumar		"modtest")
1236751faf3SViresh Kumar		# Do we have modules in place?
1246751faf3SViresh Kumar		if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
1256751faf3SViresh Kumar			echo "No driver or governor module passed with -d or -g"
1266751faf3SViresh Kumar			exit 2;
1276751faf3SViresh Kumar		fi
1286751faf3SViresh Kumar
1296751faf3SViresh Kumar		if [ $DRIVER_MOD ]; then
1306751faf3SViresh Kumar			if [ $GOVERNOR_MOD ]; then
1316751faf3SViresh Kumar				module_test $DRIVER_MOD $GOVERNOR_MOD
1326751faf3SViresh Kumar			else
1336751faf3SViresh Kumar				module_driver_test $DRIVER_MOD
1346751faf3SViresh Kumar			fi
1356751faf3SViresh Kumar		else
1366751faf3SViresh Kumar			if [ $count = 0 ]; then
1376751faf3SViresh Kumar				echo "No cpu is managed by cpufreq core, exiting"
1386751faf3SViresh Kumar				exit 2;
1396751faf3SViresh Kumar			fi
1406751faf3SViresh Kumar
1416751faf3SViresh Kumar			module_governor_test $GOVERNOR_MOD
1426751faf3SViresh Kumar		fi
1436751faf3SViresh Kumar		;;
1446751faf3SViresh Kumar
1451e4c2830SViresh Kumar		"sptest1")
1461e4c2830SViresh Kumar		simple_lockdep
1471e4c2830SViresh Kumar		;;
1481e4c2830SViresh Kumar
1491e4c2830SViresh Kumar		"sptest2")
1501e4c2830SViresh Kumar		concurrent_lockdep
1511e4c2830SViresh Kumar		;;
1521e4c2830SViresh Kumar
1531e4c2830SViresh Kumar		"sptest3")
1541e4c2830SViresh Kumar		governor_race
1551e4c2830SViresh Kumar		;;
1561e4c2830SViresh Kumar
1571e4c2830SViresh Kumar		"sptest4")
1581e4c2830SViresh Kumar		hotplug_with_updates
1591e4c2830SViresh Kumar		;;
1601e4c2830SViresh Kumar
161e66d5b67SViresh Kumar		*)
162e66d5b67SViresh Kumar		echo "Invalid [-f] function type"
163e66d5b67SViresh Kumar		helpme
164e66d5b67SViresh Kumar		;;
165e66d5b67SViresh Kumar	esac
166e66d5b67SViresh Kumar}
167e66d5b67SViresh Kumar
168e66d5b67SViresh Kumar# clear dumps
169e66d5b67SViresh Kumar# $1: file name
170e66d5b67SViresh Kumarclear_dumps()
171e66d5b67SViresh Kumar{
172e66d5b67SViresh Kumar	echo "" > $1.txt
173e66d5b67SViresh Kumar	echo "" > $1.dmesg_cpufreq.txt
174e66d5b67SViresh Kumar	echo "" > $1.dmesg_full.txt
175e66d5b67SViresh Kumar}
176e66d5b67SViresh Kumar
177e66d5b67SViresh Kumar# $1: output file name
178e66d5b67SViresh Kumardmesg_dumps()
179e66d5b67SViresh Kumar{
180e66d5b67SViresh Kumar	dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
181e66d5b67SViresh Kumar
182e66d5b67SViresh Kumar	# We may need the full logs as well
183e66d5b67SViresh Kumar	dmesg >> $1.dmesg_full.txt
184e66d5b67SViresh Kumar}
185e66d5b67SViresh Kumar
186e66d5b67SViresh Kumar# Parse arguments
187e66d5b67SViresh Kumarparse_arguments $@
188e66d5b67SViresh Kumar
189e66d5b67SViresh Kumar# Make sure all requirements are met
190e66d5b67SViresh Kumarprerequisite
191e66d5b67SViresh Kumar
192e66d5b67SViresh Kumar# Run requested functions
193e66d5b67SViresh Kumarclear_dumps $OUTFILE
194e66d5b67SViresh Kumardo_test >> $OUTFILE.txt
195e66d5b67SViresh Kumardmesg_dumps $OUTFILE
196