xref: /aosp_15_r20/external/ltp/testcases/kernel/power_management/runpwtests03.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#! /bin/sh
2*49cdfc7eSAndroid Build Coastguard Worker#
3*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker# Author: Nageswara R Sastry <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker#
6*49cdfc7eSAndroid Build Coastguard Worker# This program is free software;  you can redistribute it and#or modify
7*49cdfc7eSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by
8*49cdfc7eSAndroid Build Coastguard Worker# the Free Software Foundation; either version 2 of the License, or
9*49cdfc7eSAndroid Build Coastguard Worker# (at your option) any later version.
10*49cdfc7eSAndroid Build Coastguard Worker#
11*49cdfc7eSAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful, but
12*49cdfc7eSAndroid Build Coastguard Worker# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13*49cdfc7eSAndroid Build Coastguard Worker# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*49cdfc7eSAndroid Build Coastguard Worker# for more details.
15*49cdfc7eSAndroid Build Coastguard Worker#
16*49cdfc7eSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License
17*49cdfc7eSAndroid Build Coastguard Worker# along with this program;  if not, write to the Free Software Foundation,
18*49cdfc7eSAndroid Build Coastguard Worker# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*49cdfc7eSAndroid Build Coastguard Worker#
20*49cdfc7eSAndroid Build Coastguard Worker
21*49cdfc7eSAndroid Build Coastguard Workerexport TCID="Power_Management03"
22*49cdfc7eSAndroid Build Coastguard Workerexport TST_TOTAL=4
23*49cdfc7eSAndroid Build Coastguard Worker
24*49cdfc7eSAndroid Build Coastguard Worker. test.sh
25*49cdfc7eSAndroid Build Coastguard Worker. pm_include.sh
26*49cdfc7eSAndroid Build Coastguard Worker
27*49cdfc7eSAndroid Build Coastguard Workercheck_cpufreq_sysfs_files() {
28*49cdfc7eSAndroid Build Coastguard Worker	total_cpus=`expr $(tst_ncpus) - 1`
29*49cdfc7eSAndroid Build Coastguard Worker	RC=0
30*49cdfc7eSAndroid Build Coastguard Worker
31*49cdfc7eSAndroid Build Coastguard Worker	for cpu in $(seq 0 "${total_cpus}" )
32*49cdfc7eSAndroid Build Coastguard Worker	do
33*49cdfc7eSAndroid Build Coastguard Worker		cpufiles=$(find /sys/devices/system/cpu/cpu"${cpu}"/cpufreq/ \
34*49cdfc7eSAndroid Build Coastguard Worker			-name "*" -type f -perm /400)
35*49cdfc7eSAndroid Build Coastguard Worker		for files in ${cpufiles}
36*49cdfc7eSAndroid Build Coastguard Worker		do
37*49cdfc7eSAndroid Build Coastguard Worker			cat ${files} >/dev/null 2>&1
38*49cdfc7eSAndroid Build Coastguard Worker			if [ $? -ne 0 ] ; then
39*49cdfc7eSAndroid Build Coastguard Worker				echo "${0}: FAIL: cat ${files}"
40*49cdfc7eSAndroid Build Coastguard Worker				RC=1
41*49cdfc7eSAndroid Build Coastguard Worker			fi
42*49cdfc7eSAndroid Build Coastguard Worker		done
43*49cdfc7eSAndroid Build Coastguard Worker	done
44*49cdfc7eSAndroid Build Coastguard Worker	if [ ${RC} -eq 0 ] ; then
45*49cdfc7eSAndroid Build Coastguard Worker		echo "${0}: PASS: Checking cpu freq sysfs files"
46*49cdfc7eSAndroid Build Coastguard Worker	fi
47*49cdfc7eSAndroid Build Coastguard Worker	return $RC
48*49cdfc7eSAndroid Build Coastguard Worker}
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Workerchange_govr() {
51*49cdfc7eSAndroid Build Coastguard Worker	available_govr=$(get_supporting_govr)
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker	total_cpus=`expr $(tst_ncpus) - 1`
54*49cdfc7eSAndroid Build Coastguard Worker	RC=0
55*49cdfc7eSAndroid Build Coastguard Worker
56*49cdfc7eSAndroid Build Coastguard Worker	for cpu in $(seq 0 "${total_cpus}" )
57*49cdfc7eSAndroid Build Coastguard Worker	do
58*49cdfc7eSAndroid Build Coastguard Worker		for govr in ${available_govr}
59*49cdfc7eSAndroid Build Coastguard Worker		do
60*49cdfc7eSAndroid Build Coastguard Worker			echo ${govr} > \
61*49cdfc7eSAndroid Build Coastguard Worker	/sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor
62*49cdfc7eSAndroid Build Coastguard Worker			if [ "$?" -ne "0" ] ; then
63*49cdfc7eSAndroid Build Coastguard Worker				echo "${0}: FAIL: Unable to set" \
64*49cdfc7eSAndroid Build Coastguard Worker					"governor -- ${govr} for cpu${cpu}"
65*49cdfc7eSAndroid Build Coastguard Worker				RC=1
66*49cdfc7eSAndroid Build Coastguard Worker			fi
67*49cdfc7eSAndroid Build Coastguard Worker		done
68*49cdfc7eSAndroid Build Coastguard Worker	done
69*49cdfc7eSAndroid Build Coastguard Worker	if [ ${RC} -eq 0 ] ; then
70*49cdfc7eSAndroid Build Coastguard Worker		echo "${0}: PASS: Changing cpu governors"
71*49cdfc7eSAndroid Build Coastguard Worker	fi
72*49cdfc7eSAndroid Build Coastguard Worker	return $RC
73*49cdfc7eSAndroid Build Coastguard Worker}
74*49cdfc7eSAndroid Build Coastguard Worker
75*49cdfc7eSAndroid Build Coastguard Workerchange_freq() {
76*49cdfc7eSAndroid Build Coastguard Worker	available_freq=$(get_supporting_freq)
77*49cdfc7eSAndroid Build Coastguard Worker	available_govr=$(get_supporting_govr)
78*49cdfc7eSAndroid Build Coastguard Worker	RC=0
79*49cdfc7eSAndroid Build Coastguard Worker
80*49cdfc7eSAndroid Build Coastguard Worker	total_cpus=`expr $(tst_ncpus) - 1`
81*49cdfc7eSAndroid Build Coastguard Worker
82*49cdfc7eSAndroid Build Coastguard Worker	if ( echo ${available_govr} | grep -i "userspace" \
83*49cdfc7eSAndroid Build Coastguard Worker		>/dev/null 2>&1 ); then
84*49cdfc7eSAndroid Build Coastguard Worker		for cpu in $(seq 0 "${total_cpus}" )
85*49cdfc7eSAndroid Build Coastguard Worker		do
86*49cdfc7eSAndroid Build Coastguard Worker			echo userspace > \
87*49cdfc7eSAndroid Build Coastguard Worker	/sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor
88*49cdfc7eSAndroid Build Coastguard Worker			if [ $? -ne 0 ] ; then
89*49cdfc7eSAndroid Build Coastguard Worker				RC=1
90*49cdfc7eSAndroid Build Coastguard Worker			fi
91*49cdfc7eSAndroid Build Coastguard Worker		done
92*49cdfc7eSAndroid Build Coastguard Worker		if [ ${RC} -ne 1 ] ; then
93*49cdfc7eSAndroid Build Coastguard Worker			for cpu in $(seq 0 "${total_cpus}" )
94*49cdfc7eSAndroid Build Coastguard Worker			do
95*49cdfc7eSAndroid Build Coastguard Worker				for freq in ${available_freq}
96*49cdfc7eSAndroid Build Coastguard Worker				do
97*49cdfc7eSAndroid Build Coastguard Worker					echo ${freq} > \
98*49cdfc7eSAndroid Build Coastguard Worker	/sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_setspeed
99*49cdfc7eSAndroid Build Coastguard Worker					if [ "$?" -ne "0" ] ; then
100*49cdfc7eSAndroid Build Coastguard Worker						echo "${0}: FAIL: Unable" \
101*49cdfc7eSAndroid Build Coastguard Worker							"to set frequency -- ${freq} for cpu${cpu}"
102*49cdfc7eSAndroid Build Coastguard Worker						RC=1
103*49cdfc7eSAndroid Build Coastguard Worker					fi
104*49cdfc7eSAndroid Build Coastguard Worker				done
105*49cdfc7eSAndroid Build Coastguard Worker			done
106*49cdfc7eSAndroid Build Coastguard Worker		fi
107*49cdfc7eSAndroid Build Coastguard Worker	fi
108*49cdfc7eSAndroid Build Coastguard Worker	if [ ${RC} -eq 0 ] ; then
109*49cdfc7eSAndroid Build Coastguard Worker		echo "${0}: PASS: Changing cpu frequencies"
110*49cdfc7eSAndroid Build Coastguard Worker	fi
111*49cdfc7eSAndroid Build Coastguard Worker	return $RC
112*49cdfc7eSAndroid Build Coastguard Worker}
113*49cdfc7eSAndroid Build Coastguard Worker
114*49cdfc7eSAndroid Build Coastguard Workerpwkm_load_unload() {
115*49cdfc7eSAndroid Build Coastguard Worker	RC=0
116*49cdfc7eSAndroid Build Coastguard Worker	loaded_governor=`cat \
117*49cdfc7eSAndroid Build Coastguard Worker		/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
118*49cdfc7eSAndroid Build Coastguard Worker	for module in `modprobe -l | grep cpufreq_ | \
119*49cdfc7eSAndroid Build Coastguard Worker		cut -f8 -d"/" | cut -f1 -d"."`
120*49cdfc7eSAndroid Build Coastguard Worker	do
121*49cdfc7eSAndroid Build Coastguard Worker		#echo -n "Loading $module ... "
122*49cdfc7eSAndroid Build Coastguard Worker		if [ $module != "cpufreq_$loaded_governor" ]; then
123*49cdfc7eSAndroid Build Coastguard Worker			modprobe $module >/dev/null
124*49cdfc7eSAndroid Build Coastguard Worker			if [ $? -ne 0 ] ; then
125*49cdfc7eSAndroid Build Coastguard Worker				echo "${0}: FAIL: Loading of module $module" \
126*49cdfc7eSAndroid Build Coastguard Worker					"or check whether you compiled as module or not"
127*49cdfc7eSAndroid Build Coastguard Worker				RC=1
128*49cdfc7eSAndroid Build Coastguard Worker			fi
129*49cdfc7eSAndroid Build Coastguard Worker		fi
130*49cdfc7eSAndroid Build Coastguard Worker	done
131*49cdfc7eSAndroid Build Coastguard Worker	for module in `modprobe -l | grep cpufreq_ | \
132*49cdfc7eSAndroid Build Coastguard Worker		cut -f8 -d"/" | cut -f1 -d"."`
133*49cdfc7eSAndroid Build Coastguard Worker		do
134*49cdfc7eSAndroid Build Coastguard Worker		#echo -n "Unloading $module ... "
135*49cdfc7eSAndroid Build Coastguard Worker		if [ $module != "cpufreq_$loaded_governor" ]; then
136*49cdfc7eSAndroid Build Coastguard Worker			modprobe -r $module >/dev/null
137*49cdfc7eSAndroid Build Coastguard Worker			if [ $? -ne 0 ] ; then
138*49cdfc7eSAndroid Build Coastguard Worker				echo "${0}: FAIL: Loading of module $module" \
139*49cdfc7eSAndroid Build Coastguard Worker					"or check whether you compiled as module or not"
140*49cdfc7eSAndroid Build Coastguard Worker				RC=1
141*49cdfc7eSAndroid Build Coastguard Worker			fi
142*49cdfc7eSAndroid Build Coastguard Worker		fi
143*49cdfc7eSAndroid Build Coastguard Worker	done
144*49cdfc7eSAndroid Build Coastguard Worker	return $RC
145*49cdfc7eSAndroid Build Coastguard Worker}
146*49cdfc7eSAndroid Build Coastguard Worker
147*49cdfc7eSAndroid Build Coastguard Worker# Checking test environment
148*49cdfc7eSAndroid Build Coastguard Workercheck_arch
149*49cdfc7eSAndroid Build Coastguard Worker
150*49cdfc7eSAndroid Build Coastguard Worker# Checking cpufreq sysfs interface files
151*49cdfc7eSAndroid Build Coastguard Workerif [ ! -d /sys/devices/system/cpu/cpu0/cpufreq ] ; then
152*49cdfc7eSAndroid Build Coastguard Worker	tst_brkm TCONF "Required kernel configuration for CPU_FREQ NOT set"
153*49cdfc7eSAndroid Build Coastguard Workerfi
154*49cdfc7eSAndroid Build Coastguard Worker
155*49cdfc7eSAndroid Build Coastguard Workerif check_cpufreq_sysfs_files ; then
156*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TPASS "CPUFREQ sysfs tests"
157*49cdfc7eSAndroid Build Coastguard Workerelse
158*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TFAIL "CPUFREQ sysfs tests"
159*49cdfc7eSAndroid Build Coastguard Workerfi
160*49cdfc7eSAndroid Build Coastguard Worker
161*49cdfc7eSAndroid Build Coastguard Worker# Changing governors
162*49cdfc7eSAndroid Build Coastguard Workerif change_govr ; then
163*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TPASS "Changing governors"
164*49cdfc7eSAndroid Build Coastguard Workerelse
165*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TFAIL "Changing governors"
166*49cdfc7eSAndroid Build Coastguard Workerfi
167*49cdfc7eSAndroid Build Coastguard Worker
168*49cdfc7eSAndroid Build Coastguard Worker# Changing frequencies
169*49cdfc7eSAndroid Build Coastguard Workerif change_freq ; then
170*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TPASS "Changing frequncies"
171*49cdfc7eSAndroid Build Coastguard Workerelse
172*49cdfc7eSAndroid Build Coastguard Worker    tst_resm TFAIL "Changing frequncies"
173*49cdfc7eSAndroid Build Coastguard Workerfi
174*49cdfc7eSAndroid Build Coastguard Worker
175*49cdfc7eSAndroid Build Coastguard Worker# Loading and Unloading governor related kernel modules
176*49cdfc7eSAndroid Build Coastguard Workerif pwkm_load_unload ; then
177*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TPASS "Loading and Unloading of governor kernel" \
178*49cdfc7eSAndroid Build Coastguard Worker		"modules"
179*49cdfc7eSAndroid Build Coastguard Workerelse
180*49cdfc7eSAndroid Build Coastguard Worker	tst_resm TFAIL "Loading and Unloading of governor kernel" \
181*49cdfc7eSAndroid Build Coastguard Worker		"modules got failed"
182*49cdfc7eSAndroid Build Coastguard Workerfi
183*49cdfc7eSAndroid Build Coastguard Worker
184*49cdfc7eSAndroid Build Coastguard Workertst_exit
185