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 kill the sleep process.
     24 # Then we unfreeze the sleep process and see what happens. We expect the
     25 # sleep process to receive the kill signals and exit almost immediately
     26 # after the cgroup is thawed.
     27 #
     28 
     29 . "${CGROUPS_TESTROOT}/libcgroup_freezer"
     30 SETS_DEFAULTS="${TCID=freeze_kill_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
     31 declare -r TCID
     32 declare -r TST_COUNT
     33 declare -r TST_TOTAL
     34 export TCID TST_COUNT TST_TOTAL
     35 
     36 running_cgroup_test
     37 mount_freezer && {
     38 make_sample_cgroup && {
     39 start_sample_proc && {
     40 
     41 while /bin/true ; do
     42 	trap 'break' ERR
     43 	assert_cgroup_freezer_state "THAWED" \
     44 			"ERROR: cgroup freezer started in non-THAWED state"
     45 	add_sample_proc_to_cgroup
     46 
     47 	# FREEZE
     48 	issue_freeze_cmd
     49 	wait_until_frozen
     50 	assert_sample_proc_is_frozen
     51 
     52 	# KILL
     53 	# NOTE: not "send_signal" because we're in the freezer tests
     54 	echo -n "INFO: Killing $sample_proc ..."
     55 	kill $sample_proc || kill -9 $sample_proc
     56 	echo " done."
     57 
     58 	# THAW
     59 	# We expect that kill will not complete until the sample process is
     60 	# thawed. We also expect the task to remain visible to 'ps'.
     61 	# TODO: reliably fix race between signal and assert ??
     62 	assert_sample_proc_is_frozen
     63 
     64 	issue_thaw_cmd
     65 	wait_until_thawed
     66 
     67 	# We do NOT call
     68 	#      assert_task_not_frozen $sample_proc
     69 	# here because we've killed the sample process.
     70 	assert_sample_proc_does_not_exist
     71 	sample_proc=""
     72 	result=$FINISHED
     73 	break
     74 done
     75 trap '' ERR
     76 cleanup_cgroup_test
     77 tst_resm TINFO " Cleaning up $0"
     78 
     79 # We may need to stop the sample process because we could have failed before the
     80 # rest of the test caused it to stop.
     81 kill_sample_proc ; }
     82 rm_sample_cgroup ; }
     83 umount_freezer ; }
     84 
     85 # Failsafe cleanup
     86 cleanup_freezer || /bin/true
     87 
     88 exit $result
     89 
     90