Commit effaadab authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

- 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.
parent 32e40a6e
......@@ -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 "==================="
......
......@@ -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 */
......
......@@ -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);
......@@ -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;
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment