1#!/bin/bash 2 3TMPDIR=/tmp 4 5PASS=0 6FAIL=1 7NOSUPPORT=2 8MISSING_FILE=3 9UNTESTED=4 10YES=0 11 12cleanup() { 13 if [ -f ${1} ] ; then 14 rm -f ${1} 15 fi 16} 17 18check_kervel_arch() { 19 # Checking required kernel version and architecture 20 if tst_kvcmp -lt "2.6.21"; then 21 tst_brkm TCONF "Kernel version not supported; not " \ 22 "running testcases" 23 else 24 case "$(uname -m)" in 25 i[4-6]86|x86_64) 26 ;; 27 *) 28 tst_brkm TCONF "Arch not supported; not running " \ 29 "testcases" 30 ;; 31 esac 32 fi 33} 34 35check_config_options() { 36 if ( ! ${3} "${1}" ${2} | grep -v "#" > /dev/null ) ; then 37 tst_brkm TCONF "NOSUPPORT: current system dosen't support ${1}" 38 fi 39} 40 41get_topology() { 42 declare -a cpus 43 declare -a phyid 44 45 total_cpus=`tst_ncpus` 46 (( total_cpus-=1 )) 47 for cpu in $(seq 0 "${total_cpus}" ) 48 do 49 cpus[$cpu]=cpu${cpu} 50 phyid[$cpu]=$(cat \ 51 /sys/devices/system/cpu/cpu${cpu}/topology/physical_package_id) 52 done 53 j=0 54 while [ "${j}" -lt "${total_cpus}" ] 55 do 56 (( k = $j + 1 )) 57 if [ ${phyid[$j]} -eq ${phyid[$k]} ] ; then 58 echo "${cpus[$j]} -P ${cpus[$k]}" | sed -e "s/cpu//g" 59 fi 60 (( j+=1 )) 61 done 62} 63 64check_cpufreq() { 65 total_cpus=`tst_ncpus` 66 (( total_cpus-=1 )) 67 68 for cpu in $(seq 0 "${total_cpus}" ) 69 do 70 if [ ! -d /sys/devices/system/cpu/cpu${cpu}/cpufreq ] ; then 71 tst_brkm TCONF "NOSUPPORT: cpufreq support not " \ 72 "found please check Kernel configuration " \ 73 "or BIOS settings" 74 fi 75 done 76} 77 78get_supporting_freq() { 79 cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies \ 80 | uniq 81} 82 83get_supporting_govr() { 84 cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors \ 85 | uniq 86} 87 88is_hyper_threaded() { 89 siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'` 90 cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq | cut -f2 -d':'` 91 [ $siblings -gt $cpu_cores ]; echo $? 92} 93 94check_input() { 95 validity_check=${2:-valid} 96 testfile=$3 97 if [ "${validity_check}" = "invalid" ] ; then 98 PASS="Testcase FAIL - Able to execute" 99 FAIL="Testcase PASS - Unable to execute" 100 else 101 PASS="Testcase PASS" 102 FAIL="Testcase FAIL" 103 fi 104 RC=0 105 for input in ${1} 106 do 107 echo ${input} > ${test_file} 2>/dev/null 108 return_value=$? 109 output=$(cat ${test_file}) 110 if [ "${return_value}" = "0" -a "${input}" = "${output}" ] ; then 111 echo "${0}: ${PASS}: echo ${input} > ${test_file}" 112 if [ "${validity_check}" = "invalid" ] ; then 113 RC=1 114 fi 115 else 116 echo "${0}: ${FAIL}: echo ${input} > ${test_file}" 117 if [ "${validity_check}" = "valid" ] ; then 118 RC=1 119 fi 120 fi 121 done 122 return $RC 123} 124 125is_multi_socket() { 126 no_of_sockets=`cat \ 127 /sys/devices/system/cpu/cpu?/topology/physical_package_id \ 128 | uniq | wc -l` 129 [ $no_of_sockets -gt 1 ] ; echo $? 130} 131 132is_multi_core() { 133 siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'` 134 cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq | cut -f2 -d':'` 135 if [ $siblings -eq $cpu_cores ]; then 136 [ $cpu_cores -gt 1 ]; echo $? 137 else 138 : $(( num_of_cpus = siblings / cpu_cores )) 139 [ $num_of_cpus -gt 1 ]; echo $? 140 fi 141} 142 143is_dual_core() { 144 siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'` 145 cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq \ 146 | cut -f2 -d':'` 147 if [ $siblings -eq $cpu_cores ]; then 148 [ $cpu_cores -eq 2 ]; echo $? 149 else 150 : $(( num_of_cpus = siblings / cpu_cores )) 151 [ $num_of_cpus -eq 2 ]; echo $? 152 fi 153} 154 155get_kernel_version() { 156 # Get kernel minor version 157 export kernel_version=`uname -r | awk -F. '{print $1"."$2"."$3}' \ 158 | cut -f1 -d'-'` 159} 160 161get_valid_input() { 162 kernel_version=$1 163 case "$kernel_version" in 164 '2.6.26' | '2.6.27' | '2.6.28') 165 export valid_input="0 1" ;; 166 *) export valid_input="0 1 2" ;; 167 esac 168} 169 170analyze_result_hyperthreaded() { 171 sched_mc=$1 172 pass_count=$2 173 sched_smt=$3 174 PASS="Test PASS" 175 FAIL="Test FAIL" 176 177 RC=0 178 case "$sched_mc" in 179 0) 180 case "$sched_smt" in 181 0) 182 if [ $pass_count -lt 5 ]; then 183 echo "${PASS}: cpu consolidation failed for" \ 184 "sched_mc=$sched_mc & sched_smt=$sched_smt" 185 else 186 RC=1 187 echo "${FAIL}: cpu consolidation passed for" \ 188 "sched_mc=$sched_mc & sched_smt=$sched_smt" 189 fi 190 ;; 191 *) 192 if [ $pass_count -lt 5 ]; then 193 RC=1 194 echo "${FAIL}: cpu consolidation for" \ 195 "sched_mc=$sched_mc & sched_smt=$sched_smt" 196 else 197 echo "${PASS}: cpu consolidation for" \ 198 "sched_mc=$sched_mc & sched_smt=$sched_smt" 199 fi 200 ;; 201 esac ;; 202 *) 203 if [ $pass_count -lt 5 ]; then 204 RC=1 205 echo "${FAIL}: cpu consolidation for" \ 206 "sched_mc=$sched_mc & sched_smt=$sched_smt" 207 else 208 echo "${PASS}: cpu consolidation for" \ 209 "sched_mc=$sched_mc & sched_smt=$sched_smt" 210 fi 211 ;; 212 esac 213 return $RC 214} 215 216analyze_package_consolidation_result() { 217 sched_mc=$1 218 pass_count=$2 219 220 if [ $# -gt 2 ] 221 then 222 sched_smt=$3 223 else 224 sched_smt=-1 225 fi 226 227 PASS="Test PASS" 228 FAIL="Test FAIL" 229 230 RC=0 231 if [ $hyper_threaded -eq $YES -a $sched_smt -gt -1 ]; then 232 analyze_result_hyperthreaded $sched_mc $pass_count $sched_smt 233 else 234 case "$sched_mc" in 235 0) 236 if [ $pass_count -lt 5 ]; then 237 echo "${PASS}: cpu consolidation failed for" \ 238 "sched_mc=$sched_mc" 239 else 240 RC=1 241 echo "${FAIL}: cpu consolidation passed for" \ 242 "sched_mc=$sched_mc" 243 fi 244 ;; 245 *) 246 if [ $pass_count -lt 5 ]; then 247 RC=1 248 echo "${FAIL}: consolidation at package level" \ 249 "failed for sched_mc=$sched_mc" 250 else 251 echo "${PASS}: consolidation at package level" \ 252 "passed for sched_mc=$sched_mc" 253 fi 254 ;; 255 esac 256 fi 257 return $RC 258} 259 260analyze_core_consolidation_result() { 261 sched_smt=$1 262 pass_count=$2 263 PASS="Test PASS" 264 FAIL="Test FAIL" 265 266 RC=0 267 case "$sched_smt" in 268 0) 269 if [ $pass_count -lt 5 ]; then 270 echo "${PASS}: consolidation at core level failed" \ 271 "when sched_smt=$sched_smt" 272 else 273 RC=1 274 echo "${FAIL}: consolidation at core level passed for" \ 275 "sched_smt=$sched_smt" 276 fi ;; 277 *) 278 if [ $pass_count -lt 5 ]; then 279 RC=1 280 echo "${FAIL}: consolidation at core level failed for" \ 281 "sched_smt=$sched_smt" 282 else 283 echo "${PASS}: consolidation at core level passed for" \ 284 "sched_smt=$sched_smt" 285 fi ;; 286 esac 287 return $RC 288} 289 290analyze_sched_domain_result(){ 291 sched_mc=$1 292 result=$2 293 sched_smt=$3 294 PASS="Test PASS" 295 FAIL="Test FAIL" 296 297 RC=0 298 if [ $hyper_threaded -eq $YES ]; then 299 if [ $sched_smt ]; then 300 if [ "$result" = 0 ];then 301 echo "${PASS}: sched domain test for" \ 302 "sched_mc=$sched_mc & sched_smt=$sched_smt" 303 else 304 RC=1 305 echo "${FAIL}: sched domain test for" \ 306 "sched_mc=$sched_mc & sched_smt=$sched_smt" 307 fi 308 else 309 if [ "$result" = 0 ];then 310 echo "${PASS}: sched domain test for" \ 311 "sched_mc=$sched_mc" 312 else 313 RC=1 314 echo "${FAIL}: sched domain test for" \ 315 "sched_mc=$sched_mc" 316 fi 317 fi 318 else 319 if [ "$result" = 0 ];then 320 echo "${PASS}: sched domain test for sched_mc=$sched_mc" 321 else 322 RC=1 323 echo "${FAIL}: sched domain test for sched_mc=$sched_mc" 324 fi 325 fi 326 return $RC 327} 328