[master] 109f441c2 Move 'delay', 'shell' and 'barrier' to a new category of "global" commands.

Poul-Henning Kamp phk at FreeBSD.org
Wed Sep 26 11:14:11 UTC 2018


commit 109f441c20992ad2acb96002aaccd8ec1718a5e5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Sep 26 11:10:14 2018 +0000

    Move 'delay', 'shell' and 'barrier' to a new category of "global" commands.

diff --git a/bin/varnishtest/cmds.h b/bin/varnishtest/cmds.h
index d3244c258..fd140efe2 100644
--- a/bin/varnishtest/cmds.h
+++ b/bin/varnishtest/cmds.h
@@ -29,21 +29,29 @@
 
 /*lint -save -e525 -e539 */
 
-CMD(barrier)
-CMD(client)
-CMD(delay)
-CMD(err_shell)
-CMD(feature)
-CMD(haproxy)
-CMD(logexpect)
-CMD(process)
-CMD(server)
-CMD(setenv)
-CMD(shell)
-CMD(syslog)
-CMD(varnish)
-CMD(varnishtest)
-CMD(vtest)
-#undef CMD
+#ifndef CMD_GLOBAL
+  #define CMD_GLOBAL(x)
+#endif
+CMD_GLOBAL(barrier)
+CMD_GLOBAL(delay)
+CMD_GLOBAL(shell)
+#undef CMD_GLOBAL
+
+#ifndef CMD_TOP
+  #define CMD_TOP(x)
+#endif
+CMD_TOP(client)
+CMD_TOP(err_shell)
+CMD_TOP(feature)
+CMD_TOP(haproxy)
+CMD_TOP(logexpect)
+CMD_TOP(process)
+CMD_TOP(server)
+CMD_TOP(setenv)
+CMD_TOP(syslog)
+CMD_TOP(varnish)
+CMD_TOP(varnishtest)
+CMD_TOP(vtest)
+#undef CMD_TOP
 
 /*lint -restore */
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 276566514..2b98596a8 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -290,6 +290,13 @@ macro_expand(struct vtclog *vl, const char *text)
  * Static checkers like Coverity may bitch about this, but we don't care.
  */
 
+static const struct cmds global_cmds[] = {
+#define CMD_GLOBAL(n) { #n, cmd_##n },
+#include "cmds.h"
+	{ NULL, NULL }
+};
+
+
 void
 parse_string(const char *spec, const struct cmds *cmd, void *priv,
     struct vtclog *vl)
@@ -410,6 +417,12 @@ parse_string(const char *spec, const struct cmds *cmd, void *priv,
 			if (!strcmp(token_s[0], cp->name))
 				break;
 
+		if (cp->name == NULL) {
+			for (cp = global_cmds; cp->name != NULL; cp++)
+				if (!strcmp(token_s[0], cp->name))
+					break;
+		}
+
 		if (cp->name == NULL)
 			vtc_fatal(vl, "Unknown command: \"%s\"", token_s[0]);
 
@@ -435,7 +448,7 @@ reset_cmds(const struct cmds *cmd)
  */
 
 static const struct cmds cmds[] = {
-#define CMD(n) { #n, cmd_##n },
+#define CMD_TOP(n) { #n, cmd_##n },
 #include "cmds.h"
 	{ NULL, NULL }
 };
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 6ebff08a5..182f258e9 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -69,7 +69,8 @@ void parse_string(const char *spec, const struct cmds *cmd, void *priv,
     struct vtclog *vl);
 int fail_out(void);
 
-#define CMD(n) cmd_f cmd_##n;
+#define CMD_GLOBAL(n) cmd_f cmd_##n;
+#define CMD_TOP(n) cmd_f cmd_##n;
 #include "cmds.h"
 
 extern volatile sig_atomic_t vtc_error; /* Error, bail out */
diff --git a/bin/varnishtest/vtc_barrier.c b/bin/varnishtest/vtc_barrier.c
index 3f0f69065..7f2f0c1ce 100644
--- a/bin/varnishtest/vtc_barrier.c
+++ b/bin/varnishtest/vtc_barrier.c
@@ -348,8 +348,7 @@ barrier_sync(struct barrier *b, struct vtclog *vl)
 
 /* SECTION: barrier barrier
  *
- * NOTE: this can be used from the top-level as well as from client and server
- * specifications.
+ * NOTE: This command is available everywhere commands are given.
  *
  * Barriers allows you to synchronize different threads to make sure events
  * occur in the right order. It's even possible to use them in VCL.
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 6c4fcc8da..03aa7f7e5 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -1659,17 +1659,6 @@ cmd_http_fatal(CMD_ARGS)
 
 #define cmd_http_non_fatal cmd_http_fatal
 
-/* SECTION: client-server.spec.delay
- *
- * delay
- *	Same as for the top-level delay.
- *
- * SECTION: client-server.spec.barrier
- *
- * barrier
- *	Same as for the top-level barrier
- */
-
 static const char PREFACE[24] = {
 	0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54,
 	0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a,
@@ -1815,7 +1804,6 @@ cmd_http_write_body(CMD_ARGS)
  */
 
 const struct cmds http_cmds[] = {
-#define CMD(n) { #n, cmd_##n },
 #define CMD_HTTP(n) { #n, cmd_http_##n },
 	/* session */
 	CMD_HTTP(accept)
@@ -1864,13 +1852,7 @@ const struct cmds http_cmds[] = {
 	CMD_HTTP(expect)
 	CMD_HTTP(expect_close)
 	CMD_HTTP(expect_pattern)
-
-	/* general purpose */
-	CMD(barrier)
-	CMD(delay)
-	CMD(shell)
 #undef CMD_HTTP
-#undef CMD
 	{ NULL, NULL }
 };
 
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 404b68da0..ed72ea37a 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -2445,7 +2445,6 @@ cmd_write_body(CMD_ARGS)
  * client or a server.
  */
 static const struct cmds stream_cmds[] = {
-#define CMD(n) { #n, cmd_##n },
 #define CMD_STREAM(n) { #n, cmd_##n },
 	/* spec */
 	CMD_STREAM(expect)
@@ -2475,14 +2474,8 @@ static const struct cmds stream_cmds[] = {
 	CMD_STREAM(txsettings)
 	CMD_STREAM(txwinup)
 	CMD_STREAM(write_body)
-
-	/* general purpose */
-	CMD(barrier)
-	CMD(delay)
-	CMD(shell)
 	{ NULL, NULL }
 #undef CMD_STREAM
-#undef CMD
 };
 
 static void *
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index f04003da7..2fcf5e0e2 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -99,6 +99,8 @@ cmd_varnishtest(CMD_ARGS)
 }
 
 /* SECTION: shell shell
+ *
+ * NOTE: This command is available everywhere commands are given.
  *
  * Pass the string given as argument to a shell. If you have multiple
  * commands to run, you can use curly brackets to describe a multi-lines
@@ -311,13 +313,12 @@ cmd_setenv(CMD_ARGS)
 }
 
 /* SECTION: delay delay
+ *
+ * NOTE: This command is available everywhere commands are given.
  *
  * Sleep for the number of seconds specified in the argument. The number
  * can include a fractional part, e.g. 1.5.
- */
-/* SECTION: stream.spec.delay delay
  *
- * Same as for the top-level delay.
  */
 void
 cmd_delay(CMD_ARGS)


More information about the varnish-commit mailing list