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