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