0001
0002
0003
0004
0005 if [ $FILE_CPUFREQ ]; then
0006 return 0
0007 else
0008 FILE_CPUFREQ=DONE
0009 fi
0010
0011 source cpu.sh
0012
0013
0014
0015 cpu_should_have_cpufreq_directory()
0016 {
0017 if [ ! -d $CPUROOT/$1/cpufreq ]; then
0018 printf "Warning: No cpufreq directory present for $1\n"
0019 fi
0020 }
0021
0022 cpu_should_not_have_cpufreq_directory()
0023 {
0024 if [ -d $CPUROOT/$1/cpufreq ]; then
0025 printf "Warning: cpufreq directory present for $1\n"
0026 fi
0027 }
0028
0029 for_each_policy()
0030 {
0031 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
0032 for policy in $policies; do
0033 $@ $policy
0034 done
0035 }
0036
0037 for_each_policy_concurrent()
0038 {
0039 policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
0040 for policy in $policies; do
0041 $@ $policy &
0042 done
0043 }
0044
0045
0046 read_cpufreq_files_in_dir()
0047 {
0048 local files=`ls $1`
0049
0050 printf "Printing directory: $1\n\n"
0051
0052 for file in $files; do
0053 if [ -f $1/$file ]; then
0054 printf "$file:"
0055 cat $1/$file
0056 else
0057 printf "\n"
0058 read_cpufreq_files_in_dir "$1/$file"
0059 fi
0060 done
0061 printf "\n"
0062 }
0063
0064
0065 read_all_cpufreq_files()
0066 {
0067 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
0068
0069 read_cpufreq_files_in_dir $CPUFREQROOT
0070
0071 printf "%s\n\n" "------------------------------------------------"
0072 }
0073
0074
0075
0076
0077
0078 update_cpufreq_files_in_dir()
0079 {
0080 local files=`ls $1`
0081
0082 printf "Updating directory: $1\n\n"
0083
0084 for file in $files; do
0085 if [ -f $1/$file ]; then
0086
0087 local wfile=$(ls -l $1/$file | awk '$1 ~ /^.*w.*/ { print $NF; }')
0088
0089 if [ ! -z $wfile ]; then
0090
0091
0092 if [ $file != "scaling_setspeed" ]; then
0093 local val=$(cat $1/$file)
0094 printf "Writing $val to: $file\n"
0095 echo $val > $1/$file
0096 fi
0097 fi
0098 else
0099 printf "\n"
0100 update_cpufreq_files_in_dir "$1/$file"
0101 fi
0102 done
0103
0104 printf "\n"
0105 }
0106
0107
0108 update_all_cpufreq_files()
0109 {
0110 printf "** Test: Running ${FUNCNAME[0]} **\n\n"
0111
0112 update_cpufreq_files_in_dir $CPUFREQROOT
0113
0114 printf "%s\n\n" "------------------------------------------------"
0115 }
0116
0117
0118
0119
0120
0121 find_current_freq()
0122 {
0123 cat $CPUFREQROOT/$1/scaling_cur_freq
0124 }
0125
0126
0127
0128 set_cpu_frequency()
0129 {
0130 printf "Change frequency for $1 to $2\n"
0131 echo $2 > $CPUFREQROOT/$1/scaling_setspeed
0132 }
0133
0134
0135 test_all_frequencies()
0136 {
0137 local filepath="$CPUFREQROOT/$1"
0138
0139 backup_governor $1
0140
0141 local found=$(switch_governor $1 "userspace")
0142 if [ $found = 1 ]; then
0143 printf "${FUNCNAME[0]}: userspace governor not available for: $1\n"
0144 return;
0145 fi
0146
0147 printf "Switched governor for $1 to userspace\n\n"
0148
0149 local freqs=$(cat $filepath/scaling_available_frequencies)
0150 printf "Available frequencies for $1: $freqs\n\n"
0151
0152
0153 for freq in $freqs; do
0154 set_cpu_frequency $1 $freq
0155 done
0156
0157 printf "\n"
0158
0159 restore_governor $1
0160 }
0161
0162
0163 shuffle_frequency_for_all_cpus()
0164 {
0165 printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
0166
0167 for i in `seq 1 $1`; do
0168 for_each_policy test_all_frequencies
0169 done
0170 printf "\n%s\n\n" "------------------------------------------------"
0171 }
0172
0173
0174 cpufreq_basic_tests()
0175 {
0176 printf "*** RUNNING CPUFREQ SANITY TESTS ***\n"
0177 printf "====================================\n\n"
0178
0179 count=$(count_cpufreq_managed_cpus)
0180 if [ $count = 0 ]; then
0181 printf "No cpu is managed by cpufreq core, exiting\n"
0182 exit;
0183 else
0184 printf "CPUFreq manages: $count CPUs\n\n"
0185 fi
0186
0187
0188 print_unmanaged_cpus
0189
0190
0191 read_all_cpufreq_files
0192 update_all_cpufreq_files
0193
0194
0195 reboot_cpus 5
0196
0197
0198 shuffle_frequency_for_all_cpus 2
0199
0200
0201 shuffle_governors_for_all_cpus 1
0202 }
0203
0204
0205
0206 do_suspend()
0207 {
0208 printf "** Test: Running ${FUNCNAME[0]}: Trying $1 for $2 loops **\n\n"
0209
0210
0211 if [ ! -d $SYSFS/power/ -o ! -f $SYSFS/power/state ]; then
0212 printf "$SYSFS/power/state not available\n"
0213 return 1
0214 fi
0215
0216 if [ $1 = "suspend" ]; then
0217 filename="mem"
0218 elif [ $1 = "hibernate" ]; then
0219 filename="disk"
0220 else
0221 printf "$1 is not a valid option\n"
0222 return 1
0223 fi
0224
0225 if [ -n $filename ]; then
0226 present=$(cat $SYSFS/power/state | grep $filename)
0227
0228 if [ -z "$present" ]; then
0229 printf "Tried to $1 but $filename isn't present in $SYSFS/power/state\n"
0230 return 1;
0231 fi
0232
0233 for i in `seq 1 $2`; do
0234 printf "Starting $1\n"
0235 echo $filename > $SYSFS/power/state
0236 printf "Came out of $1\n"
0237
0238 printf "Do basic tests after finishing $1 to verify cpufreq state\n\n"
0239 cpufreq_basic_tests
0240 done
0241 fi
0242 }