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