[master] cab6b85 Add -D macro option to varnishtest
Martin Blix Grydeland
martin at varnish-cache.org
Tue Mar 22 09:07:49 CET 2011
commit cab6b85befea47fdff8cdd61ce456d97a3ba0485
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Fri Mar 18 14:30:09 2011 +0100
Add -D macro option to varnishtest
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index f601dbc..909e588 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -76,6 +76,8 @@ struct macro {
static VTAILQ_HEAD(,macro) macro_list = VTAILQ_HEAD_INITIALIZER(macro_list);
+struct _extmacro_list extmacro_list = VTAILQ_HEAD_INITIALIZER(extmacro_list);
+
static pthread_mutex_t macro_mtx;
static void
@@ -479,6 +481,7 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
char *cwd, *p;
char topbuild[BUFSIZ];
FILE *f;
+ struct extmacro *m;
vtc_loginit(logbuf, loglen);
vltop = vtc_logopen("top");
@@ -501,6 +504,10 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
AZ(chdir(tmpdir));
macro_def(vltop, NULL, "tmpdir", tmpdir);
+ /* Apply extmacro definitions */
+ VTAILQ_FOREACH(m, &extmacro_list, list)
+ macro_def(vltop, NULL, m->name, m->val);
+
/* Drop file to tell what was going on here */
f = fopen("INFO", "w");
AN(f);
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 843b8ec..28a5ca3 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -34,6 +34,7 @@
#ifdef HAVE_PTHREAD_NP_H
#include <pthread_np.h>
#endif
+#include "vqueue.h"
struct vsb;
struct vtclog;
@@ -49,6 +50,15 @@ struct cmds {
cmd_f *cmd;
};
+struct extmacro {
+ VTAILQ_ENTRY(extmacro) list;
+ char *name;
+ char *val;
+};
+
+VTAILQ_HEAD(_extmacro_list, extmacro);
+extern struct _extmacro_list extmacro_list;
+
void parse_string(char *buf, const struct cmds *cmd, void *priv,
struct vtclog *vl);
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index cd67225..07a876e 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -92,6 +92,32 @@ static int vtc_fail;
static int leave_temp;
/**********************************************************************
+ * Parse a -D option argument into a name/val pair, and insert
+ * into extmacro list
+ */
+
+int
+parse_D_opt(char *arg)
+{
+ int i;
+ char *p, *q;
+ struct extmacro *m;
+
+ p = arg;
+ q = strchr(p, '=');
+ if (!q)
+ return (0);
+ *q++ = '\0';
+ m = calloc(sizeof *m, 1);
+ AN(m);
+ REPLACE(m->name, p);
+ REPLACE(m->val, q);
+ VTAILQ_INSERT_TAIL(&extmacro_list, m, list);
+
+ return (1);
+}
+
+/**********************************************************************
* Read a file into memory
*/
@@ -130,6 +156,7 @@ usage(void)
{
fprintf(stderr, "usage: varnishtest [options] file ...\n");
#define FMT " %-28s # %s\n"
+ fprintf(stderr, FMT, "-D name=val", "Define macro for use in scripts");
fprintf(stderr, FMT, "-j jobs", "Run this many tests in parallel");
fprintf(stderr, FMT, "-k", "Continue on test failure");
fprintf(stderr, FMT, "-l", "Leave /tmp/vtc.* if test fails");
@@ -310,8 +337,15 @@ main(int argc, char * const *argv)
setbuf(stdout, NULL);
setbuf(stderr, NULL);
- while ((ch = getopt(argc, argv, "j:klLn:qt:v")) != -1) {
+ while ((ch = getopt(argc, argv, "D:j:klLn:qt:v")) != -1) {
switch (ch) {
+ case 'D':
+ if (!parse_D_opt(optarg)) {
+ fprintf(stderr, "Cannot parse D opt '%s'\n",
+ optarg);
+ exit (2);
+ }
+ break;
case 'j':
npar = strtoul(optarg, NULL, 0);
break;
More information about the varnish-commit
mailing list