16751faf3SViresh Kumar#!/bin/bash 2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 36751faf3SViresh Kumar# 46751faf3SViresh Kumar# Modules specific tests cases 56751faf3SViresh Kumar 66751faf3SViresh Kumar# protect against multiple inclusion 76751faf3SViresh Kumarif [ $FILE_MODULE ]; then 86751faf3SViresh Kumar return 0 96751faf3SViresh Kumarelse 106751faf3SViresh Kumar FILE_MODULE=DONE 116751faf3SViresh Kumarfi 126751faf3SViresh Kumar 136751faf3SViresh Kumarsource cpu.sh 146751faf3SViresh Kumarsource cpufreq.sh 156751faf3SViresh Kumarsource governor.sh 166751faf3SViresh Kumar 176751faf3SViresh Kumar# Check basic insmod/rmmod 186751faf3SViresh Kumar# $1: module 196751faf3SViresh Kumartest_basic_insmod_rmmod() 206751faf3SViresh Kumar{ 216751faf3SViresh Kumar printf "** Test: Running ${FUNCNAME[0]} **\n\n" 226751faf3SViresh Kumar 236751faf3SViresh Kumar printf "Inserting $1 module\n" 246751faf3SViresh Kumar # insert module 256751faf3SViresh Kumar insmod $1 266751faf3SViresh Kumar if [ $? != 0 ]; then 27*c7e84706SMuhammad Usama Anjum ktap_exit_fail_msg "Insmod $1 failed\n" 286751faf3SViresh Kumar fi 296751faf3SViresh Kumar 306751faf3SViresh Kumar printf "Removing $1 module\n" 316751faf3SViresh Kumar # remove module 326751faf3SViresh Kumar rmmod $1 336751faf3SViresh Kumar if [ $? != 0 ]; then 34*c7e84706SMuhammad Usama Anjum ktap_exit_fail_msg "rmmod $1 failed\n" 356751faf3SViresh Kumar fi 366751faf3SViresh Kumar 376751faf3SViresh Kumar printf "\n" 386751faf3SViresh Kumar} 396751faf3SViresh Kumar 406751faf3SViresh Kumar# Insert cpufreq driver module and perform basic tests 416751faf3SViresh Kumar# $1: cpufreq-driver module to insert 426751faf3SViresh Kumar# $2: If we want to play with CPUs (1) or not (0) 436751faf3SViresh Kumarmodule_driver_test_single() 446751faf3SViresh Kumar{ 456751faf3SViresh Kumar printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n" 466751faf3SViresh Kumar 476751faf3SViresh Kumar if [ $2 -eq 1 ]; then 486751faf3SViresh Kumar # offline all non-boot CPUs 496751faf3SViresh Kumar for_each_non_boot_cpu offline_cpu 506751faf3SViresh Kumar printf "\n" 516751faf3SViresh Kumar fi 526751faf3SViresh Kumar 536751faf3SViresh Kumar # insert module 546751faf3SViresh Kumar printf "Inserting $1 module\n\n" 556751faf3SViresh Kumar insmod $1 566751faf3SViresh Kumar if [ $? != 0 ]; then 576751faf3SViresh Kumar printf "Insmod $1 failed\n" 586751faf3SViresh Kumar return; 596751faf3SViresh Kumar fi 606751faf3SViresh Kumar 616751faf3SViresh Kumar if [ $2 -eq 1 ]; then 626751faf3SViresh Kumar # online all non-boot CPUs 636751faf3SViresh Kumar for_each_non_boot_cpu online_cpu 646751faf3SViresh Kumar printf "\n" 656751faf3SViresh Kumar fi 666751faf3SViresh Kumar 676751faf3SViresh Kumar # run basic tests 686751faf3SViresh Kumar cpufreq_basic_tests 696751faf3SViresh Kumar 706751faf3SViresh Kumar # remove module 716751faf3SViresh Kumar printf "Removing $1 module\n\n" 726751faf3SViresh Kumar rmmod $1 736751faf3SViresh Kumar if [ $? != 0 ]; then 746751faf3SViresh Kumar printf "rmmod $1 failed\n" 756751faf3SViresh Kumar return; 766751faf3SViresh Kumar fi 776751faf3SViresh Kumar 786751faf3SViresh Kumar # There shouldn't be any cpufreq directories now. 796751faf3SViresh Kumar for_each_cpu cpu_should_not_have_cpufreq_directory 806751faf3SViresh Kumar printf "\n" 816751faf3SViresh Kumar} 826751faf3SViresh Kumar 836751faf3SViresh Kumar# $1: cpufreq-driver module to insert 846751faf3SViresh Kumarmodule_driver_test() 856751faf3SViresh Kumar{ 866751faf3SViresh Kumar printf "** Test: Running ${FUNCNAME[0]} **\n\n" 876751faf3SViresh Kumar 886751faf3SViresh Kumar # check if module is present or not 896751faf3SViresh Kumar ls $1 > /dev/null 906751faf3SViresh Kumar if [ $? != 0 ]; then 916751faf3SViresh Kumar printf "$1: not present in `pwd` folder\n" 926751faf3SViresh Kumar return; 936751faf3SViresh Kumar fi 946751faf3SViresh Kumar 956751faf3SViresh Kumar # test basic module tests 966751faf3SViresh Kumar test_basic_insmod_rmmod $1 976751faf3SViresh Kumar 986751faf3SViresh Kumar # Do simple module test 996751faf3SViresh Kumar module_driver_test_single $1 0 1006751faf3SViresh Kumar 1016751faf3SViresh Kumar # Remove CPUs before inserting module and then bring them back 1026751faf3SViresh Kumar module_driver_test_single $1 1 1036751faf3SViresh Kumar printf "\n" 1046751faf3SViresh Kumar} 1056751faf3SViresh Kumar 1066751faf3SViresh Kumar# find governor name based on governor module name 1076751faf3SViresh Kumar# $1: governor module name 1086751faf3SViresh Kumarfind_gov_name() 1096751faf3SViresh Kumar{ 1106751faf3SViresh Kumar if [ $1 = "cpufreq_ondemand.ko" ]; then 1116751faf3SViresh Kumar printf "ondemand" 1126751faf3SViresh Kumar elif [ $1 = "cpufreq_conservative.ko" ]; then 1136751faf3SViresh Kumar printf "conservative" 1146751faf3SViresh Kumar elif [ $1 = "cpufreq_userspace.ko" ]; then 1156751faf3SViresh Kumar printf "userspace" 1166751faf3SViresh Kumar elif [ $1 = "cpufreq_performance.ko" ]; then 1176751faf3SViresh Kumar printf "performance" 1186751faf3SViresh Kumar elif [ $1 = "cpufreq_powersave.ko" ]; then 1196751faf3SViresh Kumar printf "powersave" 1206751faf3SViresh Kumar elif [ $1 = "cpufreq_schedutil.ko" ]; then 1216751faf3SViresh Kumar printf "schedutil" 1226751faf3SViresh Kumar fi 1236751faf3SViresh Kumar} 1246751faf3SViresh Kumar 1256751faf3SViresh Kumar# $1: governor string, $2: governor module, $3: policy 1266751faf3SViresh Kumar# example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2 1276751faf3SViresh Kumarmodule_governor_test_single() 1286751faf3SViresh Kumar{ 1296751faf3SViresh Kumar printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n" 1306751faf3SViresh Kumar 1316751faf3SViresh Kumar backup_governor $3 1326751faf3SViresh Kumar 1336751faf3SViresh Kumar # switch to new governor 1346751faf3SViresh Kumar printf "Switch from $CUR_GOV to $1\n" 1356751faf3SViresh Kumar switch_show_governor $3 $1 1366751faf3SViresh Kumar 1376751faf3SViresh Kumar # try removing module, it should fail as governor is used 1386751faf3SViresh Kumar printf "Removing $2 module\n\n" 1396751faf3SViresh Kumar rmmod $2 1406751faf3SViresh Kumar if [ $? = 0 ]; then 1416751faf3SViresh Kumar printf "WARN: rmmod $2 succeeded even if governor is used\n" 1426751faf3SViresh Kumar insmod $2 1436751faf3SViresh Kumar else 1446751faf3SViresh Kumar printf "Pass: unable to remove $2 while it is being used\n\n" 1456751faf3SViresh Kumar fi 1466751faf3SViresh Kumar 1476751faf3SViresh Kumar # switch back to old governor 1486751faf3SViresh Kumar printf "Switchback to $CUR_GOV from $1\n" 1496751faf3SViresh Kumar restore_governor $3 1506751faf3SViresh Kumar printf "\n" 1516751faf3SViresh Kumar} 1526751faf3SViresh Kumar 1536751faf3SViresh Kumar# Insert cpufreq governor module and perform basic tests 1546751faf3SViresh Kumar# $1: cpufreq-governor module to insert 1556751faf3SViresh Kumarmodule_governor_test() 1566751faf3SViresh Kumar{ 1576751faf3SViresh Kumar printf "** Test: Running ${FUNCNAME[0]} **\n\n" 1586751faf3SViresh Kumar 1596751faf3SViresh Kumar # check if module is present or not 1606751faf3SViresh Kumar ls $1 > /dev/null 1616751faf3SViresh Kumar if [ $? != 0 ]; then 1626751faf3SViresh Kumar printf "$1: not present in `pwd` folder\n" 1636751faf3SViresh Kumar return; 1646751faf3SViresh Kumar fi 1656751faf3SViresh Kumar 1666751faf3SViresh Kumar # test basic module tests 1676751faf3SViresh Kumar test_basic_insmod_rmmod $1 1686751faf3SViresh Kumar 1696751faf3SViresh Kumar # insert module 1706751faf3SViresh Kumar printf "Inserting $1 module\n\n" 1716751faf3SViresh Kumar insmod $1 1726751faf3SViresh Kumar if [ $? != 0 ]; then 1736751faf3SViresh Kumar printf "Insmod $1 failed\n" 1746751faf3SViresh Kumar return; 1756751faf3SViresh Kumar fi 1766751faf3SViresh Kumar 1776751faf3SViresh Kumar # switch to new governor for each cpu 1786751faf3SViresh Kumar for_each_policy module_governor_test_single $(find_gov_name $1) $1 1796751faf3SViresh Kumar 1806751faf3SViresh Kumar # remove module 1816751faf3SViresh Kumar printf "Removing $1 module\n\n" 1826751faf3SViresh Kumar rmmod $1 1836751faf3SViresh Kumar if [ $? != 0 ]; then 1846751faf3SViresh Kumar printf "rmmod $1 failed\n" 1856751faf3SViresh Kumar return; 1866751faf3SViresh Kumar fi 1876751faf3SViresh Kumar printf "\n" 1886751faf3SViresh Kumar} 1896751faf3SViresh Kumar 1906751faf3SViresh Kumar# test modules: driver and governor 1916751faf3SViresh Kumar# $1: driver module, $2: governor module 1926751faf3SViresh Kumarmodule_test() 1936751faf3SViresh Kumar{ 1946751faf3SViresh Kumar printf "** Test: Running ${FUNCNAME[0]} **\n\n" 1956751faf3SViresh Kumar 1966751faf3SViresh Kumar # check if modules are present or not 1976751faf3SViresh Kumar ls $1 $2 > /dev/null 1986751faf3SViresh Kumar if [ $? != 0 ]; then 1996751faf3SViresh Kumar printf "$1 or $2: is not present in `pwd` folder\n" 2006751faf3SViresh Kumar return; 2016751faf3SViresh Kumar fi 2026751faf3SViresh Kumar 2036751faf3SViresh Kumar # TEST1: Insert gov after driver 2046751faf3SViresh Kumar # insert driver module 2056751faf3SViresh Kumar printf "Inserting $1 module\n\n" 2066751faf3SViresh Kumar insmod $1 2076751faf3SViresh Kumar if [ $? != 0 ]; then 2086751faf3SViresh Kumar printf "Insmod $1 failed\n" 2096751faf3SViresh Kumar return; 2106751faf3SViresh Kumar fi 2116751faf3SViresh Kumar 2126751faf3SViresh Kumar # run governor tests 2136751faf3SViresh Kumar module_governor_test $2 2146751faf3SViresh Kumar 2156751faf3SViresh Kumar # remove driver module 2166751faf3SViresh Kumar printf "Removing $1 module\n\n" 2176751faf3SViresh Kumar rmmod $1 2186751faf3SViresh Kumar if [ $? != 0 ]; then 2196751faf3SViresh Kumar printf "rmmod $1 failed\n" 2206751faf3SViresh Kumar return; 2216751faf3SViresh Kumar fi 2226751faf3SViresh Kumar 2236751faf3SViresh Kumar # TEST2: Insert driver after governor 2246751faf3SViresh Kumar # insert governor module 2256751faf3SViresh Kumar printf "Inserting $2 module\n\n" 2266751faf3SViresh Kumar insmod $2 2276751faf3SViresh Kumar if [ $? != 0 ]; then 2286751faf3SViresh Kumar printf "Insmod $2 failed\n" 2296751faf3SViresh Kumar return; 2306751faf3SViresh Kumar fi 2316751faf3SViresh Kumar 2326751faf3SViresh Kumar # run governor tests 2336751faf3SViresh Kumar module_driver_test $1 2346751faf3SViresh Kumar 2356751faf3SViresh Kumar # remove driver module 2366751faf3SViresh Kumar printf "Removing $2 module\n\n" 2376751faf3SViresh Kumar rmmod $2 2386751faf3SViresh Kumar if [ $? != 0 ]; then 2396751faf3SViresh Kumar printf "rmmod $2 failed\n" 2406751faf3SViresh Kumar return; 2416751faf3SViresh Kumar fi 2426751faf3SViresh Kumar} 243