cgroup_regression_test.sh revision c5d8805b5dc5cf79b729ff3b60617649e2f9ea0c
1#! /bin/bash 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: Li Zefan <lizf@cn.fujitsu.com> ## 22## ## 23################################################################################ 24 25cd $LTPROOT/testcases/bin 26 27export TCID="cgroup_regression_test" 28export TST_TOTAL=10 29export TST_COUNT=1 30 31if [ ! -f /proc/cgroups ]; then 32 echo "CONTROLLERS TESTCASES: WARNING" 33 echo "Kernel does not support for control groups"; 34 echo "Skipping all controllers testcases...."; 35 exit 0 36fi 37 38if [ "$USER" != root ]; then 39 tst_brkm TBROK ignored "Test must be run as root" 40 exit 0 41fi 42 43tst_kvercmp 2 6 29 44if [ $? -eq 0 ]; then 45 tst_brkm TBROK ignored "Test should be run with kernel 2.6.29 or newer" 46 exit 1 47fi 48 49nr_bug=`dmesg | grep -c "kernel BUG"` 50nr_null=`dmesg | grep -c "kernel NULL pointer dereference"` 51nr_warning=`dmesg | grep -c "^WARNING"` 52nr_lockdep=`dmesg | grep -c "possible recursive locking detected"` 53 54# check_kernel_bug - check if some kind of kernel bug happened 55check_kernel_bug() 56{ 57 new_bug=`dmesg | grep -c "kernel BUG"` 58 new_null=`dmesg | grep -c "kernel NULL pointer dereference"` 59 new_warning=`dmesg | grep -c "^WARNING"` 60 new_lockdep=`dmesg | grep -c "possible recursive locking detected"` 61 62 # no kernel bug is detected 63 if [ $new_bug -eq $nr_bug -a $new_warning -eq $nr_warning -a \ 64 $new_null -eq $nr_null -a $new_lockdep -eq $nr_lockdep ]; then 65 return 1 66 fi 67 68 # some kernel bug is detected 69 if [ $new_bug -gt $nr_bug ]; then 70 tst_resm TFAIL "kernel BUG was detected!" 71 fi 72 if [ $new_warning -gt $nr_warning ]; then 73 tst_resm TFAIL "kernel WARNING was detected!" 74 fi 75 if [ $new_null -gt $nr_null ]; then 76 tst_resm TFAIL "kernel NULL pointer dereference!" 77 fi 78 if [ $new_lockdep -gt $nr_lockdep ]; then 79 tst_resm TFAIL "kernel lockdep warning was detected!" 80 fi 81 82 nr_bug=$new_bug 83 nr_null=$new_null 84 nr_warning=$new_warning 85 nr_lockdep=$new_lockdep 86 87 failed=1 88 return 0 89} 90 91#--------------------------------------------------------------------------- 92# Bug: There was a race when keeping forking processes and at the same 93# time cat /cgroup/tasks (should be the very first time to read 94# /cgroup/tasks, otherwise this bug won't be triggered) 95# Kernel: 2.6.24, 2.6.25-rcX 96# Links: http://lkml.org/lkml/2007/10/17/224 97# http://lkml.org/lkml/2008/3/5/332 98# http://lkml.org/lkml/2008/4/16/493 99# Fix: commit 0e04388f0189fa1f6812a8e1cb6172136eada87e 100#--------------------------------------------------------------------------- 101test_1() 102{ 103 ./fork_processes & 104 sleep 1 105 106 mount -t cgroup xxx cgroup/ 107 if [ $? -ne 0 ]; then 108 tst_resm TFAIL "failed to mount cgroup filesystem" 109 failed=1 110 /bin/kill -SIGTERM $! 111 return 112 fi 113 cat cgroup/tasks > /dev/null 114 115 check_kernel_bug 116 if [ $? -eq 1 ]; then 117 tst_resm TPASS "no kernel bug was found" 118 fi 119 120 /bin/kill -SIGTERM $! 121 wait $! 122 umount cgroup/ 123} 124 125#--------------------------------------------------------------------------- 126# Bug: a cgroup's notify_on_release flag did not inherit from its parent. 127# Kernel: 2.6.24-rcX 128# Links: http://lkml.org/lkml/2008/2/25/12 129# Fix: commit bc231d2a048010d5e0b49ac7fddbfa822fc41109 130#--------------------------------------------------------------------------- 131test_2() 132{ 133 mount -t cgroup xxx cgroup/ 134 if [ $? -ne 0 ]; then 135 tst_resm TFAIL "Failed to mount cgroup filesystem" 136 failed=1 137 return 1 138 fi 139 140 echo 0 > cgroup/notify_on_release 141 mkdir cgroup/0 142 val1=`cat cgroup/0/notify_on_release` 143 144 echo 1 > cgroup/notify_on_release 145 mkdir cgroup/1 146 val2=`cat cgroup/1/notify_on_release` 147 148 if [ $val1 -ne 0 -o $val2 -ne 1 ]; then 149 tst_resm TFAIL "wrong notify_on_release value" 150 failed=1 151 else 152 tst_resm TPASS "notify_on_release is inherited" 153 fi 154 155 rmdir cgroup/0 cgroup/1 156 umount cgroup/ 157 158 return $failed 159} 160 161#--------------------------------------------------------------------------- 162# Bug: Accessing NULL cgrp->dentry when reading /proc/sched_debug 163# Kernel: 2.6.26-2.6.28 164# Links: http://lkml.org/lkml/2008/10/30/44 165# http://lkml.org/lkml/2008/12/12/107 166# http://lkml.org/lkml/2008/12/16/481 167# Fix: commit a47295e6bc42ad35f9c15ac66f598aa24debd4e2 168#--------------------------------------------------------------------------- 169test_3() 170{ 171 if [ ! -e /proc/sched_debug ]; then 172 tst_resm TCONF "CONFIG_SCHED_DEBUG is not enabled" 173 return 174 fi 175 176 grep -q -w "cpu" /proc/cgroups 177 if [ $? -ne 0 ]; then 178 tst_resm TCONF "CONFIG_CGROUP_SCHED is not enabled" 179 return 180 fi 181 182 # Run the test for 30 secs 183 mount -t cgroup -o cpu xxx cgroup/ 184 if [ $? -ne 0 ]; then 185 tst_resm TFAIL "Failed to mount cpu subsys" 186 failed=1 187 return 188 fi 189 190 ./test_3_1.sh & 191 pid1=$! 192 ./test_3_2.sh & 193 pid2=$! 194 195 sleep 30 196 /bin/kill -SIGUSR1 $pid1 $pid2 197 wait $pid1 198 wait $pid2 199 200 check_kernel_bug 201 if [ $? -eq 1 ]; then 202 tst_resm TPASS "no kernel bug was found" 203 fi 204 205 rmdir cgroup/* 2> /dev/null 206 umount cgroup/ 207} 208 209#--------------------------------------------------------------------------- 210# Bug: cgroup hierarchy lock's lockdep subclass may overflow 211# Kernel: 2.6.29-rcX 212# Link: http://lkml.org/lkml/2009/2/4/67 213# Fix: 214#--------------------------------------------------------------------------- 215test_4() 216{ 217 if [ ! -e /proc/lockdep ]; then 218 tst_resm TCONF "CONFIG_LOCKDEP is not enabled" 219 return 220 fi 221 222 # MAX_LOCKDEP_SUBCLASSES is 8, so number of subsys should be > 8 223 lines=`cat /proc/cgroups | wc -l` 224 if [ $lines -le 9 ]; then 225 tst_resm TCONF "require more than 8 cgroup subsystems" 226 return 227 fi 228 229 mount -t cgroup xxx cgroup/ 230 mkdir cgroup/0 231 rmdir cgroup/0 232 umount cgroup/ 233 234 dmesg | grep -q "MAX_LOCKDEP_SUBCLASSES too low" 235 if [ $? -eq 0 ]; then 236 tst_resm TFAIL "lockdep BUG was found" 237 failed=1 238 return 239 else 240 tst_resm TPASS "no lockdep BUG was found" 241 fi 242} 243 244#--------------------------------------------------------------------------- 245# Bug: When mount cgroup fs and the fs was busy, root_count should not be 246# decremented in cgroup_kill_sb() 247# Kernel: 2.6.29-rcX 248# Links: https://openvz.org/pipermail/devel/2009-January/016345.html 249# http://lkml.org/lkml/2009/1/28/190 250# Fix: commit 839ec5452ebfd5905b9c69b20ceb640903a8ea1a 251#--------------------------------------------------------------------------- 252test_5() 253{ 254 lines=`cat /proc/cgroups | wc -l` 255 if [ $lines -le 2 ]; then 256 tst_resm TCONF "require at least 2 cgroup subsystems" 257 return 258 fi 259 260 subsys1=`tail -n 1 /proc/cgroups | awk '{ print $1 }'` 261 subsys2=`tail -n 2 /proc/cgroups | head -1 | awk '{ print $1 }'` 262 263 mount -t cgroup -o $subsys1,$subsys xxx cgroup/ 264 if [ $? -ne 0 ]; then 265 tst_resm TFAIL "mount $subsys1 and $subsys2 failed" 266 failed=1 267 return 268 fi 269 270 # This 2nd mount should fail 271 mount -t cgroup -o $subsys1 xxx cgroup/ 2> /dev/null 272 if [ $? -eq 0 ]; then 273 tst_resm TFAIL "mount $subsys1 should fail" 274 umount cgroup/ 275 failed=1 276 return 277 fi 278 279 mkdir cgroup/0 280 # Otherwise we can't attach task 281 if [ "$subsys1" == cpuset -o "$subsys2" == cpuset ]; then 282 echo 0 > cgroup/0/cpuset.cpus 2> /dev/null 283 echo 0 > cgroup/0/cpuset.mems 2> /dev/null 284 fi 285 286 sleep 100 & 287 echo $! > cgroup/0/tasks 288 289 check_kernel_bug 290 if [ $? -eq 1 ]; then 291 tst_resm TPASS "no kernel bug was found" 292 fi 293 294 # clean up 295 /bin/kill -SIGTERM $! > /dev/null 296 wait $! 297 rmdir cgroup/0 298 umount cgroup/ 299} 300 301#--------------------------------------------------------------------------- 302# Bug: There was a race between cgroup_clone and umount 303# Kernel: 2.6.24 - 2.6.28, 2.6.29-rcX 304# Links: http://lkml.org/lkml/2008/12/24/124 305# Fix: commit 7b574b7b0124ed344911f5d581e9bc2d83bbeb19 306#--------------------------------------------------------------------------- 307test_6() 308{ 309 grep -q -w "ns" /proc/cgroups 310 if [ $? -ne 0 ]; then 311 tst_resm TCONF "CONFIG_CGROUP_NS" 312 return 313 fi 314 315 # run the test for 30 secs 316 ./test_6_1.sh & 317 pid1=$! 318 ./test_6_2 & 319 pid2=$! 320 321 sleep 30 322 /bin/kill -SIGUSR1 $pid1 323 /bin/kill -SIGTERM $pid2 324 wait $pid1 325 wait $pid2 326 327 check_kernel_bug 328 if [ $? -eq 1 ]; then 329 tst_resm TPASS "no kernel bug was found" 330 fi 331 332 # clean up 333 mount -t cgroup -o ns xxx cgroup/ > /dev/null 2>&1 334 rmdir cgroup/[1-9] > /dev/null 2>&1 335 umount cgroup/ 336} 337 338#--------------------------------------------------------------------------- 339# Bug: There was a bug when remount cgroup fs with some dead subdirs in 340# it (rmdir()ed but still has some refcnts on it). It caused memory 341# leak, and may cause oops when cat /proc/sched_debug. 342# Kernel: 2.6.24 - 2.6.27, 2.6.28-rcX 343# Links: http://lkml.org/lkml/2008/12/10/369 344# Fix: commit 307257cf475aac25db30b669987f13d90c934e3a 345#--------------------------------------------------------------------------- 346test_7_1() 347{ 348 mount -t cgroup -o $subsys xxx cgroup/ 349 if [ $? -ne 0 ]; then 350 tst_resm TFAIL "failed to mount $subsys" 351 failed=1 352 return 353 fi 354 355 mkdir cgroup/0 356 sleep 100 < cgroup/0 & # add refcnt to this dir 357 rmdir cgroup/0 358 359 # remount with new subsystems added 360 # since 2.6.28, this remount will fail 361 mount -t cgroup -o remount xxx cgroup/ 2> /dev/null 362 /bin/kill -SIGTERM $! 363 wait $! 364 umount cgroup/ 365} 366 367test_7_2() 368{ 369 mount -t cgroup xxx cgroup/ 370 if [ $? -ne 0 ]; then 371 tst_resm TFAIL "failed to mount $subsys" 372 failed=1 373 return 374 fi 375 376 mkdir cgroup/0 377 sleep 100 < cgroup/0 & # add refcnt to this dir 378 rmdir cgroup/0 379 380 # remount with some subsystems removed 381 # since 2.6.28, this remount will fail 382 mount -t cgroup -o remount,$subsys xxx cgroup/ 2> /dev/null 383 /bin/kill -SIGTERM $! 384 wait $! 385 umount cgroup/ 386 387 # due to the bug, reading /proc/sched_debug may lead to oops 388 grep -q -w "cpu" /proc/cgroups 389 if [ $? -ne 0 -o ! -e /proc/sched_debug ]; then 390 return 391 fi 392 393 for ((tmp = 0; tmp < 50; tmp++)) 394 { 395 echo 3 > /proc/sys/vm/drop_caches 396 cat /proc/sched_debug > /dev/null 397 } 398} 399 400test_7() 401{ 402 lines=`cat /proc/cgroups | wc -l` 403 if [ $lines -le 2 ]; then 404 tst_resm TCONF "require at least 2 cgroup subsystems" 405 slt_result $SLT_Untested 406 return 407 fi 408 409 subsys=`tail -n 1 /proc/cgroups | awk '{ print $1 }'` 410 411 # remount to add new subsystems to the hierarchy 412 for ((i = 1; i <= 2; i++)) 413 { 414 test_7_$i 415 if [ $? -ne 0 ]; then 416 return 417 fi 418 419 check_kernel_bug 420 if [ $? -eq 0 ]; then 421 return 422 fi 423 } 424 425 tst_resm TPASS "no kernel bug was found" 426} 427 428#--------------------------------------------------------------------------- 429# Bug: oops when get cgroupstat of a cgroup control file 430# Kernel: 2.6.24 - 2.6.27, 2.6.28-rcX 431# Links: http://lkml.org/lkml/2008/11/19/53 432# Fix: commit 33d283bef23132c48195eafc21449f8ba88fce6b 433#--------------------------------------------------------------------------- 434test_8() 435{ 436 mount -t cgroup xxx cgroup/ 437 if [ $? -ne 0 ]; then 438 tst_resm TFAIL "failed to mount cgroup filesystem" 439 failed=1 440 return 441 fi 442 443 ./getdelays -C cgroup/tasks > /dev/null 2>&1 444 if [ $? -eq 0 ]; then 445 tst_resm TFAIL "should have failed to get cgroupstat of tasks file" 446 umount cgroup/ 447 failed=1 448 return 449 fi 450 451 check_kernel_bug 452 if [ $? -eq 1 ]; then 453 tst_resm TPASS "no kernel bug was found" 454 fi 455 456 umount cgroup/ 457} 458 459#--------------------------------------------------------------------------- 460# Bug: When running 2 concurrent mount/umount threads, lockdep warning 461# may be triggered, it's a false positive, and it's VFS' issue but 462# not cgroup. 463# Kernel: 2.6.24 - 2.6.29-rcX 464# Links: http://lkml.org/lkml/2009/1/4/352 465# Fix: commit ada723dcd681e2dffd7d73345cc8fda0eb0df9bd 466#--------------------------------------------------------------------------- 467test_9() 468{ 469 ./test_9_1.sh & 470 pid1=$! 471 ./test_9_2.sh & 472 pid2=$! 473 474 sleep 30 475 /bin/kill -SIGUSR1 $pid1 $pid2 476 wait $pid1 477 wait $pid2 478 479 umount cgroup/ 2> /dev/null 480 481 check_kernel_bug 482 if [ $? -eq 1 ]; then 483 tst_resm TPASS "no kernel warning was found" 484 fi 485} 486 487#--------------------------------------------------------------------------- 488# Bug: When running 2 concurrent mount/umount threads, kernel WARNING 489# may be triggered, but it's VFS' issue but not cgroup. 490# Kernel: 2.6.24 - 2.6.29-rcX 491# Links: http://lkml.org/lkml/2009/1/4/354 492# Fix: commit 1a88b5364b535edaa321d70a566e358390ff0872 493#--------------------------------------------------------------------------- 494test_10() 495{ 496 ./test_10_1.sh & 497 pid1=$! 498 ./test_10_2.sh & 499 pid2=$! 500 501 sleep 30 502 /bin/kill -SIGUSR1 $pid1 $pid2 503 wait $pid1 504 wait $pid2 505 506 rmdir cgroup/0 2> /dev/null 507 umount cgroup/ 2> /dev/null 508 509 check_kernel_bug 510 if [ $? -eq 1 ]; then 511 tst_resm TPASS "no kernel warning was found" 512 fi 513} 514 515# main 516 517mkdir cgroup/ 518 519for ((cur = 1; cur <= $TST_TOTAL; cur++)) 520{ 521 export TST_COUNT=$cur 522 523 test_$cur 524} 525 526rmdir cgroup/ 527 528exit $failed 529 530