freeze_self_thaw.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 subshell process.
  21. # The subshell process sleeps and then freezes the control group it is a
  22. # part of. We then thaw the subshell process. We expect the unthawed subshell
  23. # process to need cleanup afterwards (allows us to test successfull thawing).
  24. #
  25. . "${CGROUPS_TESTROOT}/libcgroup_freezer"
  26. SETS_DEFAULTS="${TCID=freeze_self_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
  27. declare -r TCID
  28. declare -r TST_COUNT
  29. declare -r TST_TOTAL
  30. export TCID TST_COUNT TST_TOTAL
  31. # We replace the normal sample process with a process which sleeps, issues
  32. # the freeze command, and then sleeps some more. Little does it know that it
  33. # will be freezing the cgroup it's been assigned to.
  34. function sleep_freeze_self_sleep()
  35. {
  36. ( export sample_proc=$! ; \
  37. add_sample_proc_to_cgroup ; \
  38. tst_resm TINFO " $sample_proc freezing itself" ; \
  39. "${CG_FILE_WRITE}" "${FREEZE}" > freezer.state ; \
  40. tst_resm TINFO " $sample_proc thawed successfully" ; \
  41. exec sleep $sample_sleep ) &
  42. local rc=$?
  43. export sample_proc=$!
  44. return $rc
  45. }
  46. running_cgroup_test
  47. mount_freezer && {
  48. make_sample_cgroup && {
  49. assert_cgroup_freezer_state "THAWED" \
  50. "ERROR: cgroup freezer started in non-THAWED state" && {
  51. sleep_freeze_self_sleep && {
  52. while /bin/true ; do
  53. trap 'break' ERR
  54. tst_resm TINFO " Waiting for $sample_proc to freeze itself"
  55. # WAIT until FROZEN (see FREEZE self above)
  56. wait_until_frozen
  57. assert_sample_proc_is_frozen
  58. # THAW
  59. issue_thaw_cmd
  60. wait_until_thawed
  61. assert_sample_proc_exists
  62. assert_sample_proc_not_frozen
  63. result=$FINISHED
  64. break
  65. done
  66. trap '' ERR
  67. cleanup_cgroup_test
  68. tst_resm TINFO " Cleaning up $0"
  69. # We need to stop the sample process.
  70. kill_sample_proc ; }
  71. # no inverse op needed for assert
  72. }
  73. rm_sample_cgroup ; }
  74. umount_freezer ; }
  75. # Failsafe cleanup
  76. cleanup_freezer || /bin/true
  77. exit $result