Hi Subrata,
Please accept below testcase patch for pid namespace.
Thanks,
Gowri
--
The pidns10.c testcase verifies inside the container, if kill(-1, sig)
fails with ESRCH when there are no processes in container
besides container-init.
Signed-off-by: Gowrishankar M <[email protected]>
Acked-by: Sukadev Bhattiprolu <[email protected]>
Index: ltp/testcases/kernel/containers/pidns/pidns10.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ltp/testcases/kernel/containers/pidns/pidns10.c 2008-12-12
06:20:23.000000000 -0500
@@ -0,0 +1,133 @@
+/*
+* Copyright (c) International Business Machines Corp., 2007
+* 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: pidns10.c
+* *
+* * Description:
+* * The pidns10.c testcase verifies inside the container, if kill(-1, signal)
+* * fails with ESRCH when there are no processes in container.
+* *
+* * Test Assertion & Strategy:
+* * Create a PID namespace container.
+* * Invoke kill(-1, SIGUSR1) inside container and check return code and error.
+* * kill() should have failed;except swapper & init, no process is inside.
+* *
+* * Usage: <for command-line>
+* * pidns10
+* *
+* * History:
+* * DATE NAME DESCRIPTION
+* * 13/11/08 Gowrishankar M Creation of this test.
+* * <[email protected]>
+*
+******************************************************************************/
+#define _GNU_SOURCE 1
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <usctest.h>
+#include <test.h>
+#include <libclone.h>
+
+char *TCID = "pidns10";
+int TST_TOTAL = 1;
+int errno;
+
+int child_fn(void *);
+void cleanup(void);
+
+#define CHILD_PID 1
+#define PARENT_PID 0
+
+/*
+ * child_fn() - Inside container
+ */
+int child_fn(void *arg)
+{
+ pid_t pid, ppid;
+
+ /* Set process id and parent pid */
+ pid = getpid();
+ ppid = getppid();
+ if (pid != CHILD_PID || ppid != PARENT_PID) {
+ tst_resm(TBROK, "cinit: pidns is not created.");
+ cleanup();
+ }
+
+ if (kill(-1, SIGUSR1) != -1) {
+ tst_resm(TFAIL, "cinit: kill(-1, sig) should have failed");
+ cleanup();
+ }
+
+ if (errno == ESRCH)
+ tst_resm(TPASS, "cinit: expected kill(-1, sig) failure.");
+ else
+ tst_resm(TFAIL, "cinit: kill(-1, sig) failure is not ESRCH, "
+ "but %s", strerror(errno));
+
+ /* cleanup and exit */
+ cleanup();
+ exit(0);
+}
+
+/***********************************************************************
+* M A I N
+***********************************************************************/
+
+int main(int argc, char *argv[])
+{
+ int status, ret;
+ pid_t pid;
+
+ pid = getpid();
+
+ /* Container creation on PID namespace */
+ ret = do_clone_unshare_test(T_CLONE,\
+ CLONE_NEWPID, child_fn, NULL);
+ if (ret != 0) {
+ tst_resm(TBROK, "parent: clone() failed. rc=%d(%s)",\
+ ret, strerror(errno));
+ /* Cleanup & continue with next test case */
+ cleanup();
+ }
+
+ sleep(1);
+ if (wait(&status) < 0)
+ tst_resm(TWARN, "parent: waitpid() failed.");
+
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ tst_resm(TBROK, "parent: container was terminated by %s",\
+ strsignal(WTERMSIG(status)));
+
+ cleanup();
+ exit(0);
+} /* End main */
+
+/*
+ * cleanup() - performs all ONE TIME cleanup for this test at
+ * completion or premature exit.
+ */
+void cleanup()
+{
+ /* Clean the test testcase as LTP wants*/
+ TEST_CLEANUP;
+
+ /* exit with return code appropriate for results */
+ tst_exit();
+}
Index: ltp/testcases/kernel/containers/pidns/runpidnstest.sh
===================================================================
--- ltp.orig/testcases/kernel/containers/pidns/runpidnstest.sh 2008-12-12
06:19:54.000000000 -0500
+++ ltp/testcases/kernel/containers/pidns/runpidnstest.sh 2008-12-12
06:20:10.000000000 -0500
@@ -55,6 +55,12 @@
err_code=$rc
fi
+pidns10
+rc=$?
+if [ $rc -ne 0 ] && [ -z $err_code ]; then
+ err_code=$rc
+fi
+
# If any test failed then exit with the value error-code.
if ! [ -z $err_code ]; then
exit $err_code
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list