summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-07-01 13:43:16 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-07-01 13:43:16 +0000
commitffaadffb864b22966c5adcd8f676755d00bf4d0f (patch)
tree6dcf5b39f2decdebe5527cbefe715291adaf5a1c /tests
parentee559ea2d27f859caf75633e3b4849b0420536fe (diff)
downloadlibcg-ffaadffb864b22966c5adcd8f676755d00bf4d0f.tar.gz
libcg-ffaadffb864b22966c5adcd8f676755d00bf4d0f.tar.xz
libcg-ffaadffb864b22966c5adcd8f676755d00bf4d0f.zip
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>
libcgroup: framework for libcgroup testcases This Patch creates the basic infrastructure for libcgroup testcases. This patch adds a script which runs the binary(C) file. The script does all the environment setup to run the tests and passes this info to the C file through command line arguments. The binary runs the test cases calling the API's in different environment conditions. The Makefile compiles the test. The top level Makefile.in is edited to support make test make testclean The script runs this binary total 3 times, each time with diff varaible. FS_MOUNTED=0 # cgroup fs not mounted FS_MOUNTED=1 # cgroup fs mounted FS_MOUNTED=2 # cgroup fs mounted at multiple points Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com> Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@87 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile10
-rw-r--r--tests/libcgrouptest.h38
-rw-r--r--tests/libcgrouptest01.c75
-rw-r--r--tests/runlibcgrouptest.sh211
4 files changed, 333 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 707302a..1c57de7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -3,8 +3,16 @@ LIBS = -lcgroup
INC = -I ..
CXXFLAGS = -g -O2 -Wall -DDEBUG $(INC)
+TARGET= libcgrouptest01 \
+ libcg_ba
+
+all: $(TARGET)
+
+libcgrouptest01: libcgrouptest01.c
+ $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
+
libcg_ba: libcg_ba.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
clean:
- \rm libcg_ba
+ \rm -f $(TARGET)
diff --git a/tests/libcgrouptest.h b/tests/libcgrouptest.h
new file mode 100644
index 0000000..b35c7a9
--- /dev/null
+++ b/tests/libcgrouptest.h
@@ -0,0 +1,38 @@
+
+/*
+ * Copyright IBM Corporation. 2008
+ *
+ * Author: Sudhir Kumar <skumar@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Description: This file is the header file for libcgroup test programs.
+ */
+
+#ifndef __LIBCGROUPTEST_H
+#define __LIBCGROUPTEST_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/syscall.h>
+
+#include <libcgroup.h>
+
+enum cgroup_mount_t {
+ FS_NOT_MOUNTED,
+ FS_MOUNTED,
+ FS_MULTI_MOUNTED,
+};
+
+static inline pid_t cgrouptest_gettid()
+{
+ return syscall(__NR_gettid);
+}
+#endif
diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c
new file mode 100644
index 0000000..fd4b915
--- /dev/null
+++ b/tests/libcgrouptest01.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright IBM Corporation. 2008
+ *
+ * Author: Sudhir Kumar <skumar@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Description: This file contains the test code for testing libcgroup apis.
+ */
+
+#include "libcgrouptest.h"
+
+int main(int argc, char *argv[])
+{
+ int fs_mounted;
+
+ if ((argc < 3) || (atoi(argv[1]) < 0)) {
+ printf("ERROR: Wrong no of parameters recieved from script\n");
+ printf("Exiting the libcgroup testset\n");
+ exit(1);
+ }
+ fs_mounted = atoi(argv[1]);
+
+ /*
+ * Testsets: Testcases are broadly devided into 3 categories based on
+ * filesystem(fs) mount scenario. fs not mounted, fs mounted, fs multi
+ * mounted. Call different apis in these different scenarios.
+ */
+
+ switch (fs_mounted) {
+
+ case FS_NOT_MOUNTED:
+ /*
+ * Test01: call apis and check return values
+ * Exp outcome:
+ */
+ printf("First set\n");
+
+ break;
+
+ case FS_MOUNTED:
+ /*
+ * Test01: call apis and check return values
+ * Exp outcome:
+ */
+ printf("Second set\n");
+
+ break;
+
+ case FS_MULTI_MOUNTED:
+ /*
+ * Test01: call apis and check return values
+ * Exp outcome:
+ */
+ printf("Third set\n");
+ /*
+ * Will add testcases once multiple mount patch is in
+ */
+
+ break;
+
+ default:
+ fprintf(stderr, "ERROR: Wrong parameters recieved from script. \
+ Exiting tests\n");
+ exit(1);
+ break;
+ }
+ return 0;
+}
diff --git a/tests/runlibcgrouptest.sh b/tests/runlibcgrouptest.sh
new file mode 100644
index 0000000..4e74cb5
--- /dev/null
+++ b/tests/runlibcgrouptest.sh
@@ -0,0 +1,211 @@
+#!/bin/bash
+# usage ./runlibcgrouptest.sh
+# Copyright IBM Corporation. 2008
+#
+# Author: Sudhir Kumar <skumar@linux.vnet.ibm.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of version 2.1 of the GNU Lesser General Public License
+# as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Description: This script runs the the basic tests for testing libcgroup apis.
+#
+
+DEBUG=true # for debug messages
+FS_MOUNTED=0; # 0 for not mounted, 1 for mounted, 2 for multimounted
+MOUNTPOINT="/tmp"; # Just to initialize
+TARGET=/dev/cgroup_controllers;
+CONTROLLERS=cpu,memory;
+
+debug()
+{
+ # Function parameter is the string to print out
+ if [ $DEBUG ]
+ then
+ echo SH:DBG: $1;
+ fi
+}
+
+umount_fs ()
+{
+ PROC_ENTRY=`cat /proc/mounts|grep cgroup|tr -s [:space:]|cut -d" " -f2`;
+
+ # Need to handle multiple mount points ?
+ if [ -n "$PROC_ENTRY" ] && [ "$PROC_ENTRY" != "$TARGET" ]
+ then
+ TARGET=$PROC_ENTRY;
+ fi;
+
+ # 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`;
+ if [ "$CGROUP" = "cgroup" ]
+ then
+ FS_MOUNTED=1;
+ else
+ FS_MOUNTED=0;
+ fi
+}
+
+# Check if kernel is not having any of the controllers enabled
+no_controllers()
+{
+ local CPU;
+ local 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;
+
+ if [ -n $CPU ] && [ -n $MEMORY ]
+ then
+ CONTROLLERS=$CPU,$MEMORY ;
+ return 1; # false
+ elif [ -n $CPU ]
+ then
+ CONTROLLERS=$CPU ;
+ return 1; # false
+ elif [ -n $MEMORY ]
+ then
+ CONTROLLERS=$MEMORY ;
+ return 1; # false
+ fi;
+ # Kernel has no controllers enabled
+ return 0; # true
+}
+
+mount_fs ()
+{
+ if no_controllers
+ then
+ echo "Kernel has no controllers enabled";
+ echo "Recompile your kernel with controllers enabled"
+ echo "Exiting the tests.....";
+ exit 1;
+ fi;
+
+ # Proceed further as kernel has controllers support
+ if [ -e $TARGET ]
+ then
+ echo "WARN: $TARGET already exist..overwriting"; # any issue ?
+ umount_fs;
+ fi;
+
+ mkdir $TARGET;
+
+ 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
+
+ # Group created earlier may again be visible if not cleaned properly.
+ # So clean them all
+ if [ -e $TARGET/group1 ] # first group that is created
+ 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"
+}
+
+get_mountpoint()
+{
+ # ??? need to handle multiple mount point
+ MOUNTPOINT=`cat /proc/mounts|grep -w cgroup|tr -s [:space:]| \
+ cut -d" " -f2`;
+ debug "mountpoint is $MOUNTPOINT"
+}
+runtest()
+{
+ MOUNT_INFO=$1;
+ TEST_EXEC=$2;
+ if [ -f $TEST_EXEC ]
+ then
+ ./$TEST_EXEC $MOUNT_INFO $MOUNTPOINT;
+ if [ $? -ne 0 ]
+ then
+ echo Error in running ./$TEST_EXEC
+ echo Exiting tests.
+ else
+ PID=$!;
+ fi;
+ else
+ echo Sources not compiled. please run make;
+ fi
+}
+# TestSet01: Run tests without mounting cgroup filesystem
+ echo;
+ echo Running first set of testcases;
+ echo ==============================
+ FS_MOUNTED=0;
+ FILE=libcgrouptest01;
+ check_mount_fs;
+ # unmount fs if already mounted
+ if [ $FS_MOUNTED -eq 1 ]
+ then
+ umount_fs;
+ fi;
+ debug "FS_MOUNTED = $FS_MOUNTED"
+ runtest $FS_MOUNTED $FILE
+
+ wait $PID;
+ RC=$?;
+ if [ $RC -ne 0 ]
+ then
+ echo Test binary $FILE exited abnormaly with return value $RC;
+ # Do not exit here. Failure in this case does not imply
+ # failure in other cases also
+ fi;
+
+# TestSet02: Run tests with mounting cgroup filesystem
+ echo;
+ echo Running second set of testcases;
+ echo ==============================
+ FILE=libcgrouptest01;
+ check_mount_fs;
+ # mount fs if not already mounted
+ if [ $FS_MOUNTED -eq 0 ]
+ then
+ mount_fs;
+ 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;
+ # Same commments as above
+ fi;
+
+
+# TestSet03: Run tests with mounting cgroup filesystem at multiple points
+ echo;
+ echo Running third set of testcases;
+ echo ==============================
+ # To be done
+
+ umount_fs;
+ exit 0;