freeze_move_thaw.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # Copyright (c) International Business Machines Corp., 2008
  3. # Author: Matt Helsley <matthltc@us.ibm.com>
  4. #
  5. # This library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9. #
  10. # This library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public
  16. # License along with this library; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. #
  20. # This bash script tests freezer code by starting a long sleep process.
  21. # The sleep process is frozen. We then move the sleep process to a THAWED
  22. # cgroup. We expect moving the sleep process to fail. [While developing
  23. # the cgroup freezer it was undecided whether moving would fail or it would
  24. # cause the frozen task to thaw. If it causes the task to thaw then replace the
  25. # previous sentence with "We expect the moving task to thaw.". This note can
  26. # be removed once the cgroup freezer is in mainline. ]
  27. #
  28. . "${CGROUPS_TESTROOT}/libcgroup_freezer"
  29. SETS_DEFAULTS="${TCID=freeze_move_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
  30. declare -r TCID
  31. declare -r TST_COUNT
  32. declare -r TST_TOTAL
  33. export TCID TST_COUNT TST_TOTAL
  34. running_cgroup_test
  35. mount_freezer && {
  36. make_sample_cgroup_named "child2" && {
  37. make_sample_cgroup && {
  38. start_sample_proc && {
  39. while /bin/true ; do
  40. trap 'break' ERR
  41. assert_cgroup_freezer_state "THAWED" \
  42. "ERROR: cgroup freezer started in non-THAWED state"
  43. add_sample_proc_to_cgroup
  44. # FREEZE
  45. issue_freeze_cmd
  46. wait_until_frozen
  47. assert_sample_proc_is_frozen
  48. # MOVE
  49. "${CG_FILE_WRITE}" $sample_proc > "$(dirname $(pwd))/child2/tasks" 2> /dev/null && {
  50. result=${result:-1}
  51. /bin/false
  52. } || {
  53. /bin/true
  54. }
  55. # IF the semantics are: the moved task is unfrozen THEN remove everthing
  56. # after "2> /dev/null" in the line above (don't redirect stdder and
  57. # don't invert the result)
  58. # This block of comments can be removed once the cgroup freezer has
  59. # been added to mainline.
  60. sleep 1
  61. assert_sample_proc_is_frozen
  62. assert_sample_proc_in_cgroup
  63. assert_sample_proc_not_in_named_cgroup "$(dirname $(pwd))/child2"
  64. # IF the semantics are: the moved task is unfrozen THEN replace the
  65. # asserts above with these and make the THAW section consistent:
  66. # assert_sample_proc_not_in_cgroup # it's in child2 after all
  67. # assert_sample_proc_in_named_cgroup "$(dirname $(pwd))/child2"
  68. # assert_sample_proc_not_frozen
  69. # This block of comments can be removed once the cgroup freezer has
  70. # been added to mainline.
  71. # THAW
  72. issue_thaw_cmd
  73. wait_until_thawed
  74. assert_sample_proc_not_frozen
  75. assert_sample_proc_in_cgroup
  76. assert_sample_proc_not_in_named_cgroup "$(dirname $(pwd))/child2"
  77. # IF the semantics are: the moved task is unfrozen before adding to
  78. # child2 THEN
  79. # assert_sample_proc_not_frozen
  80. # assert_sample_proc_not_in_cgroup
  81. # assert_sample_proc_in_named_cgroup "$(dirname $(pwd))/child2"
  82. # This block of comments can be removed once the cgroup freezer has
  83. # been added to mainline.
  84. result=$FINISHED
  85. break
  86. done
  87. trap '' ERR
  88. cleanup_cgroup_test
  89. tst_resm TINFO " Cleaning up $0"
  90. # We may need to stop the sample process because we could have failed before the
  91. # rest of the test caused it to stop.
  92. kill_sample_proc ; }
  93. rm_sample_cgroup ; }
  94. rm_sample_cgroup_named "child2" ; }
  95. umount_freezer ; }
  96. # Failsafe cleanup
  97. cleanup_freezer || /bin/true
  98. exit $result