Quoting Veerendra (vee...@linux.vnet.ibm.com):
> Hi
>
>
>    Submitting a new testcase on semaphore to test the IPCNS in the  
> containers. This patch contains the batch file to run the test on LTP.
>
> In this patch , I am checking  the IPCNS functionaity:
> "Semaphore in parent NS is isolated from the container"
>
>
> Changelog:
>       Removed the extra semget call in the check_semaphore().
>       Corrected the indentation.
>
> Results:
>
> sysvipc: Semaphore none
> sem_nstest    0  INFO  :  Semaphore namespaces Isolation test : none
>
> sem_nstest    0  INFO  :  PID 9262: Fetched existing semaphore..id = 2031616
>
> sem_nstest    1  PASS  :  Plain cloned process found semaphore inside 
> container
>
> sysvipc: Semaphore clone
> sem_nstest    0  INFO  :  Semaphore namespaces Isolation test : clone
>
> sem_nstest    1  PASS  :  clone: Container didn't find semaphore
> sysvipc: Semaphore unshare
> sem_nstest    0  INFO  :  Semaphore namespaces Isolation test : unshare
>
> sem_nstest    1  PASS  :  unshare: Container didn't find semaphore
>
>
>
>
>
> Regardz
> Veerendra C
>
>
>
>

> Signed-off-by: Veerendra C <veeren...@in.ibm.com>

Acked-by: Serge Hallyn <se...@us.ibm.com>

EXCEPT  you should probably use a tst_resm(TBROK) + tst_exit() when
semget fails in main().

thanks,
-serge

> Index: ltp-full-20081231/testcases/kernel/containers/sysvipc/sem_nstest.c
> ===================================================================
> --- /dev/null
> +++ ltp-full-20081231/testcases/kernel/containers/sysvipc/sem_nstest.c
> @@ -0,0 +1,143 @@
> +/* *************************************************************************
> +* Copyright (c) International Business Machines Corp., 2009
> +* 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
> +*
> +* Author: Veerendra C <vecha...@in.ibm.com>
> +*
> +* In Parent Process , create semaphore with key 154326L
> +* Now create container by passing 1 of the below flag values..
> +*    clone(NONE), clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
> +* In cloned process, try to access the created semaphore
> +* Test PASS: If the semaphore is readable when flag is None.
> +* Test FAIL: If the semaphore is readable when flag is Unshare or Clone.
> +***************************************************************************/
> +
> +#define _GNU_SOURCE 1
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <sys/ipc.h>
> +#include <sys/sem.h>
> +#include <libclone.h>
> +#include <test.h>
> +
> +#define MY_KEY     154326L
> +#define UNSHARESTR "unshare"
> +#define CLONESTR   "clone"
> +#define NONESTR    "none"
> +
> +char *TCID = "sem_nstest";
> +int TST_TOTAL = 1;
> +int p1[2];
> +int p2[2];
> +
> +int check_semaphore(void *vtest)
> +{
> +     char buf[3];
> +     int id;
> +
> +     close(p1[1]);
> +     close(p2[0]);
> +
> +     read(p1[0], buf, 3);
> +     id = semget(MY_KEY, 1, 0);
> +     if (id == -1)
> +             write(p2[1], "notfnd", 7);
> +     else {
> +             write(p2[1], "exists", 7);
> +             tst_resm(TINFO, "PID %d: Fetched existing semaphore..id = %d\n",
> +                                             getpid(), id );
> +     }
> +     tst_exit();
> +
> +     /* NOT REACHED */
> +     return 0;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +     int ret, use_clone = T_NONE, id;
> +     char *tsttype = NONESTR;
> +     char buf[7];
> +
> +     if (argc != 2) {
> +             tst_resm(TFAIL, "Usage: %s <clone| unshare| none>\n", argv[0]);
> +             tst_resm(TFAIL, " where clone, unshare, or fork specifies"
> +                             " unshare method.");
> +             tst_exit();
> +     }
> +
> +     /* Using PIPE's to sync between container and Parent */
> +     if (pipe(p1) == -1) { perror("pipe"); exit(EXIT_FAILURE); }
> +     if (pipe(p2) == -1) { perror("pipe"); exit(EXIT_FAILURE); }
> +
> +     if (strcmp(argv[1], "clone") == 0) {
> +             use_clone = T_CLONE;
> +             tsttype = CLONESTR;
> +     } else if (strcmp(argv[1], "unshare") == 0) {
> +             use_clone = T_UNSHARE;
> +             tsttype = UNSHARESTR;
> +     }
> +
> +
> +       /* 1. Create (or fetch if existing) the binary semaphore */
> +       id = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
> +       if (id == -1) {
> +                 perror( "Semaphore create" );
> +                 if (errno != EEXIST) {
> +                             perror("semget failure");
> +                             exit(1);
> +                 }
> +                 id = semget(MY_KEY, 1, 0);
> +                 if (id == -1)
> +                             perror( "Semaphore create" ), exit(1);
> +       }
> +
> +     tst_resm(TINFO, "Semaphore namespaces Isolation test : %s\n", tsttype);
> +     /* fire off the test */
> +     ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_semaphore, 
> NULL);
> +     if (ret < 0) {
> +             tst_resm(TFAIL, "%s failed\n", tsttype);
> +             tst_exit();
> +     }
> +
> +     close(p1[0]);
> +     close(p2[1]);
> +     write(p1[1], "go", 3);
> +     read(p2[0], buf, 7);
> +
> +     if (strcmp(buf, "exists") == 0) {
> +             if (use_clone == T_NONE)
> +                     tst_resm(TPASS, "Plain cloned process found semaphore "
> +                                                 "inside container\n");
> +             else
> +                     tst_resm(TFAIL, "%s: Container init process found 
> semaphore\n",
> +                                                     tsttype);
> +     } else {
> +             if (use_clone == T_NONE)
> +                     tst_resm(TFAIL, "Plain cloned process didn't find 
> semaphore\n");
> +             else
> +                     tst_resm(TPASS, "%s: Container didn't find semaphore", 
> tsttype);
> +     }
> +
> +     /* Delete the semaphore */
> +     id = semget(MY_KEY, 1, 0);
> +     semctl(id, IPC_RMID, 0);
> +
> +     tst_exit();
> +
> +     /* NOT REACHED */
> +     return 0;
> +}
> Index: ltp-full-20081231/testcases/kernel/containers/sysvipc/runipcnstest.sh
> ===================================================================
> --- ltp-full-20081231.orig/testcases/kernel/containers/sysvipc/runipcnstest.sh
> +++ ltp-full-20081231/testcases/kernel/containers/sysvipc/runipcnstest.sh
> @@ -31,6 +31,7 @@ for type in none clone unshare; do
>        fi
>  done
>  echo
> +
>  for type in none clone unshare; do
>        echo "sysvipc: MesgQ $type"
>        mesgq_nstest $type
> @@ -40,4 +41,15 @@ for type in none clone unshare; do
>        fi
>  done
>  echo
> +
> +for type in none clone unshare; do
> +      echo "sysvipc: Semaphore $type"
> +      sem_nstest $type
> +      ret=$?
> +      if [ $exit_code -ne 0 ]; then
> +              exit_code=$ret
> +      fi
> +done
> +echo
> +
>  exit $exit_code

> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to