1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # 3 # 4 # Modules specific tests cases 4 # Modules specific tests cases 5 5 6 # protect against multiple inclusion 6 # protect against multiple inclusion 7 if [ $FILE_MODULE ]; then 7 if [ $FILE_MODULE ]; then 8 return 0 8 return 0 9 else 9 else 10 FILE_MODULE=DONE 10 FILE_MODULE=DONE 11 fi 11 fi 12 12 13 source cpu.sh 13 source cpu.sh 14 source cpufreq.sh 14 source cpufreq.sh 15 source governor.sh 15 source governor.sh 16 16 17 # Check basic insmod/rmmod 17 # Check basic insmod/rmmod 18 # $1: module 18 # $1: module 19 test_basic_insmod_rmmod() 19 test_basic_insmod_rmmod() 20 { 20 { 21 printf "** Test: Running ${FUNCNAME[0] 21 printf "** Test: Running ${FUNCNAME[0]} **\n\n" 22 22 23 printf "Inserting $1 module\n" 23 printf "Inserting $1 module\n" 24 # insert module 24 # insert module 25 insmod $1 25 insmod $1 26 if [ $? != 0 ]; then 26 if [ $? != 0 ]; then 27 ktap_exit_fail_msg "Insmod $1 27 ktap_exit_fail_msg "Insmod $1 failed\n" 28 fi 28 fi 29 29 30 printf "Removing $1 module\n" 30 printf "Removing $1 module\n" 31 # remove module 31 # remove module 32 rmmod $1 32 rmmod $1 33 if [ $? != 0 ]; then 33 if [ $? != 0 ]; then 34 ktap_exit_fail_msg "rmmod $1 f 34 ktap_exit_fail_msg "rmmod $1 failed\n" 35 fi 35 fi 36 36 37 printf "\n" 37 printf "\n" 38 } 38 } 39 39 40 # Insert cpufreq driver module and perform bas 40 # Insert cpufreq driver module and perform basic tests 41 # $1: cpufreq-driver module to insert 41 # $1: cpufreq-driver module to insert 42 # $2: If we want to play with CPUs (1) or not 42 # $2: If we want to play with CPUs (1) or not (0) 43 module_driver_test_single() 43 module_driver_test_single() 44 { 44 { 45 printf "** Test: Running ${FUNCNAME[0] 45 printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n" 46 46 47 if [ $2 -eq 1 ]; then 47 if [ $2 -eq 1 ]; then 48 # offline all non-boot CPUs 48 # offline all non-boot CPUs 49 for_each_non_boot_cpu offline_ 49 for_each_non_boot_cpu offline_cpu 50 printf "\n" 50 printf "\n" 51 fi 51 fi 52 52 53 # insert module 53 # insert module 54 printf "Inserting $1 module\n\n" 54 printf "Inserting $1 module\n\n" 55 insmod $1 55 insmod $1 56 if [ $? != 0 ]; then 56 if [ $? != 0 ]; then 57 printf "Insmod $1 failed\n" 57 printf "Insmod $1 failed\n" 58 return; 58 return; 59 fi 59 fi 60 60 61 if [ $2 -eq 1 ]; then 61 if [ $2 -eq 1 ]; then 62 # online all non-boot CPUs 62 # online all non-boot CPUs 63 for_each_non_boot_cpu online_c 63 for_each_non_boot_cpu online_cpu 64 printf "\n" 64 printf "\n" 65 fi 65 fi 66 66 67 # run basic tests 67 # run basic tests 68 cpufreq_basic_tests 68 cpufreq_basic_tests 69 69 70 # remove module 70 # remove module 71 printf "Removing $1 module\n\n" 71 printf "Removing $1 module\n\n" 72 rmmod $1 72 rmmod $1 73 if [ $? != 0 ]; then 73 if [ $? != 0 ]; then 74 printf "rmmod $1 failed\n" 74 printf "rmmod $1 failed\n" 75 return; 75 return; 76 fi 76 fi 77 77 78 # There shouldn't be any cpufreq direc 78 # There shouldn't be any cpufreq directories now. 79 for_each_cpu cpu_should_not_have_cpufr 79 for_each_cpu cpu_should_not_have_cpufreq_directory 80 printf "\n" 80 printf "\n" 81 } 81 } 82 82 83 # $1: cpufreq-driver module to insert 83 # $1: cpufreq-driver module to insert 84 module_driver_test() 84 module_driver_test() 85 { 85 { 86 printf "** Test: Running ${FUNCNAME[0] 86 printf "** Test: Running ${FUNCNAME[0]} **\n\n" 87 87 88 # check if module is present or not 88 # check if module is present or not 89 ls $1 > /dev/null 89 ls $1 > /dev/null 90 if [ $? != 0 ]; then 90 if [ $? != 0 ]; then 91 printf "$1: not present in `pw 91 printf "$1: not present in `pwd` folder\n" 92 return; 92 return; 93 fi 93 fi 94 94 95 # test basic module tests 95 # test basic module tests 96 test_basic_insmod_rmmod $1 96 test_basic_insmod_rmmod $1 97 97 98 # Do simple module test 98 # Do simple module test 99 module_driver_test_single $1 0 99 module_driver_test_single $1 0 100 100 101 # Remove CPUs before inserting module 101 # Remove CPUs before inserting module and then bring them back 102 module_driver_test_single $1 1 102 module_driver_test_single $1 1 103 printf "\n" 103 printf "\n" 104 } 104 } 105 105 106 # find governor name based on governor module 106 # find governor name based on governor module name 107 # $1: governor module name 107 # $1: governor module name 108 find_gov_name() 108 find_gov_name() 109 { 109 { 110 if [ $1 = "cpufreq_ondemand.ko" ]; the 110 if [ $1 = "cpufreq_ondemand.ko" ]; then 111 printf "ondemand" 111 printf "ondemand" 112 elif [ $1 = "cpufreq_conservative.ko" 112 elif [ $1 = "cpufreq_conservative.ko" ]; then 113 printf "conservative" 113 printf "conservative" 114 elif [ $1 = "cpufreq_userspace.ko" ]; 114 elif [ $1 = "cpufreq_userspace.ko" ]; then 115 printf "userspace" 115 printf "userspace" 116 elif [ $1 = "cpufreq_performance.ko" ] 116 elif [ $1 = "cpufreq_performance.ko" ]; then 117 printf "performance" 117 printf "performance" 118 elif [ $1 = "cpufreq_powersave.ko" ]; 118 elif [ $1 = "cpufreq_powersave.ko" ]; then 119 printf "powersave" 119 printf "powersave" 120 elif [ $1 = "cpufreq_schedutil.ko" ]; 120 elif [ $1 = "cpufreq_schedutil.ko" ]; then 121 printf "schedutil" 121 printf "schedutil" 122 fi 122 fi 123 } 123 } 124 124 125 # $1: governor string, $2: governor module, $3 125 # $1: governor string, $2: governor module, $3: policy 126 # example: module_governor_test_single "ondema 126 # example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2 127 module_governor_test_single() 127 module_governor_test_single() 128 { 128 { 129 printf "** Test: Running ${FUNCNAME[0] 129 printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n" 130 130 131 backup_governor $3 131 backup_governor $3 132 132 133 # switch to new governor 133 # switch to new governor 134 printf "Switch from $CUR_GOV to $1\n" 134 printf "Switch from $CUR_GOV to $1\n" 135 switch_show_governor $3 $1 135 switch_show_governor $3 $1 136 136 137 # try removing module, it should fail 137 # try removing module, it should fail as governor is used 138 printf "Removing $2 module\n\n" 138 printf "Removing $2 module\n\n" 139 rmmod $2 139 rmmod $2 140 if [ $? = 0 ]; then 140 if [ $? = 0 ]; then 141 printf "WARN: rmmod $2 succeed 141 printf "WARN: rmmod $2 succeeded even if governor is used\n" 142 insmod $2 142 insmod $2 143 else 143 else 144 printf "Pass: unable to remove 144 printf "Pass: unable to remove $2 while it is being used\n\n" 145 fi 145 fi 146 146 147 # switch back to old governor 147 # switch back to old governor 148 printf "Switchback to $CUR_GOV from $1 148 printf "Switchback to $CUR_GOV from $1\n" 149 restore_governor $3 149 restore_governor $3 150 printf "\n" 150 printf "\n" 151 } 151 } 152 152 153 # Insert cpufreq governor module and perform b 153 # Insert cpufreq governor module and perform basic tests 154 # $1: cpufreq-governor module to insert 154 # $1: cpufreq-governor module to insert 155 module_governor_test() 155 module_governor_test() 156 { 156 { 157 printf "** Test: Running ${FUNCNAME[0] 157 printf "** Test: Running ${FUNCNAME[0]} **\n\n" 158 158 159 # check if module is present or not 159 # check if module is present or not 160 ls $1 > /dev/null 160 ls $1 > /dev/null 161 if [ $? != 0 ]; then 161 if [ $? != 0 ]; then 162 printf "$1: not present in `pw 162 printf "$1: not present in `pwd` folder\n" 163 return; 163 return; 164 fi 164 fi 165 165 166 # test basic module tests 166 # test basic module tests 167 test_basic_insmod_rmmod $1 167 test_basic_insmod_rmmod $1 168 168 169 # insert module 169 # insert module 170 printf "Inserting $1 module\n\n" 170 printf "Inserting $1 module\n\n" 171 insmod $1 171 insmod $1 172 if [ $? != 0 ]; then 172 if [ $? != 0 ]; then 173 printf "Insmod $1 failed\n" 173 printf "Insmod $1 failed\n" 174 return; 174 return; 175 fi 175 fi 176 176 177 # switch to new governor for each cpu 177 # switch to new governor for each cpu 178 for_each_policy module_governor_test_s 178 for_each_policy module_governor_test_single $(find_gov_name $1) $1 179 179 180 # remove module 180 # remove module 181 printf "Removing $1 module\n\n" 181 printf "Removing $1 module\n\n" 182 rmmod $1 182 rmmod $1 183 if [ $? != 0 ]; then 183 if [ $? != 0 ]; then 184 printf "rmmod $1 failed\n" 184 printf "rmmod $1 failed\n" 185 return; 185 return; 186 fi 186 fi 187 printf "\n" 187 printf "\n" 188 } 188 } 189 189 190 # test modules: driver and governor 190 # test modules: driver and governor 191 # $1: driver module, $2: governor module 191 # $1: driver module, $2: governor module 192 module_test() 192 module_test() 193 { 193 { 194 printf "** Test: Running ${FUNCNAME[0] 194 printf "** Test: Running ${FUNCNAME[0]} **\n\n" 195 195 196 # check if modules are present or not 196 # check if modules are present or not 197 ls $1 $2 > /dev/null 197 ls $1 $2 > /dev/null 198 if [ $? != 0 ]; then 198 if [ $? != 0 ]; then 199 printf "$1 or $2: is not prese 199 printf "$1 or $2: is not present in `pwd` folder\n" 200 return; 200 return; 201 fi 201 fi 202 202 203 # TEST1: Insert gov after driver 203 # TEST1: Insert gov after driver 204 # insert driver module 204 # insert driver module 205 printf "Inserting $1 module\n\n" 205 printf "Inserting $1 module\n\n" 206 insmod $1 206 insmod $1 207 if [ $? != 0 ]; then 207 if [ $? != 0 ]; then 208 printf "Insmod $1 failed\n" 208 printf "Insmod $1 failed\n" 209 return; 209 return; 210 fi 210 fi 211 211 212 # run governor tests 212 # run governor tests 213 module_governor_test $2 213 module_governor_test $2 214 214 215 # remove driver module 215 # remove driver module 216 printf "Removing $1 module\n\n" 216 printf "Removing $1 module\n\n" 217 rmmod $1 217 rmmod $1 218 if [ $? != 0 ]; then 218 if [ $? != 0 ]; then 219 printf "rmmod $1 failed\n" 219 printf "rmmod $1 failed\n" 220 return; 220 return; 221 fi 221 fi 222 222 223 # TEST2: Insert driver after governor 223 # TEST2: Insert driver after governor 224 # insert governor module 224 # insert governor module 225 printf "Inserting $2 module\n\n" 225 printf "Inserting $2 module\n\n" 226 insmod $2 226 insmod $2 227 if [ $? != 0 ]; then 227 if [ $? != 0 ]; then 228 printf "Insmod $2 failed\n" 228 printf "Insmod $2 failed\n" 229 return; 229 return; 230 fi 230 fi 231 231 232 # run governor tests 232 # run governor tests 233 module_driver_test $1 233 module_driver_test $1 234 234 235 # remove driver module 235 # remove driver module 236 printf "Removing $2 module\n\n" 236 printf "Removing $2 module\n\n" 237 rmmod $2 237 rmmod $2 238 if [ $? != 0 ]; then 238 if [ $? != 0 ]; then 239 printf "rmmod $2 failed\n" 239 printf "rmmod $2 failed\n" 240 return; 240 return; 241 fi 241 fi 242 } 242 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.