Home | History | Annotate | Download | only in freezer
      1 #!/bin/bash
      2 
      3 # Copyright (c) International Business Machines  Corp., 2008
      4 # Author: Matt Helsley <matthltc (at] us.ibm.com>
      5 #
      6 # This library is free software; you can redistribute it and/or
      7 # modify it under the terms of the GNU Lesser General Public
      8 # License as published by the Free Software Foundation; either
      9 # version 2.1 of the License, or (at your option) any later version.
     10 #
     11 # This library is distributed in the hope that it will be useful,
     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 # Lesser General Public License for more details.
     15 #
     16 # You should have received a copy of the GNU Lesser General Public
     17 # License along with this library; if not, write to the Free Software
     18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     19 #
     20 
     21 #
     22 # This bash script tests freezer code by starting a long sleep process.
     23 # The sleep process is frozen. We then wait until the sleep process should
     24 # have exited. Then we unfreeze the sleep process. We expect the
     25 # sleep process to wakeup almost immediately after the cgroup is thawed,
     26 # recognize that its expiration time has long since passed, and exit before
     27 # we get a chance to "see" it again.
     28 #
     29 
     30 . "${CGROUPS_TESTROOT}/libcgroup_freezer"
     31 SETS_DEFAULTS="${TCID=freeze_sleep_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
     32 declare -r TCID
     33 declare -r TST_COUNT
     34 declare -r TST_TOTAL
     35 export TCID TST_COUNT TST_TOTAL
     36 
     37 running_cgroup_test
     38 mount_freezer && {
     39 make_sample_cgroup && {
     40 start_sample_proc && {
     41 
     42 while /bin/true ; do
     43 	trap 'break' ERR
     44 	add_sample_proc_to_cgroup
     45 	assert_cgroup_freezer_state "THAWED" \
     46 			"ERROR: cgroup freezer started in non-THAWED state"
     47 	issue_freeze_cmd
     48 	wait_until_frozen
     49 	assert_sample_proc_is_frozen
     50 
     51 	echo -n "INFO: Waiting until sleep command should have finished ($sample_proc) ... "
     52 	/bin/sleep $(($sample_sleep * 2))
     53 	echo "done."
     54 
     55 	# We expect the task to remain until it is thawed even though its
     56 	# sleep period has long since expired.
     57 	assert_sample_proc_is_frozen
     58 
     59 	issue_thaw_cmd
     60 	wait_until_thawed
     61 
     62 	# We do NOT call
     63 	#      assert_task_not_frozen $sample_proc
     64 	# here because we've slept past the point in time when the task should've
     65 	# exited.
     66 	assert_sample_proc_does_not_exist
     67 
     68 	sample_proc=""
     69 	result=$FINISHED
     70 	break
     71 done
     72 trap '' ERR
     73 cleanup_cgroup_test
     74 tst_resm TINFO " Cleaning up $0"
     75 
     76 # We may need to stop the sample process because we could have failed before the
     77 # rest of the test caused it to stop.
     78 kill_sample_proc ; }
     79 rm_sample_cgroup ; }
     80 umount_freezer ; }
     81 
     82 # Failsafe cleanup
     83 cleanup_freezer || /bin/true
     84 
     85 exit $result
     86