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