summaryrefslogtreecommitdiffstats
path: root/tests/runlibcgrouptest.sh
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:56:40 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:56:40 +0000
commit39424259a3a058cb5e5368848bf153a5b5e82318 (patch)
tree80bd442251a2d6dccb37847e27c24a6cf0e9e90d /tests/runlibcgrouptest.sh
parent4091c043bf7ab0d2f8e12771c4b5d2b63ade89dd (diff)
downloadlibcg-39424259a3a058cb5e5368848bf153a5b5e82318.tar.gz
libcg-39424259a3a058cb5e5368848bf153a5b5e82318.tar.xz
libcg-39424259a3a058cb5e5368848bf153a5b5e82318.zip
libcgroup Test: multi-mount-script-enhanced
This patch modifies the script to handle multiple mounts. The earlier functions are modified and new ones are added. There is still some hard coding with respect to the number of mountpoints and controllers. I will update this code part once I get an idea of a better design. Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@240 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/runlibcgrouptest.sh')
-rw-r--r--tests/runlibcgrouptest.sh204
1 files changed, 151 insertions, 53 deletions
diff --git a/tests/runlibcgrouptest.sh b/tests/runlibcgrouptest.sh
index 4e74cb5..69a7a68 100644
--- a/tests/runlibcgrouptest.sh
+++ b/tests/runlibcgrouptest.sh
@@ -15,57 +15,78 @@
# Description: This script runs the the basic tests for testing libcgroup apis.
#
-DEBUG=true # for debug messages
+DEBUG=false; # for debug messages
FS_MOUNTED=0; # 0 for not mounted, 1 for mounted, 2 for multimounted
-MOUNTPOINT="/tmp"; # Just to initialize
+MOUNTPOINT=/dev/cgroup_controllers; # Just to initialize
TARGET=/dev/cgroup_controllers;
CONTROLLERS=cpu,memory;
+NUM_MOUNT=1; # Number of places to be mounted on
debug()
{
# Function parameter is the string to print out
- if [ $DEBUG ]
+ if $DEBUG
then
echo SH:DBG: $1;
fi
}
-umount_fs ()
+check_mount_fs ()
{
- PROC_ENTRY=`cat /proc/mounts|grep cgroup|tr -s [:space:]|cut -d" " -f2`;
+ local NUM_MOUNT=0;
+ CGROUP=`cat /proc/mounts|grep -w cgroup|tr -s [:space:]|cut -d" " -f3`;
- # Need to handle multiple mount points ?
- if [ -n "$PROC_ENTRY" ] && [ "$PROC_ENTRY" != "$TARGET" ]
- then
- TARGET=$PROC_ENTRY;
- fi;
+ # get first word in case of multiple mounts
+ CGROUP=`echo $CGROUP|cut -d" " -f1`;
- # Need to take care if there are tasks running in any group ??
- # Also need to take care if there are groups in the hierarchy ?
- rmdir $TARGET/* 2> /dev/null ;
- umount $TARGET;
- rmdir $TARGET;
- FS_MOUNTED=0;
- TARGET=/dev/cgroup_controllers;
- echo "Cleanup done";
-}
-
-check_mount_fs()
-{
- CGROUP=`cat /proc/mounts|grep -w cgroup|tr -s [:space:]|cut -d" " -f3`;
+ debug "check_mount_fs(): CGROUP is $CGROUP";
if [ "$CGROUP" = "cgroup" ]
then
- FS_MOUNTED=1;
+ NUM_MOUNT=`cat /proc/mounts|grep -w cgroup|wc -l`;
+ debug "check_mount_fs(): fs mounted at $NUM_MOUNT places";
+
+ if [ $NUM_MOUNT -eq 1 ]
+ then
+ FS_MOUNTED=1;
+ else
+ # Any number of mounts is multi mount
+ FS_MOUNTED=2;
+ fi;
+ return 0; # True
else
FS_MOUNTED=0;
+ return 1; # false
fi
}
+umount_fs ()
+{
+ while check_mount_fs
+ do
+ PROC_ENTRY=`cat /proc/mounts|grep cgroup|tr -s [:space:]|cut -d" " -f2`;
+ # Get first mountpoint in case of multiple mounts
+ PROC_ENTRY=`echo $PROC_ENTRY|cut -d" " -f1`;
+ if [ -n "$PROC_ENTRY" ]
+ then
+ TARGET=$PROC_ENTRY;
+ # Need to take care if there are tasks running in any group ??
+ # Also need to care if cpu and memory are mounted at different places
+ rmdir $TARGET/* 2> /dev/null ;
+ umount $TARGET;
+ rmdir $TARGET;
+ debug "umounted $TARGET";
+ fi;
+ done
+ FS_MOUNTED=0;
+ TARGET=/dev/cgroup_controllers; #??
+ echo "Cleanup done";
+}
+
# Check if kernel is not having any of the controllers enabled
no_controllers()
{
- local CPU;
- local MEMORY;
+ CPU="";
+ MEMORY="";
if [ -e /proc/cgroups ]
then
CPU=`cat /proc/cgroups|grep -w cpu|cut -f1`;
@@ -89,8 +110,14 @@ no_controllers()
return 0; # true
}
+
mount_fs ()
{
+ local NUM_MOUNT=0; # On how many places to mount on
+ local CUR_MOUNT=1;
+ FS_MOUNTED=0;
+
+ # Check if kernel has controllers enabled
if no_controllers
then
echo "Kernel has no controllers enabled";
@@ -99,38 +126,82 @@ mount_fs ()
exit 1;
fi;
- # Proceed further as kernel has controllers support
- if [ -e $TARGET ]
+ # At least one Controller is enabled. So proceed further.
+ if [ -z $1 ]
then
- echo "WARN: $TARGET already exist..overwriting"; # any issue ?
- umount_fs;
+ echo "WARN: No parameter passed to function mount_fs";
+ echo "taking default as 0....So not mounting cgroup fs";
+ else
+ NUM_MOUNT=$1;
+ debug "mount_fs fs will be mounted on $NUM_MOUNT places";
fi;
- mkdir $TARGET;
+ # create so many directories i.e. mountpoints
+ while [ $NUM_MOUNT -ge $CUR_MOUNT ]
+ do
+ NEWTARGET="$TARGET-$CUR_MOUNT";
+ if [ -e $NEWTARGET ]
+ then
+ echo "WARN: $NEWTARGET already exist..overwriting";
+ check_mount_fs; # Possibly fs might be mounted on it
+ if [ $FS_MOUNTED -gt 0 ]
+ then
+ umount_fs;
+ else
+ rmdir $NEWTARGET ;
+ fi;
+ fi;
+ mkdir $NEWTARGET;
- mount -t cgroup -o $CONTROLLERS cgroup $TARGET; # 2> /dev/null?
- if [ $? -ne 0 ]
- then
- echo "ERROR: Could not mount cgroup filesystem on $TARGET."
- echo "Exiting test";
- umount_fs;
- exit -1;
- fi
+ # In case of multimount, mount controllers at diff points
+ if $MULTIMOUNT ; then
+ if [ $CPU ] && [ $MEMORY ] ; then
+ if [ $CUR_MOUNT -eq 1 ] ; then
+ CONTROLLERS="cpu";
+ else
+ CONTROLLERS="memory";
+ fi;
+ else
+ echo "Only 1 controleer enabled in kernel";
+ echo "So not running multiple mount testcases";
+ exit 1;
+ fi;
+ fi;
+
+ mount -t cgroup -o $CONTROLLERS cgroup $NEWTARGET; # 2> /dev/null?
+ if [ $? -ne 0 ]
+ then
+ echo "ERROR: Could not mount cgroup filesystem on $NEWTARGET."
+ echo "Exiting test";
+ umount_fs;
+ exit -1;
+ fi;
+ CUR_MOUNT=`expr $CUR_MOUNT + 1`;
+ FS_MOUNTED=`expr $FS_MOUNTED + 1`;
+
+ # Group created earlier may again be visible if not cleaned.
+ # So clean them all
+ if [ -e $NEWTARGET/group1 ] # first group that is created
+ then
+ # Need to handle if tasks are running in them
+ rmdir $NEWTARGET/group*
+ echo "WARN: Earlier groups found and removed...";
+ fi;
- # Group created earlier may again be visible if not cleaned properly.
- # So clean them all
- if [ -e $TARGET/group1 ] # first group that is created
+ debug "cgroup filesystem mounted on $NEWTARGET directory"
+ done;
+
+ if [ $FS_MOUNTED -gt 2 ]
then
- rmdir $TARGET/* 2>/dev/null
- echo "WARN: Earlier groups found and removed...";
- fi
- FS_MOUNTED=1;
- debug "INFO: cgroup filesystem mounted on $TARGET directory"
+ FS_MOUNTED=2;
+ fi;
+
}
get_mountpoint()
{
- # ??? need to handle multiple mount point
+ # need to handle how to pass multiple mount points to C file
+ # It will depend on the requirements if any
MOUNTPOINT=`cat /proc/mounts|grep -w cgroup|tr -s [:space:]| \
cut -d" " -f2`;
debug "mountpoint is $MOUNTPOINT"
@@ -161,7 +232,7 @@ runtest()
FILE=libcgrouptest01;
check_mount_fs;
# unmount fs if already mounted
- if [ $FS_MOUNTED -eq 1 ]
+ if [ $FS_MOUNTED -ne 0 ]
then
umount_fs;
fi;
@@ -183,10 +254,15 @@ runtest()
echo ==============================
FILE=libcgrouptest01;
check_mount_fs;
- # mount fs if not already mounted
+ # mount fs at one point if not already mounted or multimounted
+ NUM_MOUNT=1;
if [ $FS_MOUNTED -eq 0 ]
then
- mount_fs;
+ mount_fs $NUM_MOUNT;
+ elif [ $FS_MOUNTED -gt 1 ]
+ then
+ umount_fs;
+ mount_fs $NUM_MOUNT;
fi;
debug "FS_MOUNTED = $FS_MOUNTED"
get_mountpoint;
@@ -197,15 +273,37 @@ runtest()
if [ $RC -ne 0 ]
then
echo Test binary $FILE exited abnormaly with return value $RC;
- # Same commments as above
fi;
+ umount_fs;
# TestSet03: Run tests with mounting cgroup filesystem at multiple points
echo;
echo Running third set of testcases;
echo ==============================
- # To be done
+ FILE=libcgrouptest01;
+ check_mount_fs;
+ # mount fs at multiple points
+ MULTIMOUNT=true;
+ NUM_MOUNT=2;
+ if [ $FS_MOUNTED -eq 0 ]
+ then
+ mount_fs $NUM_MOUNT;
+ elif [ $FS_MOUNTED -eq 1 ]
+ then
+ umount_fs;
+ mount_fs $NUM_MOUNT;
+ fi;
+ debug "FS_MOUNTED = $FS_MOUNTED"
+ get_mountpoint;
+ runtest $FS_MOUNTED $FILE
+ wait $PID;
+ RC=$?;
+ if [ $RC -ne 0 ]
+ then
+ echo Test binary $FILE exited abnormaly with return value $RC;
+ fi;
umount_fs;
+
exit 0;