xref: /linux/tools/testing/selftests/cpufreq/main.sh (revision 40d70d4d60974c28054a60316f2aec8810833526)
1e66d5b67SViresh Kumar#!/bin/bash
2b2441318SGreg 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
164c5b95c1SShuah Khan (Samsung OSG)# Kselftest framework requirement - SKIP code is 4.
174c5b95c1SShuah Khan (Samsung OSG)ksft_skip=4
184c5b95c1SShuah Khan (Samsung OSG)
19e66d5b67SViresh Kumarhelpme()
20e66d5b67SViresh Kumar{
216751faf3SViresh Kumar	printf "Usage: $0 [-h] [-todg args]
22e66d5b67SViresh Kumar	[-h <help>]
23e66d5b67SViresh Kumar	[-o <output-file-for-dump>]
24b03eaf8dSViresh Kumar	[-t <basic: Basic cpufreq testing
25b03eaf8dSViresh Kumar	     suspend: suspend/resume,
266751faf3SViresh Kumar	     hibernate: hibernate/resume,
271e4c2830SViresh Kumar	     modtest: test driver or governor modules. Only to be used with -d or -g options,
281e4c2830SViresh Kumar	     sptest1: Simple governor switch to produce lockdep.
291e4c2830SViresh Kumar	     sptest2: Concurrent governor switch to produce lockdep.
301e4c2830SViresh Kumar	     sptest3: Governor races, shuffle between governors quickly.
311e4c2830SViresh Kumar	     sptest4: CPU hotplugs with updates to cpufreq files.>]
326751faf3SViresh Kumar	[-d <driver's module name: only with \"-t modtest>\"]
336751faf3SViresh Kumar	[-g <governor's module name: only with \"-t modtest>\"]
34e66d5b67SViresh Kumar	\n"
35e66d5b67SViresh Kumar	exit 2
36e66d5b67SViresh Kumar}
37e66d5b67SViresh Kumar
38e66d5b67SViresh Kumarprerequisite()
39e66d5b67SViresh Kumar{
40e66d5b67SViresh Kumar	msg="skip all tests:"
41e66d5b67SViresh Kumar
42e66d5b67SViresh Kumar	if [ $UID != 0 ]; then
43e66d5b67SViresh Kumar		echo $msg must be run as root >&2
444c5b95c1SShuah Khan (Samsung OSG)		exit $ksft_skip
45e66d5b67SViresh Kumar	fi
46e66d5b67SViresh Kumar
47e66d5b67SViresh Kumar	taskset -p 01 $$
48e66d5b67SViresh Kumar
49e66d5b67SViresh Kumar	SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
50e66d5b67SViresh Kumar
51e66d5b67SViresh Kumar	if [ ! -d "$SYSFS" ]; then
52e66d5b67SViresh Kumar		echo $msg sysfs is not mounted >&2
53e66d5b67SViresh Kumar		exit 2
54e66d5b67SViresh Kumar	fi
55e66d5b67SViresh Kumar
56e66d5b67SViresh Kumar	CPUROOT=$SYSFS/devices/system/cpu
57e66d5b67SViresh Kumar	CPUFREQROOT="$CPUROOT/cpufreq"
58e66d5b67SViresh Kumar
59e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
60e66d5b67SViresh Kumar		echo $msg cpus not available in sysfs >&2
61e66d5b67SViresh Kumar		exit 2
62e66d5b67SViresh Kumar	fi
63e66d5b67SViresh Kumar
64e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
65e66d5b67SViresh Kumar		echo $msg cpufreq directory not available in sysfs >&2
66e66d5b67SViresh Kumar		exit 2
67e66d5b67SViresh Kumar	fi
68e66d5b67SViresh Kumar}
69e66d5b67SViresh Kumar
70e66d5b67SViresh Kumarparse_arguments()
71e66d5b67SViresh Kumar{
726751faf3SViresh Kumar	while getopts ht:o:d:g: arg
73e66d5b67SViresh Kumar	do
74e66d5b67SViresh Kumar		case $arg in
75e66d5b67SViresh Kumar			h) # --help
76e66d5b67SViresh Kumar				helpme
77e66d5b67SViresh Kumar				;;
78e66d5b67SViresh Kumar
791e4c2830SViresh Kumar			t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
80e66d5b67SViresh Kumar				FUNC=$OPTARG
81e66d5b67SViresh Kumar				;;
82e66d5b67SViresh Kumar
83e66d5b67SViresh Kumar			o) # --output-file (Output file to store dumps)
84e66d5b67SViresh Kumar				OUTFILE=$OPTARG
85e66d5b67SViresh Kumar				;;
86e66d5b67SViresh Kumar
876751faf3SViresh Kumar			d) # --driver-mod-name (Name of the driver module)
886751faf3SViresh Kumar				DRIVER_MOD=$OPTARG
896751faf3SViresh Kumar				;;
906751faf3SViresh Kumar
916751faf3SViresh Kumar			g) # --governor-mod-name (Name of the governor module)
926751faf3SViresh Kumar				GOVERNOR_MOD=$OPTARG
936751faf3SViresh Kumar				;;
946751faf3SViresh Kumar
95e66d5b67SViresh Kumar			\?)
96e66d5b67SViresh Kumar				helpme
97e66d5b67SViresh Kumar				;;
98e66d5b67SViresh Kumar		esac
99e66d5b67SViresh Kumar	done
100e66d5b67SViresh Kumar}
101e66d5b67SViresh Kumar
102e66d5b67SViresh Kumardo_test()
103e66d5b67SViresh Kumar{
104e66d5b67SViresh Kumar	# Check if CPUs are managed by cpufreq or not
105e66d5b67SViresh Kumar	count=$(count_cpufreq_managed_cpus)
106e66d5b67SViresh Kumar
1076751faf3SViresh Kumar	if [ $count = 0 -a $FUNC != "modtest" ]; then
108e66d5b67SViresh Kumar		echo "No cpu is managed by cpufreq core, exiting"
109e66d5b67SViresh Kumar		exit 2;
110e66d5b67SViresh Kumar	fi
111e66d5b67SViresh Kumar
112e66d5b67SViresh Kumar	case "$FUNC" in
113e66d5b67SViresh Kumar		"basic")
114e66d5b67SViresh Kumar		cpufreq_basic_tests
115e66d5b67SViresh Kumar		;;
116e66d5b67SViresh Kumar
117b03eaf8dSViresh Kumar		"suspend")
118b03eaf8dSViresh Kumar		do_suspend "suspend" 1
119b03eaf8dSViresh Kumar		;;
120b03eaf8dSViresh Kumar
121b03eaf8dSViresh Kumar		"hibernate")
122b03eaf8dSViresh Kumar		do_suspend "hibernate" 1
123b03eaf8dSViresh Kumar		;;
124b03eaf8dSViresh Kumar
1256751faf3SViresh Kumar		"modtest")
1266751faf3SViresh Kumar		# Do we have modules in place?
1276751faf3SViresh Kumar		if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
1286751faf3SViresh Kumar			echo "No driver or governor module passed with -d or -g"
1296751faf3SViresh Kumar			exit 2;
1306751faf3SViresh Kumar		fi
1316751faf3SViresh Kumar
1326751faf3SViresh Kumar		if [ $DRIVER_MOD ]; then
1336751faf3SViresh Kumar			if [ $GOVERNOR_MOD ]; then
1346751faf3SViresh Kumar				module_test $DRIVER_MOD $GOVERNOR_MOD
1356751faf3SViresh Kumar			else
1366751faf3SViresh Kumar				module_driver_test $DRIVER_MOD
1376751faf3SViresh Kumar			fi
1386751faf3SViresh Kumar		else
1396751faf3SViresh Kumar			if [ $count = 0 ]; then
1406751faf3SViresh Kumar				echo "No cpu is managed by cpufreq core, exiting"
1416751faf3SViresh Kumar				exit 2;
1426751faf3SViresh Kumar			fi
1436751faf3SViresh Kumar
1446751faf3SViresh Kumar			module_governor_test $GOVERNOR_MOD
1456751faf3SViresh Kumar		fi
1466751faf3SViresh Kumar		;;
1476751faf3SViresh Kumar
1481e4c2830SViresh Kumar		"sptest1")
1491e4c2830SViresh Kumar		simple_lockdep
1501e4c2830SViresh Kumar		;;
1511e4c2830SViresh Kumar
1521e4c2830SViresh Kumar		"sptest2")
1531e4c2830SViresh Kumar		concurrent_lockdep
1541e4c2830SViresh Kumar		;;
1551e4c2830SViresh Kumar
1561e4c2830SViresh Kumar		"sptest3")
1571e4c2830SViresh Kumar		governor_race
1581e4c2830SViresh Kumar		;;
1591e4c2830SViresh Kumar
1601e4c2830SViresh Kumar		"sptest4")
1611e4c2830SViresh Kumar		hotplug_with_updates
1621e4c2830SViresh Kumar		;;
1631e4c2830SViresh Kumar
164e66d5b67SViresh Kumar		*)
165e66d5b67SViresh Kumar		echo "Invalid [-f] function type"
166e66d5b67SViresh Kumar		helpme
167e66d5b67SViresh Kumar		;;
168e66d5b67SViresh Kumar	esac
169e66d5b67SViresh Kumar}
170e66d5b67SViresh Kumar
171e66d5b67SViresh Kumar# clear dumps
172e66d5b67SViresh Kumar# $1: file name
173e66d5b67SViresh Kumarclear_dumps()
174e66d5b67SViresh Kumar{
175e66d5b67SViresh Kumar	echo "" > $1.txt
176e66d5b67SViresh Kumar	echo "" > $1.dmesg_cpufreq.txt
177e66d5b67SViresh Kumar	echo "" > $1.dmesg_full.txt
178e66d5b67SViresh Kumar}
179e66d5b67SViresh Kumar
180e66d5b67SViresh Kumar# $1: output file name
181e66d5b67SViresh Kumardmesg_dumps()
182e66d5b67SViresh Kumar{
183e66d5b67SViresh Kumar	dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
184e66d5b67SViresh Kumar
185e66d5b67SViresh Kumar	# We may need the full logs as well
186e66d5b67SViresh Kumar	dmesg >> $1.dmesg_full.txt
187e66d5b67SViresh Kumar}
188e66d5b67SViresh Kumar
189e66d5b67SViresh Kumar# Parse arguments
190e66d5b67SViresh Kumarparse_arguments $@
191e66d5b67SViresh Kumar
192e66d5b67SViresh Kumar# Make sure all requirements are met
193e66d5b67SViresh Kumarprerequisite
194e66d5b67SViresh Kumar
195e66d5b67SViresh Kumar# Run requested functions
196e66d5b67SViresh Kumarclear_dumps $OUTFILE
197*40d70d4dSNícolas F. R. A. Pradodo_test | tee -a $OUTFILE.txt
198e66d5b67SViresh Kumardmesg_dumps $OUTFILE
199