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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # 20 # # 21 # Author: Miao Xie <miaox (at] cn.fujitsu.com> # 22 # # 23 ################################################################################ 24 25 export TCID="cpuset_hotplug" 26 export TST_TOTAL=13 27 export TST_COUNT=1 28 29 . cpuset_funcs.sh 30 31 check 32 33 exit_status=0 34 35 nr_cpus=$NR_CPUS 36 nr_mems=$N_NODES 37 38 cpus_all="$(seq -s, 0 $((nr_cpus-1)))" 39 cpus_all="`cpuset_list_compute $cpus_all`" 40 mems_all="$(seq -s, 0 $((nr_mems-1)))" 41 42 # check_result <result> <expect> 43 check_result() 44 { 45 local result="$1" 46 local expect="$2" 47 48 case "$expect" in 49 EMPTY) 50 test -z "$result" 51 return $? 52 ;; 53 *) 54 test "$expect" = "$result" 55 return $? 56 ;; 57 esac 58 } 59 60 # root_cpu_hotplug_test <cpuhotplug> <expect_cpus> <expect_task_cpus> 61 root_cpu_hotplug_test() 62 { 63 local cpuhotplug="$1" 64 local expect_cpus="$2" 65 local expect_task_cpus="$3" 66 67 local root_cpus= 68 local task_cpus= 69 local tst_pid= 70 local ret= 71 72 setup_test_environment $cpuhotplug 2> $CPUSET_TMP/stderr 73 if [ $? -ne 0 ]; then 74 cpuset_log_error $CPUSET_TMP/stderr 75 tst_resm TFAIL "setup test environment(offline CPU#$HOTPLUG_CPU) failed" 76 return 1 77 fi 78 79 /bin/cat /dev/zero > /dev/null 2>&1 & 80 tst_pid=$! 81 82 cpu_hotplug $HOTPLUG_CPU $cpuhotplug 2> $CPUSET_TMP/stderr 83 if [ $? -ne 0 ]; then 84 cpuset_log_error $CPUSET_TMP/stderr 85 tst_resm TFAIL "$cpuoffline CPU#$HOTPLUG_CPU failed." 86 return 1 87 fi 88 89 root_cpus="`cat $CPUSET/cpus`" 90 91 task_cpus="`cat /proc/$tst_pid/status | grep Cpus_allowed_list`" 92 task_cpus="`echo $task_cpus | sed -e 's/Cpus_allowed_list: //'`" 93 94 check_result "$root_cpus" "$expect_cpus" 95 ret=$? 96 if [ $ret -eq 0 ] 97 then 98 check_result "$task_cpus" "$expect_task_cpus" 99 ret=$? 100 if [ $ret -ne 0 ]; then 101 tst_resm TFAIL "task's allowed list isn't expected.(Result: $task_cpus, Expect: $expect_task_cpus)" 102 fi 103 else 104 tst_resm TFAIL "root group's cpus isn't expected(Result: $root_cpus, Expect: $expect_cpus)." 105 fi 106 107 /bin/kill -9 $tst_pid > /dev/null 2>&1 108 109 return $ret 110 } 111 112 # general_cpu_hotplug_test <cpuhotplug> <cpus> <expect_cpus> <expect_task_cpus> 113 general_cpu_hotplug_test() 114 { 115 local cpuhotplug="$1" 116 local cpus="$2" 117 local expect_cpus="$3" 118 local expect_task_cpus="$4" 119 local path="$CPUSET/1" 120 121 local tst_pid= 122 local task_cpus= 123 local ret= 124 125 setup_test_environment $cpuhotplug 2> $CPUSET_TMP/stderr 126 if [ $? -ne 0 ]; then 127 cpuset_log_error $CPUSET_TMP/stderr 128 tst_resm TFAIL "setup test environment(offline CPU#$HOTPLUG_CPU) failed" 129 return 1 130 fi 131 132 cpuset_set "$path" "$cpus" "$mems_all" "0" 2> $CPUSET_TMP/stderr 133 if [ $? -ne 0 ]; then 134 cpuset_log_error $CPUSET_TMP/stderr 135 tst_resm TFAIL "set general group parameter failed." 136 return 1 137 fi 138 139 /bin/cat /dev/zero > /dev/null 2>&1 & 140 tst_pid=$! 141 142 echo $tst_pid > "$path/tasks" 2> $CPUSET_TMP/stderr 143 if [ $? -ne 0 ]; then 144 cpuset_log_error $CPUSET_TMP/stderr 145 tst_resm TFAIL "attach test tasks to group failed." 146 /bin/kill -s SIGKILL $tst_pid 147 return 1 148 fi 149 150 cpu_hotplug $HOTPLUG_CPU $cpuhotplug 2> $CPUSET_TMP/stderr 151 if [ $? -ne 0 ]; then 152 cpuset_log_error $CPUSET_TMP/stderr 153 tst_resm TFAIL "$cpuoffline CPU#$HOTPLUG_CPU failed." 154 /bin/kill -s SIGKILL $tst_pid 155 return 1 156 fi 157 158 cpus="`cat $path/cpus`" 159 160 task_cpus="`cat /proc/$tst_pid/status | grep Cpus_allowed_list`" 161 task_cpus="`echo $task_cpus | sed -e 's/Cpus_allowed_list: //'`" 162 163 if [ "$expect_cpus" = "EMPTY" ]; then 164 local tasks=`cat $path/tasks | grep "\b$tst_pid\b"` 165 check_result "$tasks" "EMPTY" 166 if [ $? -ne 0 ]; then 167 tst_resm TFAIL "test task was still in general group, but its cpus is NULL" 168 /bin/kill -s SIGKILL $tst_pid 169 return 1 170 fi 171 172 tasks=`cat $CPUSET/tasks | grep "\b$tst_pid\b"` 173 check_result "$tasks" "$tst_pid" 174 if [ $? -ne 0 ]; then 175 tst_resm TFAIL "test task wasn't moved to parent group" 176 /bin/kill -s SIGKILL $tst_pid 177 return 1 178 fi 179 fi 180 181 check_result "$cpus" "$expect_cpus" 182 ret=$? 183 if [ $ret -eq 0 ]; then 184 check_result $task_cpus $expect_task_cpus 185 ret=$? 186 if [ $ret -ne 0 ]; then 187 tst_resm TFAIL "task's cpu allowed list isn't expected(Result: $task_cpus, Expect: $expect_task_cpus)." 188 fi 189 else 190 if [ "$cpus" = "" ]; then 191 cpus="EMPTY" 192 fi 193 tst_resm TFAIL "general group's cpus isn't expected(Result: $cpus, Expect: $expect_cpus)." 194 fi 195 /bin/kill -s SIGKILL $tst_pid > /dev/null 2>&1 196 197 return $ret 198 } 199 200 base_test() 201 { 202 setup 203 if [ $? -ne 0 ]; then 204 exit_status=1 205 else 206 "$test_function" "$@" 207 if [ $? -ne 0 ]; then 208 exit_status=1 209 cleanup 210 else 211 cleanup 212 if [ $? -ne 0 ]; then 213 exit_status=1 214 else 215 tst_resm TPASS "Cpuset vs CPU hotplug test succeeded." 216 fi 217 fi 218 219 cpu_hotplug_cleanup 220 fi 221 TST_COUNT=$(($TST_COUNT + 1)) 222 } 223 224 # Test Case 1-2 225 test_root_cpu_hotplug() 226 { 227 local tmp_cpus="`cpuset_list_compute -s $cpus_all $HOTPLUG_CPU`" 228 229 test_function="root_cpu_hotplug_test" 230 while read hotplug cpus_expect task_expect 231 do 232 base_test "$hotplug" "$cpus_expect" "$task_expect" 233 done <<- EOF 234 offline $tmp_cpus $cpus_all 235 online $cpus_all $cpus_all 236 EOF 237 # while read hotplug cpus_expect task_expect 238 } 239 240 # Test Case 3-6 241 test_general_cpu_hotplug() 242 { 243 local tmp_cpus="`cpuset_list_compute -s $cpus_all $HOTPLUG_CPU`" 244 245 test_function="general_cpu_hotplug_test" 246 while read hotplug cpus cpus_expect task_expect 247 do 248 base_test "$hotplug" "$cpus" "$cpus_expect" "$task_expect" 249 done <<- EOF 250 offline 0-1 0 0 251 offline 1 EMPTY $cpus_all 252 offline 0 0 0 253 online 0 0 0 254 EOF 255 # while read hotplug cpus cpus_expect task_expect 256 } 257 258 test_root_cpu_hotplug 259 test_general_cpu_hotplug 260 261 exit $exit_status 262