1#!/bin/bash 2 3# Copyright (c) International Business Machines Corp., 2008 4# Author: Matt Helsley <matthltc@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" 30SETS_DEFAULTS="${TCID=freeze_kill_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}" 31declare -r TCID 32declare -r TST_COUNT 33declare -r TST_TOTAL 34export TCID TST_COUNT TST_TOTAL 35 36running_cgroup_test 37mount_freezer && { 38make_sample_cgroup && { 39start_sample_proc && { 40 41while /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 74done 75trap '' ERR 76cleanup_cgroup_test 77tst_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. 81kill_sample_proc ; } 82rm_sample_cgroup ; } 83umount_freezer ; } 84 85# Failsafe cleanup 86cleanup_freezer || /bin/true 87 88exit $result 89 90