stop_freeze_sleep_thaw_cont.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 stopped and then frozen. We then thaw the process
  22. # after it normally would have exited.
  23. # We expect the process to still be around as we cleanup the test.
  24. #
  25. . "${CGROUPS_TESTROOT}/libcgroup_freezer"
  26. SETS_DEFAULTS="${TCID=stop_freeze_sleep_thaw_cont.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. running_cgroup_test
  32. mount_freezer && {
  33. make_sample_cgroup && {
  34. start_sample_proc && {
  35. while /bin/true ; do
  36. trap 'break' ERR
  37. assert_cgroup_freezer_state "THAWED" \
  38. "ERROR: cgroup freezer started in non-THAWED state"
  39. add_sample_proc_to_cgroup
  40. kill -SIGSTOP $sample_proc
  41. # TODO: reliably fix race between signal and assertion?
  42. /bin/sleep 1
  43. assert_sample_proc_stopped
  44. issue_freeze_cmd
  45. wait_until_frozen
  46. assert_sample_proc_is_frozen
  47. echo -n "INFO: Waiting until sleep command should have finished ($sample_proc) ... "
  48. /bin/sleep $(($sample_sleep * 2))
  49. echo "done."
  50. issue_thaw_cmd
  51. wait_until_thawed
  52. assert_sample_proc_exists
  53. assert_sample_proc_not_frozen
  54. assert_sample_proc_stopped
  55. kill -SIGCONT $sample_proc
  56. # TODO: reliably fix race between signal and assertion?
  57. /bin/sleep 1
  58. assert_sample_proc_does_not_exist
  59. # We don't need to kill the sample process.
  60. sample_proc=""
  61. result=$FINISHED
  62. break
  63. done
  64. trap '' ERR
  65. cleanup_cgroup_test
  66. tst_resm TINFO " Cleaning up $0"
  67. # We may not need to kill the sample process.
  68. kill_sample_proc ; }
  69. rm_sample_cgroup ; }
  70. umount_freezer ; }
  71. # Failsafe cleanup
  72. cleanup_freezer || /bin/true
  73. exit $result