Home | History | Annotate | Download | only in functional
      1 #! /bin/sh
      2 
      3 ################################################################################
      4 ##                                                                            ##
      5 ## Copyright (c) 2012 FUJITSU LIMITED                                         ##
      6 ##                                                                            ##
      7 ## This program is free software;  you can redistribute it and#or modify      ##
      8 ## it under the terms of the GNU General Public License as published by       ##
      9 ## the Free Software Foundation; either version 2 of the License, or          ##
     10 ## (at your option) any later version.                                        ##
     11 ##                                                                            ##
     12 ## This program is distributed in the hope that it will be useful, but        ##
     13 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
     14 ## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
     15 ## for more details.                                                          ##
     16 ##                                                                            ##
     17 ## You should have received a copy of the GNU General Public License          ##
     18 ## along with this program;  if not, write to the Free Software               ##
     19 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
     20 ##                                                                            ##
     21 ################################################################################
     22 #
     23 # File :        memcg_use_hierarchy_test.sh
     24 # Description:  Tests memory.use_hierarchy.
     25 # Author:       Peng Haitao <penght (at] cn.fujitsu.com>
     26 # History:      2012/01/14 - Created.
     27 #
     28 
     29 export TCID="memcg_use_hierarchy_test"
     30 export TST_TOTAL=3
     31 export TST_COUNT=0
     32 
     33 . memcg_lib.sh || exit 1
     34 
     35 # test if one of the ancestors goes over its limit, the proces will be killed
     36 testcase_1()
     37 {
     38 	echo 1 > memory.use_hierarchy
     39 	echo $PAGESIZE > memory.limit_in_bytes
     40 
     41 	mkdir subgroup
     42 	cd subgroup
     43 	test_proc_kill $((PAGESIZE*3)) "--mmap-lock1" $((PAGESIZE*2)) 0
     44 
     45 	cd ..
     46 	rmdir subgroup
     47 }
     48 
     49 # test Enabling will fail if the cgroup already has other cgroups
     50 testcase_2()
     51 {
     52 	mkdir subgroup
     53 	echo 1 > memory.use_hierarchy 2> /dev/null
     54 	result $(( !($? != 0) )) "return value is $?"
     55 
     56 	rmdir subgroup
     57 }
     58 
     59 # test disabling will fail if the parent cgroup has enabled hierarchy.
     60 testcase_3()
     61 {
     62 	echo 1 > memory.use_hierarchy
     63 	mkdir subgroup
     64 	echo 0 > subgroup/memory.use_hierarchy 2> /dev/null
     65 	result $(( !($? != 0) )) "return value is $?"
     66 
     67 	rmdir subgroup
     68 }
     69 
     70 # Run all the test cases
     71 for i in $(seq 1 $TST_TOTAL)
     72 do
     73 	export TST_COUNT=$(( $TST_COUNT + 1 ))
     74 	cur_id=$i
     75 
     76 	do_mount
     77 	if [ $? -ne 0 ]; then
     78 		echo "Cannot create memcg"
     79 		exit 1
     80 	fi
     81 
     82 	# prepare
     83 	mkdir /dev/memcg/$i 2> /dev/null
     84 	cd /dev/memcg/$i
     85 
     86 	# run the case
     87 	testcase_$i
     88 
     89 	# clean up
     90 	sleep 1
     91 	cd $TEST_PATH
     92 	rmdir /dev/memcg/$i
     93 
     94 	cleanup
     95 done
     96 
     97 if [ $failed -ne 0 ]; then
     98 	exit $failed
     99 else
    100 	exit 0
    101 fi
    102