[master] f2bccc2 Renovate varnishtest a bit.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Nov 11 23:15:01 CET 2013
commit f2bccc2bde6f303aa6a1851e85ef5874c605e608
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Nov 11 21:44:46 2013 +0000
Renovate varnishtest a bit.
Define a macro for all programs, so they can be overwritten from
the command line.
Change '-i' to mean "You're in a source tree":
Find top of build-tree by reading Makefile
Set $PATH which can find all programs
diff --git a/bin/varnishtest/programs.h b/bin/varnishtest/programs.h
new file mode 100644
index 0000000..f7ffbf9
--- /dev/null
+++ b/bin/varnishtest/programs.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2013 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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.
+ *
+ */
+
+VTC_PROG(varnishd)
+VTC_PROG(varnishadm)
+VTC_PROG(varnishstat)
+VTC_PROG(varnishhist)
+VTC_PROG(varnishlog)
+VTC_PROG(varnishncsa)
diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc
index 7a2cee2..34a56f0 100644
--- a/bin/varnishtest/tests/a00009.vtc
+++ b/bin/varnishtest/tests/a00009.vtc
@@ -1,5 +1,5 @@
varnishtest "Code coverage of VCL compiler and RSTdump"
-shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1"
-shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprstparam > /dev/null 2>&1"
-shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprstvsl > /dev/null 2>&1"
+shell "${varnishd} -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1"
+shell "${varnishd} -x dumprstparam > /dev/null 2>&1"
+shell "${varnishd} -x dumprstvsl > /dev/null 2>&1"
diff --git a/bin/varnishtest/tests/b00041.vtc b/bin/varnishtest/tests/b00041.vtc
new file mode 100644
index 0000000..f299c1b
--- /dev/null
+++ b/bin/varnishtest/tests/b00041.vtc
@@ -0,0 +1,5 @@
+varnishtest "Test varnishadm and the Telnet CLI"
+
+varnish v1 -vcl {backend foo { .host = "127.0.0.1"; } } -start
+
+shell "${varnishadm} -n ${tmpdir}/v1 help > /dev/null"
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 0aa4769..687e52f 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -545,7 +545,7 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen)
{
unsigned old_err;
- char *cwd, *p;
+ char *p;
FILE *f;
struct extmacro *m;
@@ -562,11 +562,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
VTAILQ_FOREACH(m, &extmacro_list, list)
macro_def(vltop, NULL, m->name, "%s", m->val);
- /* Other macro definitions */
- cwd = getcwd(NULL, PATH_MAX);
- macro_def(vltop, NULL, "pwd", "%s", cwd);
- macro_def(vltop, NULL, "topbuild", "%s/%s", cwd, TOP_BUILDDIR);
-
/*
* We need an IP number which will not repond, ever, and that is a
* lot harder than it sounds. This IP# is from RFC5737 and a
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index c4ef35c..ff3cae1 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -86,6 +86,7 @@ static int vtc_good;
static int vtc_fail;
static int leave_temp;
static char *tmppath;
+static char *cwd = NULL;
/**********************************************************************
* Parse a -D option argument into a name/val pair, and insert
@@ -147,7 +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, "-D name=val", "Define macro");
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");
@@ -158,8 +159,6 @@ usage(void)
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);
}
@@ -323,6 +322,76 @@ start_test(void)
}
/**********************************************************************
+ * i-mode = "we're inside a src-tree"
+ *
+ * Find the abs path to top of source dir from Makefile
+ *
+ * Set path to all programs build directories
+ *
+ */
+
+static void
+i_mode(void)
+{
+ const char *sep;
+ struct vsb *vsb;
+ char *p;
+ char *topbuild;
+
+ /*
+ * This code has a rather intimate knowledge of auto* generated
+ * makefiles.
+ */
+
+ p = read_file("Makefile");
+ if (p == NULL) {
+ fprintf(stderr, "No Makefile for -i flag\n");
+ exit(2);
+ }
+ p = strstr(p, "\nabs_top_builddir");
+ if (p == NULL) {
+ fprintf(stderr,
+ "could not find 'abs_top_builddir' in Makefile\n");
+ exit(2);
+ }
+ topbuild = strchr(p + 1, '\n');
+ if (topbuild == NULL) {
+ fprintf(stderr,
+ "No NL after 'abs_top_builddir' in Makefile\n");
+ exit(2);
+ }
+ *topbuild = '\0';
+ topbuild = strchr(p, '/');
+ if (topbuild == NULL) {
+ fprintf(stderr,
+ "No '/' after 'abs_top_builddir' in Makefile\n");
+ exit(2);
+ }
+
+ extmacro_def("topbuild", "%s", topbuild);
+
+ /*
+ * Build $PATH which can find all programs in the build tree
+ */
+ vsb = VSB_new_auto();
+ AN(vsb);
+ VSB_printf(vsb, "PATH=");
+ sep = "";
+#define VTC_PROG(l) \
+ do { \
+ VSB_printf(vsb, "%s%s/bin/%s/", sep, topbuild, #l); \
+ sep = ":"; \
+ } while (0);
+#include "programs.h"
+#undef VTC_PROG
+ VSB_printf(vsb, ":%s", getenv("PATH"));
+ AZ(VSB_finish(vsb));
+
+ AZ(putenv(strdup(VSB_data(vsb))));
+ VSB_delete(vsb);
+}
+
+/**********************************************************************
* Main
*/
@@ -333,13 +402,21 @@ main(int argc, char * const *argv)
int ntest = 1; /* Run tests this many times */
struct vtc_tst *tp;
char *p;
+ int iflg = 0;
+
+ /* Default names of programs */
+#define VTC_PROG(l) extmacro_def(#l, #l);
+#include "programs.h"
+#undef VTC_PROG
- extmacro_def("varnishd", "varnishd"); /* Default to path lookup */
if (getenv("TMPDIR") != NULL)
tmppath = strdup(getenv("TMPDIR"));
else
tmppath = strdup("/tmp");
+ cwd = getcwd(NULL, PATH_MAX);
+ extmacro_def("pwd", "%s", cwd);
+
setbuf(stdout, NULL);
setbuf(stderr, NULL);
while ((ch = getopt(argc, argv, "D:ij:klLn:qt:v")) != -1) {
@@ -352,8 +429,7 @@ main(int argc, char * const *argv)
}
break;
case 'i':
- /* Look for varnishd relative to varnishtest */
- extmacro_def("varnishd", "../varnishd/varnishd");
+ iflg = 1;
break;
case 'j':
npar = strtoul(optarg, NULL, 0);
@@ -405,6 +481,9 @@ main(int argc, char * const *argv)
VTAILQ_INSERT_TAIL(&tst_head, tp, list);
}
+ if (iflg)
+ i_mode();
+
vb = vev_new_base();
i = 0;
More information about the varnish-commit
mailing list