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@cn.fujitsu.com> # 22# # 23################################################################################ 24 25export TCID="cpuset_syscall" 26export TST_TOTAL=16 27export TST_COUNT=1 28 29. cpuset_funcs.sh 30 31check 32 33tst_flag2mask TCONF 34TCONF=$? 35exit_status=0 36 37nr_mems=$N_NODES 38 39TEST_CPUSET="$CPUSET/0" 40TEST_OUTPUT="$CPUSET_TMP/result" 41TEST_PROCSTATUS="$CPUSET_TMP/status" 42TEST_PROCNUMA="$CPUSET_TMP/numa_maps" 43 44# do_syscall_test - call syscall_test 45# $1 - cpus 46# $2 - mems 47# $3 - syscall_test's args 48# $4 - expect return value of test task 49 50do_syscall_test() 51{ 52 local testpid= 53 local ret= 54 55 mkdir -p "$TEST_CPUSET" 56 if [ $? -ne 0 ]; then 57 tst_resm TFAIL "mkdir -p $TEST_CPUSET fail." 58 return 1 59 fi 60 echo "$1" > "$TEST_CPUSET/cpuset.cpus" 61 if [ $? -ne 0 ]; then 62 tst_resm TFAIL "set $TEST_CPUSET/cupset.cpus as $1 fail." 63 return 1 64 fi 65 echo "$2" > "$TEST_CPUSET/cpuset.mems" 66 if [ $? -ne 0 ]; then 67 tst_resm TFAIL "set $TEST_CPUSET/cpuset.mems as $2 fail." 68 return 1 69 fi 70 cpuset_syscall_test $3 >"$TEST_OUTPUT" & 71 testpid=$! 72 echo $testpid > "$TEST_CPUSET/tasks" 73 if [ $? -ne 0 ]; then 74 tst_resm TFAIL "Attaching test task into group fail." 75 return 1 76 fi 77 sleep 1 78 /bin/kill -s SIGUSR1 $testpid 79 sleep 1 80 cat /proc/$testpid/status > $TEST_PROCSTATUS 81 cat /proc/$testpid/numa_maps > $TEST_PROCNUMA 82 /bin/kill -s SIGINT $testpid 83 wait $testpid 84 ret=$? 85 86 if [ "$ret" -eq "$TCONF" ]; then 87 return $TCONF 88 fi 89 90 if [ $4 -eq 0 ]; then 91 if [ $ret -ne 0 ]; then 92 tst_resm TFAIL "Test task exited abnormally.(expect return value is 0)" 93 return 1 94 fi 95 else 96 if [ $ret -eq 0 ]; then 97 tst_resm TFAIL "Test task exited abnormally.(expect return value is !0)" 98 return 1 99 fi 100 fi 101 return 0 102} 103 104test1() 105{ 106 do_syscall_test 0 0 --setaffinity=1 0 || return $? 107 allowed_list="$(awk '/Cpus_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 108 test "$allowed_list" = "0" 109 if [ $? -ne 0 ]; then 110 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0\"" 111 return 1 112 fi 113 return 0 114} 115 116test2() 117{ 118 do_syscall_test 0-1 0 --setaffinity=1 0 || return $? 119 allowed_list="$(awk '/Cpus_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 120 test "$allowed_list" = "0" 121 if [ $? -ne 0 ]; then 122 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0\"" 123 return 1 124 fi 125 return 0 126} 127 128test3() 129{ 130 do_syscall_test 0-1 0 --setaffinity=6 0 || return $? 131 allowed_list="$(awk '/Cpus_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 132 test "$allowed_list" = "1" 133 if [ $? -ne 0 ]; then 134 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"1\"" 135 return 1 136 fi 137 return 0 138} 139 140test4() 141{ 142 do_syscall_test 0-1 0 --setaffinity=12 1 || return $? 143 allowed_list="$(awk '/Cpus_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 144 test "$allowed_list" = "0-1" || return 1 145 if [ $? -ne 0 ]; then 146 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0-1\"" 147 return 1 148 fi 149 return 0 150} 151 152test5() 153{ 154 do_syscall_test 0 0 --getaffinity 0 || return $? 155 allowed_list="$(awk '/Cpus_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 156 test "$(cat "$TEST_OUTPUT")" = "0," 157 if [ $? -ne 0 ]; then 158 tst_resm TFAIL "Result(getaffinity) = \"$(cat $TEST_OUTPUT)\", expect = \"0,\")" 159 return 1 160 fi 161 test "$allowed_list" = "0" 162 if [ $? -ne 0 ]; then 163 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0\")" 164 return 1 165 fi 166 return 0 167} 168 169test6() 170{ 171 do_syscall_test 0-1 0 --getaffinity 0 || return $? 172 allowed_list="$(awk '/Cpus_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 173 test "$(cat "$TEST_OUTPUT")" = "0,1," 174 if [ $? -ne 0 ]; then 175 tst_resm TFAIL "Result(getaffinity) = \"$(cat $TEST_OUTPUT)\", expect = \"0,1,\")" 176 return 1 177 fi 178 test "$allowed_list" = "0-1" 179 if [ $? -ne 0 ]; then 180 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0-1\")" 181 return 1 182 fi 183 return 0 184} 185 186test7() 187{ 188 do_syscall_test 0 0 --mbind=1 0 || return $? 189 memory_addr="$(cat $TEST_OUTPUT)" 190 memory_addr=${memory_addr##*0x} 191 allowed_list=$(grep "$memory_addr" $TEST_PROCNUMA | \ 192 awk '{print $2}') 193 allowed_list="$(echo $allowed_list | sed -e s/bind://)" 194 test "$allowed_list" = "0" || return 1 195 if [ $? -ne 0 ]; then 196 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0\")" 197 return 1 198 fi 199 return 0 200} 201 202test8() 203{ 204 do_syscall_test 0 0-1 --mbind=1 0 || return $? 205 memory_addr="$(cat $TEST_OUTPUT)" 206 memory_addr=${memory_addr##*0x} 207 allowed_list=$(grep "$memory_addr" $TEST_PROCNUMA | \ 208 awk '{print $2}') 209 allowed_list="$(echo $allowed_list | sed -e s/bind://)" 210 test "$allowed_list" = "0" 211 if [ $? -ne 0 ]; then 212 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0\")" 213 return 1 214 fi 215 return 0 216} 217 218test9() 219{ 220 do_syscall_test 0 0-1 --mbind=6 0 || return $? 221 memory_addr="$(cat $TEST_OUTPUT)" 222 memory_addr=${memory_addr##*0x} 223 allowed_list=$(grep "$memory_addr" $TEST_PROCNUMA | \ 224 awk '{print $2}') 225 allowed_list="$(echo $allowed_list | sed -e s/bind://)" 226 test "$allowed_list" = "1" 227 if [ $? -ne 0 ]; then 228 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"1\")" 229 return 1 230 fi 231 return 0 232} 233 234test10() 235{ 236 do_syscall_test 0 0 --mbind=6 1 || return $? 237 memory_addr="$(cat $TEST_OUTPUT)" 238 memory_addr=${memory_addr##*0x} 239 allowed_list=$(grep "$memory_addr" $TEST_PROCNUMA | \ 240 awk '{print $2}') 241 allowed_list="$(echo $allowed_list | sed -e s/bind://)" 242 243 task_policy=$(grep -e " *stack *anon" $TEST_PROCNUMA | \ 244 awk '{print $2}') 245 246 test "$allowed_list" = "$task_policy" 247 if [ $? -ne 0 ]; then 248 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\",\ 249 expect = \"$task_policy\")" 250 return 1 251 fi 252 return 0 253} 254 255# this function is used by case 11-13 256# check_result <expect> 257check_result() 258{ 259 local expect=$1 260 while read allowed_list; do 261 allowed_list="$(echo $allowed_list | awk '{print $2}')" 262 allowed_list="$(echo $allowed_list | sed -e s/bind://)" 263 test "$allowed_list" = "$expect" 264 if [ $? -ne 0 ]; then 265 tst_resm TFAIL "Result(/proc/<pid>/numa_maps) = \"$allowed_list\", expect = \"$expect\")" 266 return 1 267 fi 268 done < $TEST_PROCNUMA 269 return 0 270} 271 272test11() 273{ 274 do_syscall_test 0 0 --set_mempolicy=1 0 || return $? 275 check_result "0" 276 return $? 277} 278 279test12() 280{ 281 do_syscall_test 0 0-1 --set_mempolicy=1 0 || return $? 282 check_result "0" 283 return $? 284} 285 286test13() 287{ 288 if [ $nr_mems -ge 3 ]; then 289 do_syscall_test 0 0-1 --set_mempolicy=6 0 || return $? 290 else 291 do_syscall_test 0 0-1 --set_mempolicy=2 0 || return $? 292 fi 293 check_result "1" 294 return $? 295} 296 297test14() 298{ 299 if [ $nr_mems -ge 3 ]; then 300 do_syscall_test 0 0 --set_mempolicy=6 1 || return $? 301 else 302 do_syscall_test 0 0 --set_mempolicy=2 1 || return $? 303 fi 304 return 0 305} 306 307test15() 308{ 309 do_syscall_test 0 0 --get_mempolicy 0 || return $? 310 allowed_list="$(awk '/Mems_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 311 test "$(cat "$TEST_OUTPUT")" = "0" 312 if [ $? -ne 0 ]; then 313 tst_resm TFAIL "Result(get_mempolicy) = \"$(cat $TEST_OUTPUT)\", expect = \"1\")" 314 return 1 315 fi 316 test "$allowed_list" = "0" 317 if [ $? -ne 0 ]; then 318 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0\")" 319 return 1 320 fi 321 return 0 322} 323 324test16() 325{ 326 do_syscall_test 0 0-1 --get_mempolicy 0 || return $? 327 allowed_list="$(awk '/Mems_allowed_list:/{print $2}' $TEST_PROCSTATUS )" 328 test "$(cat "$TEST_OUTPUT")" = "0-1" 329 if [ $? -ne 0 ]; then 330 tst_resm TFAIL "Result(get_mempolicy) = \"$(cat $TEST_OUTPUT)\", expect = \"3\")" 331 return 1 332 fi 333 test "$allowed_list" = "0-1" 334 if [ $? -ne 0 ]; then 335 tst_resm TFAIL "Result(/proc/<pid>/status) = \"$allowed_list\", expect = \"0-1\")" 336 return 1 337 fi 338 return 0 339} 340 341for c in $(seq 1 $TST_TOTAL) 342do 343 tst_resm TINFO "Starting test no. $c" 344 setup 345 if [ $? -ne 0 ]; then 346 exit_status=1 347 else 348 test$c 349 ret=$? 350 cleanup 351 ret=$((ret | $?)) 352 353 case $ret in 354 0) 355 tst_resm TPASS "Cpuset vs systemcall test succeeded." 356 ;; 357 "$TCONF") 358 tst_resm TCONF "Test exited with TCONF" 359 ;; 360 *) 361 exit_status=1 362 ;; 363 esac 364 fi 365 TST_COUNT=$(($TST_COUNT + 1)) 366done 367 368exit $exit_status 369 370