* [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c
@ 2014-09-04 13:33 Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 2/3] containers: added sysvipc/msg_comm.c Matus Marhefka
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Matus Marhefka @ 2014-09-04 13:33 UTC (permalink / raw)
To: ltp-list
* Tests communication over shared memory segments (shm)
with identical keys between two separate IPC namespaces
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
runtest/containers | 1 +
testcases/kernel/containers/sysvipc/.gitignore | 1 +
testcases/kernel/containers/sysvipc/shm_comm.c | 215 +++++++++++++++++++++++++
3 files changed, 217 insertions(+)
create mode 100644 testcases/kernel/containers/sysvipc/shm_comm.c
diff --git a/runtest/containers b/runtest/containers
index fc61ada..84ae736 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -39,6 +39,7 @@ shmnstest_unshare shmnstest unshare
shmem_2nstest_none shmem_2nstest none
shmem_2nstest_clone shmem_2nstest clone
shmem_2nstest_unshare shmem_2nstest unshare
+shm_comm shm_comm
mesgq_nstest_none mesgq_nstest none
mesgq_nstest_clone mesgq_nstest clone
mesgq_nstest_unshare mesgq_nstest unshare
diff --git a/testcases/kernel/containers/sysvipc/.gitignore b/testcases/kernel/containers/sysvipc/.gitignore
index 58cfbee..b5a4cbd 100644
--- a/testcases/kernel/containers/sysvipc/.gitignore
+++ b/testcases/kernel/containers/sysvipc/.gitignore
@@ -3,3 +3,4 @@
/semtest_2ns
/shmem_2nstest
/shmnstest
+/shm_comm
diff --git a/testcases/kernel/containers/sysvipc/shm_comm.c b/testcases/kernel/containers/sysvipc/shm_comm.c
new file mode 100644
index 0000000..ef8803b
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/shm_comm.c
@@ -0,0 +1,215 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: shm_comm.c
+ *
+ * Description:
+ * 1. Clones two child processes with CLONE_NEWIPC flag, each child
+ * allocates System V shared memory segment (shm) with the _identical_
+ * key and attaches that segment into its address space.
+ * 2. Child1 writes into the shared memory segment.
+ * 3. Child2 writes into the shared memory segment.
+ * 4. Writes to the shared memory segment with the identical key but from
+ * two different IPC namespaces should not interfere with each other
+ * and so child1 checks whether its shared segment wasn't changed
+ * by child2, if it wasn't test passes, otherwise test fails.
+ */
+
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+#include "ipcns_helper.h"
+
+
+#define TESTKEY 124426L
+#define SHMSIZE 50
+char *TCID = "shm_comm";
+int TST_TOTAL = 1;
+int p1[2];
+int p2[2];
+
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ check_newipc();
+}
+
+int chld1_shm(void *arg)
+{
+ int id, rval = 0;
+ char *shmem, buf;
+
+ close(p1[0]);
+ close(p2[1]);
+
+ /* allocate a System V shared memory segment */
+ id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
+ if (id == -1) {
+ perror("shmget");
+ close(p1[1]);
+ close(p2[0]);
+ return 2;
+ }
+
+ /* attach the segment reffered by id into the child1 data space */
+ if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
+ perror("shmat");
+ close(p1[1]);
+ close(p2[0]);
+ shmctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* write to the shared segment */
+ *shmem = 'A';
+
+ /* tell child2 to continue */
+ write(p1[1], "1", 1);
+
+ /* wait for child2 */
+ read(p2[0], &buf, 1);
+
+ /* if child1 shared segment has changed (by child2) report fail */
+ if (*shmem != 'A')
+ rval = 1;
+
+ /* tell child2 to continue */
+ write(p1[1], "1", 1);
+
+ close(p1[1]);
+ close(p2[0]);
+
+ /* detaches the shared memory segment */
+ shmdt(shmem);
+ /* remove the shared memory segment */
+ shmctl(id, IPC_RMID, NULL);
+
+ return rval;
+}
+
+int chld2_shm(void *arg)
+{
+ int id;
+ char *shmem, buf;
+
+ close(p1[1]);
+ close(p2[0]);
+
+ /* allocate a System V shared memory segment */
+ id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
+ if (id == -1) {
+ perror("shmget");
+ close(p1[0]);
+ close(p2[1]);
+ return 2;
+ }
+
+ /* attach the segment referred by id into the child2 data space */
+ if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
+ perror("shmat");
+ close(p1[0]);
+ close(p2[1]);
+ shmctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* wait for child1 to write to his segment */
+ read(p1[0], &buf, 1);
+
+ /* write to the shared segment */
+ *shmem = 'B';
+
+ /* tell child1 to continue */
+ write(p2[1], "1", 1);
+
+ /* wait for child1 */
+ read(p1[0], &buf, 1);
+
+ close(p1[0]);
+ close(p2[1]);
+
+ /* detaches the shared memory segment */
+ shmdt(shmem);
+ /* remove the shared memory segment */
+ shmctl(id, IPC_RMID, NULL);
+
+ return 0;
+}
+
+static void test(void)
+{
+ int status, ret = 0;
+
+ SAFE_PIPE(NULL, p1);
+ SAFE_PIPE(NULL, p2);
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, NULL, "clone failed");
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, NULL, "clone failed");
+
+ close(p1[0]);
+ close(p1[1]);
+ close(p2[0]);
+ close(p2[1]);
+
+ /* wait for child processes */
+ while (wait(&status) > 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
+ ret = 1;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
+ tst_brkm(TBROK | TERRNO, NULL, "error in child");
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+ }
+
+ if (ret)
+ tst_resm(TFAIL, "SysV shm: communication with identical keys"
+ " between namespaces");
+ else
+ tst_resm(TPASS, "SysV shm: communication with identical keys"
+ " between namespaces");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH 2/3] containers: added sysvipc/msg_comm.c
2014-09-04 13:33 [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c Matus Marhefka
@ 2014-09-04 13:33 ` Matus Marhefka
2014-10-02 14:47 ` [LTP] [PATCH 2/3 v2] " Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c Matus Marhefka
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Matus Marhefka @ 2014-09-04 13:33 UTC (permalink / raw)
To: ltp-list
* Tests communication over message queues with identical
keys between two separate IPC namespaces
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
runtest/containers | 1 +
testcases/kernel/containers/sysvipc/.gitignore | 1 +
testcases/kernel/containers/sysvipc/msg_comm.c | 221 +++++++++++++++++++++++++
3 files changed, 223 insertions(+)
create mode 100644 testcases/kernel/containers/sysvipc/msg_comm.c
diff --git a/runtest/containers b/runtest/containers
index 84ae736..7dbf049 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -43,6 +43,7 @@ shm_comm shm_comm
mesgq_nstest_none mesgq_nstest none
mesgq_nstest_clone mesgq_nstest clone
mesgq_nstest_unshare mesgq_nstest unshare
+msg_comm msg_comm
sem_nstest_none sem_nstest none
sem_nstest_clone sem_nstest clone
sem_nstest_unshare sem_nstest unshare
diff --git a/testcases/kernel/containers/sysvipc/.gitignore b/testcases/kernel/containers/sysvipc/.gitignore
index b5a4cbd..68f18bf 100644
--- a/testcases/kernel/containers/sysvipc/.gitignore
+++ b/testcases/kernel/containers/sysvipc/.gitignore
@@ -4,3 +4,4 @@
/shmem_2nstest
/shmnstest
/shm_comm
+/msg_comm
diff --git a/testcases/kernel/containers/sysvipc/msg_comm.c b/testcases/kernel/containers/sysvipc/msg_comm.c
new file mode 100644
index 0000000..3ecf2a8
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/msg_comm.c
@@ -0,0 +1,221 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: msg_comm.c
+ *
+ * Description:
+ * 1. Clones two child processes with CLONE_NEWIPC flag, each child
+ * gets System V message queue (msg) with the _identical_ key.
+ * 2. Child1 appends a message with identifier #1 to the message queue.
+ * 3. Child2 appends a message with identifier #2 to the message queue.
+ * 4. Appends to the message queue with the identical key but from
+ * two different IPC namespaces should not interfere with each other
+ * and so child1 checks whether its message queue doesn't contain
+ * a message with identifier #2, if it doesn't test passes, otherwise
+ * test fails.
+ */
+
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+#include "ipcns_helper.h"
+
+
+#define TESTKEY 124426L
+#define MSGSIZE 50
+char *TCID = "msg_comm";
+int TST_TOTAL = 1;
+int p1[2];
+int p2[2];
+struct sysv_msg {
+ long mtype;
+ char mtext[MSGSIZE];
+};
+
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ check_newipc();
+}
+
+int chld1_msg(void *arg)
+{
+ int id, n, rval = 0;
+ char buf;
+ struct sysv_msg m;
+ struct sysv_msg rec;
+
+ close(p1[0]);
+ close(p2[1]);
+
+ /* get a System V message queue identifier */
+ id = msgget(TESTKEY, IPC_CREAT | 0600);
+ if (id == -1) {
+ perror("msgget");
+ close(p1[1]);
+ close(p2[0]);
+ return 2;
+ }
+
+ /* write to the message queue */
+ m.mtype = 1;
+ m.mtext[0] = 'A';
+ if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
+ perror("msgsnd");
+ close(p1[1]);
+ close(p2[0]);
+ msgctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* wait for child2 to write into the message queue */
+ read(p2[0], &buf, 1);
+
+ /* if child1 message queue has changed (by child2) report fail */
+ n = msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long),
+ 2, IPC_NOWAIT);
+ if (n == -1 && errno != ENOMSG) {
+ perror("msgrcv");
+ close(p1[1]);
+ close(p2[0]);
+ msgctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+ /* if mtype #2 was found in the message queue, it is fail */
+ if (n > 0) {
+ rval = 1;
+ }
+
+ /* tell child2 to continue */
+ write(p1[1], "1", 1);
+
+ close(p1[1]);
+ close(p2[0]);
+
+ /* remove the message queue */
+ msgctl(id, IPC_RMID, NULL);
+
+ return rval;
+}
+
+int chld2_msg(void *arg)
+{
+ int id;
+ char buf;
+ struct sysv_msg m;
+
+ close(p1[1]);
+ close(p2[0]);
+
+ /* get a System V message queue identifier */
+ id = msgget(TESTKEY, IPC_CREAT | 0600);
+ if (id == -1) {
+ perror("msgget");
+ close(p1[1]);
+ close(p2[0]);
+ return 2;
+ }
+
+ /* write to the message queue */
+ m.mtype = 2;
+ m.mtext[0] = 'B';
+ if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
+ perror("msgsnd");
+ close(p1[1]);
+ close(p2[0]);
+ msgctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* tell child1 to continue */
+ write(p2[1], "1", 1);
+
+ /* wait for child1 */
+ read(p1[0], &buf, 1);
+
+ close(p1[0]);
+ close(p2[1]);
+
+ /* remove the message queue */
+ msgctl(id, IPC_RMID, NULL);
+
+ return 0;
+}
+
+static void test(void)
+{
+ int status, ret = 0;
+
+ SAFE_PIPE(NULL, p1);
+ SAFE_PIPE(NULL, p2);
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, NULL, "clone failed");
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, NULL, "clone failed");
+
+ close(p1[0]);
+ close(p1[1]);
+ close(p2[0]);
+ close(p2[1]);
+
+ /* wait for child processes */
+ while (wait(&status) > 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
+ ret = 1;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
+ tst_brkm(TBROK | TERRNO, NULL, "error in child");
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+ }
+
+ if (ret)
+ tst_resm(TFAIL, "SysV msg: communication with identical keys"
+ " between namespaces");
+ else
+ tst_resm(TPASS, "SysV msg: communication with identical keys"
+ " between namespaces");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c
2014-09-04 13:33 [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 2/3] containers: added sysvipc/msg_comm.c Matus Marhefka
@ 2014-09-04 13:33 ` Matus Marhefka
2014-09-24 11:03 ` chrubis
2014-10-02 14:48 ` [LTP] [PATCH 3/3 v2] " Matus Marhefka
2014-09-24 10:03 ` [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c chrubis
2014-10-02 14:47 ` [LTP] [PATCH 1/3 v2] " Matus Marhefka
3 siblings, 2 replies; 9+ messages in thread
From: Matus Marhefka @ 2014-09-04 13:33 UTC (permalink / raw)
To: ltp-list
* Tests communication over semaphore sets with identical
keys between two separate IPC namespaces
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
runtest/containers | 1 +
testcases/kernel/containers/sysvipc/.gitignore | 1 +
testcases/kernel/containers/sysvipc/sem_comm.c | 243 +++++++++++++++++++++++++
3 files changed, 245 insertions(+)
create mode 100644 testcases/kernel/containers/sysvipc/sem_comm.c
diff --git a/runtest/containers b/runtest/containers
index 7dbf049..6535628 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -50,6 +50,7 @@ sem_nstest_unshare sem_nstest unshare
semtest_2ns_none semtest_2ns none
semtest_2ns_clone semtest_2ns clone
semtest_2ns_unshare semtest_2ns unshare
+sem_comm sem_comm
utstest_unshare_1 utstest unshare 1
utstest_unshare_2 utstest unshare 2
diff --git a/testcases/kernel/containers/sysvipc/.gitignore b/testcases/kernel/containers/sysvipc/.gitignore
index 68f18bf..815a717 100644
--- a/testcases/kernel/containers/sysvipc/.gitignore
+++ b/testcases/kernel/containers/sysvipc/.gitignore
@@ -5,3 +5,4 @@
/shmnstest
/shm_comm
/msg_comm
+/sem_comm
diff --git a/testcases/kernel/containers/sysvipc/sem_comm.c b/testcases/kernel/containers/sysvipc/sem_comm.c
new file mode 100644
index 0000000..0b69a15
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/sem_comm.c
@@ -0,0 +1,243 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: sem_comm.c
+ *
+ * Description:
+ * 1. Clones two child processes with CLONE_NEWIPC flag, each child
+ * creates System V semaphore (sem) with the _identical_ key.
+ * 2. Child1 locks the semaphore.
+ * 3. Child2 locks the semaphore.
+ * 4. Locking the semaphore with the identical key but from two different
+ * IPC namespaces should not interfere with each other, so if child2
+ * is able to lock the semaphore (after child1 locked it), test passes,
+ * otherwise test fails.
+ */
+
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+#include "ipcns_helper.h"
+
+
+#define TESTKEY 124426L
+char *TCID = "sem_comm";
+int TST_TOTAL = 1;
+int p1[2];
+int p2[2];
+
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ check_newipc();
+}
+
+int chld1_sem(void *arg)
+{
+ int id;
+ char buf;
+ struct sembuf sm;
+
+ close(p1[0]);
+ close(p2[1]);
+
+ /* get a System V semaphore set identifier */
+ id = semget(TESTKEY, 1, IPC_CREAT);
+ if (id == -1) {
+ perror("semget");
+ close(p1[1]);
+ close(p2[0]);
+ return 2;
+ }
+
+ /* set semval to 1 */
+ if (semctl(id, 0, SETVAL, 1) == -1) {
+ perror("semctl");
+ close(p1[1]);
+ close(p2[0]);
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+
+ /* tell child2 to continue */
+ write(p1[1], "1", 1);
+
+ /* wait for child2 to create the semaphore */
+ read(p2[0], &buf, 1);
+
+ /* lock the semaphore */
+ sm.sem_num = 0;
+ sm.sem_op = -1;
+ sm.sem_flg = IPC_NOWAIT;
+ if (semop(id, &sm, 1) == -1) {
+ perror("semop");
+ close(p1[1]);
+ close(p2[0]);
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+
+ /* tell child2 to continue */
+ write(p1[1], "1", 1);
+
+ /* wait for child2 to lock the semaphore */
+ read(p2[0], &buf, 1);
+
+ close(p1[1]);
+ close(p2[0]);
+
+ /* unlock the semaphore */
+ sm.sem_op = 1;
+ semop(id, &sm, 1);
+
+ /* remove the semaphore */
+ semctl(id, 0, IPC_RMID);
+
+ return 0;
+}
+
+int chld2_sem(void *arg)
+{
+ int id, rval = 0;
+ char buf;
+ struct sembuf sm;
+
+ close(p1[1]);
+ close(p2[0]);
+
+ /* wait for child1 to create the semaphore */
+ read(p1[0], &buf, 1);
+
+ /* get a System V semaphore set identifier */
+ id = semget(TESTKEY, 1, IPC_CREAT);
+ if (id == -1) {
+ perror("semget");
+ close(p1[1]);
+ close(p2[0]);
+ return 2;
+ }
+
+ /* set semval to 1 */
+ if (semctl(id, 0, SETVAL, 1) == -1) {
+ perror("semctl");
+ close(p1[1]);
+ close(p2[0]);
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+
+ /* tell child1 to continue */
+ write(p2[1], "1", 1);
+
+ /* wait for child1 to lock the semaphore */
+ read(p1[0], &buf, 1);
+
+ /* lock the semaphore */
+ sm.sem_num = 0;
+ sm.sem_op = -1;
+ sm.sem_flg = IPC_NOWAIT;
+ if (semop(id, &sm, 1) == -1) {
+ if (errno == EAGAIN) {
+ rval = 1;
+ } else {
+ perror("semop");
+ close(p1[1]);
+ close(p2[0]);
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+ }
+
+ /* tell child1 to continue */
+ write(p2[1], "1", 1);
+
+ close(p1[0]);
+ close(p2[1]);
+
+ /* unlock the semaphore */
+ sm.sem_op = 1;
+ semop(id, &sm, 1);
+
+ /* remove the semaphore */
+ semctl(id, 0, IPC_RMID);
+
+ return rval;
+}
+
+static void test(void)
+{
+ int status, ret = 0;
+
+ SAFE_PIPE(NULL, p1);
+ SAFE_PIPE(NULL, p2);
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, NULL, "clone failed");
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, NULL, "clone failed");
+
+ close(p1[0]);
+ close(p1[1]);
+ close(p2[0]);
+ close(p2[1]);
+
+ /* wait for child processes */
+ while (wait(&status) > 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
+ ret = 1;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
+ tst_brkm(TBROK | TERRNO, NULL, "error in child");
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+ }
+
+ if (ret)
+ tst_resm(TFAIL, "SysV sem: communication with identical keys"
+ " between namespaces");
+ else
+ tst_resm(TPASS, "SysV sem: communication with identical keys"
+ " between namespaces");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c
2014-09-04 13:33 [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 2/3] containers: added sysvipc/msg_comm.c Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c Matus Marhefka
@ 2014-09-24 10:03 ` chrubis
2014-10-02 14:47 ` [LTP] [PATCH 1/3 v2] " Matus Marhefka
3 siblings, 0 replies; 9+ messages in thread
From: chrubis @ 2014-09-24 10:03 UTC (permalink / raw)
To: Matus Marhefka; +Cc: ltp-list
Hi!
> --- /dev/null
> +++ b/testcases/kernel/containers/sysvipc/shm_comm.c
> @@ -0,0 +1,215 @@
> +/* Copyright (c) 2014 Red Hat, Inc.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of version 2 the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * 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, see <http://www.gnu.org/licenses/>.
> + ***********************************************************************
> + * File: shm_comm.c
> + *
> + * Description:
> + * 1. Clones two child processes with CLONE_NEWIPC flag, each child
> + * allocates System V shared memory segment (shm) with the _identical_
> + * key and attaches that segment into its address space.
> + * 2. Child1 writes into the shared memory segment.
> + * 3. Child2 writes into the shared memory segment.
> + * 4. Writes to the shared memory segment with the identical key but from
> + * two different IPC namespaces should not interfere with each other
> + * and so child1 checks whether its shared segment wasn't changed
> + * by child2, if it wasn't test passes, otherwise test fails.
> + */
> +
> +#define _GNU_SOURCE
> +#include <sys/ipc.h>
> +#include <sys/shm.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <stdio.h>
> +#include <errno.h>
> +#include "usctest.h"
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "libclone.h"
> +#include "ipcns_helper.h"
> +
> +
> +#define TESTKEY 124426L
> +#define SHMSIZE 50
> +char *TCID = "shm_comm";
> +int TST_TOTAL = 1;
> +int p1[2];
> +int p2[2];
> +
> +
> +static void setup(void)
> +{
> + tst_require_root(NULL);
> + check_newipc();
> +}
> +
> +int chld1_shm(void *arg)
> +{
> + int id, rval = 0;
> + char *shmem, buf;
> +
> + close(p1[0]);
> + close(p2[1]);
> +
> + /* allocate a System V shared memory segment */
> + id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
> + if (id == -1) {
> + perror("shmget");
> + close(p1[1]);
> + close(p2[0]);
> + return 2;
> + }
> +
> + /* attach the segment reffered by id into the child1 data space */
> + if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
> + perror("shmat");
> + close(p1[1]);
> + close(p2[0]);
> + shmctl(id, IPC_RMID, NULL);
> + return 2;
> + }
> +
> + /* write to the shared segment */
> + *shmem = 'A';
The comments here are more or less useless, everybody can see that
shmat() does attach the memory.
> + /* tell child2 to continue */
> + write(p1[1], "1", 1);
> +
> + /* wait for child2 */
> + read(p2[0], &buf, 1);
Please use the CHECKPOINT interface instead.
> + /* if child1 shared segment has changed (by child2) report fail */
> + if (*shmem != 'A')
> + rval = 1;
> +
> + /* tell child2 to continue */
> + write(p1[1], "1", 1);
> +
> + close(p1[1]);
> + close(p2[0]);
> +
> + /* detaches the shared memory segment */
> + shmdt(shmem);
> + /* remove the shared memory segment */
> + shmctl(id, IPC_RMID, NULL);
Here the comments are redundant as well.
> + return rval;
> +}
> +
> +int chld2_shm(void *arg)
> +{
> + int id;
> + char *shmem, buf;
> +
> + close(p1[1]);
> + close(p2[0]);
> +
> + /* allocate a System V shared memory segment */
> + id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
> + if (id == -1) {
> + perror("shmget");
> + close(p1[0]);
> + close(p2[1]);
> + return 2;
> + }
> +
> + /* attach the segment referred by id into the child2 data space */
> + if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
> + perror("shmat");
> + close(p1[0]);
> + close(p2[1]);
> + shmctl(id, IPC_RMID, NULL);
> + return 2;
> + }
> +
> + /* wait for child1 to write to his segment */
> + read(p1[0], &buf, 1);
> +
> + /* write to the shared segment */
> + *shmem = 'B';
> +
> + /* tell child1 to continue */
> + write(p2[1], "1", 1);
> +
> + /* wait for child1 */
> + read(p1[0], &buf, 1);
> +
> + close(p1[0]);
> + close(p2[1]);
> +
> + /* detaches the shared memory segment */
> + shmdt(shmem);
> + /* remove the shared memory segment */
> + shmctl(id, IPC_RMID, NULL);
Comments and CHECKPOINT interface here as well.
> + return 0;
> +}
> +
> +static void test(void)
> +{
> + int status, ret = 0;
> +
> + SAFE_PIPE(NULL, p1);
> + SAFE_PIPE(NULL, p2);
> +
> + ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
> + if (ret == -1)
> + tst_brkm(TBROK | TERRNO, NULL, "clone failed");
> +
> + ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
> + if (ret == -1)
> + tst_brkm(TBROK | TERRNO, NULL, "clone failed");
> +
> + close(p1[0]);
> + close(p1[1]);
> + close(p2[0]);
> + close(p2[1]);
> +
> + /* wait for child processes */
> + while (wait(&status) > 0) {
> + if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
> + ret = 1;
> + if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
> + tst_brkm(TBROK | TERRNO, NULL, "error in child");
> + if (WIFSIGNALED(status)) {
> + tst_resm(TFAIL, "child was killed with signal %s",
> + tst_strsig(WTERMSIG(status)));
> + return;
> + }
> + }
> +
> + if (ret)
> + tst_resm(TFAIL, "SysV shm: communication with identical keys"
> + " between namespaces");
> + else
> + tst_resm(TPASS, "SysV shm: communication with identical keys"
> + " between namespaces");
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + const char *msg;
> + int lc;
> +
> + msg = parse_opts(argc, argv, NULL, NULL);
> + if (msg != NULL)
> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> + setup();
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++)
> + test();
> +
> + tst_exit();
> +}
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c
2014-09-04 13:33 ` [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c Matus Marhefka
@ 2014-09-24 11:03 ` chrubis
2014-10-02 14:48 ` [LTP] [PATCH 3/3 v2] " Matus Marhefka
1 sibling, 0 replies; 9+ messages in thread
From: chrubis @ 2014-09-24 11:03 UTC (permalink / raw)
To: Matus Marhefka; +Cc: ltp-list
Hi!
And the same that applied to 1/3 applies to 2/3 and 3/3 as well.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH 1/3 v2] containers: added sysvipc/shm_comm.c
2014-09-04 13:33 [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c Matus Marhefka
` (2 preceding siblings ...)
2014-09-24 10:03 ` [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c chrubis
@ 2014-10-02 14:47 ` Matus Marhefka
2014-10-30 11:09 ` Cyril Hrubis
3 siblings, 1 reply; 9+ messages in thread
From: Matus Marhefka @ 2014-10-02 14:47 UTC (permalink / raw)
To: ltp-list
* Tests communication over shared memory segments (shm)
with identical keys between two separate IPC namespaces
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
runtest/containers | 1 +
testcases/kernel/containers/sysvipc/.gitignore | 1 +
testcases/kernel/containers/sysvipc/shm_comm.c | 184 +++++++++++++++++++++++++
3 files changed, 186 insertions(+)
create mode 100644 testcases/kernel/containers/sysvipc/shm_comm.c
diff --git a/runtest/containers b/runtest/containers
index fc61ada..84ae736 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -39,6 +39,7 @@ shmnstest_unshare shmnstest unshare
shmem_2nstest_none shmem_2nstest none
shmem_2nstest_clone shmem_2nstest clone
shmem_2nstest_unshare shmem_2nstest unshare
+shm_comm shm_comm
mesgq_nstest_none mesgq_nstest none
mesgq_nstest_clone mesgq_nstest clone
mesgq_nstest_unshare mesgq_nstest unshare
diff --git a/testcases/kernel/containers/sysvipc/.gitignore b/testcases/kernel/containers/sysvipc/.gitignore
index 58cfbee..b5a4cbd 100644
--- a/testcases/kernel/containers/sysvipc/.gitignore
+++ b/testcases/kernel/containers/sysvipc/.gitignore
@@ -3,3 +3,4 @@
/semtest_2ns
/shmem_2nstest
/shmnstest
+/shm_comm
diff --git a/testcases/kernel/containers/sysvipc/shm_comm.c b/testcases/kernel/containers/sysvipc/shm_comm.c
new file mode 100644
index 0000000..6475155
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/shm_comm.c
@@ -0,0 +1,184 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: shm_comm.c
+ *
+ * Description:
+ * 1. Clones two child processes with CLONE_NEWIPC flag, each child
+ * allocates System V shared memory segment (shm) with the _identical_
+ * key and attaches that segment into its address space.
+ * 2. Child1 writes into the shared memory segment.
+ * 3. Child2 writes into the shared memory segment.
+ * 4. Writes to the shared memory segment with the identical key but from
+ * two different IPC namespaces should not interfere with each other
+ * and so child1 checks whether its shared segment wasn't changed
+ * by child2, if it wasn't test passes, otherwise test fails.
+ */
+
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+#include "ipcns_helper.h"
+
+
+#define TESTKEY 124426L
+#define SHMSIZE 50
+char *TCID = "shm_comm";
+int TST_TOTAL = 1;
+struct tst_checkpoint checkpoint1;
+struct tst_checkpoint checkpoint2;
+
+
+static void cleanup(void)
+{
+ tst_rmdir();
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ check_newipc();
+ tst_tmpdir();
+ TST_CHECKPOINT_INIT(&checkpoint1);
+ TST_CHECKPOINT_INIT(&checkpoint2);
+}
+
+int chld1_shm(void *arg)
+{
+ int id, rval = 0;
+ char *shmem;
+
+ id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
+ if (id == -1) {
+ perror("shmget");
+ return 2;
+ }
+
+ if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
+ perror("shmat");
+ shmctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ *shmem = 'A';
+
+ /* tell child2 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint1);
+
+ /* wait for child2 */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+ /* if child1 shared segment has changed (by child2) report fail */
+ if (*shmem != 'A')
+ rval = 1;
+
+ /* tell child2 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint1);
+
+ shmdt(shmem);
+ shmctl(id, IPC_RMID, NULL);
+ return rval;
+}
+
+int chld2_shm(void *arg)
+{
+ int id;
+ char *shmem;
+
+ id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
+ if (id == -1) {
+ perror("shmget");
+ return 2;
+ }
+
+ if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
+ perror("shmat");
+ shmctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* wait for child1 to write to his segment */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint1);
+
+ *shmem = 'B';
+
+ /* tell child1 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint2);
+
+ /* wait for child1 */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint1);
+
+ shmdt(shmem);
+ shmctl(id, IPC_RMID, NULL);
+ return 0;
+}
+
+static void test(void)
+{
+ int status, ret = 0;
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+
+ while (wait(&status) > 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
+ ret = 1;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
+ tst_brkm(TBROK | TERRNO, cleanup, "error in child");
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+ }
+
+ if (ret)
+ tst_resm(TFAIL, "SysV shm: communication with identical keys"
+ " between namespaces");
+ else
+ tst_resm(TPASS, "SysV shm: communication with identical keys"
+ " between namespaces");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH 2/3 v2] containers: added sysvipc/msg_comm.c
2014-09-04 13:33 ` [LTP] [PATCH 2/3] containers: added sysvipc/msg_comm.c Matus Marhefka
@ 2014-10-02 14:47 ` Matus Marhefka
0 siblings, 0 replies; 9+ messages in thread
From: Matus Marhefka @ 2014-10-02 14:47 UTC (permalink / raw)
To: ltp-list
* Tests communication over message queues with identical
keys between two separate IPC namespaces
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
runtest/containers | 1 +
testcases/kernel/containers/sysvipc/.gitignore | 1 +
testcases/kernel/containers/sysvipc/msg_comm.c | 190 +++++++++++++++++++++++++
3 files changed, 192 insertions(+)
create mode 100644 testcases/kernel/containers/sysvipc/msg_comm.c
diff --git a/runtest/containers b/runtest/containers
index 84ae736..7dbf049 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -43,6 +43,7 @@ shm_comm shm_comm
mesgq_nstest_none mesgq_nstest none
mesgq_nstest_clone mesgq_nstest clone
mesgq_nstest_unshare mesgq_nstest unshare
+msg_comm msg_comm
sem_nstest_none sem_nstest none
sem_nstest_clone sem_nstest clone
sem_nstest_unshare sem_nstest unshare
diff --git a/testcases/kernel/containers/sysvipc/.gitignore b/testcases/kernel/containers/sysvipc/.gitignore
index b5a4cbd..68f18bf 100644
--- a/testcases/kernel/containers/sysvipc/.gitignore
+++ b/testcases/kernel/containers/sysvipc/.gitignore
@@ -4,3 +4,4 @@
/shmem_2nstest
/shmnstest
/shm_comm
+/msg_comm
diff --git a/testcases/kernel/containers/sysvipc/msg_comm.c b/testcases/kernel/containers/sysvipc/msg_comm.c
new file mode 100644
index 0000000..b3c62df
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/msg_comm.c
@@ -0,0 +1,190 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: msg_comm.c
+ *
+ * Description:
+ * 1. Clones two child processes with CLONE_NEWIPC flag, each child
+ * gets System V message queue (msg) with the _identical_ key.
+ * 2. Child1 appends a message with identifier #1 to the message queue.
+ * 3. Child2 appends a message with identifier #2 to the message queue.
+ * 4. Appends to the message queue with the identical key but from
+ * two different IPC namespaces should not interfere with each other
+ * and so child1 checks whether its message queue doesn't contain
+ * a message with identifier #2, if it doesn't test passes, otherwise
+ * test fails.
+ */
+
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+#include "ipcns_helper.h"
+
+
+#define TESTKEY 124426L
+#define MSGSIZE 50
+char *TCID = "msg_comm";
+int TST_TOTAL = 1;
+struct tst_checkpoint checkpoint1;
+struct tst_checkpoint checkpoint2;
+struct sysv_msg {
+ long mtype;
+ char mtext[MSGSIZE];
+};
+
+
+static void cleanup(void)
+{
+ tst_rmdir();
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ check_newipc();
+ tst_tmpdir();
+ TST_CHECKPOINT_INIT(&checkpoint1);
+ TST_CHECKPOINT_INIT(&checkpoint2);
+}
+
+int chld1_msg(void *arg)
+{
+ int id, n, rval = 0;
+ struct sysv_msg m;
+ struct sysv_msg rec;
+
+ id = msgget(TESTKEY, IPC_CREAT | 0600);
+ if (id == -1) {
+ perror("msgget");
+ return 2;
+ }
+
+ m.mtype = 1;
+ m.mtext[0] = 'A';
+ if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
+ perror("msgsnd");
+ msgctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* wait for child2 to write into the message queue */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+ /* if child1 message queue has changed (by child2) report fail */
+ n = msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long),
+ 2, IPC_NOWAIT);
+ if (n == -1 && errno != ENOMSG) {
+ perror("msgrcv");
+ msgctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+ /* if mtype #2 was found in the message queue, it is fail */
+ if (n > 0) {
+ rval = 1;
+ }
+
+ /* tell child2 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint1);
+
+ msgctl(id, IPC_RMID, NULL);
+ return rval;
+}
+
+int chld2_msg(void *arg)
+{
+ int id;
+ struct sysv_msg m;
+
+ id = msgget(TESTKEY, IPC_CREAT | 0600);
+ if (id == -1) {
+ perror("msgget");
+ return 2;
+ }
+
+ m.mtype = 2;
+ m.mtext[0] = 'B';
+ if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
+ perror("msgsnd");
+ msgctl(id, IPC_RMID, NULL);
+ return 2;
+ }
+
+ /* tell child1 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint2);
+
+ /* wait for child1 */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint1);
+
+ msgctl(id, IPC_RMID, NULL);
+ return 0;
+}
+
+static void test(void)
+{
+ int status, ret = 0;
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+
+ while (wait(&status) > 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
+ ret = 1;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
+ tst_brkm(TBROK | TERRNO, cleanup, "error in child");
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+ }
+
+ if (ret)
+ tst_resm(TFAIL, "SysV msg: communication with identical keys"
+ " between namespaces");
+ else
+ tst_resm(TPASS, "SysV msg: communication with identical keys"
+ " between namespaces");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH 3/3 v2] containers: added sysvipc/sem_comm.c
2014-09-04 13:33 ` [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c Matus Marhefka
2014-09-24 11:03 ` chrubis
@ 2014-10-02 14:48 ` Matus Marhefka
1 sibling, 0 replies; 9+ messages in thread
From: Matus Marhefka @ 2014-10-02 14:48 UTC (permalink / raw)
To: ltp-list
* Tests communication over semaphore sets with identical
keys between two separate IPC namespaces
Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
---
runtest/containers | 1 +
testcases/kernel/containers/sysvipc/.gitignore | 1 +
testcases/kernel/containers/sysvipc/sem_comm.c | 206 +++++++++++++++++++++++++
3 files changed, 208 insertions(+)
create mode 100644 testcases/kernel/containers/sysvipc/sem_comm.c
diff --git a/runtest/containers b/runtest/containers
index 7dbf049..6535628 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -50,6 +50,7 @@ sem_nstest_unshare sem_nstest unshare
semtest_2ns_none semtest_2ns none
semtest_2ns_clone semtest_2ns clone
semtest_2ns_unshare semtest_2ns unshare
+sem_comm sem_comm
utstest_unshare_1 utstest unshare 1
utstest_unshare_2 utstest unshare 2
diff --git a/testcases/kernel/containers/sysvipc/.gitignore b/testcases/kernel/containers/sysvipc/.gitignore
index 68f18bf..815a717 100644
--- a/testcases/kernel/containers/sysvipc/.gitignore
+++ b/testcases/kernel/containers/sysvipc/.gitignore
@@ -5,3 +5,4 @@
/shmnstest
/shm_comm
/msg_comm
+/sem_comm
diff --git a/testcases/kernel/containers/sysvipc/sem_comm.c b/testcases/kernel/containers/sysvipc/sem_comm.c
new file mode 100644
index 0000000..d4c9393
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/sem_comm.c
@@ -0,0 +1,206 @@
+/* Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ * File: sem_comm.c
+ *
+ * Description:
+ * 1. Clones two child processes with CLONE_NEWIPC flag, each child
+ * creates System V semaphore (sem) with the _identical_ key.
+ * 2. Child1 locks the semaphore.
+ * 3. Child2 locks the semaphore.
+ * 4. Locking the semaphore with the identical key but from two different
+ * IPC namespaces should not interfere with each other, so if child2
+ * is able to lock the semaphore (after child1 locked it), test passes,
+ * otherwise test fails.
+ */
+
+#define _GNU_SOURCE
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <errno.h>
+#include "usctest.h"
+#include "test.h"
+#include "safe_macros.h"
+#include "libclone.h"
+#include "ipcns_helper.h"
+
+
+#define TESTKEY 124426L
+char *TCID = "sem_comm";
+int TST_TOTAL = 1;
+struct tst_checkpoint checkpoint1;
+struct tst_checkpoint checkpoint2;
+
+
+static void cleanup(void)
+{
+ tst_rmdir();
+}
+
+static void setup(void)
+{
+ tst_require_root(NULL);
+ check_newipc();
+ tst_tmpdir();
+ TST_CHECKPOINT_INIT(&checkpoint1);
+ TST_CHECKPOINT_INIT(&checkpoint2);
+}
+
+int chld1_sem(void *arg)
+{
+ int id;
+ struct sembuf sm;
+
+ id = semget(TESTKEY, 1, IPC_CREAT);
+ if (id == -1) {
+ perror("semget");
+ return 2;
+ }
+
+ if (semctl(id, 0, SETVAL, 1) == -1) {
+ perror("semctl");
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+
+ /* tell child2 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint1);
+
+ /* wait for child2 to create the semaphore */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+ sm.sem_num = 0;
+ sm.sem_op = -1;
+ sm.sem_flg = IPC_NOWAIT;
+ if (semop(id, &sm, 1) == -1) {
+ perror("semop");
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+
+ /* tell child2 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint1);
+
+ /* wait for child2 to lock the semaphore */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+ sm.sem_op = 1;
+ semop(id, &sm, 1);
+
+ semctl(id, 0, IPC_RMID);
+ return 0;
+}
+
+int chld2_sem(void *arg)
+{
+ int id, rval = 0;
+ struct sembuf sm;
+
+ /* wait for child1 to create the semaphore */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint1);
+
+ id = semget(TESTKEY, 1, IPC_CREAT);
+ if (id == -1) {
+ perror("semget");
+ return 2;
+ }
+
+ if (semctl(id, 0, SETVAL, 1) == -1) {
+ perror("semctl");
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+
+ /* tell child1 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint2);
+
+ /* wait for child1 to lock the semaphore */
+ TST_CHECKPOINT_CHILD_WAIT(&checkpoint1);
+
+ sm.sem_num = 0;
+ sm.sem_op = -1;
+ sm.sem_flg = IPC_NOWAIT;
+ if (semop(id, &sm, 1) == -1) {
+ if (errno == EAGAIN) {
+ rval = 1;
+ } else {
+ perror("semop");
+ semctl(id, 0, IPC_RMID);
+ return 2;
+ }
+ }
+
+ /* tell child1 to continue */
+ TST_CHECKPOINT_SIGNAL_CHILD(NULL, &checkpoint2);
+
+ sm.sem_op = 1;
+ semop(id, &sm, 1);
+
+ semctl(id, 0, IPC_RMID);
+ return rval;
+}
+
+static void test(void)
+{
+ int status, ret = 0;
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+ ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL);
+ if (ret == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+
+
+ while (wait(&status) > 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
+ ret = 1;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
+ tst_brkm(TBROK | TERRNO, cleanup, "error in child");
+ if (WIFSIGNALED(status)) {
+ tst_resm(TFAIL, "child was killed with signal %s",
+ tst_strsig(WTERMSIG(status)));
+ return;
+ }
+ }
+
+ if (ret)
+ tst_resm(TFAIL, "SysV sem: communication with identical keys"
+ " between namespaces");
+ else
+ tst_resm(TPASS, "SysV sem: communication with identical keys"
+ " between namespaces");
+}
+
+int main(int argc, char *argv[])
+{
+ const char *msg;
+ int lc;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++)
+ test();
+
+ cleanup();
+ tst_exit();
+}
--
1.8.3.1
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 1/3 v2] containers: added sysvipc/shm_comm.c
2014-10-02 14:47 ` [LTP] [PATCH 1/3 v2] " Matus Marhefka
@ 2014-10-30 11:09 ` Cyril Hrubis
0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2014-10-30 11:09 UTC (permalink / raw)
To: Matus Marhefka; +Cc: ltp-list
Hi!
Patchset pushed with change from TST_CHECKPOINT_INIT() to
TST_CHECKPOINT_CREATE(), thanks.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-10-30 11:10 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04 13:33 [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 2/3] containers: added sysvipc/msg_comm.c Matus Marhefka
2014-10-02 14:47 ` [LTP] [PATCH 2/3 v2] " Matus Marhefka
2014-09-04 13:33 ` [LTP] [PATCH 3/3] containers: added sysvipc/sem_comm.c Matus Marhefka
2014-09-24 11:03 ` chrubis
2014-10-02 14:48 ` [LTP] [PATCH 3/3 v2] " Matus Marhefka
2014-09-24 10:03 ` [LTP] [PATCH 1/3] containers: added sysvipc/shm_comm.c chrubis
2014-10-02 14:47 ` [LTP] [PATCH 1/3 v2] " Matus Marhefka
2014-10-30 11:09 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.