memcg_regression_test.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #! /bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) 2009 FUJITSU LIMITED ##
  5. ## ##
  6. ## This program is free software; you can redistribute it and#or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation; either version 2 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, but ##
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  13. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  14. ## for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program; if not, write to the Free Software ##
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## Author: Li Zefan <lizf@cn.fujitsu.com> ##
  21. ## Added memcg enable/disable functinality: Rishikesh K Rajak ##
  22. ## <risrajak@linux.vnet.ibm.com ##
  23. ## ##
  24. ################################################################################
  25. cd $LTPROOT/testcases/bin
  26. export TCID="memcg_regression_test"
  27. export TST_TOTAL=4
  28. export TST_COUNT=1
  29. if [ "$(id -ru)" != 0 ]; then
  30. tst_brkm TBROK ignored "Test must be run as root"
  31. exit 0
  32. fi
  33. if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then
  34. tst_resm TCONF "Either memory resource controller kernel support absent"
  35. tst_resm TCONF "or feature is not enabled; skipping all memcgroup testcases."
  36. exit 0
  37. fi
  38. if tst_kvcmp -lt "2.6.30"; then
  39. tst_brkm TBROK ignored "Test should be run with kernel 2.6.30 or newer"
  40. exit 0
  41. fi
  42. #buffer can rotate and number of found bugs can actually go down
  43. #so clear the buffer to avoid this
  44. dmesg -c > /dev/null
  45. nr_bug=0
  46. nr_null=0
  47. nr_warning=0
  48. nr_lockdep=0
  49. # check_kernel_bug - check if some kind of kernel bug happened
  50. check_kernel_bug()
  51. {
  52. new_bug=`dmesg | grep -c "kernel BUG"`
  53. new_null=`dmesg | grep -c "kernel NULL pointer dereference"`
  54. new_warning=`dmesg | grep -c "^WARNING"`
  55. new_lockdep=`dmesg | grep -c "possible recursive locking detected"`
  56. # no kernel bug is detected
  57. if [ $new_bug -eq $nr_bug -a $new_warning -eq $nr_warning -a \
  58. $new_null -eq $nr_null -a $new_lockdep -eq $nr_lockdep ]; then
  59. return 1
  60. fi
  61. # some kernel bug is detected
  62. if [ $new_bug -gt $nr_bug ]; then
  63. tst_resm TFAIL "kernel BUG was detected!"
  64. fi
  65. if [ $new_warning -gt $nr_warning ]; then
  66. tst_resm TFAIL "kernel WARNING was detected!"
  67. fi
  68. if [ $new_null -gt $nr_null ]; then
  69. tst_resm "kernel NULL pointer dereference!"
  70. fi
  71. if [ $new_lockdep -gt $nr_lockdep ]; then
  72. tst_resm "kernel lockdep warning was detected!"
  73. fi
  74. nr_bug=$new_bug
  75. nr_null=$new_null
  76. nr_warning=$new_warning
  77. nr_lockdep=$new_lockdep
  78. echo "check_kernel_bug found something!"
  79. dmesg
  80. failed=1
  81. return 0
  82. }
  83. #---------------------------------------------------------------------------
  84. # Bug: The bug was, while forking mass processes, trigger memcgroup OOM,
  85. # then NULL pointer dereference may be hit.
  86. # Kernel: 2.6.25-rcX
  87. # Links: http://lkml.org/lkml/2008/4/14/38
  88. # Fix: commit e115f2d89253490fb2dbf304b627f8d908df26f1
  89. #---------------------------------------------------------------------------
  90. test_1()
  91. {
  92. mkdir memcg/0/
  93. echo 0 > memcg/0/memory.limit_in_bytes
  94. ./memcg_test_1
  95. rmdir memcg/0/
  96. check_kernel_bug
  97. if [ $? -eq 1 ]; then
  98. tst_resm TPASS "no kernel bug was found"
  99. fi
  100. }
  101. #---------------------------------------------------------------------------
  102. # Bug: Shrink memory might never return, unless send signal to stop it.
  103. # Kernel: 2.6.29
  104. # Links: http://marc.info/?t=123199973900003&r=1&w=2
  105. # http://lkml.org/lkml/2009/2/3/72
  106. # Fix: 81d39c20f5ee2437d71709beb82597e2a38efbbc
  107. #---------------------------------------------------------------------------
  108. test_2()
  109. {
  110. ./memcg_test_2 &
  111. pid1=$!
  112. sleep 1
  113. mkdir memcg/0
  114. echo $pid1 > memcg/0/tasks
  115. # let pid1 'test_2' allocate memory
  116. /bin/kill -SIGUSR1 $pid1
  117. sleep 1
  118. # shrink memory
  119. echo 1 > memcg/0/memory.limit_in_bytes 2>&1 &
  120. pid2=$!
  121. # check if 'echo' will exit and exit with failure
  122. for tmp in $(seq 0 4); do
  123. sleep 1
  124. ps -p $! > /dev/null
  125. if [ $? -ne 0 ]; then
  126. wait $pid2
  127. if [ $? -eq 0 ]; then
  128. tst_resm TFAIL "echo should return failure"
  129. failed=1
  130. kill -9 $pid1 $pid2 > /dev/null 2>&1
  131. wait $pid1 $pid2
  132. rmdir memcg/0
  133. fi
  134. break
  135. fi
  136. done
  137. if [ $tmp -eq 5 ]; then
  138. tst_resm TFAIL "'echo' doesn't exit!"
  139. failed=1
  140. else
  141. tst_resm TPASS "EBUSY was returned as expected"
  142. fi
  143. kill -9 $pid1 $pid2 > /dev/null 2>&1
  144. wait $pid1 $pid2 > /dev/null 2>&1
  145. rmdir memcg/0
  146. }
  147. #---------------------------------------------------------------------------
  148. # Bug: crash when rmdir a cgroup on IA64
  149. # Kernel: 2.6.29-rcX
  150. # Links: http://marc.info/?t=123235660300001&r=1&w=2
  151. # Fix: commit 299b4eaa302138426d5a9ecd954de1f565d76c94
  152. #---------------------------------------------------------------------------
  153. test_3()
  154. {
  155. mkdir memcg/0
  156. for pid in `cat memcg/tasks`; do
  157. echo $pid > memcg/0/tasks 2> /dev/null
  158. done
  159. for pid in `cat memcg/0/tasks`; do
  160. echo $pid > memcg/tasks 2> /dev/null
  161. done
  162. rmdir memcg/0
  163. check_kernel_bug
  164. if [ $? -eq 1 ]; then
  165. tst_resm TPASS "no kernel bug was found"
  166. fi
  167. }
  168. #---------------------------------------------------------------------------
  169. # Bug: the memcg's refcnt handling at swapoff was wrong, causing crash
  170. # Kernel: 2.6.29-rcX
  171. # Links: http://marc.info/?t=123208656300004&r=1&w=2
  172. # Fix: commit 85d9fc89fb0f0703df6444f260187c088a8d59ff
  173. #---------------------------------------------------------------------------
  174. test_4()
  175. {
  176. ./memcg_test_4.sh
  177. check_kernel_bug
  178. if [ $? -eq 1 ]; then
  179. tst_resm TPASS "no kernel bug was found"
  180. fi
  181. # test_4.sh might be killed by oom, so do clean up here
  182. killall -9 memcg_test_4 2> /dev/null
  183. killall -9 memcg_test_4.sh 2> /dev/null
  184. # if test_4.sh gets killed, it won't clean cgroup it created
  185. rmdir memcg/0 2> /dev/null
  186. swapon -a
  187. }
  188. # main
  189. failed=0
  190. mkdir memcg/
  191. for cur in $(seq 1 $TST_TOTAL); do
  192. export TST_COUNT=$cur
  193. mount -t cgroup -o memory xxx memcg/
  194. if [ $? -ne 0 ]; then
  195. tst_resm TFAIL "failed to mount memory subsystem"
  196. failed=1
  197. continue
  198. fi
  199. test_$cur
  200. umount memcg/
  201. done
  202. rmdir memcg/
  203. exit $failed