1e66d5b67SViresh Kumar#!/bin/bash 2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 3e66d5b67SViresh Kumar 4e66d5b67SViresh Kumarsource cpu.sh 5e66d5b67SViresh Kumarsource cpufreq.sh 6e66d5b67SViresh Kumarsource governor.sh 76751faf3SViresh Kumarsource module.sh 81e4c2830SViresh Kumarsource special-tests.sh 9e66d5b67SViresh Kumar 10*c7e84706SMuhammad Usama AnjumDIR="$(dirname $(readlink -f "$0"))" 11*c7e84706SMuhammad Usama Anjumsource "${DIR}"/../kselftest/ktap_helpers.sh 12*c7e84706SMuhammad Usama Anjum 13e66d5b67SViresh KumarFUNC=basic # do basic tests by default 14e66d5b67SViresh KumarOUTFILE=cpufreq_selftest 15e66d5b67SViresh KumarSYSFS= 16e66d5b67SViresh KumarCPUROOT= 17e66d5b67SViresh KumarCPUFREQROOT= 18e66d5b67SViresh Kumar 19e66d5b67SViresh Kumarhelpme() 20e66d5b67SViresh Kumar{ 216751faf3SViresh Kumar printf "Usage: $0 [-h] [-todg args] 22e66d5b67SViresh Kumar [-h <help>] 23e66d5b67SViresh Kumar [-o <output-file-for-dump>] 24b03eaf8dSViresh Kumar [-t <basic: Basic cpufreq testing 25b03eaf8dSViresh Kumar suspend: suspend/resume, 266751faf3SViresh Kumar hibernate: hibernate/resume, 271e4c2830SViresh Kumar modtest: test driver or governor modules. Only to be used with -d or -g options, 281e4c2830SViresh Kumar sptest1: Simple governor switch to produce lockdep. 291e4c2830SViresh Kumar sptest2: Concurrent governor switch to produce lockdep. 301e4c2830SViresh Kumar sptest3: Governor races, shuffle between governors quickly. 311e4c2830SViresh Kumar sptest4: CPU hotplugs with updates to cpufreq files.>] 326751faf3SViresh Kumar [-d <driver's module name: only with \"-t modtest>\"] 336751faf3SViresh Kumar [-g <governor's module name: only with \"-t modtest>\"] 34e66d5b67SViresh Kumar \n" 35*c7e84706SMuhammad Usama Anjum exit "${KSFT_FAIL}" 36e66d5b67SViresh Kumar} 37e66d5b67SViresh Kumar 38e66d5b67SViresh Kumarprerequisite() 39e66d5b67SViresh Kumar{ 40e66d5b67SViresh Kumar msg="skip all tests:" 41e66d5b67SViresh Kumar 42e66d5b67SViresh Kumar if [ $UID != 0 ]; then 43*c7e84706SMuhammad Usama Anjum ktap_skip_all "$msg must be run as root" 44*c7e84706SMuhammad Usama Anjum exit "${KSFT_SKIP}" 45e66d5b67SViresh Kumar fi 46e66d5b67SViresh Kumar 47e66d5b67SViresh Kumar taskset -p 01 $$ 48e66d5b67SViresh Kumar 49e66d5b67SViresh Kumar SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'` 50e66d5b67SViresh Kumar 51e66d5b67SViresh Kumar if [ ! -d "$SYSFS" ]; then 52*c7e84706SMuhammad Usama Anjum ktap_skip_all "$msg sysfs is not mounted" 53*c7e84706SMuhammad Usama Anjum exit "${KSFT_SKIP}" 54e66d5b67SViresh Kumar fi 55e66d5b67SViresh Kumar 56e66d5b67SViresh Kumar CPUROOT=$SYSFS/devices/system/cpu 57e66d5b67SViresh Kumar CPUFREQROOT="$CPUROOT/cpufreq" 58e66d5b67SViresh Kumar 59e66d5b67SViresh Kumar if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then 60*c7e84706SMuhammad Usama Anjum ktap_skip_all "$msg cpus not available in sysfs" 61*c7e84706SMuhammad Usama Anjum exit "${KSFT_SKIP}" 62e66d5b67SViresh Kumar fi 63e66d5b67SViresh Kumar 64e66d5b67SViresh Kumar if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then 65*c7e84706SMuhammad Usama Anjum ktap_skip_all "$msg cpufreq directory not available in sysfs" 66*c7e84706SMuhammad Usama Anjum exit "${KSFT_SKIP}" 67e66d5b67SViresh Kumar fi 68e66d5b67SViresh Kumar} 69e66d5b67SViresh Kumar 70e66d5b67SViresh Kumarparse_arguments() 71e66d5b67SViresh Kumar{ 726751faf3SViresh Kumar while getopts ht:o:d:g: arg 73e66d5b67SViresh Kumar do 74e66d5b67SViresh Kumar case $arg in 75e66d5b67SViresh Kumar h) # --help 76e66d5b67SViresh Kumar helpme 77e66d5b67SViresh Kumar ;; 78e66d5b67SViresh Kumar 791e4c2830SViresh Kumar t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic)) 80e66d5b67SViresh Kumar FUNC=$OPTARG 81e66d5b67SViresh Kumar ;; 82e66d5b67SViresh Kumar 83e66d5b67SViresh Kumar o) # --output-file (Output file to store dumps) 84e66d5b67SViresh Kumar OUTFILE=$OPTARG 85e66d5b67SViresh Kumar ;; 86e66d5b67SViresh Kumar 876751faf3SViresh Kumar d) # --driver-mod-name (Name of the driver module) 886751faf3SViresh Kumar DRIVER_MOD=$OPTARG 896751faf3SViresh Kumar ;; 906751faf3SViresh Kumar 916751faf3SViresh Kumar g) # --governor-mod-name (Name of the governor module) 926751faf3SViresh Kumar GOVERNOR_MOD=$OPTARG 936751faf3SViresh Kumar ;; 946751faf3SViresh Kumar 95e66d5b67SViresh Kumar \?) 96e66d5b67SViresh Kumar helpme 97e66d5b67SViresh Kumar ;; 98e66d5b67SViresh Kumar esac 99e66d5b67SViresh Kumar done 100e66d5b67SViresh Kumar} 101e66d5b67SViresh Kumar 102e66d5b67SViresh Kumardo_test() 103e66d5b67SViresh Kumar{ 104e66d5b67SViresh Kumar # Check if CPUs are managed by cpufreq or not 105e66d5b67SViresh Kumar count=$(count_cpufreq_managed_cpus) 106e66d5b67SViresh Kumar 1076751faf3SViresh Kumar if [ $count = 0 -a $FUNC != "modtest" ]; then 108*c7e84706SMuhammad Usama Anjum ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting" 109e66d5b67SViresh Kumar fi 110e66d5b67SViresh Kumar 111e66d5b67SViresh Kumar case "$FUNC" in 112e66d5b67SViresh Kumar "basic") 113e66d5b67SViresh Kumar cpufreq_basic_tests 114e66d5b67SViresh Kumar ;; 115e66d5b67SViresh Kumar 116b03eaf8dSViresh Kumar "suspend") 117b03eaf8dSViresh Kumar do_suspend "suspend" 1 118b03eaf8dSViresh Kumar ;; 119b03eaf8dSViresh Kumar 120b03eaf8dSViresh Kumar "hibernate") 121b03eaf8dSViresh Kumar do_suspend "hibernate" 1 122b03eaf8dSViresh Kumar ;; 123b03eaf8dSViresh Kumar 1246751faf3SViresh Kumar "modtest") 1256751faf3SViresh Kumar # Do we have modules in place? 1266751faf3SViresh Kumar if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then 127*c7e84706SMuhammad Usama Anjum ktap_exit_fail_msg "No driver or governor module passed with -d or -g" 1286751faf3SViresh Kumar fi 1296751faf3SViresh Kumar 1306751faf3SViresh Kumar if [ $DRIVER_MOD ]; then 1316751faf3SViresh Kumar if [ $GOVERNOR_MOD ]; then 1326751faf3SViresh Kumar module_test $DRIVER_MOD $GOVERNOR_MOD 1336751faf3SViresh Kumar else 1346751faf3SViresh Kumar module_driver_test $DRIVER_MOD 1356751faf3SViresh Kumar fi 1366751faf3SViresh Kumar else 1376751faf3SViresh Kumar if [ $count = 0 ]; then 138*c7e84706SMuhammad Usama Anjum ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting" 1396751faf3SViresh Kumar fi 1406751faf3SViresh Kumar 1416751faf3SViresh Kumar module_governor_test $GOVERNOR_MOD 1426751faf3SViresh Kumar fi 1436751faf3SViresh Kumar ;; 1446751faf3SViresh Kumar 1451e4c2830SViresh Kumar "sptest1") 1461e4c2830SViresh Kumar simple_lockdep 1471e4c2830SViresh Kumar ;; 1481e4c2830SViresh Kumar 1491e4c2830SViresh Kumar "sptest2") 1501e4c2830SViresh Kumar concurrent_lockdep 1511e4c2830SViresh Kumar ;; 1521e4c2830SViresh Kumar 1531e4c2830SViresh Kumar "sptest3") 1541e4c2830SViresh Kumar governor_race 1551e4c2830SViresh Kumar ;; 1561e4c2830SViresh Kumar 1571e4c2830SViresh Kumar "sptest4") 1581e4c2830SViresh Kumar hotplug_with_updates 1591e4c2830SViresh Kumar ;; 1601e4c2830SViresh Kumar 161e66d5b67SViresh Kumar *) 162*c7e84706SMuhammad Usama Anjum ktap_print_msg "Invalid [-f] function type" 163e66d5b67SViresh Kumar helpme 164e66d5b67SViresh Kumar ;; 165e66d5b67SViresh Kumar esac 166e66d5b67SViresh Kumar} 167e66d5b67SViresh Kumar 168e66d5b67SViresh Kumar# clear dumps 169e66d5b67SViresh Kumar# $1: file name 170e66d5b67SViresh Kumarclear_dumps() 171e66d5b67SViresh Kumar{ 172e66d5b67SViresh Kumar echo "" > $1.txt 173e66d5b67SViresh Kumar echo "" > $1.dmesg_cpufreq.txt 174e66d5b67SViresh Kumar echo "" > $1.dmesg_full.txt 175e66d5b67SViresh Kumar} 176e66d5b67SViresh Kumar 177e66d5b67SViresh Kumar# $1: output file name 178e66d5b67SViresh Kumardmesg_dumps() 179e66d5b67SViresh Kumar{ 180e66d5b67SViresh Kumar dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt 181e66d5b67SViresh Kumar 182e66d5b67SViresh Kumar # We may need the full logs as well 183e66d5b67SViresh Kumar dmesg >> $1.dmesg_full.txt 184e66d5b67SViresh Kumar} 185e66d5b67SViresh Kumar 186*c7e84706SMuhammad Usama Anjumktap_print_header 187*c7e84706SMuhammad Usama Anjum 188e66d5b67SViresh Kumar# Parse arguments 189e66d5b67SViresh Kumarparse_arguments $@ 190e66d5b67SViresh Kumar 191*c7e84706SMuhammad Usama Anjumktap_set_plan 1 192*c7e84706SMuhammad Usama Anjum 193e66d5b67SViresh Kumar# Make sure all requirements are met 194e66d5b67SViresh Kumarprerequisite 195e66d5b67SViresh Kumar 196e66d5b67SViresh Kumar# Run requested functions 197e66d5b67SViresh Kumarclear_dumps $OUTFILE 19840d70d4dSNícolas F. R. A. Pradodo_test | tee -a $OUTFILE.txt 199*c7e84706SMuhammad Usama Anjumif [ "${PIPESTATUS[0]}" -ne 0 ]; then 200*c7e84706SMuhammad Usama Anjum exit ${PIPESTATUS[0]}; 201*c7e84706SMuhammad Usama Anjumfi 202e66d5b67SViresh Kumardmesg_dumps $OUTFILE 203*c7e84706SMuhammad Usama Anjum 204*c7e84706SMuhammad Usama Anjumktap_test_pass "Completed successfully" 205*c7e84706SMuhammad Usama Anjum 206*c7e84706SMuhammad Usama Anjumktap_print_totals 207*c7e84706SMuhammad Usama Anjumexit "${KSFT_PASS}" 208