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