Revert "tty: hvc: Fix data abort due to race in hvc_open"
[linux/fpc-iii.git] / tools / testing / selftests / cpufreq / cpufreq.sh
blobb583a2fb4504257daa0c71d09ec82d679ec9535e
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # protect against multiple inclusion
5 if [ $FILE_CPUFREQ ]; then
6 return 0
7 else
8 FILE_CPUFREQ=DONE
9 fi
11 source cpu.sh
14 # $1: cpu
15 cpu_should_have_cpufreq_directory()
17 if [ ! -d $CPUROOT/$1/cpufreq ]; then
18 printf "Warning: No cpufreq directory present for $1\n"
22 cpu_should_not_have_cpufreq_directory()
24 if [ -d $CPUROOT/$1/cpufreq ]; then
25 printf "Warning: cpufreq directory present for $1\n"
29 for_each_policy()
31 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
32 for policy in $policies; do
33 $@ $policy
34 done
37 for_each_policy_concurrent()
39 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
40 for policy in $policies; do
41 $@ $policy &
42 done
45 # $1: Path
46 read_cpufreq_files_in_dir()
48 local files=`ls $1`
50 printf "Printing directory: $1\n\n"
52 for file in $files; do
53 if [ -f $1/$file ]; then
54 printf "$file:"
55 cat $1/$file
56 else
57 printf "\n"
58 read_cpufreq_files_in_dir "$1/$file"
60 done
61 printf "\n"
65 read_all_cpufreq_files()
67 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
69 read_cpufreq_files_in_dir $CPUFREQROOT
71 printf "%s\n\n" "------------------------------------------------"
75 # UPDATE CPUFREQ FILES
77 # $1: directory path
78 update_cpufreq_files_in_dir()
80 local files=`ls $1`
82 printf "Updating directory: $1\n\n"
84 for file in $files; do
85 if [ -f $1/$file ]; then
86 # file is writable ?
87 local wfile=$(ls -l $1/$file | awk '$1 ~ /^.*w.*/ { print $NF; }')
89 if [ ! -z $wfile ]; then
90 # scaling_setspeed is a special file and we
91 # should skip updating it
92 if [ $file != "scaling_setspeed" ]; then
93 local val=$(cat $1/$file)
94 printf "Writing $val to: $file\n"
95 echo $val > $1/$file
98 else
99 printf "\n"
100 update_cpufreq_files_in_dir "$1/$file"
102 done
104 printf "\n"
107 # Update all writable files with their existing values
108 update_all_cpufreq_files()
110 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
112 update_cpufreq_files_in_dir $CPUFREQROOT
114 printf "%s\n\n" "------------------------------------------------"
118 # CHANGE CPU FREQUENCIES
120 # $1: policy
121 find_current_freq()
123 cat $CPUFREQROOT/$1/scaling_cur_freq
126 # $1: policy
127 # $2: frequency
128 set_cpu_frequency()
130 printf "Change frequency for $1 to $2\n"
131 echo $2 > $CPUFREQROOT/$1/scaling_setspeed
134 # $1: policy
135 test_all_frequencies()
137 local filepath="$CPUFREQROOT/$1"
139 backup_governor $1
141 local found=$(switch_governor $1 "userspace")
142 if [ $found = 1 ]; then
143 printf "${FUNCNAME[0]}: userspace governor not available for: $1\n"
144 return;
147 printf "Switched governor for $1 to userspace\n\n"
149 local freqs=$(cat $filepath/scaling_available_frequencies)
150 printf "Available frequencies for $1: $freqs\n\n"
152 # Set all frequencies one-by-one
153 for freq in $freqs; do
154 set_cpu_frequency $1 $freq
155 done
157 printf "\n"
159 restore_governor $1
162 # $1: loop count
163 shuffle_frequency_for_all_cpus()
165 printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
167 for i in `seq 1 $1`; do
168 for_each_policy test_all_frequencies
169 done
170 printf "\n%s\n\n" "------------------------------------------------"
173 # Basic cpufreq tests
174 cpufreq_basic_tests()
176 printf "*** RUNNING CPUFREQ SANITY TESTS ***\n"
177 printf "====================================\n\n"
179 count=$(count_cpufreq_managed_cpus)
180 if [ $count = 0 ]; then
181 printf "No cpu is managed by cpufreq core, exiting\n"
182 exit;
183 else
184 printf "CPUFreq manages: $count CPUs\n\n"
187 # Detect & print which CPUs are not managed by cpufreq
188 print_unmanaged_cpus
190 # read/update all cpufreq files
191 read_all_cpufreq_files
192 update_all_cpufreq_files
194 # hotplug cpus
195 reboot_cpus 5
197 # Test all frequencies
198 shuffle_frequency_for_all_cpus 2
200 # Test all governors
201 shuffle_governors_for_all_cpus 1
204 # Suspend/resume
205 # $1: "suspend" or "hibernate", $2: loop count
206 do_suspend()
208 printf "** Test: Running ${FUNCNAME[0]}: Trying $1 for $2 loops **\n\n"
210 # Is the directory available
211 if [ ! -d $SYSFS/power/ -o ! -f $SYSFS/power/state ]; then
212 printf "$SYSFS/power/state not available\n"
213 return 1
216 if [ $1 = "suspend" ]; then
217 filename="mem"
218 elif [ $1 = "hibernate" ]; then
219 filename="disk"
220 else
221 printf "$1 is not a valid option\n"
222 return 1
225 if [ -n $filename ]; then
226 present=$(cat $SYSFS/power/state | grep $filename)
228 if [ -z "$present" ]; then
229 printf "Tried to $1 but $filename isn't present in $SYSFS/power/state\n"
230 return 1;
233 for i in `seq 1 $2`; do
234 printf "Starting $1\n"
235 echo $filename > $SYSFS/power/state
236 printf "Came out of $1\n"
238 printf "Do basic tests after finishing $1 to verify cpufreq state\n\n"
239 cpufreq_basic_tests
240 done