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: Li Zefan <lizf (at] cn.fujitsu.com> ## 22 ## Added memcg enable/disable functinality: Rishikesh K Rajak ## 23 ## <risrajak (at] linux.vnet.ibm.com ## 24 ## ## 25 ################################################################################ 26 27 cd $LTPROOT/testcases/bin 28 29 export TCID="memcg_regression_test" 30 export TST_TOTAL=4 31 export TST_COUNT=1 32 33 if [ "$(id -ru)" != 0 ]; then 34 tst_brkm TBROK ignored "Test must be run as root" 35 exit 0 36 fi 37 38 if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then 39 tst_resm TCONF "Either memory resource controller kernel support absent" 40 tst_resm TCONF "or feature is not enabled; skipping all memcgroup testcases." 41 exit 0 42 fi 43 44 tst_kvercmp 2 6 30 45 if [ $? -eq 0 ]; then 46 tst_brkm TBROK ignored "Test should be run with kernel 2.6.30 or newer" 47 exit 0 48 fi 49 50 #buffer can rotate and number of found bugs can actually go down 51 #so clear the buffer to avoid this 52 dmesg -c > /dev/null 53 nr_bug=0 54 nr_null=0 55 nr_warning=0 56 nr_lockdep=0 57 58 # check_kernel_bug - check if some kind of kernel bug happened 59 check_kernel_bug() 60 { 61 new_bug=`dmesg | grep -c "kernel BUG"` 62 new_null=`dmesg | grep -c "kernel NULL pointer dereference"` 63 new_warning=`dmesg | grep -c "^WARNING"` 64 new_lockdep=`dmesg | grep -c "possible recursive locking detected"` 65 66 # no kernel bug is detected 67 if [ $new_bug -eq $nr_bug -a $new_warning -eq $nr_warning -a \ 68 $new_null -eq $nr_null -a $new_lockdep -eq $nr_lockdep ]; then 69 return 1 70 fi 71 72 # some kernel bug is detected 73 if [ $new_bug -gt $nr_bug ]; then 74 tst_resm TFAIL "kernel BUG was detected!" 75 fi 76 if [ $new_warning -gt $nr_warning ]; then 77 tst_resm TFAIL "kernel WARNING was detected!" 78 fi 79 if [ $new_null -gt $nr_null ]; then 80 tst_resm "kernel NULL pointer dereference!" 81 fi 82 if [ $new_lockdep -gt $nr_lockdep ]; then 83 tst_resm "kernel lockdep warning was detected!" 84 fi 85 86 nr_bug=$new_bug 87 nr_null=$new_null 88 nr_warning=$new_warning 89 nr_lockdep=$new_lockdep 90 91 echo "check_kernel_bug found something!" 92 dmesg 93 failed=1 94 return 0 95 } 96 97 #--------------------------------------------------------------------------- 98 # Bug: The bug was, while forking mass processes, trigger memcgroup OOM, 99 # then NULL pointer dereference may be hit. 100 # Kernel: 2.6.25-rcX 101 # Links: http://lkml.org/lkml/2008/4/14/38 102 # Fix: commit e115f2d89253490fb2dbf304b627f8d908df26f1 103 #--------------------------------------------------------------------------- 104 test_1() 105 { 106 mkdir memcg/0/ 107 echo 0 > memcg/0/memory.limit_in_bytes 108 109 ./memcg_test_1 110 111 rmdir memcg/0/ 112 113 check_kernel_bug 114 if [ $? -eq 1 ]; then 115 tst_resm TPASS "no kernel bug was found" 116 fi 117 } 118 119 #--------------------------------------------------------------------------- 120 # Bug: Shrink memory might never return, unless send signal to stop it. 121 # Kernel: 2.6.29 122 # Links: http://marc.info/?t=123199973900003&r=1&w=2 123 # http://lkml.org/lkml/2009/2/3/72 124 # Fix: 81d39c20f5ee2437d71709beb82597e2a38efbbc 125 #--------------------------------------------------------------------------- 126 test_2() 127 { 128 ./memcg_test_2 & 129 pid1=$! 130 sleep 1 131 132 mkdir memcg/0 133 echo $pid1 > memcg/0/tasks 134 135 # let pid1 'test_2' allocate memory 136 /bin/kill -SIGUSR1 $pid1 137 sleep 1 138 139 # shrink memory 140 echo 1 > memcg/0/memory.limit_in_bytes 2>&1 & 141 pid2=$! 142 143 # check if 'echo' will exit and exit with failure 144 for tmp in $(seq 0 4); do 145 sleep 1 146 ps -p $! > /dev/null 147 if [ $? -ne 0 ]; then 148 wait $pid2 149 if [ $? -eq 0 ]; then 150 tst_resm TFAIL "echo should return failure" 151 failed=1 152 kill -9 $pid1 $pid2 > /dev/null 2>&1 153 wait $pid1 $pid2 154 rmdir memcg/0 155 fi 156 break 157 fi 158 done 159 160 if [ $tmp -eq 5 ]; then 161 tst_resm TFAIL "'echo' doesn't exit!" 162 failed=1 163 else 164 tst_resm TPASS "EBUSY was returned as expected" 165 fi 166 167 kill -9 $pid1 $pid2 > /dev/null 2>&1 168 wait $pid1 $pid2 > /dev/null 2>&1 169 rmdir memcg/0 170 } 171 172 #--------------------------------------------------------------------------- 173 # Bug: crash when rmdir a cgroup on IA64 174 # Kernel: 2.6.29-rcX 175 # Links: http://marc.info/?t=123235660300001&r=1&w=2 176 # Fix: commit 299b4eaa302138426d5a9ecd954de1f565d76c94 177 #--------------------------------------------------------------------------- 178 test_3() 179 { 180 mkdir memcg/0 181 for pid in `cat memcg/tasks`; do 182 echo $pid > memcg/0/tasks 2> /dev/null 183 done 184 185 for pid in `cat memcg/0/tasks`; do 186 echo $pid > memcg/tasks 2> /dev/null 187 done 188 rmdir memcg/0 189 190 check_kernel_bug 191 if [ $? -eq 1 ]; then 192 tst_resm TPASS "no kernel bug was found" 193 fi 194 } 195 196 #--------------------------------------------------------------------------- 197 # Bug: the memcg's refcnt handling at swapoff was wrong, causing crash 198 # Kernel: 2.6.29-rcX 199 # Links: http://marc.info/?t=123208656300004&r=1&w=2 200 # Fix: commit 85d9fc89fb0f0703df6444f260187c088a8d59ff 201 #--------------------------------------------------------------------------- 202 test_4() 203 { 204 ./memcg_test_4.sh 205 206 check_kernel_bug 207 if [ $? -eq 1 ]; then 208 tst_resm TPASS "no kernel bug was found" 209 fi 210 211 # test_4.sh might be killed by oom, so do clean up here 212 killall -9 memcg_test_4 2> /dev/null 213 killall -9 memcg_test_4.sh 2> /dev/null 214 215 # if test_4.sh gets killed, it won't clean cgroup it created 216 rmdir memcg/0 2> /dev/null 217 218 swapon -a 219 } 220 221 # main 222 failed=0 223 mkdir memcg/ 224 225 for cur in $(seq 1 $TST_TOTAL); do 226 export TST_COUNT=$cur 227 228 mount -t cgroup -o memory xxx memcg/ 229 if [ $? -ne 0 ]; then 230 tst_resm TFAIL "failed to mount memory subsytem" 231 failed=1 232 continue 233 fi 234 235 test_$cur 236 237 umount memcg/ 238 done 239 240 rmdir memcg/ 241 242 exit $failed 243 244