1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 << 3 2 4 source cpu.sh 3 source cpu.sh 5 source cpufreq.sh 4 source cpufreq.sh 6 source governor.sh 5 source governor.sh 7 source module.sh 6 source module.sh 8 source special-tests.sh 7 source special-tests.sh 9 8 10 DIR="$(dirname $(readlink -f "$0"))" << 11 source "${DIR}"/../kselftest/ktap_helpers.sh << 12 << 13 FUNC=basic # do basic tests by default 9 FUNC=basic # do basic tests by default 14 OUTFILE=cpufreq_selftest 10 OUTFILE=cpufreq_selftest 15 SYSFS= 11 SYSFS= 16 CPUROOT= 12 CPUROOT= 17 CPUFREQROOT= 13 CPUFREQROOT= 18 14 19 helpme() 15 helpme() 20 { 16 { 21 printf "Usage: $0 [-h] [-todg args] 17 printf "Usage: $0 [-h] [-todg args] 22 [-h <help>] 18 [-h <help>] 23 [-o <output-file-for-dump>] 19 [-o <output-file-for-dump>] 24 [-t <basic: Basic cpufreq testing 20 [-t <basic: Basic cpufreq testing 25 suspend: suspend/resume, 21 suspend: suspend/resume, 26 hibernate: hibernate/resume, 22 hibernate: hibernate/resume, 27 suspend_rtc: suspend/resume back << 28 hibernate_rtc: hibernate/resume b << 29 modtest: test driver or governor 23 modtest: test driver or governor modules. Only to be used with -d or -g options, 30 sptest1: Simple governor switch t 24 sptest1: Simple governor switch to produce lockdep. 31 sptest2: Concurrent governor swit 25 sptest2: Concurrent governor switch to produce lockdep. 32 sptest3: Governor races, shuffle 26 sptest3: Governor races, shuffle between governors quickly. 33 sptest4: CPU hotplugs with update 27 sptest4: CPU hotplugs with updates to cpufreq files.>] 34 [-d <driver's module name: only with \ 28 [-d <driver's module name: only with \"-t modtest>\"] 35 [-g <governor's module name: only with 29 [-g <governor's module name: only with \"-t modtest>\"] 36 \n" 30 \n" 37 exit "${KSFT_FAIL}" !! 31 exit 2 38 } 32 } 39 33 40 prerequisite() 34 prerequisite() 41 { 35 { 42 msg="skip all tests:" 36 msg="skip all tests:" 43 37 44 if [ $UID != 0 ]; then 38 if [ $UID != 0 ]; then 45 ktap_skip_all "$msg must be ru !! 39 echo $msg must be run as root >&2 46 exit "${KSFT_SKIP}" !! 40 exit 2 47 fi 41 fi 48 42 49 taskset -p 01 $$ 43 taskset -p 01 $$ 50 44 51 SYSFS=`mount -t sysfs | head -1 | awk 45 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 52 46 53 if [ ! -d "$SYSFS" ]; then 47 if [ ! -d "$SYSFS" ]; then 54 ktap_skip_all "$msg sysfs is n !! 48 echo $msg sysfs is not mounted >&2 55 exit "${KSFT_SKIP}" !! 49 exit 2 56 fi 50 fi 57 51 58 CPUROOT=$SYSFS/devices/system/cpu 52 CPUROOT=$SYSFS/devices/system/cpu 59 CPUFREQROOT="$CPUROOT/cpufreq" 53 CPUFREQROOT="$CPUROOT/cpufreq" 60 54 61 if ! ls $CPUROOT/cpu* > /dev/null 2>&1 55 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then 62 ktap_skip_all "$msg cpus not a !! 56 echo $msg cpus not available in sysfs >&2 63 exit "${KSFT_SKIP}" !! 57 exit 2 64 fi 58 fi 65 59 66 if ! ls $CPUROOT/cpufreq > /dev/null 2 60 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then 67 ktap_skip_all "$msg cpufreq di !! 61 echo $msg cpufreq directory not available in sysfs >&2 68 exit "${KSFT_SKIP}" !! 62 exit 2 69 fi 63 fi 70 } 64 } 71 65 72 parse_arguments() 66 parse_arguments() 73 { 67 { 74 while getopts ht:o:d:g: arg 68 while getopts ht:o:d:g: arg 75 do 69 do 76 case $arg in 70 case $arg in 77 h) # --help 71 h) # --help 78 helpme 72 helpme 79 ;; 73 ;; 80 74 81 t) # --func_type (Func !! 75 t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic)) 82 # suspend_rtc, hibe << 83 FUNC=$OPTARG 76 FUNC=$OPTARG 84 ;; 77 ;; 85 78 86 o) # --output-file (Ou 79 o) # --output-file (Output file to store dumps) 87 OUTFILE=$OPTAR 80 OUTFILE=$OPTARG 88 ;; 81 ;; 89 82 90 d) # --driver-mod-name 83 d) # --driver-mod-name (Name of the driver module) 91 DRIVER_MOD=$OP 84 DRIVER_MOD=$OPTARG 92 ;; 85 ;; 93 86 94 g) # --governor-mod-na 87 g) # --governor-mod-name (Name of the governor module) 95 GOVERNOR_MOD=$ 88 GOVERNOR_MOD=$OPTARG 96 ;; 89 ;; 97 90 98 \?) 91 \?) 99 helpme 92 helpme 100 ;; 93 ;; 101 esac 94 esac 102 done 95 done 103 } 96 } 104 97 105 do_test() 98 do_test() 106 { 99 { 107 # Check if CPUs are managed by cpufreq 100 # Check if CPUs are managed by cpufreq or not 108 count=$(count_cpufreq_managed_cpus) 101 count=$(count_cpufreq_managed_cpus) 109 102 110 if [ $count = 0 -a $FUNC != "modtest" 103 if [ $count = 0 -a $FUNC != "modtest" ]; then 111 ktap_exit_fail_msg "No cpu is !! 104 echo "No cpu is managed by cpufreq core, exiting" >> 105 exit 2; 112 fi 106 fi 113 107 114 case "$FUNC" in 108 case "$FUNC" in 115 "basic") 109 "basic") 116 cpufreq_basic_tests 110 cpufreq_basic_tests 117 ;; 111 ;; 118 112 119 "suspend") 113 "suspend") 120 do_suspend "suspend" 1 114 do_suspend "suspend" 1 121 ;; 115 ;; 122 116 123 "hibernate") 117 "hibernate") 124 do_suspend "hibernate" 1 118 do_suspend "hibernate" 1 125 ;; 119 ;; 126 120 127 "suspend_rtc") << 128 do_suspend "suspend" 1 rtc << 129 ;; << 130 << 131 "hibernate_rtc") << 132 do_suspend "hibernate" 1 rtc << 133 ;; << 134 << 135 "modtest") 121 "modtest") 136 # Do we have modules in place? 122 # Do we have modules in place? 137 if [ -z $DRIVER_MOD ] && [ -z 123 if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then 138 ktap_exit_fail_msg "No !! 124 echo "No driver or governor module passed with -d or -g" >> 125 exit 2; 139 fi 126 fi 140 127 141 if [ $DRIVER_MOD ]; then 128 if [ $DRIVER_MOD ]; then 142 if [ $GOVERNOR_MOD ]; 129 if [ $GOVERNOR_MOD ]; then 143 module_test $D 130 module_test $DRIVER_MOD $GOVERNOR_MOD 144 else 131 else 145 module_driver_ 132 module_driver_test $DRIVER_MOD 146 fi 133 fi 147 else 134 else 148 if [ $count = 0 ]; the 135 if [ $count = 0 ]; then 149 ktap_exit_fail !! 136 echo "No cpu is managed by cpufreq core, exiting" >> 137 exit 2; 150 fi 138 fi 151 139 152 module_governor_test $ 140 module_governor_test $GOVERNOR_MOD 153 fi 141 fi 154 ;; 142 ;; 155 143 156 "sptest1") 144 "sptest1") 157 simple_lockdep 145 simple_lockdep 158 ;; 146 ;; 159 147 160 "sptest2") 148 "sptest2") 161 concurrent_lockdep 149 concurrent_lockdep 162 ;; 150 ;; 163 151 164 "sptest3") 152 "sptest3") 165 governor_race 153 governor_race 166 ;; 154 ;; 167 155 168 "sptest4") 156 "sptest4") 169 hotplug_with_updates 157 hotplug_with_updates 170 ;; 158 ;; 171 159 172 *) 160 *) 173 ktap_print_msg "Invalid [-f] f !! 161 echo "Invalid [-f] function type" 174 helpme 162 helpme 175 ;; 163 ;; 176 esac 164 esac 177 } 165 } 178 166 179 # clear dumps 167 # clear dumps 180 # $1: file name 168 # $1: file name 181 clear_dumps() 169 clear_dumps() 182 { 170 { 183 echo "" > $1.txt 171 echo "" > $1.txt 184 echo "" > $1.dmesg_cpufreq.txt 172 echo "" > $1.dmesg_cpufreq.txt 185 echo "" > $1.dmesg_full.txt 173 echo "" > $1.dmesg_full.txt 186 } 174 } 187 175 188 # $1: output file name 176 # $1: output file name 189 dmesg_dumps() 177 dmesg_dumps() 190 { 178 { 191 dmesg | grep cpufreq >> $1.dmesg_cpufr 179 dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt 192 180 193 # We may need the full logs as well 181 # We may need the full logs as well 194 dmesg >> $1.dmesg_full.txt 182 dmesg >> $1.dmesg_full.txt 195 } 183 } 196 184 197 ktap_print_header << 198 << 199 # Parse arguments 185 # Parse arguments 200 parse_arguments $@ 186 parse_arguments $@ 201 187 202 ktap_set_plan 1 << 203 << 204 # Make sure all requirements are met 188 # Make sure all requirements are met 205 prerequisite 189 prerequisite 206 190 207 # Run requested functions 191 # Run requested functions 208 clear_dumps $OUTFILE 192 clear_dumps $OUTFILE 209 do_test | tee -a $OUTFILE.txt !! 193 do_test >> $OUTFILE.txt 210 if [ "${PIPESTATUS[0]}" -ne 0 ]; then << 211 exit ${PIPESTATUS[0]}; << 212 fi << 213 dmesg_dumps $OUTFILE 194 dmesg_dumps $OUTFILE 214 << 215 ktap_test_pass "Completed successfully" << 216 << 217 ktap_print_totals << 218 exit "${KSFT_PASS}" <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.