Add a multi-process IPC test
PATCH 1/1 Add a multi-process IPC test
This test forks off several children in various states to ensure that the IPC namespace information is properly restored after restart.
--- Makefile | 2 +- tst_ipcshm_multi.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 267 insertions(+), 1 deletions(-) create mode 100644 tst_ipcshm_multi.c
Makefile +1 -1
@@ -19,7 +19,7 @@ CFLAGS += -g $(WARNS) $(PATHS) $(DEBUG) PROGS = self ckpt rstr mktree TESTS= tst_onetask tst_multitask tst_bigmem tst_pipes tst_pipes2 tst_shmem \ - tst_ipcshm tst_ipcmsq + tst_ipcshm tst_ipcmsq tst_ipcshm_multi LDLIBS = -lm
tst_ipcshm_multi.c new file +266 -0
266 lines not on this page · raw message
Signature · 1 line
1.6.0.3
A message that is not in the archive (sent off-list or not yet received): 1239299170-14827-1-git-send-email-danms-r/[email protected]
DS> This test forks off several children in various states to ensure DS> that the IPC namespace information is properly restored after DS> restart.
I should have mentioned that this test behaves as expected with the latest IPC patches from Oren. If I run it and wait about ten seconds to checkpoint it, on restart everything gets hooked back up properly.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
Quoted 2 lines · Dan Smith
This test forks off several children in various states to ensure that the IPC namespace information is properly restored after restart.
Thanks, Dan. I've got a few other simple c/r tests collected which I want to automate in the next few days so one can just run 'check_cr' and get a list of pass/fails. I'll also add some tests which Nathan had written for IPC. Hmm, I suppose the easiest thing for now will be to put a tarball on lxc.sf.net.
-serge
A message that is not in the archive (sent off-list or not yet received): 20090409185159.GA32610-r/[email protected]
SH> Thanks, Dan. I've got a few other simple c/r tests collected SH> which I want to automate in the next few days so one can just run SH> 'check_cr' and get a list of pass/fails. I'll also add some tests SH> which Nathan had written for IPC. Hmm, I suppose the easiest SH> thing for now will be to put a tarball on lxc.sf.net.
Okay. I should probably add a little more logic to make this test validate the result (instead of requiring an eye-parse of the log) so it can be automated.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
Quoted 9 lines · Serge E. Hallyn
Quoted 2 lines · Dan Smith
This test forks off several children in various states to ensure that the IPC namespace information is properly restored after restart.
Thanks, Dan. I've got a few other simple c/r tests collected which I want to automate in the next few days so one can just run '
check_cr' and get a list of pass/fails. I'll also add some tests which Nathan had written for IPC. Hmm, I suppose the easiest thing for now will be to put a tarball on lxc.sf.net.
I include the c/r tests with the c/r userland tools (ckpt, mktree etc). That's a natural repository to collect/hold them.
Oren.
Quoted 7 lines
-serge
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Oren Laadan
Quoted 4 lines · Serge E. Hallyn
Quoted 2 lines · Dan Smith
This test forks off several children in various states to ensure that the IPC namespace information is properly restored after restart.
Quoted 8 lines
Quoted 5 lines
Thanks, Dan. I've got a few other simple c/r tests collected which I want to automate in the next few days so one can just run '
check_cr' and get a list of pass/fails. I'll also add some tests which Nathan had written for IPC. Hmm, I suppose the easiest thing for now will be to put a tarball on lxc.sf.net.I include the c/r tests with the c/r userland tools (ckpt, mktree etc). That's a natural repository to collect/hold them.
The natural place is ltp :) Meanwhile I wanted to automate a few tests, but if you wanted to add those to your user-cr tree that'd be great. I don't actually *want* them on lxc.sf.net, just had nowhere else to put them.
thanks,
-serge
Thanks, added to user-cr.git for next version.
Oren.
Quoted 296 lines · Dan Smith
This test forks off several children in various states to ensure that the IPC namespace information is properly restored after restart.
Signed-off-by Dan Smith <danms-r/[email protected]>--- Makefile | 2 +- tst_ipcshm_multi.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 267 insertions(+), 1 deletions(-) create mode 100644 tst_ipcshm_multi.cMakefile +1
-1@@ -19,7 +19,7 @@ CFLAGS += -g $(WARNS) $(PATHS) $(DEBUG) PROGS = self ckpt rstr mktree TESTS= tst_onetask tst_multitask tst_bigmem tst_pipes tst_pipes2 tst_shmem \ - tst_ipcshm tst_ipcmsq + tst_ipcshm tst_ipcmsq tst_ipcshm_multi LDLIBS = -lmtst_ipcshm_multi.c new file +266
-0@@ -0,0 +1,266 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#include <linux/sched.h> +#include <sched.h> + +#define OUTFILE "/tmp/cr-test.out" +#define SEG_SIZE (20 * 4096) +#define DELAY 20 + +int attach (unsigned char **seg,int num) +{ +int id; + + id =shmget (123 ,SEG_SIZE ,0700 |IPC_EXCL ); +if (id <0 ) { +printf ("[CHILD %i] shmget: %m\n" , num); +return -1 ; + } + + *seg =shmat (id,NULL ,0 ); +if (!*seg) { +printf ("[CHILD %i] shmat: %m\n" , num); +return -1 ; + } + +printf ("[CHILD %i] Attached\n" , num); + +return 0 ; +} + +int validate (unsigned char *seg,int num) +{ +int i; + +for (i =1 ; i <SEG_SIZE ; i++) { +if (seg[i] != (unsigned char )(i %256 )) { +printf ("[CHILD %i] Mismatch at %hhu: %hhu\n" , + num, i, seg[i]); +return -1 ; + } + } + +printf ("[CHILD %i] Validated\n" , num); + +return 0 ; +} + +void track (unsigned char *seg,int num) +{ +int i; + +for (i =0 ; i <20 ; i++) { +printf ("[CHILD %i] Seg[0]: %i\n" , num, seg[0 ]); +sleep (1 ); + } +} + +/* +* Attach to the shared segment *before* the checkpoint and then track +* the changing seg[0] position afterwards. +*/ +int child1 (void ) +{ +unsigned char *seg; +int num =1 ; + +printf ("[CHILD %i] Running\n" , num); + +sleep (1 );/* Allow master to finish initializing the array */ + +if (attach (&seg, num)) +return -1 ; + +if (validate (seg, num)) +return -1 ; + +sleep (DELAY -1 );/* Wait until after the checkpoint */ + +track (seg, num); + +return 0 ; +} + +/* +* Attempt to attach to the shared segment *after* the checkpoint to +* verify that things are hooked up properly after restart by tracking +* seg[0]. +*/ +int child2 (void ) +{ +unsigned char *seg; +int num =2 ; + +printf ("[CHILD %i] Running\n" , num); + +sleep (DELAY );/* Wait until after the checkpoint */ + +if (attach (&seg, num)) +return -1 ; + +if (validate (seg, num)) +return -1 ; + +track (seg, num); + +return 0 ; +} + +int child4 (void ); + +/* +* Detach from the parent's IPC namespace and verify that: +* 1. We can't attach to the parent's segment +* 2. We can create our own of the same ID without conflict +* 3. We do not see the parent's changing seg[0] after restart +*/ +int child3 (void ) +{ +unsigned char *seg; +int num =3 ; + +if (unshare (CLONE_NEWIPC ) !=0 ) { +printf ("[CHILD %i] unshare(CLONE_NEWIPC): %m" , num); +return -1 ; + } + +if (fork () ==0 ) +return child4 (); + +printf ("[CHILD %i] Running (new IPC NS)\n" , num); + +printf ("[CHILD %i] Attempting parent attach (should fail)\n" , num); +if (!attach (&seg, num)) { +printf ("[CHILD %i] Attached to parent's IPC!\n" , num); +return -1 ; + } + +if (shmget (123 ,SEG_SIZE ,0700 |IPC_CREAT |IPC_EXCL ) <0 ) { +printf ("[CHILD %i] Failed to create shm in namespace: %m\n" , + num); +return -1 ; + } + +if (attach (&seg, num)) +return -1 ; + + seg[0 ] =123 ; + +sleep (DELAY );/* Wait until after checkpoint, then attach */ + +track (seg, num); + +return 0 ; +} + +/* +* This child is forked from child3 under the new IPC namespace. +* Verify that post-restart, we do not see the changing seg[0] +*/ +int child4 (void ) +{ +unsigned char *seg; +int num =4 ; + +printf ("[CHILD %i] Running (new IPC NS)\n" , num); + +sleep (DELAY );/* Wait past my parent creating the IPC */ + +if (attach (&seg, num)) +return -1 ; + +track (seg, num); + +return 0 ; +} + +void shm_destroy (void ) +{ +int id; + + id =shmget (123 ,SEG_SIZE ,0700 ); +if (id <0 ) +return ; + +if (shmctl (id,IPC_RMID ,NULL ) ==0 ) +printf ("Deleted SHM %i\n" , id); +} + +int main (int argc,char *argv[]) +{ +int id; +unsigned char *seg; +int i; +int pid1, pid2, pid3; +#ifndef TEST +FILE *file; + +close (0 ); +close (1 ); +close (2 ); + +unlink (OUTFILE ); + file =fopen (OUTFILE ,"w+" ); +if (!file) { +perror ("open" ); +exit (1 ); + } +if (dup2 (0 ,2 ) <0 ) { +perror ("dup2" ); +exit (2 ); + } + stdout = file; +setlinebuf (file); +#endif +shm_destroy (); + + pid1 =fork (); +if (pid1 ==0 ) +return child1 (); + + pid2 =fork (); +if (pid2 ==0 ) +return child2 (); + + pid3 =fork (); +if (pid3 ==0 ) +return child3 (); + + id =shmget (123 ,SEG_SIZE ,0700 |IPC_CREAT |IPC_EXCL ); +if (id <0 ) { +perror ("shmget" ); +exit (1 ); + } + + seg = (unsigned char *)shmat (id,NULL ,0 ); +if (seg == ((void *)-1 )) { +perror ("shmat" ); +exit (1 ); + } + +for (i =0 ; i <SEG_SIZE ; i++) + seg[i] = i; + +printf ("[MSTER] Waiting for checkpoint\n" ); +sleep (DELAY ); +printf ("[MSTER] Woke\n" ); + +for (i =0 ; i <15 ; i++) { + seg[0 ] = i; +sleep (1 ); + } + +if (shmdt (seg) <0 ) +perror ("shmdt" ); + +shm_destroy (); + +printf ("[MSTER] Completed\n" ); + +return 0 ; +}