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 move the sleep process to a THAWED
     24 # cgroup. We expect moving the sleep process to fail. [While developing
     25 # the cgroup freezer it was undecided whether moving would fail or it would
     26 # cause the frozen task to thaw. If it causes the task to thaw then replace the
     27 # previous sentence with "We expect the moving task to thaw.". This note can
     28 # be removed once the cgroup freezer is in mainline. ]
     29 #
     30 
     31 . "${CGROUPS_TESTROOT}/libcgroup_freezer"
     32 SETS_DEFAULTS="${TCID=freeze_move_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}"
     33 declare -r TCID
     34 declare -r TST_COUNT
     35 declare -r TST_TOTAL
     36 export TCID TST_COUNT TST_TOTAL
     37 
     38 running_cgroup_test
     39 mount_freezer && {
     40 make_sample_cgroup_named "child2" && {
     41 make_sample_cgroup && {
     42 start_sample_proc && {
     43 
     44 while /bin/true ; do
     45 	trap 'break' ERR
     46 	assert_cgroup_freezer_state "THAWED" \
     47 			"ERROR: cgroup freezer started in non-THAWED state"
     48 	add_sample_proc_to_cgroup
     49 
     50 	# FREEZE
     51 	issue_freeze_cmd
     52 	wait_until_frozen
     53 	assert_sample_proc_is_frozen
     54 
     55 	# MOVE
     56 	"${CG_FILE_WRITE}" $sample_proc > "$(dirname $(pwd))/child2/tasks" 2> /dev/null && {
     57 		result=${result:-1}
     58 		/bin/false
     59 	} || {
     60 		/bin/true
     61 	}
     62 
     63 	# IF the semantics are: the moved task is unfrozen THEN remove everthing
     64 	# after "2> /dev/null" in the line above (don't redirect stdder and
     65 	# don't invert the result)
     66 	# This block of comments can be removed once the cgroup freezer has
     67 	# been added to mainline.
     68 
     69 	sleep 1
     70 
     71 	assert_sample_proc_is_frozen
     72 	assert_sample_proc_in_cgroup
     73 	assert_sample_proc_not_in_named_cgroup "$(dirname $(pwd))/child2"
     74 	# IF the semantics are: the moved task is unfrozen THEN replace the
     75 	# asserts above with these and make the THAW section consistent:
     76 		# assert_sample_proc_not_in_cgroup # it's in child2 after all
     77 		# assert_sample_proc_in_named_cgroup "$(dirname $(pwd))/child2"
     78 		# assert_sample_proc_not_frozen
     79 	# This block of comments can be removed once the cgroup freezer has
     80 	# been added to mainline.
     81 
     82 	# THAW
     83 	issue_thaw_cmd
     84 	wait_until_thawed
     85 	assert_sample_proc_not_frozen
     86 	assert_sample_proc_in_cgroup
     87 	assert_sample_proc_not_in_named_cgroup "$(dirname $(pwd))/child2"
     88 	# IF the semantics are: the moved task is unfrozen before adding to
     89 	# child2 THEN
     90 		# assert_sample_proc_not_frozen
     91 		# assert_sample_proc_not_in_cgroup
     92 		# assert_sample_proc_in_named_cgroup "$(dirname $(pwd))/child2"
     93 	# This block of comments can be removed once the cgroup freezer has
     94 	# been added to mainline.
     95 	result=$FINISHED
     96 	break
     97 done
     98 trap '' ERR
     99 cleanup_cgroup_test
    100 tst_resm TINFO " Cleaning up $0"
    101 
    102 # We may need to stop the sample process because we could have failed before the
    103 # rest of the test caused it to stop.
    104 kill_sample_proc ; }
    105 rm_sample_cgroup ; }
    106 rm_sample_cgroup_named "child2" ; }
    107 umount_freezer ; }
    108 
    109 # Failsafe cleanup
    110 cleanup_freezer || /bin/true
    111 
    112 exit $result
    113 
    114