[master] 16848b72a Register the current commands on the current vtclog, and complain on mismatch.

Poul-Henning Kamp phk at FreeBSD.org
Mon Oct 19 09:29:07 UTC 2020


commit 16848b72a207b4699fec88b3659ac28fb4906945
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Oct 19 08:53:20 2020 +0000

    Register the current commands on the current vtclog, and complain on mismatch.

diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index b6346f398..4968b4803 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -89,7 +89,7 @@ static const struct cmds global_cmds[] = {
 	{ NULL, NULL }
 };
 
-static const struct cmds cmds[] = {
+static const struct cmds top_cmds[] = {
 #define CMD_TOP(n) { #n, cmd_##n },
 #include "cmds.h"
 	{ NULL, NULL }
@@ -319,6 +319,7 @@ parse_string(const char *spec, const struct cmds *cmd, void *priv,
 	unsigned n, m;
 	const struct cmds *cp;
 
+	vtc_log_chk_cmd(vl, cmd);
 	AN(spec);
 	buf = strdup(spec);
 	AN(buf);
@@ -492,7 +493,7 @@ fail_out(void)
 		vtc_stop = 1;
 	vtc_log(vltop, 1, "RESETTING after %s", tfn);
 	reset_cmds(global_cmds);
-	reset_cmds(cmds);
+	reset_cmds(top_cmds);
 	vtc_error |= old_err;
 
 	if (vtc_error)
@@ -525,6 +526,7 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
 	vtc_loginit(logbuf, loglen);
 	vltop = vtc_logopen("top");
 	AN(vltop);
+	vtc_log_set_cmd(vltop, top_cmds);
 
 	vtc_log(vltop, 1, "TEST %s starting", fn);
 
@@ -564,6 +566,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
 	vtc_stop = 0;
 
 	vtc_thread = pthread_self();
-	parse_string(script, cmds, NULL, vltop);
+	parse_string(script, top_cmds, NULL, vltop);
 	return (fail_out());
 }
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 9983527db..103c8e58a 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -114,6 +114,8 @@ char * synth_body(const char *len, int rnd);
 void cmd_server_gen_vcl(struct vsb *vsb);
 void cmd_server_gen_haproxy_conf(struct vsb *vsb);
 
+void vtc_log_set_cmd(struct vtclog *vl, const void *cmds);
+void vtc_log_chk_cmd(struct vtclog *vl, const void *cmds);
 void vtc_loginit(char *buf, unsigned buflen);
 struct vtclog *vtc_logopen(const char *id, ...) v_printflike_(1, 2);
 void vtc_logclose(void *arg);
diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c
index b42831798..d49d1555c 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -478,6 +478,7 @@ haproxy_cli_new(struct haproxy *h)
 	AN(hc);
 
 	hc->vl = h->vl;
+	vtc_log_set_cmd(hc->vl, haproxy_cli_cmds);
 	hc->sock = -1;
 	bprintf(hc->connect, "${%s_cli_sock}", h->name);
 
@@ -500,6 +501,7 @@ haproxy_mcli_new(struct haproxy *h)
 	AN(hc);
 
 	hc->vl = h->vl;
+	vtc_log_set_cmd(hc->vl, haproxy_cli_cmds);
 	hc->sock = -1;
 	bprintf(hc->connect, "${%s_mcli_sock}", h->name);
 
@@ -566,6 +568,7 @@ haproxy_new(const char *name)
 	h->args = VSB_new_auto();
 
 	h->vl = vtc_logopen("%s", name);
+	vtc_log_set_cmd(h->vl, haproxy_cli_cmds);
 	AN(h->vl);
 
 	h->filename = getenv(HAPROXY_PROGRAM_ENV_VAR);
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 08ceabd52..a62c817c8 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -1822,6 +1822,7 @@ http_process(struct vtclog *vl, struct vtc_sess *vsp, const char *spec,
 	hp->sess->fd = sock;
 	hp->timeout = vtc_maxdur * 1000 / 2;
 
+
 	if (rcvbuf) {
 		// XXX setsockopt() too late on SunOS
 		// https://github.com/varnishcache/varnish-cache/pull/2980#issuecomment-486214661
@@ -1855,6 +1856,7 @@ http_process(struct vtclog *vl, struct vtc_sess *vsp, const char *spec,
 	AN(hp->rem_port);
 
 	hp->vl = vl;
+	vtc_log_set_cmd(hp->vl, http_cmds);
 	hp->gziplevel = 0;
 	hp->gzipresidual = -1;
 
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index fda5143e0..07d7339b5 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -2601,6 +2601,7 @@ stream_new(const char *name, struct http *h)
 	VTAILQ_INIT(&s->fq);
 	s->ws = h->iws;
 	s->vl = vtc_logopen("%s.%s", h->sess->name, name);
+	vtc_log_set_cmd(s->vl, stream_cmds);
 
 	s->weight = 16;
 	s->dependency = 0;
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index c60eab94b..5c7a41d64 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -51,11 +51,25 @@ struct vtclog {
 	struct vsb	*vsb;
 	pthread_mutex_t	mtx;
 	int		act;
+	const void	*cmds;
 };
 
 static pthread_key_t log_key;
 static double t0;
 
+void
+vtc_log_set_cmd(struct vtclog *vl, const void *cmds)
+{
+	vl->cmds = cmds;
+}
+
+void
+vtc_log_chk_cmd(struct vtclog *vl, const void *cmds)
+{
+	if (vl->cmds != cmds)
+		vtc_log(vl, 4, "LOGCMDS mismatch %p vs %p", vl->cmds, cmds);
+}
+
 /**********************************************************************/
 
 #define GET_VL(vl)					\
@@ -323,4 +337,3 @@ vtc_loginit(char *buf, unsigned buflen)
 	AZ(pthread_mutex_init(&vtclog_mtx, NULL));
 	AZ(pthread_key_create(&log_key, NULL));
 }
-
diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c
index 32a64d7aa..538387f31 100644
--- a/bin/varnishtest/vtc_logexp.c
+++ b/bin/varnishtest/vtc_logexp.c
@@ -171,6 +171,13 @@ struct logexp {
 static VTAILQ_HEAD(, logexp)		logexps =
 	VTAILQ_HEAD_INITIALIZER(logexps);
 
+static cmd_f cmd_logexp_expect;
+
+static const struct cmds logexp_cmds[] = {
+	{ "expect",		cmd_logexp_expect },
+	{ NULL,			NULL },
+};
+
 static void
 logexp_delete_tests(struct logexp *le)
 {
@@ -215,6 +222,7 @@ logexp_new(const char *name, const char *varg)
 	AN(le);
 	REPLACE(le->name, name);
 	le->vl = vtc_logopen("%s", name);
+	vtc_log_set_cmd(le->vl, logexp_cmds);
 	VTAILQ_INIT(&le->tests);
 
 	le->d_arg = 0;
@@ -500,11 +508,6 @@ cmd_logexp_expect(CMD_ARGS)
 	VTAILQ_INSERT_TAIL(&le->tests, test, list);
 }
 
-static const struct cmds logexp_cmds[] = {
-	{ "expect",		cmd_logexp_expect },
-	{ NULL,			NULL },
-};
-
 static void
 logexp_spec(struct logexp *le, const char *spec)
 {
diff --git a/bin/varnishtest/vtc_syslog.c b/bin/varnishtest/vtc_syslog.c
index aa81095f7..1bf58f78a 100644
--- a/bin/varnishtest/vtc_syslog.c
+++ b/bin/varnishtest/vtc_syslog.c
@@ -72,6 +72,21 @@ static pthread_mutex_t			syslog_mtx;
 static VTAILQ_HEAD(, syslog_srv)	syslogs =
     VTAILQ_HEAD_INITIALIZER(syslogs);
 
+#define SYSLOGCMDS \
+	CMD_SYSLOG(expect) \
+	CMD_SYSLOG(recv)
+
+#define CMD_SYSLOG(nm) static cmd_f cmd_syslog_##nm;
+SYSLOGCMDS
+#undef CMD_SYSLOG
+
+static const struct cmds syslog_cmds[] = {
+#define CMD_SYSLOG(n) { #n, cmd_syslog_##n },
+SYSLOGCMDS
+#undef CMD_SYSLOG
+	{ NULL, NULL }
+};
+
 static const char * const syslog_levels[] = {
 	"emerg",
 	"alert",
@@ -248,6 +263,7 @@ syslog_new(const char *name, struct vtclog *vl)
 	REPLACE(s->name, name);
 	s->vl = vtc_logopen("%s", s->name);
 	AN(s->vl);
+	vtc_log_set_cmd(s->vl, syslog_cmds);
 
 	bprintf(s->bind, "%s", "127.0.0.1 0");
 	s->repeat = 1;
@@ -419,15 +435,6 @@ cmd_syslog_recv(CMD_ARGS)
 	syslog_rx(s, lvl);
 }
 
-static const struct cmds syslog_cmds[] = {
-#define CMD_SYSLOG(n) { #n, cmd_syslog_##n },
-	/* session */
-	CMD_SYSLOG(expect)
-	CMD_SYSLOG(recv)
-#undef CMD_SYSLOG
-	{ NULL, NULL }
-};
-
 /**********************************************************************
  * Syslog server thread
  */


More information about the varnish-commit mailing list