xref: /linux/tools/testing/selftests/cpufreq/main.sh (revision 6751faf3d8338d525e8d9c35ae87cbfed48ce958)
1e66d5b67SViresh Kumar#!/bin/bash
2e66d5b67SViresh Kumar
3e66d5b67SViresh Kumarsource cpu.sh
4e66d5b67SViresh Kumarsource cpufreq.sh
5e66d5b67SViresh Kumarsource governor.sh
6*6751faf3SViresh Kumarsource module.sh
7e66d5b67SViresh Kumar
8e66d5b67SViresh KumarFUNC=basic	# do basic tests by default
9e66d5b67SViresh KumarOUTFILE=cpufreq_selftest
10e66d5b67SViresh KumarSYSFS=
11e66d5b67SViresh KumarCPUROOT=
12e66d5b67SViresh KumarCPUFREQROOT=
13e66d5b67SViresh Kumar
14e66d5b67SViresh Kumarhelpme()
15e66d5b67SViresh Kumar{
16*6751faf3SViresh Kumar	printf "Usage: $0 [-h] [-todg args]
17e66d5b67SViresh Kumar	[-h <help>]
18e66d5b67SViresh Kumar	[-o <output-file-for-dump>]
19b03eaf8dSViresh Kumar	[-t <basic: Basic cpufreq testing
20b03eaf8dSViresh Kumar	     suspend: suspend/resume,
21*6751faf3SViresh Kumar	     hibernate: hibernate/resume,
22*6751faf3SViresh Kumar	     modtest: test driver or governor modules. Only to be used with -d or -g options>]
23*6751faf3SViresh Kumar	[-d <driver's module name: only with \"-t modtest>\"]
24*6751faf3SViresh Kumar	[-g <governor's module name: only with \"-t modtest>\"]
25e66d5b67SViresh Kumar	\n"
26e66d5b67SViresh Kumar	exit 2
27e66d5b67SViresh Kumar}
28e66d5b67SViresh Kumar
29e66d5b67SViresh Kumarprerequisite()
30e66d5b67SViresh Kumar{
31e66d5b67SViresh Kumar	msg="skip all tests:"
32e66d5b67SViresh Kumar
33e66d5b67SViresh Kumar	if [ $UID != 0 ]; then
34e66d5b67SViresh Kumar		echo $msg must be run as root >&2
35e66d5b67SViresh Kumar		exit 2
36e66d5b67SViresh Kumar	fi
37e66d5b67SViresh Kumar
38e66d5b67SViresh Kumar	taskset -p 01 $$
39e66d5b67SViresh Kumar
40e66d5b67SViresh Kumar	SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
41e66d5b67SViresh Kumar
42e66d5b67SViresh Kumar	if [ ! -d "$SYSFS" ]; then
43e66d5b67SViresh Kumar		echo $msg sysfs is not mounted >&2
44e66d5b67SViresh Kumar		exit 2
45e66d5b67SViresh Kumar	fi
46e66d5b67SViresh Kumar
47e66d5b67SViresh Kumar	CPUROOT=$SYSFS/devices/system/cpu
48e66d5b67SViresh Kumar	CPUFREQROOT="$CPUROOT/cpufreq"
49e66d5b67SViresh Kumar
50e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
51e66d5b67SViresh Kumar		echo $msg cpus not available in sysfs >&2
52e66d5b67SViresh Kumar		exit 2
53e66d5b67SViresh Kumar	fi
54e66d5b67SViresh Kumar
55e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
56e66d5b67SViresh Kumar		echo $msg cpufreq directory not available in sysfs >&2
57e66d5b67SViresh Kumar		exit 2
58e66d5b67SViresh Kumar	fi
59e66d5b67SViresh Kumar}
60e66d5b67SViresh Kumar
61e66d5b67SViresh Kumarparse_arguments()
62e66d5b67SViresh Kumar{
63*6751faf3SViresh Kumar	while getopts ht:o:d:g: arg
64e66d5b67SViresh Kumar	do
65e66d5b67SViresh Kumar		case $arg in
66e66d5b67SViresh Kumar			h) # --help
67e66d5b67SViresh Kumar				helpme
68e66d5b67SViresh Kumar				;;
69e66d5b67SViresh Kumar
70*6751faf3SViresh Kumar			t) # --func_type (Function to perform: basic, suspend, hibernate, modtest (default: basic))
71e66d5b67SViresh Kumar				FUNC=$OPTARG
72e66d5b67SViresh Kumar				;;
73e66d5b67SViresh Kumar
74e66d5b67SViresh Kumar			o) # --output-file (Output file to store dumps)
75e66d5b67SViresh Kumar				OUTFILE=$OPTARG
76e66d5b67SViresh Kumar				;;
77e66d5b67SViresh Kumar
78*6751faf3SViresh Kumar			d) # --driver-mod-name (Name of the driver module)
79*6751faf3SViresh Kumar				DRIVER_MOD=$OPTARG
80*6751faf3SViresh Kumar				;;
81*6751faf3SViresh Kumar
82*6751faf3SViresh Kumar			g) # --governor-mod-name (Name of the governor module)
83*6751faf3SViresh Kumar				GOVERNOR_MOD=$OPTARG
84*6751faf3SViresh Kumar				;;
85*6751faf3SViresh Kumar
86e66d5b67SViresh Kumar			\?)
87e66d5b67SViresh Kumar				helpme
88e66d5b67SViresh Kumar				;;
89e66d5b67SViresh Kumar		esac
90e66d5b67SViresh Kumar	done
91e66d5b67SViresh Kumar}
92e66d5b67SViresh Kumar
93e66d5b67SViresh Kumardo_test()
94e66d5b67SViresh Kumar{
95e66d5b67SViresh Kumar	# Check if CPUs are managed by cpufreq or not
96e66d5b67SViresh Kumar	count=$(count_cpufreq_managed_cpus)
97e66d5b67SViresh Kumar
98*6751faf3SViresh Kumar	if [ $count = 0 -a $FUNC != "modtest" ]; then
99e66d5b67SViresh Kumar		echo "No cpu is managed by cpufreq core, exiting"
100e66d5b67SViresh Kumar		exit 2;
101e66d5b67SViresh Kumar	fi
102e66d5b67SViresh Kumar
103e66d5b67SViresh Kumar	case "$FUNC" in
104e66d5b67SViresh Kumar		"basic")
105e66d5b67SViresh Kumar		cpufreq_basic_tests
106e66d5b67SViresh Kumar		;;
107e66d5b67SViresh Kumar
108b03eaf8dSViresh Kumar		"suspend")
109b03eaf8dSViresh Kumar		do_suspend "suspend" 1
110b03eaf8dSViresh Kumar		;;
111b03eaf8dSViresh Kumar
112b03eaf8dSViresh Kumar		"hibernate")
113b03eaf8dSViresh Kumar		do_suspend "hibernate" 1
114b03eaf8dSViresh Kumar		;;
115b03eaf8dSViresh Kumar
116*6751faf3SViresh Kumar		"modtest")
117*6751faf3SViresh Kumar		# Do we have modules in place?
118*6751faf3SViresh Kumar		if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
119*6751faf3SViresh Kumar			echo "No driver or governor module passed with -d or -g"
120*6751faf3SViresh Kumar			exit 2;
121*6751faf3SViresh Kumar		fi
122*6751faf3SViresh Kumar
123*6751faf3SViresh Kumar		if [ $DRIVER_MOD ]; then
124*6751faf3SViresh Kumar			if [ $GOVERNOR_MOD ]; then
125*6751faf3SViresh Kumar				module_test $DRIVER_MOD $GOVERNOR_MOD
126*6751faf3SViresh Kumar			else
127*6751faf3SViresh Kumar				module_driver_test $DRIVER_MOD
128*6751faf3SViresh Kumar			fi
129*6751faf3SViresh Kumar		else
130*6751faf3SViresh Kumar			if [ $count = 0 ]; then
131*6751faf3SViresh Kumar				echo "No cpu is managed by cpufreq core, exiting"
132*6751faf3SViresh Kumar				exit 2;
133*6751faf3SViresh Kumar			fi
134*6751faf3SViresh Kumar
135*6751faf3SViresh Kumar			module_governor_test $GOVERNOR_MOD
136*6751faf3SViresh Kumar		fi
137*6751faf3SViresh Kumar		;;
138*6751faf3SViresh Kumar
139e66d5b67SViresh Kumar		*)
140e66d5b67SViresh Kumar		echo "Invalid [-f] function type"
141e66d5b67SViresh Kumar		helpme
142e66d5b67SViresh Kumar		;;
143e66d5b67SViresh Kumar	esac
144e66d5b67SViresh Kumar}
145e66d5b67SViresh Kumar
146e66d5b67SViresh Kumar# clear dumps
147e66d5b67SViresh Kumar# $1: file name
148e66d5b67SViresh Kumarclear_dumps()
149e66d5b67SViresh Kumar{
150e66d5b67SViresh Kumar	echo "" > $1.txt
151e66d5b67SViresh Kumar	echo "" > $1.dmesg_cpufreq.txt
152e66d5b67SViresh Kumar	echo "" > $1.dmesg_full.txt
153e66d5b67SViresh Kumar}
154e66d5b67SViresh Kumar
155e66d5b67SViresh Kumar# $1: output file name
156e66d5b67SViresh Kumardmesg_dumps()
157e66d5b67SViresh Kumar{
158e66d5b67SViresh Kumar	dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
159e66d5b67SViresh Kumar
160e66d5b67SViresh Kumar	# We may need the full logs as well
161e66d5b67SViresh Kumar	dmesg >> $1.dmesg_full.txt
162e66d5b67SViresh Kumar}
163e66d5b67SViresh Kumar
164e66d5b67SViresh Kumar# Parse arguments
165e66d5b67SViresh Kumarparse_arguments $@
166e66d5b67SViresh Kumar
167e66d5b67SViresh Kumar# Make sure all requirements are met
168e66d5b67SViresh Kumarprerequisite
169e66d5b67SViresh Kumar
170e66d5b67SViresh Kumar# Run requested functions
171e66d5b67SViresh Kumarclear_dumps $OUTFILE
172e66d5b67SViresh Kumardo_test >> $OUTFILE.txt
173e66d5b67SViresh Kumardmesg_dumps $OUTFILE
174