1f08c3bdfSopenharmony_ci#!/bin/bash 2f08c3bdfSopenharmony_ci 3f08c3bdfSopenharmony_ci# Copyright (c) International Business Machines Corp., 2008 4f08c3bdfSopenharmony_ci# Author: Matt Helsley <matthltc@us.ibm.com> 5f08c3bdfSopenharmony_ci# 6f08c3bdfSopenharmony_ci# This library is free software; you can redistribute it and/or 7f08c3bdfSopenharmony_ci# modify it under the terms of the GNU Lesser General Public 8f08c3bdfSopenharmony_ci# License as published by the Free Software Foundation; either 9f08c3bdfSopenharmony_ci# version 2.1 of the License, or (at your option) any later version. 10f08c3bdfSopenharmony_ci# 11f08c3bdfSopenharmony_ci# This library is distributed in the hope that it will be useful, 12f08c3bdfSopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of 13f08c3bdfSopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14f08c3bdfSopenharmony_ci# Lesser General Public License for more details. 15f08c3bdfSopenharmony_ci# 16f08c3bdfSopenharmony_ci# You should have received a copy of the GNU Lesser General Public 17f08c3bdfSopenharmony_ci# License along with this library; if not, write to the Free Software 18f08c3bdfSopenharmony_ci# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19f08c3bdfSopenharmony_ci# 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci# 22f08c3bdfSopenharmony_ci# This bash script tests freezer code by starting a long sleep process. 23f08c3bdfSopenharmony_ci# The sleep process is frozen. We then move the sleep process to a THAWED 24f08c3bdfSopenharmony_ci# cgroup. We expect moving the sleep process to fail. [While developing 25f08c3bdfSopenharmony_ci# the cgroup freezer it was undecided whether moving would fail or it would 26f08c3bdfSopenharmony_ci# cause the frozen task to thaw. If it causes the task to thaw then replace the 27f08c3bdfSopenharmony_ci# previous sentence with "We expect the moving task to thaw.". This note can 28f08c3bdfSopenharmony_ci# be removed once the cgroup freezer is in mainline. ] 29f08c3bdfSopenharmony_ci# 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci. "${CGROUPS_TESTROOT}/libcgroup_freezer" 32f08c3bdfSopenharmony_ciSETS_DEFAULTS="${TCID=freeze_move_thaw.sh} ${TST_COUNT=1} ${TST_TOTAL=1}" 33f08c3bdfSopenharmony_cideclare -r TCID 34f08c3bdfSopenharmony_cideclare -r TST_COUNT 35f08c3bdfSopenharmony_cideclare -r TST_TOTAL 36f08c3bdfSopenharmony_ciexport TCID TST_COUNT TST_TOTAL 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_cirunning_cgroup_test 39f08c3bdfSopenharmony_cimount_freezer && { 40f08c3bdfSopenharmony_cimake_sample_cgroup_named "child2" && { 41f08c3bdfSopenharmony_cimake_sample_cgroup && { 42f08c3bdfSopenharmony_cistart_sample_proc && { 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ciwhile /bin/true ; do 45f08c3bdfSopenharmony_ci trap 'break' ERR 46f08c3bdfSopenharmony_ci assert_cgroup_freezer_state "THAWED" \ 47f08c3bdfSopenharmony_ci "ERROR: cgroup freezer started in non-THAWED state" 48f08c3bdfSopenharmony_ci add_sample_proc_to_cgroup 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_ci # FREEZE 51f08c3bdfSopenharmony_ci issue_freeze_cmd 52f08c3bdfSopenharmony_ci wait_until_frozen 53f08c3bdfSopenharmony_ci assert_sample_proc_is_frozen 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci # MOVE 56f08c3bdfSopenharmony_ci "${CG_FILE_WRITE}" $sample_proc > "$(dirname $(pwd))/child2/tasks" 2> /dev/null && { 57f08c3bdfSopenharmony_ci result=${result:-1} 58f08c3bdfSopenharmony_ci /bin/false 59f08c3bdfSopenharmony_ci } || { 60f08c3bdfSopenharmony_ci /bin/true 61f08c3bdfSopenharmony_ci } 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_ci # IF the semantics are: the moved task is unfrozen THEN remove everthing 64f08c3bdfSopenharmony_ci # after "2> /dev/null" in the line above (don't redirect stdder and 65f08c3bdfSopenharmony_ci # don't invert the result) 66f08c3bdfSopenharmony_ci # This block of comments can be removed once the cgroup freezer has 67f08c3bdfSopenharmony_ci # been added to mainline. 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_ci sleep 1 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci assert_sample_proc_is_frozen 72f08c3bdfSopenharmony_ci assert_sample_proc_in_cgroup 73f08c3bdfSopenharmony_ci assert_sample_proc_not_in_named_cgroup "$(dirname $(pwd))/child2" 74f08c3bdfSopenharmony_ci # IF the semantics are: the moved task is unfrozen THEN replace the 75f08c3bdfSopenharmony_ci # asserts above with these and make the THAW section consistent: 76f08c3bdfSopenharmony_ci # assert_sample_proc_not_in_cgroup # it's in child2 after all 77f08c3bdfSopenharmony_ci # assert_sample_proc_in_named_cgroup "$(dirname $(pwd))/child2" 78f08c3bdfSopenharmony_ci # assert_sample_proc_not_frozen 79f08c3bdfSopenharmony_ci # This block of comments can be removed once the cgroup freezer has 80f08c3bdfSopenharmony_ci # been added to mainline. 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci # THAW 83f08c3bdfSopenharmony_ci issue_thaw_cmd 84f08c3bdfSopenharmony_ci wait_until_thawed 85f08c3bdfSopenharmony_ci assert_sample_proc_not_frozen 86f08c3bdfSopenharmony_ci assert_sample_proc_in_cgroup 87f08c3bdfSopenharmony_ci assert_sample_proc_not_in_named_cgroup "$(dirname $(pwd))/child2" 88f08c3bdfSopenharmony_ci # IF the semantics are: the moved task is unfrozen before adding to 89f08c3bdfSopenharmony_ci # child2 THEN 90f08c3bdfSopenharmony_ci # assert_sample_proc_not_frozen 91f08c3bdfSopenharmony_ci # assert_sample_proc_not_in_cgroup 92f08c3bdfSopenharmony_ci # assert_sample_proc_in_named_cgroup "$(dirname $(pwd))/child2" 93f08c3bdfSopenharmony_ci # This block of comments can be removed once the cgroup freezer has 94f08c3bdfSopenharmony_ci # been added to mainline. 95f08c3bdfSopenharmony_ci result=$FINISHED 96f08c3bdfSopenharmony_ci break 97f08c3bdfSopenharmony_cidone 98f08c3bdfSopenharmony_citrap '' ERR 99f08c3bdfSopenharmony_cicleanup_cgroup_test 100f08c3bdfSopenharmony_citst_resm TINFO " Cleaning up $0" 101f08c3bdfSopenharmony_ci 102f08c3bdfSopenharmony_ci# We may need to stop the sample process because we could have failed before the 103f08c3bdfSopenharmony_ci# rest of the test caused it to stop. 104f08c3bdfSopenharmony_cikill_sample_proc ; } 105f08c3bdfSopenharmony_cirm_sample_cgroup ; } 106f08c3bdfSopenharmony_cirm_sample_cgroup_named "child2" ; } 107f08c3bdfSopenharmony_ciumount_freezer ; } 108f08c3bdfSopenharmony_ci 109f08c3bdfSopenharmony_ci# Failsafe cleanup 110f08c3bdfSopenharmony_cicleanup_freezer || /bin/true 111f08c3bdfSopenharmony_ci 112f08c3bdfSopenharmony_ciexit $result 113f08c3bdfSopenharmony_ci 114