Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | source cpu.sh |
| 4 | source cpufreq.sh |
| 5 | source governor.sh |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 6 | source module.sh |
Viresh Kumar | 1e4c283 | 2017-01-13 12:06:48 +0530 | [diff] [blame] | 7 | source special-tests.sh |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 8 | |
| 9 | FUNC=basic # do basic tests by default |
| 10 | OUTFILE=cpufreq_selftest |
| 11 | SYSFS= |
| 12 | CPUROOT= |
| 13 | CPUFREQROOT= |
| 14 | |
| 15 | helpme() |
| 16 | { |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 17 | printf "Usage: $0 [-h] [-todg args] |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 18 | [-h <help>] |
| 19 | [-o <output-file-for-dump>] |
Viresh Kumar | b03eaf8 | 2017-01-13 12:06:46 +0530 | [diff] [blame] | 20 | [-t <basic: Basic cpufreq testing |
| 21 | suspend: suspend/resume, |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 22 | hibernate: hibernate/resume, |
Viresh Kumar | 1e4c283 | 2017-01-13 12:06:48 +0530 | [diff] [blame] | 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.>] |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 28 | [-d <driver's module name: only with \"-t modtest>\"] |
| 29 | [-g <governor's module name: only with \"-t modtest>\"] |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 30 | \n" |
| 31 | exit 2 |
| 32 | } |
| 33 | |
| 34 | prerequisite() |
| 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 | |
| 66 | parse_arguments() |
| 67 | { |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 68 | while getopts ht:o:d:g: arg |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 69 | do |
| 70 | case $arg in |
| 71 | h) # --help |
| 72 | helpme |
| 73 | ;; |
| 74 | |
Viresh Kumar | 1e4c283 | 2017-01-13 12:06:48 +0530 | [diff] [blame] | 75 | t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic)) |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 76 | FUNC=$OPTARG |
| 77 | ;; |
| 78 | |
| 79 | o) # --output-file (Output file to store dumps) |
| 80 | OUTFILE=$OPTARG |
| 81 | ;; |
| 82 | |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 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 | |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 91 | \?) |
| 92 | helpme |
| 93 | ;; |
| 94 | esac |
| 95 | done |
| 96 | } |
| 97 | |
| 98 | do_test() |
| 99 | { |
| 100 | # Check if CPUs are managed by cpufreq or not |
| 101 | count=$(count_cpufreq_managed_cpus) |
| 102 | |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 103 | if [ $count = 0 -a $FUNC != "modtest" ]; then |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 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 | |
Viresh Kumar | b03eaf8 | 2017-01-13 12:06:46 +0530 | [diff] [blame] | 113 | "suspend") |
| 114 | do_suspend "suspend" 1 |
| 115 | ;; |
| 116 | |
| 117 | "hibernate") |
| 118 | do_suspend "hibernate" 1 |
| 119 | ;; |
| 120 | |
Viresh Kumar | 6751faf | 2017-01-13 12:06:47 +0530 | [diff] [blame] | 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 | |
Viresh Kumar | 1e4c283 | 2017-01-13 12:06:48 +0530 | [diff] [blame] | 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 | |
Viresh Kumar | e66d5b6 | 2017-01-13 12:06:45 +0530 | [diff] [blame] | 160 | *) |
| 161 | echo "Invalid [-f] function type" |
| 162 | helpme |
| 163 | ;; |
| 164 | esac |
| 165 | } |
| 166 | |
| 167 | # clear dumps |
| 168 | # $1: file name |
| 169 | clear_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 |
| 177 | dmesg_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 |
| 186 | parse_arguments $@ |
| 187 | |
| 188 | # Make sure all requirements are met |
| 189 | prerequisite |
| 190 | |
| 191 | # Run requested functions |
| 192 | clear_dumps $OUTFILE |
| 193 | do_test >> $OUTFILE.txt |
| 194 | dmesg_dumps $OUTFILE |