Permalink
Browse files

Add hack to wait for X bytes on stdout.

  • Loading branch information...
bsdphk committed Jan 12, 2018
1 parent 909ce71 commit 86785741b3d41dd2be66142fe701149febfcfede
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;

0 comments on commit 8678574

Please sign in to comment.