On 1 March 2010 11:58, Rishikesh K Rajak <[email protected]> wrote:
[...]
>
> Please create your patch against next tree or attach the source file
> here as text, i will create a patch.
>
[...]
Please find the patch attached. Hope this is good enough.
Naufal
diff --git a/runtest/controllers b/runtest/controllers
index 2df958e..d495010 100644
--- a/runtest/controllers
+++ b/runtest/controllers
@@ -3,5 +3,6 @@ cgroup cgroup_regression_test.sh
memcg_regression memcg_regression_test.sh
memcg_function memcg_function_test.sh
memcg_stress memcg_stress_test.sh
+memcg_control PAGESIZE=$(mem_process -p);memcg_control_test.sh $PAGESIZE $PAGESIZE $((PAGESIZE * 2))
cgroup_fj run_cgroup_test_fj.sh
controllers test_controllers.sh
diff --git a/testcases/kernel/controllers/memcg/README b/testcases/kernel/controllers/memcg/README
index 4082f12..ea4df68 100644
--- a/testcases/kernel/controllers/memcg/README
+++ b/testcases/kernel/controllers/memcg/README
@@ -15,6 +15,16 @@ of memctl..
FILES DESCRIPTION:
+control/memcg_control_test.sh
+--------------------
+This script runs the testcases of control test.
+
+control/mem_process.c
+--------------------
+The program allocates memory specified using the '-m' option when 'm' is received
+through the named pipe /tmp/status_pipe and frees it on receiving 'm' again.
+It exits on receiving 'x'. It gets the page size on specifying the '-p' option.
+
functional/memcgroup_function_test.sh
--------------------
This script runs all the 38 testcases of basis operation.
diff --git a/testcases/kernel/controllers/memcg/control/Makefile b/testcases/kernel/controllers/memcg/control/Makefile
new file mode 100644
index 0000000..0dbc994
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/control/Makefile
@@ -0,0 +1,33 @@
+#
+# kernel/controllers/memcg/stress testcase suite Makefile.
+#
+# Copyright (C) 2009, Cisco Systems Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Garrett Cooper, September 2009
+#
+
+top_srcdir ?= ../../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -I$(abs_srcdir)/../../libcontrollers
+
+INSTALL_TARGETS := *.sh
+
+LDLIBS += -lm
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/controllers/memcg/control/mem_process.c b/testcases/kernel/controllers/memcg/control/mem_process.c
new file mode 100644
index 0000000..60361aa
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/control/mem_process.c
@@ -0,0 +1,141 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) 2010 Mohamed Naufal Basheer */
+/* */
+/* This program is free software; you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
+/* the GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/* */
+/* File: mem_process.c */
+/* */
+/* Purpose: act as a memory hog for the memcg_control tests */
+/* */
+/* Author: Mohamed Naufal Basheer <[email protected] > */
+/* */
+/*******************************************************************************/
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+/*
+ * Named pipe to act as a communication channel between
+ * shell script & this process
+ */
+#define STATUS_PIPE "status_pipe"
+
+int flag_exit;
+int flag_allocated;
+unsigned long memsize;
+
+/*
+ * process_options: process user specified options
+ */
+void process_options(int argc, char **argv)
+{
+ int c;
+ char *end;
+
+ opterr = 0;
+ while ((c = getopt(argc, argv, "pm:")) != -1) {
+ switch(c) {
+ case 'p':
+ printf("%d\n",getpagesize());
+ exit(0);
+ case 'm':
+ memsize = strtoul(optarg, &end, 10);
+ if (*end)
+ errx(2, "Invalid -m usage");
+ break;
+ default:
+ errx(2, "Invalid option specifed");
+ }
+ }
+
+ if(memsize <= 0)
+ errx(3, "Invalid usage");
+}
+
+/*
+ * touch_memory: force physical memory allocation
+ */
+void touch_memory(char *p)
+{
+ int i;
+ int pagesize = getpagesize();
+
+ for (i = 0; i < memsize; i += pagesize)
+ p[i] = 0xef;
+}
+
+void mem_map()
+{
+ static char *p;
+
+ if (!flag_allocated) {
+ p = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+ if(p == MAP_FAILED)
+ errx(4, "mmap failed");
+ touch_memory(p);
+ }else {
+ if (munmap(p, memsize) == -1)
+ errx(5, "munmap failed");
+ }
+ flag_allocated ^= 1;
+}
+
+/*
+ * done: retrieve instructions from the named pipe
+ */
+char action()
+{
+ char ch;
+ int fd;
+
+ fd = open(STATUS_PIPE, O_RDONLY);
+ if (fd < 0)
+ errx(6, "Error opening named pipe");
+
+ if (read(fd, &ch, 1) < 0)
+ errx(7, "Error reading named pipe");
+
+ close(fd);
+
+ return ch;
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ char ch;
+
+ process_options(argc, argv);
+
+ ret = mkfifo(STATUS_PIPE, 0666);
+
+ if (ret == -1 && errno != EEXIST)
+ errx(1, "Error creating named pipe");
+
+ do {
+ ch = action();
+
+ if (ch == 'm')
+ mem_map();
+ }while(ch != 'x');
+
+ remove(STATUS_PIPE);
+
+ return 0;
+}
diff --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
new file mode 100644
index 0000000..da36e05
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
@@ -0,0 +1,166 @@
+#!/bin/sh
+
+################################################################################
+## ##
+## Copyright (c) 2010 Mohamed Naufal Basheer ##
+## ##
+## This program is free software; you can redistribute it and/or modify ##
+## it under the terms of the GNU General Public License as published by ##
+## the Free Software Foundation; either version 2 of the License, or ##
+## (at your option) any later version. ##
+## ##
+## This program is distributed in the hope that it will be useful, ##
+## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See ##
+## the GNU General Public License for more details. ##
+## ##
+## You should have received a copy of the GNU General Public License ##
+## along with this program; if not, write to the Free Software ##
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
+## ##
+## ##
+## File: memcg_control_test.sh ##
+## ##
+## Purpose: Implement various memory controller tests ##
+## ##
+## Author: Mohamed Naufal Basheer <[email protected]> ##
+## ##
+################################################################################
+
+if [ "$(grep -w memory /proc/cgroups | cut -f4)" -ne "1" ]; then
+ echo "WARNING:"
+ echo "Either kernel does not support memory resource controller or feature not enabled"
+ echo "Skipping all memcg_control testcases...."
+ exit 0
+fi
+
+export TCID="memcg_control"
+export TST_TOTAL=1
+export TST_COUNT=0
+
+export TMP=${TMP:-/tmp}
+cd $TMP
+
+TOT_MEM_LIMIT=$1
+ACTIVE_MEM_LIMIT=$2
+PROC_MEM=$3
+
+TST_PATH=$PWD
+STATUS_PIPE="$TMP/status_pipe"
+
+PASS=0
+FAIL=1
+
+# Check if the test process is killed on crossing boundary
+test_proc_kill()
+{
+ pushd $TMP > /dev/null
+ mem_process -m $PROC_MEM &
+ popd > /dev/null
+ sleep 1
+ echo $! > tasks
+
+ #Instruct the test process to start acquiring memory
+ echo m > $STATUS_PIPE
+ sleep 5
+
+ #Check if killed
+ ps -p $! > /dev/null 2> /dev/null
+ if [ $? -eq 0 ]; then
+ echo m > $STATUS_PIPE
+ echo x > $STATUS_PIPE
+ else
+ : $((KILLED_CNT += 1))
+ fi
+}
+
+# Validate the memory usage limit imposed by the hierarchically topmost group
+testcase_1()
+{
+ TST_COUNT=1
+ tst_resm TINFO "Test #1: Checking if the memory usage limit imposed by the topmost group is enforced"
+
+ echo "$ACTIVE_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.limit_in_bytes
+ echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.memsw.limit_in_bytes
+
+ mkdir sub
+ pushd sub > /dev/null
+
+ KILLED_CNT=0
+ test_proc_kill
+
+ if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then
+ result $FAIL "Test #1: failed"
+ else
+ result $PASS "Test #1: passed"
+ fi
+
+ popd > /dev/null
+ rmdir sub
+}
+
+# Record the test results
+#
+# $1: Result of the test case, $PASS or $FAIL
+# $2: Output information
+result()
+{
+ RES=$1
+ INFO=$2
+
+ if [ $RES -eq $PASS ]; then
+ tst_resm TPASS "$INFO"
+ else
+ : $((FAILED_CNT += 1))
+ tst_resm TFAIL "$INFO"
+ fi
+}
+
+cleanup()
+{
+ if [ -e $TST_PATH/mnt ]; then
+ umount $TST_PATH/mnt 2> /dev/null
+ rm -rf $TST_PATH/mnt
+ fi
+}
+
+do_mount()
+{
+ cleanup
+
+ mkdir $TST_PATH/mnt
+ mount -t cgroup -o memory cgroup $TST_PATH/mnt 2> /dev/null
+ if [ $? -ne 0 ]; then
+ tst_brkm TBROK NULL "Mounting cgroup to temp dir failed"
+ rmdir $TST_PATH/mnt
+ exit 1
+ fi
+}
+
+do_mount
+
+echo 1 > mnt/memory.use_hierarchy 2> /dev/null
+
+FAILED_CNT=0
+
+TST_NUM=1
+while [ $TST_NUM -le $TST_TOTAL ]; do
+ mkdir $TST_PATH/mnt/$TST_NUM
+ pushd $TST_PATH/mnt/$TST_NUM > /dev/null
+
+ testcase_$TST_NUM
+
+ popd > /dev/null
+ rmdir $TST_PATH/mnt/$TST_NUM
+ : $((TST_NUM += 1))
+done
+
+cleanup
+
+if [ "$FAILED_CNT" -ne 0 ]; then
+ tst_resm TFAIL "memcg_control: failed"
+ exit 1
+else
+ tst_resm TPASS "memcg_control: passed"
+ exit 0
+fi
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list