freeze_sleep_thaw.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 wait until the sleep process should
  22. # have exited. Then we unfreeze the sleep process. We expect the
  23. # sleep process to wakeup almost immediately after the cgroup is thawed,
  24. # recognize that its expiration time has long since passed, and exit before
  25. # we get a chance to "see" it again.
  26. #
  27. . "${CGROUPS_TESTROOT}/libcgroup_freezer"
  28. SETS_DEFAULTS="${TCID=freeze_sleep_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
  29. declare -r TCID
  30. declare -r TST_COUNT
  31. declare -r TST_TOTAL
  32. export TCID TST_COUNT TST_TOTAL
  33. running_cgroup_test
  34. mount_freezer && {
  35. make_sample_cgroup && {
  36. start_sample_proc && {
  37. while /bin/true ; do
  38. trap 'break' ERR
  39. add_sample_proc_to_cgroup
  40. assert_cgroup_freezer_state "THAWED" \
  41. "ERROR: cgroup freezer started in non-THAWED state"
  42. issue_freeze_cmd
  43. wait_until_frozen
  44. assert_sample_proc_is_frozen
  45. echo -n "INFO: Waiting until sleep command should have finished ($sample_proc) ... "
  46. /bin/sleep $(($sample_sleep * 2))
  47. echo "done."
  48. # We expect the task to remain until it is thawed even though its
  49. # sleep period has long since expired.
  50. assert_sample_proc_is_frozen
  51. issue_thaw_cmd
  52. wait_until_thawed
  53. # We do NOT call
  54. # assert_task_not_frozen $sample_proc
  55. # here because we've slept past the point in time when the task should've
  56. # exited.
  57. assert_sample_proc_does_not_exist
  58. sample_proc=""
  59. result=$FINISHED
  60. break
  61. done
  62. trap '' ERR
  63. cleanup_cgroup_test
  64. tst_resm TINFO " Cleaning up $0"
  65. # We may need to stop the sample process because we could have failed before the
  66. # rest of the test caused it to stop.
  67. kill_sample_proc ; }
  68. rm_sample_cgroup ; }
  69. umount_freezer ; }
  70. # Failsafe cleanup
  71. cleanup_freezer || /bin/true
  72. exit $result