cpuset_load_balance_test.sh revision 70259d6e7ec2569972fb663ea85f959c4f2b4f81
1#!/bin/sh 2 3################################################################################ 4# # 5# Copyright (c) 2009 FUJITSU LIMITED # 6# # 7# This program is free software; you can redistribute it and#or modify # 8# it under the terms of the GNU General Public License as published by # 9# the Free Software Foundation; either version 2 of the License, or # 10# (at your option) any later version. # 11# # 12# This program is distributed in the hope that it will be useful, but # 13# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # 14# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # 15# for more details. # 16# # 17# You should have received a copy of the GNU General Public License # 18# along with this program; if not, write to the Free Software # 19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20# # 21# Author: Miao Xie <miaox@cn.fujitsu.com> # 22# # 23################################################################################ 24 25source ./cpuset_funcs.sh 26 27cd $LTPROOT/testcases/bin 28 29export TCID="cpuset07" 30export TST_TOTAL=13 31export TST_COUNT=1 32 33exit_status=0 34 35# must >= 3 for: 1-$((nr_mems-2)) 36nr_cpus=4 37nr_mems=3 38 39cpus_all="$(seq -s, 0 $((nr_cpus-1)))" 40mems_all="$(seq -s, 0 $((nr_mems-1)))" 41 42runtime=30 43 44#cpuset_set_opt <path> <cfile> <value> 45cpuset_set_opt() 46{ 47 local path=$1 48 local cfile=$2 49 local value=$3 50 51 /bin/echo $value > $path/$cfile 52 return $? 53} 54 55# general_load_balance_test1 <g_cpus> <g_balance> <r_balance> 56general_load_balance_test1() 57{ 58 local g_cpus="$1" 59 local g_balance="$2" 60 local r_balance="$3" 61 local g_path="$CPUSET/1" 62 63 local fifo= 64 local ret= 65 66 cpuset_log "general group load balance test" 67 cpuset_log "root group info:" 68 cpuset_log " sched load balance:" $r_balance 69 cpuset_log "general group info:" 70 cpuset_log " cpus:" $g_cpus 71 cpuset_log " sched load balance:" $g_balance 72 73 cpuset_set "$CPUSET" "-" "$mems_all" "$r_balance" 2> $CPUSET_TMP/stderr 74 if [ $? -ne 0 ]; then 75 cpuset_log_error $CPUSET_TMP/stderr 76 tst_resm TFAIL "set root group parameter failed." 77 return 1 78 fi 79 80 cpuset_set "$g_path" "$g_cpus" "$mems_all" "$g_balance" 2> $CPUSET_TMP/stderr 81 if [ $? -ne 0 ]; then 82 cpuset_log_error $CPUSET_TMP/stderr 83 tst_resm TFAIL "set general group parameter failed." 84 return 1 85 fi 86 87 ./cpuset_cpu_hog 2> $CPUSET_TMP/cpu-hog_stderr & 88 pid=$! 89 90 read fifo < ./myfifo 91 if [ $fifo -ne 0 ]; then 92 cpuset_log_error $CPUSET_TMP/stderr 93 tst_resm TFAIL "There is something wrong with test tasks" 94 return 1 95 fi 96 97 if [ "$g_cpus" != "-" ]; then 98 cpuset_set_opt "$g_path" "tasks" "$pid" 2> $CPUSET_TMP/stderr 99 if [ $? -ne 0 ]; then 100 cpuset_log_error $CPUSET_TMP/stderr 101 tst_resm TFAIL "attach test tasks to group "\ 102 "failed." 103 /bin/kill -s SIGKILL $pid 104 return 1 105 fi 106 fi 107 108 # start to fork the child processes 109 /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr 110 if [ $? -ne 0 ]; then 111 cpuset_log_error $CPUSET_TMP/stderr 112 tst_resm TFAIL "send the signal to fork the child tasks " \ 113 "failed." 114 /bin/kill -s SIGKILL $pid 115 return 1 116 fi 117 118 read fifo < ./myfifo 119 if [ $fifo -ne 0 ]; then 120 cpuset_log_error $CPUSET_TMP/cpu-hog_stderr 121 tst_resm TFAIL "forking test tasks failed" 122 return 1 123 fi 124 125 # start to run the child processes 126 /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr 127 if [ $? -ne 0 ]; then 128 cpuset_log_error $CPUSET_TMP/stderr 129 tst_resm TFAIL "send the signal to run the child tasks " \ 130 "failed." 131 /bin/kill -s SIGUSR2 $pid 132 return 1 133 fi 134 135 sleep $runtime 136 /bin/kill -s SIGUSR2 $pid 2> $CPUSET_TMP/stderr 137 if [ $? -ne 0 ]; then 138 cpuset_log_error $CPUSET_TMP/stderr 139 tst_resm TFAIL "send the signal to stop the child tasks " \ 140 "failed." 141 return 1 142 fi 143 144 wait $pid 145 if [ $? -ne 0 ]; then 146 cpuset_log_error $CPUSET_TMP/cpu-hog_stderr 147 tst_resm TFAIL "load balance test failed." 148 return 1 149 fi 150 151 tst_resm TPASS "load balance test succeeded." 152} 153 154# general_load_balance_test2 <g1_cpus> <g1_balance> 155# <g2_cpus> <g2_balance> 156# <cpuoffline> 157general_load_balance_test2() 158{ 159 local g1_cpus=$1 160 local g1_balance=$2 161 local g1_path="$CPUSET/1" 162 163 local g2_cpus=$3 164 local g2_balance=$4 165 local g2_path="$CPUSET/2" 166 167 local cpuoffline=$5 168 169 local pid= 170 local ret= 171 172 cpuset_log "general group load balance test" 173 cpuset_log "root group info:" 174 cpuset_log " sched load balance:" 0 175 cpuset_log "general group1 info:" 176 cpuset_log " cpus:" $g1_cpus 177 cpuset_log " sched load balance:" $g1_balance 178 cpuset_log "general group2 info:" 179 cpuset_log " cpus:" $g2_cpus 180 cpuset_log " sched load balance:" $g2_balance 181 cpuset_log "CPU hotplug:" $cpuoffline 182 183 cpuset_set "$CPUSET" "-" "$mems_all" "0" 2> $CPUSET_TMP/stderr 184 if [ $? -ne 0 ]; then 185 cpuset_log_error $CPUSET_TMP/stderr 186 tst_resm TFAIL "set root group parameter failed." 187 return 1 188 fi 189 190 cpuset_set "$g1_path" "$g1_cpus" "$mems_all" "$g1_balance" 2> $CPUSET_TMP/stderr 191 if [ $? -ne 0 ]; then 192 cpuset_log_error $CPUSET_TMP/stderr 193 tst_resm TFAIL "set general group1 parameter failed." 194 return 1 195 fi 196 197 cpuset_set "$g2_path" "$g2_cpus" "$mems_all" "$g2_balance" 2> $CPUSET_TMP/stderr 198 if [ $? -ne 0 ]; then 199 cpuset_log_error $CPUSET_TMP/stderr 200 tst_resm TFAIL "set general group2 parameter failed." 201 return 1 202 fi 203 204 # setup test environment 205 setup_test_environment $cpuoffline 2> $CPUSET_TMP/stderr 206 if [ $? -ne 0 ]; then 207 cpuset_log_error $CPUSET_TMP/stderr 208 tst_resm TFAIL "setup test environment(offline CPU#$HOTPLUG_CPU) failed" 209 return 1 210 fi 211 212 ./cpuset_cpu_hog 2> $CPUSET_TMP/cpu-hog_stderr & 213 pid=$! 214 215 # wait for the parent to do prepare 216 read fifo < ./myfifo 217 if [ $fifo -ne 0 ]; then 218 cpuset_log_error $CPUSET_TMP/stderr 219 tst_resm TFAIL "There is something wrong with test tasks" 220 return 1 221 fi 222 223 if [ "$g1_cpus" != "-" ]; then 224 cpuset_set_opt "$g1_path" "tasks" "$pid" 2> $CPUSET_TMP/stderr 225 if [ $? -ne 0 ]; then 226 cpuset_log_error $CPUSET_TMP/stderr 227 tst_resm TFAIL "attach test tasks to group "\ 228 "failed." 229 /bin/kill -s SIGKILL $pid 230 return 1 231 fi 232 fi 233 234 # start to fork the child processes 235 /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr 236 if [ $? -ne 0 ]; then 237 cpuset_log_error $CPUSET_TMP/stderr 238 tst_resm TFAIL "send the signal to fork the child tasks " \ 239 "failed." 240 /bin/kill -s SIGKILL $pid 241 return 1 242 fi 243 244 # wait for the end of forking 245 read fifo < ./myfifo 246 if [ $fifo -ne 0 ]; then 247 cpuset_log_error $CPUSET_TMP/cpu-hog_stderr 248 tst_resm TFAIL "forking test tasks failed" 249 return 1 250 fi 251 252 sleep 1 253 cpu_hotplug $HOTPLUG_CPU $cpuoffline 2> $CPUSET_TMP/stderr 254 if [ $? -ne 0 ]; then 255 cpuset_log_error $CPUSET_TMP/stderr 256 tst_resm TFAIL "$cpuoffline CPU#$HOTPLUG_CPU failed." 257 /bin/kill -s SIGUSR2 $pid 258 wait $pid 259 return 1 260 fi 261 262 # start to run the child processes 263 /bin/kill -s SIGUSR1 $pid 2> $CPUSET_TMP/stderr 264 if [ $? -ne 0 ]; then 265 cpuset_log_error $CPUSET_TMP/stderr 266 tst_resm TFAIL "send the signal to run the child tasks " \ 267 "failed." 268 /bin/kill -s SIGUSR2 $pid 269 wait $pid 270 return 1 271 fi 272 273 sleep $runtime 274 /bin/kill -s SIGUSR2 $pid 2> $CPUSET_TMP/stderr 275 if [ $? -ne 0 ]; then 276 cpuset_log_error $CPUSET_TMP/stderr 277 tst_resm TFAIL "send the signal to stop the child tasks " \ 278 "failed." 279 return 1 280 fi 281 282 wait $pid 283 if [ $? -ne 0 ]; then 284 cpuset_log_error $CPUSET_TMP/cpu-hog_stderr 285 tst_resm TFAIL "load balance test failed." 286 return 1 287 fi 288 289 tst_resm TPASS "load balance test succeeded." 290} 291 292base_test() 293{ 294 setup 295 if [ $? -ne 0 ]; then 296 exit_status=1 297 else 298 $test_pro "$@" 299 if [ $? -ne 0 ]; then 300 exit_status=1 301 fi 302 303 cleanup 304 if [ $? -ne 0 ]; then 305 exit_status=1 306 fi 307 308 cpu_hotplug_cleanup 309 fi 310 ((TST_COUNT++)) 311} 312 313test_general_load_balance1() 314{ 315 test_pro="general_load_balance_test1" 316 317 local g_cpus= 318 local g_isbalance= 319 local r_isbalance= 320 321 while read g_cpus g_isbalance r_isbalance 322 do 323 base_test $g_cpus $g_isbalance $r_isbalance 324 done <<- EOF 325 - 1 0 326 1 0 0 327 - 1 1 328 1 1 1 329 1,2 0 0 330 1,2 1 0 331 $cpus_all 1 0 332 EOF 333 # while read g_cpus g_isbalance r_isbalance 334} 335 336test_general_load_balance2() 337{ 338 test_pro="general_load_balance_test2" 339 340 local g1_cpus= 341 local g1_isbalance= 342 343 local g2_cpus= 344 local g2_isbalance= 345 346 local hotplug= 347 348 while read g1_cpus g1_isbalance g2_cpus g2_isbalance hotplug 349 do 350 base_test $g1_cpus $g1_isbalance $g2_cpus $g2_isbalance $hotplug 351 done <<- EOF 352 1 1 0 1 none 353 1,2 1 0-3 0 none 354 1,2 1 0,3 1 none 355 1,2 1 1,3 1 none 356 1,2 1 1,3 1 offline 357 1,2 1 1,3 1 online 358 EOF 359 # while read g1_cpus g1_isbalance g2_cpus g2_isbalance hotplug 360} 361 362mkfifo myfifo 363test_general_load_balance1 364test_general_load_balance2 365rm -f myfifo 366 367exit $exit_status 368