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_base_ops" 26export TST_TOTAL=97 27export TST_COUNT=1 28 29. cpuset_funcs.sh 30 31check 32 33nr_cpus=$NR_CPUS 34nr_mems=$N_NODES 35 36cpus_all="$(seq -s, 0 $((nr_cpus-1)))" 37mems_all="$(seq -s, 0 $((nr_mems-1)))" 38 39exit_status=0 40 41cfile_name= 42 43# base_op_write_and_test <write_file_name> <write_string> <expect_string> 44base_op_write_and_test() 45{ 46 local write_file="$1" 47 local write_string="$2" 48 local expect_string="$3" 49 local write_result= 50 local ret=0 51 52 mkdir -p "$(dirname $write_file)" || { 53 tst_brkm TFAIL "Failed to mkdir -p $(basename $write_file)" 54 return 1 55 } 56 [ "$write_string" = NULL ] && write_string=" " 57 58 /bin/echo "$write_string" > "$write_file" 2> $CPUSET_TMP/stderr 59 ret=$? 60 write_result="$(cat "$write_file")" 61 62 case "$expect_string" in 63 EMPTY) 64 test -z "$write_result" -a $ret = 0 65 ret=$? 66 ;; 67 WRITE_ERROR) 68 ret=$((!$ret)) 69 ;; 70 *) 71 test "$expect_string" = "$write_result" -a $ret = 0 72 ret=$? 73 ;; 74 esac 75 76 if [ $ret -eq 0 ]; then 77 tst_resm TPASS "$cfile_name: Get the expected string" 78 else 79 tst_resm TFAIL "$cfile_name: Test result - $write_result Expected string - \"$expect_string\"" 80 fi 81 return $ret 82} 83 84base_op_test() 85{ 86 setup 87 if [ $? -ne 0 ]; then 88 exit_status=1 89 else 90 base_op_write_and_test "$@" 91 if [ $? -ne 0 ]; then 92 exit_status=1 93 fi 94 95 cleanup 96 if [ $? -ne 0 ]; then 97 exit_status=1 98 fi 99 fi 100 TST_COUNT=$(($TST_COUNT + 1)) 101} 102 103test_cpus() 104{ 105 cfile_name="cpuset.cpus" 106 while read cpus result 107 do 108 base_op_test "$CPUSET/1/cpuset.cpus" "$cpus" "$result" 109 done <<- EOF 110 NULL EMPTY 111 0 0 112 $nr_cpus WRITE_ERROR 113 $cpus_all 0-$((nr_cpus-1)) 114 ${cpus_all}$nr_cpus WRITE_ERROR 115 0,0 0 116 0-0 0 117 0-$((nr_cpus-1)) 0-$((nr_cpus-1)) 118 -1 WRITE_ERROR 119 0-$nr_cpus WRITE_ERROR 120 0--$((nr_cpus-1)) WRITE_ERROR 121 0AAA WRITE_ERROR 122 AAA WRITE_ERROR 123 EOF 124 # while read cpus result 125 126 if [ $nr_cpus -ge 3 ]; then 127 base_op_test "$CPUSET/1/cpuset.cpus" "0,1-$((nr_cpus-2)),$((nr_cpus-1))" "0-$((nr_cpus-1))" 128 base_op_test "$CPUSET/1/cpuset.cpus" "0,1-$((nr_cpus-2))," "0-$((nr_cpus-2))" 129 fi 130 131 if tst_kvcmp -lt "3.0 RHEL6:2.6.32"; then 132 base_op_test "$CPUSET/1/cpuset.cpus" "0-" "WRITE_ERROR" 133 else 134 base_op_test "$CPUSET/1/cpuset.cpus" "0-" "0" 135 fi 136} 137 138test_mems() 139{ 140 cfile_name="cpuset.mems" 141 while read mems result 142 do 143 base_op_test "$CPUSET/1/cpuset.mems" "$mems" "$result" 144 done <<- EOF 145 NULL EMPTY 146 0 0 147 $nr_mems WRITE_ERROR 148 $mems_all 0-$((nr_mems-1)) 149 ${mems_all}$nr_mems WRITE_ERROR 150 0,0 0 151 0-0 0 152 0-$((nr_mems-1)) 0-$((nr_mems-1)) 153 -1 WRITE_ERROR 154 0-$nr_mems WRITE_ERROR 155 0--$((nr_mems-1)) WRITE_ERROR 156 0AAA WRITE_ERROR 157 AAA WRITE_ERROR 158 EOF 159 # while read mems result 160 161 if [ $nr_mems -ge 3 ]; then 162 base_op_test "$CPUSET/1/cpuset.mems" "0,1-$((nr_mems-2)),$((nr_mems-1))" "0-$((nr_mems-1))" 163 base_op_test "$CPUSET/1/cpuset.mems" "0,1-$((nr_mems-2))," "0-$((nr_mems-2))" 164 fi 165 166 if tst_kvcmp -lt "3.0 RHEL6:2.6.32"; then 167 base_op_test "$CPUSET/1/cpuset.mems" "0-" "WRITE_ERROR" 168 else 169 base_op_test "$CPUSET/1/cpuset.mems" "0-" "0" 170 fi 171} 172 173test_flags() 174{ 175 for filename in cpu_exclusive mem_exclusive mem_hardwall \ 176 memory_migrate memory_spread_page memory_spread_slab \ 177 sched_load_balance memory_pressure_enabled 178 do 179 cfile_name="cpuset.$filename" 180 while read flags result 181 do 182 base_op_test "$CPUSET/cpuset.$filename" "$flags" "$result" 183 done <<- EOF 184 0 0 185 1 1 186 -1 WRITE_ERROR 187 A WRITE_ERROR 188 2 1 189 EOF 190 # while read flags, result 191 done # for filename in flagfiles 192} 193 194# attach_task_test <cpus> <mems> <expect> 195attach_task_test() 196{ 197 local cpus=$1 198 local mems=$2 199 local expect=$3 200 201 local pid= 202 local ret= 203 204 setup 205 if [ $? -ne 0 ]; then 206 exit_status=1 207 cleanup 208 TST_COUNT=$(($TST_COUNT + 1)) 209 return 210 fi 211 212 # create sub cpuset 213 mkdir "$CPUSET/sub_cpuset" > /dev/null 214 if [ $? -ne 0 ]; then 215 exit_status=1 216 cleanup 217 TST_COUNT=$(($TST_COUNT + 1)) 218 return 219 fi 220 221 if [ "$cpus" != "NULL" ]; then 222 echo $cpus > "$CPUSET/sub_cpuset/cpuset.cpus" 223 fi 224 if [ "$mems" != "NULL" ]; then 225 echo $mems > "$CPUSET/sub_cpuset/cpuset.mems" 226 fi 227 228 cat /dev/zero > /dev/null & 229 pid=$! 230 231 # attach task into the cpuset group 232 echo $pid > "$CPUSET/sub_cpuset/tasks" 2> /dev/null 233 if [ $? -eq $expect ]; then 234 tst_resm TPASS "Attaching Task Test successed!!" 235 else 236 tst_resm TFAIL "Attaching Task Test failed!! cpus - \"$cpus\", mems - \"$mems\", Expect - \"$expect\", Fact - \"$ret\". (0 - Attach Success, 1 - Attach Fail)" 237 exit_status=1 238 fi 239 240 /bin/kill $pid > /dev/null 2>&1 241 cleanup 242 if [ $? -ne 0 ]; then 243 exit_status=1 244 fi 245 TST_COUNT=$(($TST_COUNT + 1)) 246} 247 248 249test_attach_task() 250{ 251 cfile_name="tasks" 252 while read cpus mems expect 253 do 254 attach_task_test "$cpus" "$mems" "$expect" 255 done <<- EOF 256 0 NULL 1 257 0 0 0 258 NULL 0 1 259 EOF 260 # while read cpus mems expect 261} 262 263test_readonly_cfiles() 264{ 265 for filename in cpus mems memory_pressure 266 do 267 cfile_name="cpuset.$filename(READONLY)" 268 base_op_test "$CPUSET/cpuset.$filename" "0" "WRITE_ERROR" 269 done # for filename in readonly cfiles 270} 271 272# Case 1-3 273test_readonly_cfiles 274 275# Case 4-19 276test_cpus 277 278# Case 20-35 279test_mems 280 281# Case 36-83 282test_flags 283 284# Case 84-86 285test_attach_task 286 287exit $exit_status 288