Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Modules specific tests cases
0005 
0006 # protect against multiple inclusion
0007 if [ $FILE_MODULE ]; then
0008         return 0
0009 else
0010         FILE_MODULE=DONE
0011 fi
0012 
0013 source cpu.sh
0014 source cpufreq.sh
0015 source governor.sh
0016 
0017 # Check basic insmod/rmmod
0018 # $1: module
0019 test_basic_insmod_rmmod()
0020 {
0021         printf "** Test: Running ${FUNCNAME[0]} **\n\n"
0022 
0023         printf "Inserting $1 module\n"
0024         # insert module
0025         insmod $1
0026         if [ $? != 0 ]; then
0027                 printf "Insmod $1 failed\n"
0028                 exit;
0029         fi
0030 
0031         printf "Removing $1 module\n"
0032         # remove module
0033         rmmod $1
0034         if [ $? != 0 ]; then
0035                 printf "rmmod $1 failed\n"
0036                 exit;
0037         fi
0038 
0039         printf "\n"
0040 }
0041 
0042 # Insert cpufreq driver module and perform basic tests
0043 # $1: cpufreq-driver module to insert
0044 # $2: If we want to play with CPUs (1) or not (0)
0045 module_driver_test_single()
0046 {
0047         printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n"
0048 
0049         if [ $2 -eq 1 ]; then
0050                 # offline all non-boot CPUs
0051                 for_each_non_boot_cpu offline_cpu
0052                 printf "\n"
0053         fi
0054 
0055         # insert module
0056         printf "Inserting $1 module\n\n"
0057         insmod $1
0058         if [ $? != 0 ]; then
0059                 printf "Insmod $1 failed\n"
0060                 return;
0061         fi
0062 
0063         if [ $2 -eq 1 ]; then
0064                 # online all non-boot CPUs
0065                 for_each_non_boot_cpu online_cpu
0066                 printf "\n"
0067         fi
0068 
0069         # run basic tests
0070         cpufreq_basic_tests
0071 
0072         # remove module
0073         printf "Removing $1 module\n\n"
0074         rmmod $1
0075         if [ $? != 0 ]; then
0076                 printf "rmmod $1 failed\n"
0077                 return;
0078         fi
0079 
0080         # There shouldn't be any cpufreq directories now.
0081         for_each_cpu cpu_should_not_have_cpufreq_directory
0082         printf "\n"
0083 }
0084 
0085 # $1: cpufreq-driver module to insert
0086 module_driver_test()
0087 {
0088         printf "** Test: Running ${FUNCNAME[0]} **\n\n"
0089 
0090         # check if module is present or not
0091         ls $1 > /dev/null
0092         if [ $? != 0 ]; then
0093                 printf "$1: not present in `pwd` folder\n"
0094                 return;
0095         fi
0096 
0097         # test basic module tests
0098         test_basic_insmod_rmmod $1
0099 
0100         # Do simple module test
0101         module_driver_test_single $1 0
0102 
0103         # Remove CPUs before inserting module and then bring them back
0104         module_driver_test_single $1 1
0105         printf "\n"
0106 }
0107 
0108 # find governor name based on governor module name
0109 # $1: governor module name
0110 find_gov_name()
0111 {
0112         if [ $1 = "cpufreq_ondemand.ko" ]; then
0113                 printf "ondemand"
0114         elif [ $1 = "cpufreq_conservative.ko" ]; then
0115                 printf "conservative"
0116         elif [ $1 = "cpufreq_userspace.ko" ]; then
0117                 printf "userspace"
0118         elif [ $1 = "cpufreq_performance.ko" ]; then
0119                 printf "performance"
0120         elif [ $1 = "cpufreq_powersave.ko" ]; then
0121                 printf "powersave"
0122         elif [ $1 = "cpufreq_schedutil.ko" ]; then
0123                 printf "schedutil"
0124         fi
0125 }
0126 
0127 # $1: governor string, $2: governor module, $3: policy
0128 # example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2
0129 module_governor_test_single()
0130 {
0131         printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n"
0132 
0133         backup_governor $3
0134 
0135         # switch to new governor
0136         printf "Switch from $CUR_GOV to $1\n"
0137         switch_show_governor $3 $1
0138 
0139         # try removing module, it should fail as governor is used
0140         printf "Removing $2 module\n\n"
0141         rmmod $2
0142         if [ $? = 0 ]; then
0143                 printf "WARN: rmmod $2 succeeded even if governor is used\n"
0144                 insmod $2
0145         else
0146                 printf "Pass: unable to remove $2 while it is being used\n\n"
0147         fi
0148 
0149         # switch back to old governor
0150         printf "Switchback to $CUR_GOV from $1\n"
0151         restore_governor $3
0152         printf "\n"
0153 }
0154 
0155 # Insert cpufreq governor module and perform basic tests
0156 # $1: cpufreq-governor module to insert
0157 module_governor_test()
0158 {
0159         printf "** Test: Running ${FUNCNAME[0]} **\n\n"
0160 
0161         # check if module is present or not
0162         ls $1 > /dev/null
0163         if [ $? != 0 ]; then
0164                 printf "$1: not present in `pwd` folder\n"
0165                 return;
0166         fi
0167 
0168         # test basic module tests
0169         test_basic_insmod_rmmod $1
0170 
0171         # insert module
0172         printf "Inserting $1 module\n\n"
0173         insmod $1
0174         if [ $? != 0 ]; then
0175                 printf "Insmod $1 failed\n"
0176                 return;
0177         fi
0178 
0179         # switch to new governor for each cpu
0180         for_each_policy module_governor_test_single $(find_gov_name $1) $1
0181 
0182         # remove module
0183         printf "Removing $1 module\n\n"
0184         rmmod $1
0185         if [ $? != 0 ]; then
0186                 printf "rmmod $1 failed\n"
0187                 return;
0188         fi
0189         printf "\n"
0190 }
0191 
0192 # test modules: driver and governor
0193 # $1: driver module, $2: governor module
0194 module_test()
0195 {
0196         printf "** Test: Running ${FUNCNAME[0]} **\n\n"
0197 
0198         # check if modules are present or not
0199         ls $1 $2 > /dev/null
0200         if [ $? != 0 ]; then
0201                 printf "$1 or $2: is not present in `pwd` folder\n"
0202                 return;
0203         fi
0204 
0205         # TEST1: Insert gov after driver
0206         # insert driver module
0207         printf "Inserting $1 module\n\n"
0208         insmod $1
0209         if [ $? != 0 ]; then
0210                 printf "Insmod $1 failed\n"
0211                 return;
0212         fi
0213 
0214         # run governor tests
0215         module_governor_test $2
0216 
0217         # remove driver module
0218         printf "Removing $1 module\n\n"
0219         rmmod $1
0220         if [ $? != 0 ]; then
0221                 printf "rmmod $1 failed\n"
0222                 return;
0223         fi
0224 
0225         # TEST2: Insert driver after governor
0226         # insert governor module
0227         printf "Inserting $2 module\n\n"
0228         insmod $2
0229         if [ $? != 0 ]; then
0230                 printf "Insmod $2 failed\n"
0231                 return;
0232         fi
0233 
0234         # run governor tests
0235         module_driver_test $1
0236 
0237         # remove driver module
0238         printf "Removing $2 module\n\n"
0239         rmmod $2
0240         if [ $? != 0 ]; then
0241                 printf "rmmod $2 failed\n"
0242                 return;
0243         fi
0244 }