[LTP] [PATCH 3/4] ltp: posix mqns: test vfs and mq interaction

2009-03-03 Thread Serge E. Hallyn
From 3bf32de589f6f6a456dbe721729a0d7273dfb7c4 Mon Sep 17 00:00:00 2001
From: Serge Hallyn se...@us.ibm.com
Date: Tue, 16 Dec 2008 22:35:16 +
Subject: [PATCH 3/4] ltp: posix mqns: test vfs and mq interaction

Test that the interaction between mqueuefs and ipc namespaces
is correct (one mqueuefs for each ipc namespace, living at least
as long as the namespace)

Signed-off-by: Serge Hallyn se...@us.ibm.com
---
 testcases/kernel/containers/mqns/mqns.h |1 +
 testcases/kernel/containers/mqns/mqns_03.c  |  196 +++
 testcases/kernel/containers/mqns/runmqnstest.sh |2 +-
 3 files changed, 198 insertions(+), 1 deletions(-)
 create mode 100644 testcases/kernel/containers/mqns/mqns_03.c

diff --git a/testcases/kernel/containers/mqns/mqns.h 
b/testcases/kernel/containers/mqns/mqns.h
index df8fc4b..4bf1e1f 100644
--- a/testcases/kernel/containers/mqns/mqns.h
+++ b/testcases/kernel/containers/mqns/mqns.h
@@ -9,5 +9,6 @@
 
 #define DEV_MQUEUE /dev/mqueue
 #define SLASH_MQ1 /MQ1
+#define SLASH_MQ2 /MQ2
 
 #endif /* __MQNS_H */
