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