[master] effaada - Make varnishtest default to use path look up varnishd, and allow macro redefinition of varnishd location on command line. This allows varnishtest to work when installed/packaged. - Added -i command line option to set in-tree varnishd lookup relative to the varnishtest directory. - Update Makefile.am to specify the build-tree varnishd during testing.

Martin Blix Grydeland martin at varnish-cache.org
Tue May 31 10:32:34 CEST 2011


commit effaadab98ef44a29bb3bd0544dfffa3f8ae1452
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue May 31 10:10:16 2011 +0200

    - Make varnishtest default to use path look up varnishd, and allow macro
    redefinition of varnishd location on command line. This allows varnishtest to
    work when installed/packaged.
    - Added -i command line option to set in-tree varnishd lookup relative to the
    varnishtest directory.
    - Update Makefile.am to specify the build-tree varnishd during testing.

diff --git a/bin/varnishtest/Makefile.am b/bin/varnishtest/Makefile.am
index e538120..4562dc5 100644
--- a/bin/varnishtest/Makefile.am
+++ b/bin/varnishtest/Makefile.am
@@ -2,7 +2,7 @@
 
 TESTS_PARALLELISM = 3
 check: varnishtest
-	./varnishtest -j$(TESTS_PARALLELISM) $(srcdir)/tests/*.vtc
+	./varnishtest -i -j$(TESTS_PARALLELISM) $(srcdir)/tests/*.vtc
 	@echo "==================="
 	@echo "All tests succeeded"
 	@echo "==================="
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index e893be1..fcf89ca 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -60,6 +60,7 @@ volatile sig_atomic_t	vtc_error;	/* Error encountered */
 int			vtc_stop;	/* Stops current test without error */
 pthread_t		vtc_thread;
 static struct vtclog	*vltop;
+int			in_tree = 0;	/* Are we running in-tree */
 
 /**********************************************************************
  * Macro facility
@@ -73,8 +74,6 @@ 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
@@ -192,6 +191,65 @@ macro_expand(struct vtclog *vl, const char *text)
 	return (vsb);
 }
 
+/* extmacro is a list of macro's that are defined from the
+   command line and are applied to the macro list of each test
+   instance. No locking is required as they are set before any tests
+   are started.
+*/
+
+struct extmacro {
+	VTAILQ_ENTRY(extmacro)	list;
+	char			*name;
+	char			*val;
+};
+
+static VTAILQ_HEAD(, extmacro) extmacro_list =
+	VTAILQ_HEAD_INITIALIZER(extmacro_list);
+
+void
+extmacro_def(const char *name, const char *fmt, ...)
+{
+	char buf[256];
+	struct extmacro *m;
+	va_list ap;
+
+	VTAILQ_FOREACH(m, &extmacro_list, list)
+		if (!strcmp(name, m->name))
+			break;
+	if (m == NULL && fmt != NULL) {
+		m = calloc(sizeof *m, 1);
+		AN(m);
+		REPLACE(m->name, name);
+		VTAILQ_INSERT_TAIL(&extmacro_list, m, list);
+	}
+	if (fmt != NULL) {
+		AN(m);
+		va_start(ap, fmt);
+		free(m->val);
+		vbprintf(buf, fmt, ap);
+		va_end(ap);
+		m->val = strdup(buf);
+		AN(m->val);
+	} else if (m != NULL) {
+		VTAILQ_REMOVE(&extmacro_list, m, list);
+		free(m->name);
+		free(m->val);
+		free(m);
+	}
+}
+
+const char *
+extmacro_get(const char *name)
+{
+	struct extmacro *m;
+
+	VTAILQ_FOREACH(m, &extmacro_list, list)
+		if (!strcmp(name, m->name))
+			return (m->val);
+
+	return (NULL);
+}
+
 /**********************************************************************
  * Execute a file
  */
