[master] 8678574 Add hack to wait for X bytes on stdout.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 12 16:43:08 UTC 2018


commit 86785741b3d41dd2be66142fe701149febfcfede
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 12 16:39:06 2018 +0000

    Add hack to wait for X bytes on stdout.

diff --git a/bin/varnishtest/tests/u00008.vtc b/bin/varnishtest/tests/u00008.vtc
new file mode 100644
index 0000000..def8166
--- /dev/null
+++ b/bin/varnishtest/tests/u00008.vtc
@@ -0,0 +1,22 @@
+varnishtest	"trivial run of varnistat in curses mode"
+
+feature term
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {} -start
+
+process p1 -dump {varnishstat -n ${v1_name}} -start
+
+process p1 -need-bytes 1
+
+client c1 {
+	txreq
+	rxresp
+} -run
+
+process p1 -need-bytes 2300 -screen_dump -write {q} -wait
+
diff --git a/bin/varnishtest/tests/u00009.vtc b/bin/varnishtest/tests/u00009.vtc
index 1e540bd..13b931c 100644
--- a/bin/varnishtest/tests/u00009.vtc
+++ b/bin/varnishtest/tests/u00009.vtc
@@ -11,15 +11,11 @@ varnish v1 -vcl+backend {} -start
 
 process p1 -dump {varnishhist -n ${v1_name}} -start
 
-delay 3
+process p1 -need-bytes 1
 
 client c1 {
 	txreq
 	rxresp
 } -run
 
-delay 10
-
-process p1 -write {q}
-
-process p1 -wait -screen_dump
+process p1 -need-bytes 300 -screen_dump -write {q} -wait
diff --git a/bin/varnishtest/tests/u00010.vtc b/bin/varnishtest/tests/u00010.vtc
index fbca6d5..e94526f 100644
--- a/bin/varnishtest/tests/u00010.vtc
+++ b/bin/varnishtest/tests/u00010.vtc
@@ -11,15 +11,11 @@ varnish v1 -vcl+backend {} -start
 
 process p1 -dump {varnishtop -n ${v1_name}} -start
 
-delay 3
+process p1 -need-bytes 1
 
 client c1 {
 	txreq
 	rxresp
 } -run
 
-delay 10
-
-process p1 -write {q}
-
-process p1 -wait -screen_dump
+process p1 -need-bytes 2500 -screen_dump -write {q} -wait
diff --git a/bin/varnishtest/tests/u00011.vtc b/bin/varnishtest/tests/u00011.vtc
index 4c29d24..8870b1a 100644
--- a/bin/varnishtest/tests/u00011.vtc
+++ b/bin/varnishtest/tests/u00011.vtc
@@ -11,19 +11,17 @@ varnish v1 -vcl+backend {} -start
 
 process p1 -dump {varnishadm -n ${v1_name}} -start
 
-delay 2
+process p1 -need-bytes 1
 
 client c1 {
 	txreq
 	rxresp
 } -run
 
-delay 2
-
 process p1 -writeln {panic.show}
 
 process p1 -writeln {quit}
 
-delay 10
+process p1 -need-bytes 400
 
-process p1 -wait -screen_dump
+process p1 -screen_dump -writeln {quit} -wait
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index 6d55975..24e3e74 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -38,6 +38,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <poll.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -76,6 +77,9 @@ struct process {
 	pid_t			pid;
 	int			expect_exit;
 
+	uintmax_t		stdout_bytes;
+	uintmax_t		stderr_bytes;
+
 	pthread_mutex_t		mtx;
 	pthread_t		tp;
 	unsigned		hasthread;
@@ -198,6 +202,9 @@ process_stdout(const struct vev *ev, int what)
 		vtc_log(p->vl, 4, "stdout read %d", i);
 		return (1);
 	}
+	AZ(pthread_mutex_lock(&p->mtx));
+	p->stdout_bytes += i;
+	AZ(pthread_mutex_unlock(&p->mtx));
 	if (p->log == 1)
 		(void)VLU_Feed(p->vlu_stdout, buf, i);
 	else if (p->log == 2)
@@ -223,6 +230,9 @@ process_stderr(const struct vev *ev, int what)
 		vtc_log(p->vl, 4, "stderr read %d", i);
 		return (1);
 	}
+	AZ(pthread_mutex_lock(&p->mtx));
+	p->stderr_bytes += i;
+	AZ(pthread_mutex_unlock(&p->mtx));
 	vtc_dump(p->vl, 4, "stderr", buf, i);
 	(void)write(p->f_stderr, buf, i);
 	return (0);
@@ -435,6 +445,8 @@ process_wait(struct process *p)
 		AZ(pthread_join(p->tp, &v));
 		p->hasthread = 0;
 	}
+	vtc_log(p->vl, 4, "stdout %ju bytes, stderr %ju bytes",
+	    p->stdout_bytes, p->stderr_bytes);
 }
 
 /**********************************************************************
@@ -601,6 +613,7 @@ void
 cmd_process(CMD_ARGS)
 {
 	struct process *p, *p2;
+	uintmax_t u, v;
 
 	(void)priv;
 	(void)cmd;
@@ -697,6 +710,17 @@ cmd_process(CMD_ARGS)
 			av++;
 			continue;
 		}
+		if (!strcmp(*av, "-need-bytes")) {
+			u = strtoumax(av[1], NULL, 0);
+			av++;
+			do {
+				usleep(100000);
+				AZ(pthread_mutex_lock(&p->mtx));
+				v = p->stdout_bytes;
+				AZ(pthread_mutex_unlock(&p->mtx));
+			} while(v < u);
+			continue;
+		}
 		if (!strcmp(*av, "-screen_dump")) {
 			Term_Dump(p->term);
 			continue;


More information about the varnish-commit mailing list