Path: blob/master/tools/testing/selftests/cpufreq/module.sh
26302 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Modules specific tests cases45# protect against multiple inclusion6if [ $FILE_MODULE ]; then7return 08else9FILE_MODULE=DONE10fi1112source cpu.sh13source cpufreq.sh14source governor.sh1516# Check basic insmod/rmmod17# $1: module18test_basic_insmod_rmmod()19{20printf "** Test: Running ${FUNCNAME[0]} **\n\n"2122printf "Inserting $1 module\n"23# insert module24insmod $125if [ $? != 0 ]; then26ktap_exit_fail_msg "Insmod $1 failed\n"27fi2829printf "Removing $1 module\n"30# remove module31rmmod $132if [ $? != 0 ]; then33ktap_exit_fail_msg "rmmod $1 failed\n"34fi3536printf "\n"37}3839# Insert cpufreq driver module and perform basic tests40# $1: cpufreq-driver module to insert41# $2: If we want to play with CPUs (1) or not (0)42module_driver_test_single()43{44printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n"4546if [ $2 -eq 1 ]; then47# offline all non-boot CPUs48for_each_non_boot_cpu offline_cpu49printf "\n"50fi5152# insert module53printf "Inserting $1 module\n\n"54insmod $155if [ $? != 0 ]; then56printf "Insmod $1 failed\n"57return;58fi5960if [ $2 -eq 1 ]; then61# online all non-boot CPUs62for_each_non_boot_cpu online_cpu63printf "\n"64fi6566# run basic tests67cpufreq_basic_tests6869# remove module70printf "Removing $1 module\n\n"71rmmod $172if [ $? != 0 ]; then73printf "rmmod $1 failed\n"74return;75fi7677# There shouldn't be any cpufreq directories now.78for_each_cpu cpu_should_not_have_cpufreq_directory79printf "\n"80}8182# $1: cpufreq-driver module to insert83module_driver_test()84{85printf "** Test: Running ${FUNCNAME[0]} **\n\n"8687# check if module is present or not88ls $1 > /dev/null89if [ $? != 0 ]; then90printf "$1: not present in `pwd` folder\n"91return;92fi9394# test basic module tests95test_basic_insmod_rmmod $19697# Do simple module test98module_driver_test_single $1 099100# Remove CPUs before inserting module and then bring them back101module_driver_test_single $1 1102printf "\n"103}104105# find governor name based on governor module name106# $1: governor module name107find_gov_name()108{109if [ $1 = "cpufreq_ondemand.ko" ]; then110printf "ondemand"111elif [ $1 = "cpufreq_conservative.ko" ]; then112printf "conservative"113elif [ $1 = "cpufreq_userspace.ko" ]; then114printf "userspace"115elif [ $1 = "cpufreq_performance.ko" ]; then116printf "performance"117elif [ $1 = "cpufreq_powersave.ko" ]; then118printf "powersave"119elif [ $1 = "cpufreq_schedutil.ko" ]; then120printf "schedutil"121fi122}123124# $1: governor string, $2: governor module, $3: policy125# example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2126module_governor_test_single()127{128printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n"129130backup_governor $3131132# switch to new governor133printf "Switch from $CUR_GOV to $1\n"134switch_show_governor $3 $1135136# try removing module, it should fail as governor is used137printf "Removing $2 module\n\n"138rmmod $2139if [ $? = 0 ]; then140printf "WARN: rmmod $2 succeeded even if governor is used\n"141insmod $2142else143printf "Pass: unable to remove $2 while it is being used\n\n"144fi145146# switch back to old governor147printf "Switchback to $CUR_GOV from $1\n"148restore_governor $3149printf "\n"150}151152# Insert cpufreq governor module and perform basic tests153# $1: cpufreq-governor module to insert154module_governor_test()155{156printf "** Test: Running ${FUNCNAME[0]} **\n\n"157158# check if module is present or not159ls $1 > /dev/null160if [ $? != 0 ]; then161printf "$1: not present in `pwd` folder\n"162return;163fi164165# test basic module tests166test_basic_insmod_rmmod $1167168# insert module169printf "Inserting $1 module\n\n"170insmod $1171if [ $? != 0 ]; then172printf "Insmod $1 failed\n"173return;174fi175176# switch to new governor for each cpu177for_each_policy module_governor_test_single $(find_gov_name $1) $1178179# remove module180printf "Removing $1 module\n\n"181rmmod $1182if [ $? != 0 ]; then183printf "rmmod $1 failed\n"184return;185fi186printf "\n"187}188189# test modules: driver and governor190# $1: driver module, $2: governor module191module_test()192{193printf "** Test: Running ${FUNCNAME[0]} **\n\n"194195# check if modules are present or not196ls $1 $2 > /dev/null197if [ $? != 0 ]; then198printf "$1 or $2: is not present in `pwd` folder\n"199return;200fi201202# TEST1: Insert gov after driver203# insert driver module204printf "Inserting $1 module\n\n"205insmod $1206if [ $? != 0 ]; then207printf "Insmod $1 failed\n"208return;209fi210211# run governor tests212module_governor_test $2213214# remove driver module215printf "Removing $1 module\n\n"216rmmod $1217if [ $? != 0 ]; then218printf "rmmod $1 failed\n"219return;220fi221222# TEST2: Insert driver after governor223# insert governor module224printf "Inserting $2 module\n\n"225insmod $2226if [ $? != 0 ]; then227printf "Insmod $2 failed\n"228return;229fi230231# run governor tests232module_driver_test $1233234# remove driver module235printf "Removing $2 module\n\n"236rmmod $2237if [ $? != 0 ]; then238printf "rmmod $2 failed\n"239return;240fi241}242243244