Hi Subrata
Please find the testcase on Containers to test the mesgQ.
Test Assertion:
This testcase verifies the MesgQ isoloation in 2 containers.
It tries to create/access a MesgQ created with the same KEY.
Changelog :
(Version 2 )
Used 1 more pipe to sync between the container1 and parent NS.
Also defined the const READMAX ad #define.
Description:
Create 2 'containers' with the below flag value
Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
In Cont1, create MesgQ with key 124326L
In Cont2, try to access the MQ created in Cont1.
PASS :
If flag = None and the MesgQ is accessible in Cont2.
If flag = unshare/clone and the MesgQ is not accessible in Cont2.
If mesgQ is not accessible in Cont2, creates new mesgQ with the
same key
to double check isloation in IPCNS.
FAIL :
If flag = none and the mesgq is not accessible.
If flag = unshare/clone and mesgq is accessible in Cont2.
If the new mesgQ creation Fails.
*RESULTS:*
sysvipc: MesgQ none
mesgq_2NStest 0 INFO : mesgq namespaces test : none
mesgq_2NStest 0 INFO : Cont1: Able to create mesgq
mesgq_2NStest 0 INFO : Mesg read of 18 bytes; Type 2: Msg: Message of
type 2!
mesgq_2NStest 1 PASS : Plain cloned process able to access the mesgq
created
sysvipc: MesgQ clone
mesgq_2NStest 0 INFO : mesgq namespaces test : clone
mesgq_2NStest 0 INFO : Cont1: Able to create mesgq
mesgq_2NStest 0 INFO : Cont2: Able to create mesgq with same key
mesgq_2NStest 1 PASS : clone : In namespace2 unable to access the mesgq
created in Namespace1
sysvipc: MesgQ unshare
mesgq_2NStest 0 INFO : mesgq namespaces test : unshare
mesgq_2NStest 0 INFO : Cont1: Able to create mesgq
mesgq_2NStest 0 INFO : Cont2: Able to create mesgq with same key
mesgq_2NStest 1 PASS : unshare : In namespace2 unable to access the mesgq
created in Namespace1
Signed-off-by: Veerendra C <[email protected]>
Index: ltp-full-20081231/testcases/kernel/containers/sysvipc/mqtest_2ns.c
===================================================================
--- /dev/null
+++ ltp-full-20081231/testcases/kernel/containers/sysvipc/mqtest_2ns.c
@@ -0,0 +1,197 @@
+/* *************************************************************************
+* 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 <[email protected]>
+*
+* Test Assertion:
+* This testcase verifies the MesgQ isoloation in 2 containers.
+* It tries to create/access a MesgQ created with the same KEY.
+*
+* Description:
+* Create 2 'containers' with the below flag value
+* Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
+* In Cont1, create MesgQ with key 124326L
+* In Cont2, try to access the MQ created in Cont1.
+* PASS :
+* If flag = None and the MesgQ is accessible in Cont2.
+* If flag = unshare/clone and the MesgQ is not accessible in Cont2.
+* If mesgQ is not accessible in Cont2, creates new mesgQ with the same key
+* to double check isloation in IPCNS.
+*
+* FAIL :
+* If flag = none and the mesgq is not accessible.
+* If flag = unshare/clone and mesgq is accessible in Cont2.
+* If the new mesgQ creation Fails.
+***************************************************************************/
+
+#define _GNU_SOURCE 1
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <libclone.h>
+#include <test.h>
+
+#define KEY_VAL 124326L
+#define UNSHARESTR "unshare"
+#define CLONESTR "clone"
+#define NONESTR "none"
+#define READMAX (sizeof(struct msg_buf))
+
+char *TCID = "mesgq_2NStest";
+int TST_TOTAL = 1;
+int p1[2];
+int p2[2];
+int p3[2];
+struct msg_buf {
+ long int mtype; /* type of received/sent message */
+ char mtext[80]; /* text of the message */
+ } msg;
+
+void mesgq_read(int id)
+{
+ int n;
+ /* read msg type 2 on the Q; msgtype, flags are last 2 params..*/
+
+ n = msgrcv(id, &msg, READMAX, 2, 0);
+ if (n == -1) {
+ perror("msgrcv");
+ exit(1);
+ }
+ tst_resm(TINFO, "Mesg read of %d bytes; Type %ld: Msg: %.*s",
+ n, msg.mtype, n, msg.mtext);
+
+}
+
+int check_mesgq1(void *vtest)
+{
+ int id1, n;
+ close(p1[0]);
+ id1 = msgget(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600);
+ if (id1 == -1) {
+ perror("msgget failure");
+ exit(1);
+ }
+
+ msg.mtype = 2;
+ strcpy(msg.mtext, "Message of type 2!");
+ n = msgsnd(id1, &msg, strlen(msg.mtext), 0);
+ if (n == -1) {
+ perror("msgsnd failure");
+ exit(1);
+ }
+ tst_resm(TINFO, "Cont1: Able to create mesgq");
+ write(p1[1], "done", 5);
+ tst_exit();
+ return 0;
+}
+
+int check_mesgq2(void *vtest)
+{
+ char buf[3];
+ int id2;
+ close(p2[0]);
+ close(p3[1]);
+
+ read(p3[0], buf, 3);
+ id2 = msgget(KEY_VAL, 0);
+
+ if (id2 != -1) {
+ mesgq_read(id2);
+ write(p2[1], "exists", 7);
+ } else {
+ write(p2[1], "notfnd", 7);
+ /* Trying to create a new MesgQ, if MesgQ is not existing */
+ id2 = msgget(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600);
+ if (id2 == -1) {
+ perror("msgget failure");
+ exit(1);
+ } else
+ tst_resm(TINFO, "Cont2: Able to create mesgq with same key");
+ }
+ tst_exit();
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret, use_clone = T_NONE;
+ char *tsttype = NONESTR;
+ char buf[7];
+ int id;
+
+ if (argc != 2) {
+ tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]);
+ tst_resm(TINFO, " where clone, unshare, or fork specifies"
+ " unshare method.\n");
+ 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 (pipe(p3) == -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;
+ }
+
+ tst_resm(TINFO, "mesgq namespaces test : %s", tsttype);
+
+ /* Create 2 containers */
+ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq1, NULL);
+ if (ret < 0) {
+ tst_resm(TFAIL, "clone/unshare failed\n");
+ tst_exit();
+ }
+
+ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq2, NULL);
+ if (ret < 0) {
+ tst_resm(TFAIL, "clone/unshare failed\n");
+ tst_exit();
+ }
+ close(p1[0]);
+ close(p2[1]);
+ close(p1[1]);
+ read(p1[0], buf, 5);
+ write(p3[1], "go", 3);
+ read(p2[0], buf, 7);
+
+ if (strcmp(buf, "exists") == 0)
+ if (use_clone == T_NONE)
+ tst_resm(TPASS, "Plain cloned process able to access the mesgq "
+ "created\n");
+ else
+ tst_resm(TPASS, "%s : In namespace2 found the mesgq "
+ "created in Namespace1\n", tsttype);
+ else
+ if (use_clone == T_NONE)
+ tst_resm(TFAIL, "Plain cloned process didn't find mesgq\n");
+ else
+ tst_resm(TPASS, "%s : In namespace2 unable to access the mesgq "
+ "created in Namespace1\n", tsttype);
+
+ id = msgget(KEY_VAL, 0);
+ msgctl(id, IPC_RMID, NULL);
+ tst_exit();
+
+ 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
@@ -39,6 +39,11 @@ for type in none clone unshare; do
if [ $exit_code -ne 0 ]; then
exit_code=$ret
fi
+ mqtest_2ns $type
+ ret=$?
+ if [ $exit_code -ne 0 ]; then
+ exit_code=$ret
+ fi
done
echo
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list