diff options
author | Balbir Singh <balbir@linux.vnet.ibm.com> | 2008-12-17 15:11:48 +0000 |
---|---|---|
committer | Balbir Singh <balbir@linux.vnet.ibm.com> | 2008-12-17 15:11:48 +0000 |
commit | 099c49cf57ec4e85d779c5f24ad51236a86b88bf (patch) | |
tree | 6366cdc9a3480654f8e82527f0fb7d8f4af066b1 /tests | |
parent | 0a6381e781145b162f3ccb72699037d413cc12b6 (diff) | |
download | libcg-099c49cf57ec4e85d779c5f24ad51236a86b88bf.tar.gz libcg-099c49cf57ec4e85d779c5f24ad51236a86b88bf.tar.xz libcg-099c49cf57ec4e85d779c5f24ad51236a86b88bf.zip |
libcgroup Test: make-controller-check-generic
The following patch adds support for a dynamical check of controllers and
choosing two of them, which are enabled in the kernel. I have given preference
to the cpu and memory controller if they exist.
I will pass these mounted controllers to the c file(will send implementation in
a next patch) and thus the c file will have no hard coding with respect to any
controller. The reason of chosing script for this part is
1. easy to implement
2. otherwise there wont be any use of script :)
One of my doubts is:
Few controllers(e.g. devices) seems not to be having a control file. Please help
me in finding the control file for each controller. Any link to documentation?
This info I need in the c file.
As per my knowledge the control files are:
*****************************
controller control_file
*****************************
cpu cpu.shares
memory memory.linit_in_bytes
debug
devices
ns
cpuacct
cpuset
Also what type of values can be written to those control files?
I need to take care before i write something stupid to a control file.
Please review the patch and give your valuable comments.
Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@256 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r-- | tests/runlibcgrouptest.sh | 108 |
1 files changed, 92 insertions, 16 deletions
diff --git a/tests/runlibcgrouptest.sh b/tests/runlibcgrouptest.sh index f3d64cd..c661153 100644 --- a/tests/runlibcgrouptest.sh +++ b/tests/runlibcgrouptest.sh @@ -21,7 +21,15 @@ MOUNTPOINT=/dev/cgroup_controllers; # Just to initialize TARGET=/dev/cgroup_controllers; CONTROLLERS=cpu,memory; NUM_MOUNT=1; # Number of places to be mounted on -MULTIMOUNT=false; # mounted at on epoint only +MULTIMOUNT=false; # mounted at one point only +NUM_CTLRS=0; # num of controllers supported +CTLR1=""; +CTLR2=""; +CPU=""; +MEMORY=""; + +declare -a allcontrollers; + debug() { # Function parameter is the string to print out @@ -82,31 +90,85 @@ umount_fs () echo "Cleanup done"; } +# Put all the supported controllers in an array +# We have the priority for cpu and memory controller. So prefer to mount +# them if they exist +get_all_controllers() +{ + while [ 1 ]; do + read line || break; + if ! echo $line | grep -q ^# + then + allcontrollers[$NUM_CTLRS]=`echo $line | cut -d" " -f1`; + if [ ${allcontrollers[$NUM_CTLRS]} == "cpu" ]; then + CPU="cpu"; + elif [ ${allcontrollers[$NUM_CTLRS]} == "memory" ]; then + MEMORY="memory"; + fi; + debug "controller: ${allcontrollers[$NUM_CTLRS]}"; + NUM_CTLRS=`expr $NUM_CTLRS + 1`; + fi + done < /proc/cgroups; + debug "Total controllers $NUM_CTLRS"; +} + +# Get a second controller other than cpu or memory +get_second_controller() +{ + local i=0; + while [ $i -lt $NUM_CTLRS ] + do + if [ "${allcontrollers[$i]}" != "cpu" ] && + [ "${allcontrollers[$i]}" != "memory" ] + then + CTLR2=${allcontrollers[$i]}; + return 0; + fi; + i=`expr $i + 1`; + done; +} + # Check if kernel is not having any of the controllers enabled no_controllers() { - CPU=""; - MEMORY=""; - if [ -e /proc/cgroups ] - then - CPU=`cat /proc/cgroups|grep -w cpu|cut -f1`; - MEMORY=`cat /proc/cgroups|grep -w memory|cut -f1`; - fi; - + # prefer if cpu and memory controller are enabled if [ ! -z $CPU ] && [ ! -z $MEMORY ] then CONTROLLERS=$CPU,$MEMORY ; + CTLR1=$CPU; + CTLR2=$MEMORY; + debug "first controller is $CTLR1"; + debug "second controller is $CTLR2"; return 1; # false elif [ ! -z $CPU ] then CONTROLLERS=$CPU ; + CTLR1=$CPU; + get_second_controller; + debug "first controller is $CTLR1"; + debug "second controller is $CTLR2"; return 1; # false elif [ ! -z $MEMORY ] then CONTROLLERS=$MEMORY ; + CTLR1=$MEMORY; + get_second_controller; + debug "first controller is $CTLR1"; + debug "second controller is $CTLR2"; return 1; # false fi; - # Kernel has no controllers enabled + # Kernel has neither cpu nor memory controller enabled. So there is + # no point in running the testcases. At least one of them should be + # supported.(or should I run testcases with controllers such as + # ns, devices etc? Thoughts???) + if [ $NUM_CTLRS -lt 1 ] + then + echo "Kernel has no controllers enabled"; + echo "Recompile your kernel with at least one controller" + echo "Exiting the tests....."; + exit 1; + fi; + return 0; # true } @@ -120,8 +182,8 @@ mount_fs () # Check if kernel has controllers enabled if no_controllers then - echo "Kernel has no controllers enabled"; - echo "Recompile your kernel with controllers enabled" + echo "Kernel has none of cpu/memory controllers enabled"; + echo "Recompile your kernel with at least one of these enabled" echo "Exiting the tests....."; exit 1; fi; @@ -155,14 +217,14 @@ mount_fs () # In case of multimount, mount controllers at diff points if $MULTIMOUNT ; then - if [ $CPU ] && [ $MEMORY ] ; then + if [ $CTLR1 ] && [ $CTLR2 ] ; then if [ $CUR_MOUNT -eq 1 ] ; then - CONTROLLERS="cpu"; + CONTROLLERS=$CTLR1; else - CONTROLLERS="memory"; + CONTROLLERS=$CTLR2; fi; else - echo "Only 1 controleer enabled in kernel"; + echo "Only 1 controler enabled in kernel"; echo "So not running multiple mount testcases"; exit 1; fi; @@ -224,6 +286,20 @@ runtest() echo Sources not compiled. please run make; fi } + +############################### +# Main starts here + # Check if kernel has controllers support + if [ -e /proc/cgroups ] + then + get_all_controllers; + else + echo "Your Kernel seems to be too old. Plz recompile your" + echo "Kernel with cgroups and appropriate controllers enabled" + echo " Exiting the testcases...." + exit 1; + fi; + # TestSet01: Run tests without mounting cgroup filesystem echo; echo Running first set of testcases; |