memcg_limit_in_bytes.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 Foundation, ##
  18. ## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## Author: Li Zefan <lizf@cn.fujitsu.com> ##
  21. ## Restructure for LTP: Shi Weihua <shiwh@cn.fujitsu.com> ##
  22. ## Added memcg enable/disable functinality: Rishikesh K Rajak ##
  23. ## <risrajak@linux.vnet.ibm.com ##
  24. ## ##
  25. ################################################################################
  26. TCID="memcg_limit_in_bytes"
  27. TST_TOTAL=15
  28. . memcg_lib.sh
  29. # Test mmap(locked) + alloc_mem > limit_in_bytes
  30. testcase_1()
  31. {
  32. test_proc_kill $PAGESIZE "--mmap-lock1" $((PAGESIZE*2)) 0
  33. }
  34. testcase_2()
  35. {
  36. test_proc_kill $PAGESIZE "--mmap-lock2" $((PAGESIZE*2)) 0
  37. }
  38. # Test swapoff + alloc_mem > limit_in_bytes
  39. testcase_3()
  40. {
  41. swapoff -a
  42. test_proc_kill $PAGESIZE "--mmap-anon" $((PAGESIZE*2)) 0
  43. swapon -a
  44. }
  45. testcase_4()
  46. {
  47. swapoff -a
  48. test_proc_kill $PAGESIZE "--mmap-file" $((PAGESIZE*2)) 0
  49. swapon -a
  50. }
  51. testcase_5()
  52. {
  53. swapoff -a
  54. test_proc_kill $PAGESIZE "--shm -k 18" $((PAGESIZE*2)) 0
  55. swapon -a
  56. }
  57. # Test limit_in_bytes == 0
  58. testcase_6()
  59. {
  60. test_proc_kill 0 "--mmap-anon" $PAGESIZE 0
  61. }
  62. testcase_7()
  63. {
  64. test_proc_kill 0 "--mmap-file" $PAGESIZE 0
  65. }
  66. testcase_8()
  67. {
  68. test_proc_kill 0 "--shm -k 21" $PAGESIZE 0
  69. }
  70. # Test limit_in_bytes will be aligned to PAGESIZE
  71. testcase_9()
  72. {
  73. test_limit_in_bytes $((PAGESIZE-1)) 0
  74. }
  75. testcase_10()
  76. {
  77. test_limit_in_bytes $((PAGESIZE+1)) 0
  78. }
  79. testcase_11()
  80. {
  81. test_limit_in_bytes 1 0
  82. }
  83. # Test invalid memory.limit_in_bytes
  84. testcase_12()
  85. {
  86. if tst_kvcmp -lt "2.6.31"; then
  87. EXPECT_FAIL echo -1 \> memory.limit_in_bytes
  88. else
  89. EXPECT_PASS echo -1 \> memory.limit_in_bytes
  90. fi
  91. }
  92. testcase_13()
  93. {
  94. EXPECT_FAIL echo 1.0 \> memory.limit_in_bytes
  95. }
  96. testcase_14()
  97. {
  98. EXPECT_FAIL echo 1xx \> memory.limit_in_bytes
  99. }
  100. testcase_15()
  101. {
  102. EXPECT_FAIL echo xx \> memory.limit_in_bytes
  103. }
  104. shmmax_setup
  105. LOCAL_CLEANUP=shmmax_cleanup
  106. run_tests
  107. tst_exit