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_memory_pressure" 26export TST_TOTAL=6 27export TST_COUNT=1 28 29. cpuset_funcs.sh 30 31check 32 33exit_status=0 34 35# usable physical memory 36py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}') 37 38# free swap space 39sw_mem=$(free -m | awk '{if(NR==4) print $4}') 40 41# the memory which is going to be used 42usemem=$((py_mem - 20)) 43 44test1() 45{ 46 echo 0 > "$CPUSET/cpuset.memory_pressure_enabled" 2> $CPUSET_TMP/stderr 47 if [ $? -ne 0 ]; then 48 cpuset_log_error $CPUSET_TMP/stderr 49 tst_resm TFAIL "Closing memory_pressure_enabled failed." 50 return 1 51 fi 52 53 local i 54 for i in $(seq 0 9) 55 do 56 if [ $(cat "$CPUSET/cpuset.memory_pressure") -ne 0 ]; then 57 tst_resm TFAIL "Memory_pressure had memory pressure rate." 58 return 1 59 fi 60 done 61} 62 63test2() 64{ 65 echo 0 > "$CPUSET/cpuset.memory_pressure_enabled" 2> $CPUSET_TMP/stderr 66 if [ $? -ne 0 ]; then 67 cpuset_log_error $CPUSET_TMP/stderr 68 tst_resm TFAIL "Closing memory_pressure_enabled failed." 69 return 1 70 fi 71 72 cpuset_memory_pressure $usemem 73 74 local i 75 for i in $(seq 0 9) 76 do 77 if [ $(cat "$CPUSET/cpuset.memory_pressure") -ne 0 ]; then 78 tst_resm TFAIL "Memory_pressure had memory pressure rate." 79 return 1 80 fi 81 done 82} 83 84test3() 85{ 86 echo 1 > "$CPUSET/cpuset.memory_pressure_enabled" 2> $CPUSET_TMP/stderr 87 if [ $? -ne 0 ]; then 88 cpuset_log_error $CPUSET_TMP/stderr 89 tst_resm TFAIL "Opening memory_pressure_enabled failed." 90 return 1 91 fi 92 93 cpuset_set "$CPUSET/sub_cpuset" "0" "0" "0" 2> $CPUSET_TMP/stderr 94 if [ $? -ne 0 ]; then 95 cpuset_log_error $CPUSET_TMP/stderr 96 tst_resm TFAIL "set general group parameter failed." 97 return 1 98 fi 99 100 local i 101 for i in $(seq 0 9) 102 do 103 if [ $(cat "$CPUSET/cpuset.memory_pressure") -ne 0 ]; then 104 tst_resm TFAIL "root group's memory_pressure had memory pressure rate." 105 return 1 106 fi 107 if [ $(cat "$CPUSET/sub_cpuset/cpuset.memory_pressure") -ne 0 ]; then 108 tst_resm TFAIL "sub group's memory_pressure had memory pressure rate." 109 return 1 110 fi 111 done 112 return 0 113} 114 115test4() 116{ 117 echo 1 > "$CPUSET/cpuset.memory_pressure_enabled" 2> $CPUSET_TMP/stderr 118 if [ $? -ne 0 ]; then 119 cpuset_log_error $CPUSET_TMP/stderr 120 tst_resm TFAIL "Opening memory_pressure_enabled failed." 121 return 1 122 fi 123 124 cpuset_set "$CPUSET/sub_cpuset" "0" "0" "0" 2> $CPUSET_TMP/stderr 125 if [ $? -ne 0 ]; then 126 cpuset_log_error $CPUSET_TMP/stderr 127 tst_resm TFAIL "set general group parameter failed." 128 return 1 129 fi 130 131 echo $$ > "$CPUSET/sub_cpuset/tasks" 2> $CPUSET_TMP/stderr 132 if [ $? -ne 0 ]; then 133 cpuset_log_error $CPUSET_TMP/stderr 134 tst_resm TFAIL "attaching self to sub group failed" 135 return 1 136 fi 137 138 cpuset_memory_pressure $usemem 139 140 echo $$ > "$CPUSET/tasks" 2> $CPUSET_TMP/stderr 141 if [ $? -ne 0 ]; then 142 cpuset_log_error $CPUSET_TMP/stderr 143 tst_resm TFAIL "moving self to root group failed" 144 return 1 145 fi 146 147 local i 148 for i in $(seq 0 9) 149 do 150 if [ $(cat "$CPUSET/cpuset.memory_pressure") -ne 0 ]; then 151 tst_resm TFAIL "root group's memory_pressure had memory pressure rate." 152 return 1 153 fi 154 if [ $(cat "$CPUSET/sub_cpuset/cpuset.memory_pressure") -eq 0 ]; then 155 tst_resm TFAIL "sub group's memory_pressure didn't have memory pressure rate." 156 return 1 157 fi 158 done 159} 160 161test5() 162{ 163 echo 1 > "$CPUSET/cpuset.memory_pressure_enabled" 2> $CPUSET_TMP/stderr 164 if [ $? -ne 0 ]; then 165 cpuset_log_error $CPUSET_TMP/stderr 166 tst_resm TFAIL "Opening memory_pressure_enabled failed." 167 return 1 168 fi 169 170 cpuset_set "$CPUSET/sub_cpuset" "0" "0" "0" 2> $CPUSET_TMP/stderr 171 if [ $? -ne 0 ]; then 172 cpuset_log_error $CPUSET_TMP/stderr 173 tst_resm TFAIL "set general group parameter failed." 174 return 1 175 fi 176 177 cpuset_memory_pressure $usemem 178 local i 179 for i in $(seq 0 9) 180 do 181 if [ $(cat "$CPUSET/cpuset.memory_pressure") -eq 0 ]; then 182 tst_resm TFAIL "root group's memory_pressure didn't have memory pressure rate." 183 return 1 184 fi 185 if [ $(cat "$CPUSET/sub_cpuset/cpuset.memory_pressure") -ne 0 ]; then 186 tst_resm TFAIL "sub group's memory_pressure had memory pressure rate." 187 return 1 188 fi 189 done 190} 191 192test6() 193{ 194 echo 1 > "$CPUSET/cpuset.memory_pressure_enabled" 2> $CPUSET_TMP/stderr 195 if [ $? -ne 0 ]; then 196 cpuset_log_error $CPUSET_TMP/stderr 197 tst_resm TFAIL "Opening memory_pressure_enabled failed." 198 return 1 199 fi 200 201 cpuset_set "$CPUSET/sub_cpuset" "0" "0" "0" 2> $CPUSET_TMP/stderr 202 if [ $? -ne 0 ]; then 203 cpuset_log_error $CPUSET_TMP/stderr 204 tst_resm TFAIL "set general group parameter failed." 205 return 1 206 fi 207 208 echo $$ > "$CPUSET/sub_cpuset/tasks" 2> $CPUSET_TMP/stderr 209 if [ $? -ne 0 ]; then 210 cpuset_log_error $CPUSET_TMP/stderr 211 tst_resm TFAIL "attaching self to sub group failed" 212 return 1 213 fi 214 cpuset_memory_pressure $usemem 215 216 echo $$ > "$CPUSET/tasks" 2> $CPUSET_TMP/stderr 217 if [ $? -ne 0 ]; then 218 cpuset_log_error $CPUSET_TMP/stderr 219 tst_resm TFAIL "attaching self to root group failed" 220 return 1 221 fi 222 223 cpuset_memory_pressure $usemem 224 local i 225 for i in $(seq 0 9) 226 do 227 if [ $(cat "$CPUSET/cpuset.memory_pressure") -eq 0 ]; then 228 tst_resm TFAIL "root group's memory_pressure didn't have memory pressure rate." 229 return 1 230 fi 231 if [ $(cat "$CPUSET/sub_cpuset/cpuset.memory_pressure") -eq 0 ]; then 232 tst_resm TFAIL "sub group's memory_pressure didn't have memory pressure rate." 233 return 1 234 fi 235 done 236} 237 238for c in $(seq 1 $TST_TOTAL) 239do 240 setup 241 if [ $? -ne 0 ]; then 242 exit_status=1 243 else 244 test$c 245 if [ $? -ne 0 ]; then 246 exit_status=1 247 cleanup 248 else 249 cleanup 250 if [ $? -ne 0 ]; then 251 exit_status=1 252 else 253 tst_resm TPASS "Cpuset memory pressure test succeeded." 254 fi 255 fi 256 fi 257 TST_COUNT=$(($TST_COUNT + 1)) 258done 259 260exit $exit_status 261