1#!/bin/bash 2 3source cpu.sh 4source cpufreq.sh 5source governor.sh 6 7FUNC=basic # do basic tests by default 8OUTFILE=cpufreq_selftest 9SYSFS= 10CPUROOT= 11CPUFREQROOT= 12 13helpme() 14{ 15 printf "Usage: $0 [-h] [-to args] 16 [-h <help>] 17 [-o <output-file-for-dump>] 18 [-t <basic: Basic cpufreq testing 19 suspend: suspend/resume, 20 hibernate: hibernate/resume>] 21 \n" 22 exit 2 23} 24 25prerequisite() 26{ 27 msg="skip all tests:" 28 29 if [ $UID != 0 ]; then 30 echo $msg must be run as root >&2 31 exit 2 32 fi 33 34 taskset -p 01 $$ 35 36 SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 37 38 if [ ! -d "$SYSFS" ]; then 39 echo $msg sysfs is not mounted >&2 40 exit 2 41 fi 42 43 CPUROOT=$SYSFS/devices/system/cpu 44 CPUFREQROOT="$CPUROOT/cpufreq" 45 46 if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then 47 echo $msg cpus not available in sysfs >&2 48 exit 2 49 fi 50 51 if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then 52 echo $msg cpufreq directory not available in sysfs >&2 53 exit 2 54 fi 55} 56 57parse_arguments() 58{ 59 while getopts ht:o: arg 60 do 61 case $arg in 62 h) # --help 63 helpme 64 ;; 65 66 t) # --func_type (Function to perform: basic, suspend, hibernate (default: basic)) 67 FUNC=$OPTARG 68 ;; 69 70 o) # --output-file (Output file to store dumps) 71 OUTFILE=$OPTARG 72 ;; 73 74 \?) 75 helpme 76 ;; 77 esac 78 done 79} 80 81do_test() 82{ 83 # Check if CPUs are managed by cpufreq or not 84 count=$(count_cpufreq_managed_cpus) 85 86 if [ $count = 0 ]; then 87 echo "No cpu is managed by cpufreq core, exiting" 88 exit 2; 89 fi 90 91 case "$FUNC" in 92 "basic") 93 cpufreq_basic_tests 94 ;; 95 96 "suspend") 97 do_suspend "suspend" 1 98 ;; 99 100 "hibernate") 101 do_suspend "hibernate" 1 102 ;; 103 104 *) 105 echo "Invalid [-f] function type" 106 helpme 107 ;; 108 esac 109} 110 111# clear dumps 112# $1: file name 113clear_dumps() 114{ 115 echo "" > $1.txt 116 echo "" > $1.dmesg_cpufreq.txt 117 echo "" > $1.dmesg_full.txt 118} 119 120# $1: output file name 121dmesg_dumps() 122{ 123 dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt 124 125 # We may need the full logs as well 126 dmesg >> $1.dmesg_full.txt 127} 128 129# Parse arguments 130parse_arguments $@ 131 132# Make sure all requirements are met 133prerequisite 134 135# Run requested functions 136clear_dumps $OUTFILE 137do_test >> $OUTFILE.txt 138dmesg_dumps $OUTFILE 139