Skip to contentSkip to conversation

controllers/pids: Add new testcases

PATCH Superseded Cedric Hnyda 2 participants 2 messages Nov 12, 2015 – Nov 19, 2015

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 controllers/pids: Add new testcases

Created new testcase to test the pids controller which is used to stop any new tasks from being fork()'d after a certain limit is reached.

---
 runtest/controllers                           |   2 +
 testcases/kernel/controllers/pids/.gitignore  |   1 +
 testcases/kernel/controllers/pids/Makefile    |  28 +++++++
 testcases/kernel/controllers/pids/pids.sh     | 109 ++++++++++++++++++++++++++
 testcases/kernel/controllers/pids/pids_task.c |  60 ++++++++++++++
 5 files changed, 200 insertions(+)
 create mode 100644 testcases/kernel/controllers/pids/.gitignore
 create mode 100644 testcases/kernel/controllers/pids/Makefile
 create mode 100644 testcases/kernel/controllers/pids/pids.sh
 create mode 100644 testcases/kernel/controllers/pids/pids_task.c
runtest/controllers +2 -0
index c62bcce..cad9d7b 100644
@@ -277,3 +277,5 @@ cpuset_memory_spread	cpuset_memory_spread_testset.sh
 cpuset_regression_test cpuset_regression_test.sh
 
 cgroup_xattr	cgroup_xattr
+
+pids pids.sh
testcases/kernel/controllers/pids/.gitignore new file +1 -0
new file mode 100644
index 0000000..d7d4e14
@@ -0,0 +1 @@
+/pids_task
testcases/kernel/controllers/pids/Makefile new file +28 -0
new file mode 100644
index 0000000..6500363
@@ -0,0 +1,28 @@
+#
+#    Copyright (C) 2015, SUSE
+#
+#    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.
+#
+# Author: Cedric Hnyda <[email protected]>
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(abs_srcdir)/../Makefile.inc
+
+INSTALL_TARGETS		:= *.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/pids/pids.sh new file +109 -0

109 lines not on this page · raw message

testcases/kernel/controllers/pids/pids_task.c new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/1 controllers/pids: Add new testcases

Hi!

Quoted 26 lines
testcases/kernel/controllers/pids/pids.sh new file +23 -0
@@ -0,0 +1,109 @@
+#!/bin/sh
+
+################################################################################
+##                                                                            ##
+## Copyright (c) 2015 SUSE                                                    ##
+##                                                                            ##
+## 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                                                                        ##
+##                                                                            ##
+## Author: Cedric Hnyda <[email protected]>                                     ##
+##                                                                            ##

testcases/kernel/controllers/pids/pids.sh line 33

Quoted 10 lines
testcases/kernel/controllers/pids/pids.sh new file +10 -0
+################################################################################
+
+# Usage
+# ./pids.sh
+#
+# Description
+#
+# 1) Find if pids is mounted, if not mounted, pids will be mounted
+# 2) Limit the number of pid avalaible and try to fork with pid_task
+#

Can we do this a bit more versatile? I.e. pass the limit to test to the pids.sh script and change the pids_task to expect failure after N - 1 forks?

I would like to test this with limit set to 1, 2, 10, 50 and make sure that we can fork limit-1 tasks. That way we will do only one test in the script and call the script several times instead.

And actually what happens when the limit is reached and we try to attach process to it, does it fail too? And what happens when we set it to 0? (these are candidates for subsequent tests)

Quoted 35 lines
testcases/kernel/controllers/pids/pids.sh new file +35 -0
+export TCID="pids"
+export TST_TOTAL=2
+mounted=1
+
+. test.sh
+
+cleanup()
+{
+	tst_resm TINFO "removing created directories"
+	rmdir $testpath
+	if [ "$mounted" -ne "1" ]; then
+		tst_resm TINFO "Umounting pids"
+		umount $mount_point
+		rmdir $mount_point
+	fi
+}
+
+setup()
+{
+	tst_require_root
+
+	exist=`grep -w pids /proc/cgroups | cut -f1`;
+	if [ "$exist" = "" ]; then
+		tst_brkm TCONF NULL "pids not supported"
+	fi
+
+	mount_point=`grep -w pids /proc/mounts | cut -f 2 | cut -d " " -f2`
+
+	if [ "$mount_point" = "" ]; then
+		mounted=0
+		mount_point=/dev/cgroup
+	fi
+
+	TST_CLEANUP=cleanup
+

testcases/kernel/controllers/pids/pids.sh line 79

Quoted 10 lines
testcases/kernel/controllers/pids/pids.sh new file +10 -0
+	testpath=$mount_point/ltp_$TCID
+
+	if [ "$mounted" -eq "0" ]; then
+		ROD mkdir -p $mount_point
+		ROD mount -t cgroup -o pids none $mount_point
+	fi
+	ROD mkdir -p $testpath
+}
+
+setup;
        ^
	Useless semicolon

testcases/kernel/controllers/pids/pids.sh line 92

Quoted 12 lines
testcases/kernel/controllers/pids/pids.sh new file +12 -0
+tst_resm TINFO "Restrict the number of pid to 1"
+ROD echo 1 > $testpath/pids.max
+
+pids_task "$testpath/tasks"
+ret=$?
+
+if [ "$ret" -eq "2" ]; then
+	tst_resm TPASS "fork failed as expected"
+elif [ "$ret" -eq "0" ]; then
+	tst_resm TFAIL "fork didn't fail despite the limit"
+else
+	tst_resm TBROK "failed to open $testpath/tasks"

Actually we may get here when the fork() failed unexpectedly as well.

It would be better to do just tst_resm TBROK "pids_task failed" here and print more detailed description of the failure from the pids_task instead.

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]