fork_freeze.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Copyright (c) International Business Machines Corp., 2009
  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 thaw the process before it exits.
  22. # We expect the process to still be alive as we cleanup the test.
  23. #
  24. SETS_DEFAULTS="${CGROUPS_TESTROOT=..} ${TCID=fork_freeze.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
  25. . "${CGROUPS_TESTROOT}/libcgroup_freezer"
  26. . "${CGROUPS_TESTROOT}/libltp"
  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 "${CGROUPS_TESTROOT}/timed_forkbomb" 4 && {
  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. echo "go" >> /proc/$sample_proc/fd/0
  41. sleep "0.5s"
  42. issue_freeze_cmd
  43. wait_until_frozen
  44. assert_sample_proc_is_frozen
  45. issue_thaw_cmd
  46. wait_until_thawed
  47. assert_sample_proc_not_frozen
  48. sleep 4
  49. result=$FINISHED
  50. break
  51. done
  52. trap '' ERR
  53. cleanup_cgroup_test
  54. tst_resm TINFO " Cleaning up $0"
  55. # We need to kill the sample process.
  56. kill_sample_proc ; }
  57. rm_sample_cgroup ; }
  58. umount_freezer ; }
  59. # Failsafe cleanup
  60. cleanup_freezer || /bin/true
  61. exit $result