ia64/xen-unstable

changeset 5873:6f4d50000179

Make testing more reliable: wait for event after async so we know
child has done command
Signed-off-by: Rusty Russel <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Jul 26 15:21:00 2005 +0000 (2005-07-26)
parents 4e833037159d
children 2ae19537f615
files tools/xenstore/testsuite/13watch-ack.sh tools/xenstore/xs_test.c
line diff
     1.1 --- a/tools/xenstore/testsuite/13watch-ack.sh	Tue Jul 26 15:20:09 2005 +0000
     1.2 +++ b/tools/xenstore/testsuite/13watch-ack.sh	Tue Jul 26 15:21:00 2005 +0000
     1.3 @@ -16,8 +16,8 @@ echo mkdir /test/3 | ./xs_test
     1.4  1 watch /test/2 token2 0
     1.5  1 watch /test/3 token3 0
     1.6  2 async write /test/2 create contents2
     1.7 -1 waitwatch
     1.8  3 async write /test/1 create contents1
     1.9  4 async write /test/3 create contents3
    1.10 +1 waitwatch
    1.11  1 ackwatch token2
    1.12  1 close' | ./xs_test 2>&1`" = "1:/test/2:token2" ]
     2.1 --- a/tools/xenstore/xs_test.c	Tue Jul 26 15:20:09 2005 +0000
     2.2 +++ b/tools/xenstore/xs_test.c	Tue Jul 26 15:21:00 2005 +0000
     2.3 @@ -406,6 +406,35 @@ static void do_ackwatch(unsigned int han
     2.4  		failed(handle);
     2.5  }
     2.6  
     2.7 +static bool wait_for_input(unsigned int handle)
     2.8 +{
     2.9 +	unsigned int i;
    2.10 +	for (i = 0; i < ARRAY_SIZE(handles); i++) {
    2.11 +		int fd;
    2.12 +
    2.13 +		if (!handles[i] || i == handle)
    2.14 +			continue;
    2.15 +
    2.16 +		fd = xs_fileno(handles[i]);
    2.17 +		if (fd == -2) {
    2.18 +			unsigned int avail;
    2.19 +			get_input_chunk(in, in->buf, &avail);
    2.20 +			if (avail != 0)
    2.21 +				return true;
    2.22 +		} else {
    2.23 +			struct timeval tv = {.tv_sec = 0, .tv_usec = 0 };
    2.24 +			fd_set set;
    2.25 +
    2.26 +			FD_ZERO(&set);
    2.27 +			FD_SET(fd, &set);
    2.28 +			if (select(fd+1, &set, NULL, NULL,&tv))
    2.29 +				return true;
    2.30 +		}
    2.31 +	}
    2.32 +	return false;
    2.33 +}
    2.34 +
    2.35 +
    2.36  /* Async wait for watch on handle */
    2.37  static void do_command(unsigned int default_handle, char *line);
    2.38  static void do_async(unsigned int handle, char *line)
    2.39 @@ -413,8 +442,14 @@ static void do_async(unsigned int handle
    2.40  	int child;
    2.41  	unsigned int i;
    2.42  	children++;
    2.43 -	if ((child = fork()) != 0)
    2.44 +	if ((child = fork()) != 0) {
    2.45 +		/* Wait until *something* happens, which indicates
    2.46 +		 * child has created an event.  V. sloppy, but we can't
    2.47 +		 * select on fake domain connections.
    2.48 +		 */
    2.49 +		while (!wait_for_input(handle));
    2.50  		return;
    2.51 +	}
    2.52  
    2.53  	/* Don't keep other handles open in parent. */
    2.54  	for (i = 0; i < ARRAY_SIZE(handles); i++) {
    2.55 @@ -632,7 +667,7 @@ static void do_command(unsigned int defa
    2.56  	command = arg(line, 0);
    2.57  
    2.58  	if (timeout)
    2.59 -		alarm(5);
    2.60 +		alarm(1);
    2.61  
    2.62  	if (streq(command, "dir"))
    2.63  		do_dir(handle, arg(line, 1));