@@ -491,14 +549,10 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
 	VTAILQ_FOREACH(m, &extmacro_list, list)
 		macro_def(vltop, NULL, m->name, m->val);
 
-	/* We are still in bin/varnishtest at this point */
+	/* Other macro definitions */
 	cwd = getcwd(NULL, PATH_MAX);
-	bprintf(topbuild, "%s/%s", cwd, TOP_BUILDDIR);
-	macro_def(vltop, NULL, "topbuild", topbuild);
-
-	AN(getcwd(topbuild, sizeof topbuild));
-	macro_def(vltop, NULL, "pwd", topbuild);
-
+	macro_def(vltop, NULL, "pwd", cwd);
+	macro_def(vltop, NULL, "topbuild", "%s/%s", cwd, TOP_BUILDDIR);
 	macro_def(vltop, NULL, "bad_ip", "10.255.255.255");
 
 	/* Move into our tmpdir */
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 16e27a9..656c0bf 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -49,15 +49,6 @@ 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);
 
@@ -92,3 +83,6 @@ int exec_file(const char *fn, const char *script, const char *tmpdir,
 void macro_def(struct vtclog *vl, const char *instance, const char *name,
     const char *fmt, ...);
 struct vsb *macro_expand(struct vtclog *vl, const char *text);
+
+void extmacro_def(const char *name, const char *fmt, ...);
+const char *extmacro_get(const char *name);
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index 3f5d518..94abbf6 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -97,18 +97,13 @@ static int
 parse_D_opt(char *arg)
 {
 	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);
+	extmacro_def(p, "%s", q);
 
 	return (1);
 }
@@ -153,6 +148,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, "-i", "Find varnishd in build tree");
 	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");
@@ -161,6 +157,9 @@ usage(void)
 	fprintf(stderr, FMT, "-q", "Quiet mode: report only failues");
 	fprintf(stderr, FMT, "-t duration", "Time tests out after this long");
 	fprintf(stderr, FMT, "-v", "Verbose mode: always report test log");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "    Overridable macro definitions:\n");
+	fprintf(stderr, FMT, "varnishd", "Path to varnishd to use [varnishd]");
 	exit(1);
 }
 
@@ -331,9 +330,11 @@ main(int argc, char * const *argv)
 	struct vtc_tst *tp;
 	char *p;
 
+	extmacro_def("varnishd", "varnishd"); /* Default to path lookup */
+
 	setbuf(stdout, NULL);
 	setbuf(stderr, NULL);
-	while ((ch = getopt(argc, argv, "D:j:klLn:qt:v")) != -1) {
+	while ((ch = getopt(argc, argv, "D:ij:klLn:qt:v")) != -1) {
 		switch (ch) {
 		case 'D':
 			if (!parse_D_opt(optarg)) {
@@ -342,6 +343,10 @@ main(int argc, char * const *argv)
 				exit(2);
 			}
 			break;
+		case 'i':
+			/* Look for varnishd relative to varnishtest */
+			extmacro_def("varnishd", "../varnishd/varnishd");
+			break;
 		case 'j':
 			npar = strtoul(optarg, NULL, 0);
 			break;
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index d416a5b..ad8605d 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -251,8 +251,8 @@ varnish_launch(struct varnish *v)
 	vtc_log(v->vl, 2, "Launch");
 	vsb = vsb_new_auto();
 	AN(vsb);
-	vsb_printf(vsb, "cd ${topbuild}/bin/varnishd &&");
-	vsb_printf(vsb, " ./varnishd -d -d -n %s", v->workdir);
+	vsb_printf(vsb, "cd ${pwd} &&");
+	vsb_printf(vsb, " ${varnishd} -d -d -n %s", v->workdir);
 	vsb_printf(vsb, " -l 10m,1m,-");
 	vsb_printf(vsb, " -p auto_restart=off");
 	vsb_printf(vsb, " -p syslog_cli_traffic=off");



More information about the varnish-commit mailing list