Path: blob/master/tools/testing/selftests/cpufreq/main.sh
26302 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023source cpu.sh4source cpufreq.sh5source governor.sh6source module.sh7source special-tests.sh89DIR="$(dirname $(readlink -f "$0"))"10source "${DIR}"/../kselftest/ktap_helpers.sh1112FUNC=basic # do basic tests by default13OUTFILE=cpufreq_selftest14SYSFS=15CPUROOT=16CPUFREQROOT=1718helpme()19{20printf "Usage: $0 [-h] [-todg args]21[-h <help>]22[-o <output-file-for-dump>]23[-t <basic: Basic cpufreq testing24suspend: suspend/resume,25hibernate: hibernate/resume,26suspend_rtc: suspend/resume back using the RTC wakeup alarm,27hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,28modtest: test driver or governor modules. Only to be used with -d or -g options,29sptest1: Simple governor switch to produce lockdep.30sptest2: Concurrent governor switch to produce lockdep.31sptest3: Governor races, shuffle between governors quickly.32sptest4: CPU hotplugs with updates to cpufreq files.>]33[-d <driver's module name: only with \"-t modtest>\"]34[-g <governor's module name: only with \"-t modtest>\"]35\n"36exit "${KSFT_FAIL}"37}3839prerequisite()40{41msg="skip all tests:"4243if [ $UID != 0 ]; then44ktap_skip_all "$msg must be run as root"45exit "${KSFT_SKIP}"46fi4748taskset -p 01 $$4950SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`5152if [ ! -d "$SYSFS" ]; then53ktap_skip_all "$msg sysfs is not mounted"54exit "${KSFT_SKIP}"55fi5657CPUROOT=$SYSFS/devices/system/cpu58CPUFREQROOT="$CPUROOT/cpufreq"5960if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then61ktap_skip_all "$msg cpus not available in sysfs"62exit "${KSFT_SKIP}"63fi6465if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then66ktap_skip_all "$msg cpufreq directory not available in sysfs"67exit "${KSFT_SKIP}"68fi69}7071parse_arguments()72{73while getopts ht:o:d:g: arg74do75case $arg in76h) # --help77helpme78;;7980t) # --func_type (Function to perform: basic, suspend, hibernate,81# suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))82FUNC=$OPTARG83;;8485o) # --output-file (Output file to store dumps)86OUTFILE=$OPTARG87;;8889d) # --driver-mod-name (Name of the driver module)90DRIVER_MOD=$OPTARG91;;9293g) # --governor-mod-name (Name of the governor module)94GOVERNOR_MOD=$OPTARG95;;9697\?)98helpme99;;100esac101done102}103104do_test()105{106# Check if CPUs are managed by cpufreq or not107count=$(count_cpufreq_managed_cpus)108109if [ $count = 0 -a $FUNC != "modtest" ]; then110ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"111fi112113case "$FUNC" in114"basic")115cpufreq_basic_tests116;;117118"suspend")119do_suspend "suspend" 1120;;121122"hibernate")123do_suspend "hibernate" 1124;;125126"suspend_rtc")127do_suspend "suspend" 1 rtc128;;129130"hibernate_rtc")131do_suspend "hibernate" 1 rtc132;;133134"modtest")135# Do we have modules in place?136if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then137ktap_exit_fail_msg "No driver or governor module passed with -d or -g"138fi139140if [ $DRIVER_MOD ]; then141if [ $GOVERNOR_MOD ]; then142module_test $DRIVER_MOD $GOVERNOR_MOD143else144module_driver_test $DRIVER_MOD145fi146else147if [ $count = 0 ]; then148ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"149fi150151module_governor_test $GOVERNOR_MOD152fi153;;154155"sptest1")156simple_lockdep157;;158159"sptest2")160concurrent_lockdep161;;162163"sptest3")164governor_race165;;166167"sptest4")168hotplug_with_updates169;;170171*)172ktap_print_msg "Invalid [-f] function type"173helpme174;;175esac176}177178# clear dumps179# $1: file name180clear_dumps()181{182echo "" > $1.txt183echo "" > $1.dmesg_cpufreq.txt184echo "" > $1.dmesg_full.txt185}186187# $1: output file name188dmesg_dumps()189{190dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt191192# We may need the full logs as well193dmesg >> $1.dmesg_full.txt194}195196ktap_print_header197198# Parse arguments199parse_arguments $@200201ktap_set_plan 1202203# Make sure all requirements are met204prerequisite205206# Run requested functions207clear_dumps $OUTFILE208do_test | tee -a $OUTFILE.txt209if [ "${PIPESTATUS[0]}" -ne 0 ]; then210exit ${PIPESTATUS[0]};211fi212dmesg_dumps $OUTFILE213214ktap_test_pass "Completed successfully"215216ktap_print_totals217exit "${KSFT_PASS}"218219220