[master] ae32f5a01 Eliminate the cmd argument from parse_string argument, pick it up from vtclog.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Oct 19 09:29:07 UTC 2020
commit ae32f5a011cfad5cb57726c0434914ee11f94cbc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Oct 19 09:17:19 2020 +0000
Eliminate the cmd argument from parse_string argument, pick it up from vtclog.
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 4968b4803..e70e7a578 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -40,6 +40,7 @@
#include <unistd.h>
#include "vtc.h"
+#include "vtc_log.h"
#include "vav.h"
#include "vrnd.h"
@@ -308,8 +309,7 @@ macro_expand(struct vtclog *vl, const char *text)
void
-parse_string(const char *spec, const struct cmds *cmd, void *priv,
- struct vtclog *vl)
+parse_string(struct vtclog *vl, void *priv, const char *spec)
{
char *token_s[MAX_TOKENS], *token_e[MAX_TOKENS];
struct vsb *token_exp;
@@ -319,7 +319,6 @@ 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);
@@ -439,12 +438,13 @@ parse_string(const char *spec, const struct cmds *cmd, void *priv,
n = strtoul(token_s[1], NULL, 0);
for (m = 0; m < n; m++) {
vtc_log(vl, 4, "Loop #%u", m);
- parse_string(token_s[2], cmd, priv, vl);
+ parse_string(vl, priv, token_s[2]);
}
continue;
}
- for (cp = cmd; cp->name != NULL; cp++)
+ AN(vl->cmds);
+ for (cp = vl->cmds; cp->name != NULL; cp++)
if (!strcmp(token_s[0], cp->name))
break;
@@ -458,7 +458,7 @@ parse_string(const char *spec, const struct cmds *cmd, void *priv,
vtc_fatal(vl, "Unknown command: \"%s\"", token_s[0]);
assert(cp->cmd != NULL);
- cp->cmd(token_s, priv, cmd, vl);
+ cp->cmd(token_s, priv, vl->cmds, vl);
}
}
@@ -566,6 +566,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
vtc_stop = 0;
vtc_thread = pthread_self();
- parse_string(script, top_cmds, NULL, vltop);
+ parse_string(vltop, NULL, script);
return (fail_out());
}
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 103c8e58a..17fd4fe15 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -67,8 +67,7 @@ struct cmds {
cmd_f *cmd;
};
-void parse_string(const char *spec, const struct cmds *cmd, void *priv,
- struct vtclog *vl);
+void parse_string(struct vtclog *vl, void *priv, const char *spec);
int fail_out(void);
#define CMD_GLOBAL(n) cmd_f cmd_##n;
@@ -108,14 +107,12 @@ Sess_Start_Thread(
const char *spec
);
-
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_log_set_cmd(struct vtclog *vl, const struct cmds *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 d49d1555c..4167097e0 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -366,7 +366,7 @@ haproxy_cli_thread(void *priv)
"CLI failed to open %s: %s", VSB_data(vsb), err);
VTCP_blocking(fd);
hc->sock = fd;
- parse_string(hc->spec, haproxy_cli_cmds, hc, hc->vl);
+ parse_string(hc->vl, hc, hc->spec);
vtc_log(hc->vl, 2, "CLI ending");
VSB_destroy(&vsb);
return (NULL);
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index a62c817c8..c669ca476 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -1007,6 +1007,7 @@ cmd_http_upgrade(CMD_ARGS)
char *h;
struct http *hp;
+ (void)cmd;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
ONLY_SERVER(hp, av);
AN(hp->sfd);
@@ -1024,21 +1025,24 @@ cmd_http_upgrade(CMD_ARGS)
if (!h)
vtc_fatal(vl, "Req misses \"HTTP2-Settings\" header");
-
- parse_string("txresp -status 101 "
- "-hdr \"Connection: Upgrade\" "
- "-hdr \"Upgrade: h2c\"\n", cmd, hp, vl);
+ parse_string(vl, hp,
+ "txresp -status 101"
+ " -hdr \"Connection: Upgrade\""
+ " -hdr \"Upgrade: h2c\"\n"
+ );
b64_settings(hp, h);
- parse_string("rxpri\n"
- "stream 0 {\n"
- "txsettings\n"
- "rxsettings\n"
- "txsettings -ack\n"
- "rxsettings\n"
- "expect settings.ack == true\n"
- "} -start\n", cmd, hp, vl);
+ parse_string(vl, hp,
+ "rxpri\n"
+ "stream 0 {\n"
+ " txsettings\n"
+ " rxsettings\n"
+ " txsettings -ack\n"
+ " rxsettings\n"
+ " expect settings.ack == true\n"
+ "} -start\n"
+ );
}
/**********************************************************************
@@ -1235,19 +1239,23 @@ cmd_http_txreq(CMD_ARGS)
http_write(hp, 4, "txreq");
if (up) {
- parse_string("rxresp\n"
- "expect resp.status == 101\n"
- "expect resp.http.connection == Upgrade\n"
- "expect resp.http.upgrade == h2c\n"
- "txpri\n", http_cmds, hp, vl);
+ parse_string(vl, hp,
+ "rxresp\n"
+ "expect resp.status == 101\n"
+ "expect resp.http.connection == Upgrade\n"
+ "expect resp.http.upgrade == h2c\n"
+ "txpri\n"
+ );
b64_settings(hp, up);
- parse_string("stream 0 {\n"
- "txsettings\n"
- "rxsettings\n"
- "txsettings -ack\n"
- "rxsettings\n"
- "expect settings.ack == true"
- "} -start\n", http_cmds, hp, vl);
+ parse_string(vl, hp,
+ "stream 0 {\n"
+ " txsettings\n"
+ " rxsettings\n"
+ " txsettings -ack\n"
+ " rxsettings\n"
+ " expect settings.ack == true"
+ "} -start\n"
+ );
}
}
@@ -1697,16 +1705,18 @@ cmd_http_stream(CMD_ARGS)
if (!hp->h2) {
vtc_log(hp->vl, 4, "Not in H/2 mode, do what's needed");
if (hp->sfd)
- parse_string("rxpri", http_cmds, hp, vl);
+ parse_string(vl, hp, "rxpri");
else
- parse_string("txpri", http_cmds, hp, vl);
- parse_string("stream 0 {\n"
- "txsettings\n"
- "rxsettings\n"
- "txsettings -ack\n"
- "rxsettings\n"
- "expect settings.ack == true"
- "} -run\n", http_cmds, hp, vl);
+ parse_string(vl, hp, "txpri");
+ parse_string(vl, hp,
+ "stream 0 {\n"
+ " txsettings\n"
+ " rxsettings\n"
+ " txsettings -ack\n"
+ " rxsettings\n"
+ " expect settings.ack == true"
+ "} -run\n"
+ );
}
cmd_stream(av, hp, cmd, vl);
}
@@ -1870,7 +1880,7 @@ http_process(struct vtclog *vl, struct vtc_sess *vsp, const char *spec,
hp->rem_path = strdup(addr);
}
pthread_cleanup_push(http_process_cleanup, hp);
- parse_string(spec, http_cmds, hp, vl);
+ parse_string(vl, hp, spec);
retval = hp->sess->fd;
pthread_cleanup_pop(0);
http_process_cleanup(hp);
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 07d7339b5..aa3e0d495 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -2579,7 +2579,7 @@ stream_thread(void *priv)
struct stream *s;
CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC);
- parse_string(s->spec, stream_cmds, s, s->vl);
+ parse_string(s->vl, s, s->spec);
vtc_log(s->vl, 2, "Ending stream %u", s->id);
return (NULL);
}
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 5c7a41d64..ec4dbda0c 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -37,6 +37,7 @@
#include <string.h>
#include "vtc.h"
+#include "vtc_log.h"
#include "vtim.h"
@@ -44,32 +45,16 @@ static pthread_mutex_t vtclog_mtx;
static char *vtclog_buf;
static unsigned vtclog_left;
-struct vtclog {
- unsigned magic;
-#define VTCLOG_MAGIC 0x82731202
- char *id;
- 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)
+vtc_log_set_cmd(struct vtclog *vl, const struct cmds *cmds)
{
+ AN(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) \
diff --git a/bin/varnishtest/vtc_log.h b/bin/varnishtest/vtc_log.h
new file mode 100644
index 000000000..0075a9001
--- /dev/null
+++ b/bin/varnishtest/vtc_log.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2008-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+struct vtclog {
+ unsigned magic;
+#define VTCLOG_MAGIC 0x82731202
+ char *id;
+ struct vsb *vsb;
+ pthread_mutex_t mtx;
+ int act;
+ const struct cmds *cmds;
+};
diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c
index 538387f31..486424f2d 100644
--- a/bin/varnishtest/vtc_logexp.c
+++ b/bin/varnishtest/vtc_logexp.c
@@ -515,7 +515,7 @@ logexp_spec(struct logexp *le, const char *spec)
logexp_delete_tests(le);
- parse_string(spec, logexp_cmds, le, le->vl);
+ parse_string(le->vl, le, spec);
}
void
diff --git a/bin/varnishtest/vtc_syslog.c b/bin/varnishtest/vtc_syslog.c
index 1bf58f78a..28f502638 100644
--- a/bin/varnishtest/vtc_syslog.c
+++ b/bin/varnishtest/vtc_syslog.c
@@ -452,7 +452,7 @@ syslog_thread(void *priv)
for (i = 0; i < s->repeat; i++) {
if (s->repeat > 1)
vtc_log(s->vl, 3, "Iteration %d", i);
- parse_string(s->spec, syslog_cmds, s, s->vl);
+ parse_string(s->vl, s, s->spec);
vtc_log(s->vl, 3, "shutting fd %d", s->sock);
}
VUDP_close(&s->sock);
More information about the varnish-commit
mailing list