diff --git a/testcases/kernel/containers/mqns/mqns_03.c 
b/testcases/kernel/containers/mqns/mqns_03.c
new file mode 100644
index 000..e7f9877
--- /dev/null
+++ b/testcases/kernel/containers/mqns/mqns_03.c
@@ -0,0 +1,196 @@
+/*
+* 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: Serge Hallyn se...@us.ibm.com
+*
+* Check ipcns+sb longevity
+*
+* Mount mqueue fs
+* unshare
+* In unshared process:
+*Create /mq1 with mq_open()
+*Mount mqueuefs
+*Check that /mq1 exists
+*Create /dev/mqueue/mq2 through vfs (create(2))
+*Umount /dev/mqueue
+*Remount /dev/mqueue
+*Check that both /mq1 and /mq2 exist
+
+***/
+
+#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
+#include mqns.h
+
+char *TCID = posixmq_namespace_03;
+int TST_TOTAL=1;
+
+int p1[2];
+int p2[2];
+
+#define FNAM1 DEV_MQUEUE2 SLASH_MQ1
+#define FNAM2 DEV_MQUEUE2 SLASH_MQ2
+
+int check_mqueue(void *vtest)
+{
+   char buf[30];
+   mqd_t mqd;
+   int rc;
+   struct stat statbuf;
+
+   close(p1[1]);
+   close(p2[0]);
+
+   read(p1[0], buf, 3); /* go */
+
+   mqd = mq_open(SLASH_MQ1, O_RDWR|O_CREAT|O_EXCL, 0755, NULL);
+   if (mqd == -1) {
+   write(p2[1], mqfail, 7);
+   tst_exit(3);
+   }
+
+   mq_close(mqd);
+
+   rc = mount(mqueue, DEV_MQUEUE2, mqueue, 0, NULL);
+   if (rc == -1) {
+   perror(mount);
+   write(p2[1], mount1, 7);
+   tst_exit(3);
+   }
+
+   rc = stat(FNAM1, statbuf);
+   if (rc == -1) {
+   write(p2[1], stat1, 6);
+   tst_exit(3);
+   }
+
+   rc = creat(FNAM2, 0755);
+   if (rc == -1) {
+   write(p2[1], creat, 6);
+   tst_exit(3);
+   }
+
+   close(rc);
+
+   rc = umount(DEV_MQUEUE2);
+   if (rc == -1) {
+   perror(umount);
+   write(p2[1], umount, 7);
+   tst_exit(3);
+   }
+
+   rc = mount(mqueue, DEV_MQUEUE2, mqueue, 0, NULL);
+   if (rc == -1) {
+   write(p2[1], mount2, 7);
+   tst_exit(3);
+   }
+
+   rc = stat(FNAM1, statbuf);
+   if (rc == -1) {
+   write(p2[1], stat2, 7);
+   tst_exit(3);
+   }
+
+   rc = stat(FNAM2, statbuf);
+   if (rc == -1) {
+   write(p2[1], stat3, 7);
+   tst_exit(3);
+   }
+
+   write(p2[1], done, 5);
+
+   tst_exit(0);
+
+   /* NOT REACHED */
+   return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+   int r;
+   char buf[30];
+   int use_clone = T_UNSHARE;
+
+   if (argc == 2  strcmp(argv[1], -clone) == 0) {
+   tst_resm(TINFO, Testing posix mq namespaces through 
clone(2).\n);
+   use_clone = T_CLONE;
+   } else
+   tst_resm(TINFO, Testing posix mq namespaces through 
unshare(2).\n);
+
+   if (pipe(p1) == -1) { perror(pipe); exit(EXIT_FAILURE); }
+   if (pipe(p2) == -1) { perror(pipe); exit(EXIT_FAILURE

Re: [LTP] [PATCH 3/4] ltp: posix mqns: test vfs and mq interaction

2009-03-03 Thread Subrata Modak
On Tue, 2009-03-03 at 17:02 -0600, Serge E. Hallyn wrote:
 From 3bf32de589f6f6a456dbe721729a0d7273dfb7c4 Mon Sep 17 00:00:00 2001
 From: Serge Hallyn se...@us.ibm.com
 Date: Tue, 16 Dec 2008 22:35:16 +
 Subject: [PATCH 3/4] ltp: posix mqns: test vfs and mq interaction
 
 Test that the interaction between mqueuefs and ipc namespaces
 is correct (one mqueuefs for each ipc namespace, living at least
 as long as the namespace)
 
 Signed-off-by: Serge Hallyn se...@us.ibm.com

Thanks.

Regards--
Subrata

 ---
  testcases/kernel/containers/mqns/mqns.h |1 +
  testcases/kernel/containers/mqns/mqns_03.c  |  196 
 +++
  testcases/kernel/containers/mqns/runmqnstest.sh |2 +-
  3 files changed, 198 insertions(+), 1 deletions(-)
  create mode 100644 testcases/kernel/containers/mqns/mqns_03.c
 
 diff --git a/testcases/kernel/containers/mqns/mqns.h 
 b/testcases/kernel/containers/mqns/mqns.h
 index df8fc4b..4bf1e1f 100644
 --- a/testcases/kernel/containers/mqns/mqns.h
 +++ b/testcases/kernel/containers/mqns/mqns.h
 @@ -9,5 +9,6 @@
 
  #define DEV_MQUEUE /dev/mqueue
  #define SLASH_MQ1 /MQ1
 +#define SLASH_MQ2 /MQ2
 
  #endif /* __MQNS_H */
 diff --git a/testcases/kernel/containers/mqns/mqns_03.c 
 b/testcases/kernel/containers/mqns/mqns_03.c
 new file mode 100644
 index 000..e7f9877
 --- /dev/null
 +++ b/testcases/kernel/containers/mqns/mqns_03.c
 @@ -0,0 +1,196 @@
 +/*
 +* 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: Serge Hallyn se...@us.ibm.com
 +*
 +* Check ipcns+sb longevity
 +*
 +* Mount mqueue fs
 +* unshare
 +* In unshared process:
 +*Create /mq1 with mq_open()
 +*Mount mqueuefs
 +*Check that /mq1 exists
 +*Create /dev/mqueue/mq2 through vfs (create(2))
 +*Umount /dev/mqueue
 +*Remount /dev/mqueue
 +*Check that both /mq1 and /mq2 exist
 +
 +***/
 +
 +#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
 +#include mqns.h
 +
 +char *TCID = posixmq_namespace_03;
 +int TST_TOTAL=1;
 +
 +int p1[2];
 +int p2[2];
 +
 +#define FNAM1 DEV_MQUEUE2 SLASH_MQ1
 +#define FNAM2 DEV_MQUEUE2 SLASH_MQ2
 +
 +int check_mqueue(void *vtest)
 +{
 + char buf[30];
 + mqd_t mqd;
 + int rc;
 + struct stat statbuf;
 +
 + close(p1[1]);
 + close(p2[0]);
 +
 + read(p1[0], buf, 3); /* go */
 +
 + mqd = mq_open(SLASH_MQ1, O_RDWR|O_CREAT|O_EXCL, 0755, NULL);
 + if (mqd == -1) {
 + write(p2[1], mqfail, 7);
 + tst_exit(3);
 + }
 +
 + mq_close(mqd);
 +
 + rc = mount(mqueue, DEV_MQUEUE2, mqueue, 0, NULL);
 + if (rc == -1) {
 + perror(mount);
 + write(p2[1], mount1, 7);
 + tst_exit(3);
 + }
 +
 + rc = stat(FNAM1, statbuf);
 + if (rc == -1) {
 + write(p2[1], stat1, 6);
 + tst_exit(3);
 + }
 +
 + rc = creat(FNAM2, 0755);
 + if (rc == -1) {
 + write(p2[1], creat, 6);
 + tst_exit(3);
 + }
 +
 + close(rc);
 +
 + rc = umount(DEV_MQUEUE2);
 + if (rc == -1) {
 + perror(umount);
 + write(p2[1], umount, 7);
 + tst_exit(3);
 + }
 +
 + rc = mount(mqueue, DEV_MQUEUE2, mqueue, 0, NULL);
 + if (rc == -1) {
 + write(p2[1], mount2, 7);
 + tst_exit(3);
 + }
 +
 + rc = stat(FNAM1, statbuf);
 + if (rc == -1) {
 + write(p2[1], stat2, 7);
 + tst_exit(3);
 + }
 +
 + rc = stat(FNAM2, statbuf);
 + if (rc == -1) {
 + write(p2[1], stat3, 7);
 + tst_exit(3);
 + }
 +
 + write(p2[1], done, 5);
 +
 + tst_exit(0);
 +
 + /* NOT REACHED */
 + return 0;
 +}
 +
 +
 +int main(int argc, char *argv[])
 +{
 + int r;
 + char buf[30];
 + int use_clone = T_UNSHARE;
 +
 + if (argc == 2  strcmp(argv[1], -clone) == 0) {
 + tst_resm(TINFO, Testing posix mq namespaces through 
 clone(2).\n);
 + use_clone = T_CLONE;
 + } else
 + tst_resm(TINFO, Testing posix mq namespaces through 
 unshare(2).\n