All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
To: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Cc: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: Re: [PATCH] Make tst_ipcshm_multi automatable
Date: Tue, 14 Apr 2009 02:58:14 -0400	[thread overview]
Message-ID: <49E43406.2020506@cs.columbia.edu> (raw)
In-Reply-To: <1239650808-22254-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>



Dan Smith wrote:
> Add a little to tst_ipcshm_multi to make it automatically validate the
> results and return a pass/fail status indication for automated runs.
> 
> Since Oren said he applied my previous patch to his repository, I'm
> sending this as a delta from the last one I sent[1].  Since the public
> user-cr is not updated yet, you'll need to apply that first to try this.

FYI current, up-to-date, of user-cr.git is avilable (branch v14)
	git://git.ncl.cs.columbia.edu/pub/git/user-cr.git

> 
> 1: https://lists.linux-foundation.org/pipermail/containers/2009-April/016827.html
> 
> Cc: orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org
> Cc: serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org
> Signed-off-by: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> ---
>  tst_ipcshm_multi.c |   86 ++++++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 70 insertions(+), 16 deletions(-)
> 
> diff --git a/tst_ipcshm_multi.c b/tst_ipcshm_multi.c
> index 1ef31f7..1bc0cd2 100644
> --- a/tst_ipcshm_multi.c
> +++ b/tst_ipcshm_multi.c
> @@ -4,6 +4,8 @@
>  #include <errno.h>
>  #include <sys/ipc.h>
>  #include <sys/shm.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
>  
>  #include <linux/sched.h>
>  #include <sched.h>
> @@ -11,6 +13,7 @@
>  #define OUTFILE  "/tmp/cr-test.out"
>  #define SEG_SIZE (20 * 4096)
>  #define DELAY 20
> +#define COUNT_MAX 15
>  
>  int attach(unsigned char **seg, int num)
>  {
> @@ -50,14 +53,45 @@ int validate(unsigned char *seg, int num)
>  	return 0;
>  }
>  
> -void track(unsigned char *seg, int num)
> +int track_incr(unsigned char *seg, int num)
>  {
>  	int i;
> +	int last = seg[0];
>  
>  	for (i = 0; i < 20; i++) {
> +		if (seg[0] == COUNT_MAX)
> +			break;
> +
> +		if (abs(last - (int)seg[0]) > 1) {
> +			printf("[CHILD %i] Expected +/-%i (got %i) %i\n",
> +			       num, last, seg[0], abs(last - seg[0]));
> +			return 1;
> +		}
> +
> +		last = seg[0] + 1;
> +
>  		printf("[CHILD %i] Seg[0]: %i\n", num, seg[0]);
>  		sleep(1);
>  	}
> +
> +	return !(seg[0] == COUNT_MAX);
> +}
> +
> +int track_const(unsigned char *seg, int num, int val)
> +{
> +	int i;
> +
> +	for (i = 0; i < 20; i++) {
> +		if (seg[0] != val) {
> +			printf("[CHILD %i] Expected %i not %i\n",
> +			       num, val, seg[0]);
> +			return 1;
> +		}
> +		printf("[CHILD %i] Seg[0]: %i\n", num, seg[0]);
> +		sleep(1);
> +	}
> +
> +	return 0;
>  }
>  
>  /*
> @@ -81,9 +115,7 @@ int child1(void)
>  
>  	sleep(DELAY - 1); /* Wait until after the checkpoint */
>  
> -	track(seg, num);
> -
> -	return 0;
> +	return track_incr(seg, num);
>  }
>  
>  /*
> @@ -106,12 +138,10 @@ int child2(void)
>  	if (validate(seg, num))
>  		return -1;
>  
> -	track(seg, num);
> -
> -	return 0;
> +	return track_incr(seg, num);
>  }
>  
> -int child4(void);
> +int child4(int constval);
>  
>  /*
>   * Detach from the parent's IPC namespace and verify that:
> @@ -123,14 +153,20 @@ int child3(void)
>  {
>  	unsigned char *seg;
>  	int num = 3;
> +	int cpid;
> +	int ret;
> +	int status;
>  
>  	if (unshare(CLONE_NEWIPC) != 0) {
>  		printf("[CHILD %i] unshare(CLONE_NEWIPC): %m", num);
>  		return -1;
>  	}
>  
> -	if (fork() == 0)
> -		return child4();
> +	cpid = fork();
> +	if (cpid < 0)
> +		return 1;
> +	else if (cpid == 0)
> +		return child4(123);
>  
>  	printf("[CHILD %i] Running (new IPC NS)\n", num);
>  
> @@ -153,16 +189,22 @@ int child3(void)
>  
>  	sleep(DELAY); /* Wait until after checkpoint, then attach */
>  
> -	track(seg, num);
> -  
> -	return 0;
> +	ret = track_const(seg, num, 123);
> +
> +	printf("[CHILD %i] Waiting for child %i\n", num, cpid);
> +	wait(&status);
> +
> +	if (ret == 0)
> +		return WEXITSTATUS(status);
> +	else
> +		return ret;
>  }
>  
>  /*
>   * 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)
> +int child4(int constval)
>  {
>  	unsigned char *seg;
>  	int num = 4;
> @@ -174,7 +216,7 @@ int child4(void)
>  	if (attach(&seg, num))
>  		return -1;
>  
> -	track(seg, num);
> +	return track_const(seg, num, constval);
>  
>  	return 0;
>  }
> @@ -250,11 +292,23 @@ int main(int argc, char *argv[])
>  	sleep(DELAY);
>  	printf("[MSTER] Woke\n");
>  
> -	for (i = 0; i < 15; i++) {
> +	for (i = 0; i <= COUNT_MAX; i++) {
>  		seg[0] = i;
>  		sleep(1);
>  	}
>  
> +	for (i = 0; i < 3; i++) {
> +		int status;
> +
> +		printf("[MSTER] Waiting on child %i\n", i+1);
> +		wait(&status);
> +		if (WEXITSTATUS(status)) {
> +			printf("[MSTER] child exited with %i\n",
> +			       WEXITSTATUS(status));
> +			return WEXITSTATUS(status);
> +		}
> +	}
> +
>  	if (shmdt(seg) < 0)
>  		perror("shmdt");
>  

      parent reply	other threads:[~2009-04-14  6:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-13 19:26 [PATCH] Make tst_ipcshm_multi automatable Dan Smith
     [not found] ` <1239650808-22254-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-13 23:15   ` Serge E. Hallyn
2009-04-14  3:44   ` Oren Laadan
2009-04-14  6:58   ` Oren Laadan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49E43406.2020506@cs.columbia.edu \
    --to=orenl-eqauephvms7envbuuze7ea@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.