Quoting Rishikesh K. Rajak ([EMAIL PROTECTED]):
> 

> This patch implements a basic test for cloning pid namespace. It
> verifies that the newly created child process has pid == 1 and ppid == 0.
> 
> <Signed-off By>: Rishikesh K Rajak <[EMAIL PROTECTED]>
> ---
> Index: ltp-full-20071130/testcases/kernel/containers/pidns/pidns01.c
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-full-20071130/testcases/kernel/containers/pidns/pidns01.c     
> 2007-12-27 16:28:09.000000000 +0530
> @@ -0,0 +1,162 @@
> +/*
> +* 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: pidns01.c
> +*
> +* Description:
> +*  The pidns01.c testcase builds into the ltp framework to verify
> +*  the basic functionality of PID Namespace.
> +*
> +* Verify that:
> +* 1. When parent clone a process with flag CLONE_NEWPID, the process ID of
> +* child should be always one.
> +*
> +* 2. When parent clone a process with flag CLONE_NEWPID, the parent process 
> ID of
> +* should be always zero.
> +*
> +* Total Tests: 6 assertions
> +*
> +* Test Name: pidns01
> +*
> +* Test Assertion & Strategy:
> +*
> +* From main() clone a new child process with passing the clone_flag as 
> CLONE_NEWPID,
> +* Inside the cloned pid check for the getpid() and getppid()
> +* Verify with global macro defined value for parent pid & child pid.
> +*
> +* Usage: <for command-line>
> +* pidns01
> +*
> +* History:
> +*
> +* FLAG DATE          NAME                    DESCRIPTION
> +* 27/12/07  RISHIKESH K RAJAK <[EMAIL PROTECTED]> Created this test
> +*
> +*******************************************************************************************/
> +#define _GNU_SOURCE 1
> +#include <sys/wait.h>
> +#include <assert.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <errno.h>
> +#ifndef NO_LTP
> +#include <usctest.h>
> +#include <test.h>
> +#include <libclone.h>
> +#else
> +#include "../../../../include/usctest.h"
> +#include "../libclone/libclone.h"
> +#endif
> +
> +char *TCID = "pid_namespace1";
> +int TST_TOTAL=1;
> +
> +void cleanup(void);
> +
> +#ifdef NO_LTP
> +#define TFAIL "FAILURE: "
> +#define TPASS "PASS: "
> +#define TINFO "INFO: "
> +#define TWARN "WARN: "
> +#define tst_resm(x, format, arg...) printf("%s:" format, x, ## arg)
> +#define tst_exit() exit(1)
> +#endif
> +
> +#define CHILD_PID       1
> +#define PARENT_PID      0
> +
> +
> +/*
> + * child_fn1() - Inside container
> + */
> +int child_fn1(void *ttype)
> +{
> +     pid_t cpid, ppid;
> +     cpid = getpid();
> +     ppid = getppid();
> +
> +     tst_resm(TINFO, "PIDNS test is running inside container\n");
> +     if(( cpid == CHILD_PID) &&
> +             ( ppid == PARENT_PID ) )
> +     {
> +                tst_resm(TPASS, "Success:" );
> +     }
> +     else
> +     {
> +             tst_resm(TFAIL, "FAIL: Got unexpected result of"
> +                     " cpid=%d ppid=%d\n", cpid, ppid);
> +     }

I'm still dubious - if this testcase fails, won't LTP claim all tests
pssed?

Yes the logs will have a FAIL message but one generally doesn't look at
those if all tests reported as passed.

So can someone confirm that LTP should report a failed test case the way
this is done?  (My own quick test suggests no)

> +     tst_exit();
> +}
> +
> +/***********************************************************************
> +*   M A I N
> +***********************************************************************/
> +
> +int main(int argc, char *argv[])
> +{
> +     int ret, status;
> +
> +     ret = do_clone_unshare_test(T_CLONE,
> +                             CLONE_NEWPID, child_fn1, NULL);
> +
> +     /* check return code */
> +     if (ret == -1) {
> +             tst_resm(TFAIL, "clone() Failed, errno = %d :"
> +                     " %s", ret, strerror(ret));
> +             /* Cleanup & continue with next test case */
> +             cleanup();
> +     }
> +
> +     /* Wait for child to finish */
> +     if ((wait(&status)) < 0) {
> +             tst_resm(TWARN, "wait() failed, skipping this"
> +                     " test case");
> +             /* Cleanup & continue with next test case */
> +             cleanup();
> +     }
> +
> +     if (WTERMSIG(status)) {
> +             tst_resm(TWARN, "child exited with signal %d",
> +                      WTERMSIG(status));
> +     }
> +
> +        /* cleanup and exit */
> +     cleanup();
> +
> +     /*NOTREACHED*/
> +     return 0;
> +
> +}    /* End main */
> +
> +/*
> + * cleanup() - performs all ONE TIME cleanup for this test at
> + *             completion or premature exit.
> + */
> +void
> +cleanup()
> +{
> +
> +#ifndef NO_LTP
> +     /* Clean the test testcase as LTP wants*/
> +     TEST_CLEANUP;
> +#endif
> +
> +     /* exit with return code appropriate for results */
> +     tst_exit();
> +}
> Index: ltp-full-20071130/testcases/kernel/containers/pidns/runpidnstest.sh
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ ltp-full-20071130/testcases/kernel/containers/pidns/runpidnstest.sh       
> 2007-12-27 16:27:39.000000000 +0530
> @@ -0,0 +1,8 @@
> +#!/bin/sh
> +
> +exit_code=0
> +pidns01
> +if [ $? -ne 0 ]; then
> +     exit_code="$?"
> +fi
> +exit $exit_code
> Index: ltp-full-20071130/testcases/kernel/containers/pidns/Makefile
> ===================================================================
> --- ltp-full-20071130.orig/testcases/kernel/containers/pidns/Makefile 
> 2007-12-27 16:26:18.000000000 +0530
> +++ ltp-full-20071130/testcases/kernel/containers/pidns/Makefile      
> 2007-12-27 16:27:39.000000000 +0530
> @@ -3,7 +3,7 @@
>  LDLIBS += -L../../../../lib -L../libclone ../libclone/libclone.a -lltp
> 
>  SRCS    = $(wildcard *.c)
> -NOLTPSRCS = 
> +NOLTPSRCS = pidns01.c
>  TARGETS = $(patsubst %.c,%,$(SRCS))
>  NOLTP_TARGETS = $(patsubst %.c,%_noltp,$(NOLTPSRCS))
> 
> @@ -18,4 +18,7 @@
>       rm -f $(TARGETS) *.o $(NOLTP_TARGETS)
> 
>  install:
> -     @set -e; for i in $(TARGETS) check_pidns_enabled; do ln -f $$i 
> ../../../bin/$$i; done
> +     @set -e; for i in $(TARGETS) runpidnstest.sh check_pidns_enabled; do ln 
> -f $$i ../../../bin/$$i ; chmod +x runpidnstest.sh ; done
> +
> +noltp_check: noltp
> +     ./runtests_noltp.sh
> Index: ltp-full-20071130/testcases/kernel/containers/container_test.sh
> ===================================================================
> --- ltp-full-20071130.orig/testcases/kernel/containers/container_test.sh      
> 2007-12-27 16:26:18.000000000 +0530
> +++ ltp-full-20071130/testcases/kernel/containers/container_test.sh   
> 2007-12-27 16:27:39.000000000 +0530
> @@ -57,6 +57,7 @@
>  check_pidns_enabled
>  if [ $? -eq 0 ]; then
>       echo "Running pidns tests."
> +     runpidnstest.sh
>  else
>       echo "pid namespaces not enabled in kernel.  Not running pidns tests."
>  fi

> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Ltp-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ltp-list


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to