Commit 230d8f2d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache

Conflicts:
	bin/varnishtest/vtc_varnish.c
parents 01fbdaca 50a77ab0
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
TESTS_PARALLELISM = 3 TESTS_PARALLELISM = 3
check: varnishtest check: varnishtest
./varnishtest -j$(TESTS_PARALLELISM) $(srcdir)/tests/*.vtc ./varnishtest -i -j$(TESTS_PARALLELISM) $(srcdir)/tests/*.vtc
@echo "===================" @echo "==================="
@echo "All tests succeeded" @echo "All tests succeeded"
@echo "===================" @echo "==================="
......
...@@ -60,6 +60,7 @@ volatile sig_atomic_t vtc_error; /* Error encountered */ ...@@ -60,6 +60,7 @@ volatile sig_atomic_t vtc_error; /* Error encountered */
int vtc_stop; /* Stops current test without error */ int vtc_stop; /* Stops current test without error */
pthread_t vtc_thread; pthread_t vtc_thread;
static struct vtclog *vltop; static struct vtclog *vltop;
int in_tree = 0; /* Are we running in-tree */
/********************************************************************** /**********************************************************************
* Macro facility * Macro facility
...@@ -73,8 +74,6 @@ struct macro { ...@@ -73,8 +74,6 @@ struct macro {
static VTAILQ_HEAD(,macro) macro_list = VTAILQ_HEAD_INITIALIZER(macro_list); 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 pthread_mutex_t macro_mtx;
static void static void
...@@ -192,6 +191,65 @@ macro_expand(struct vtclog *vl, const char *text) ...@@ -192,6 +191,65 @@ macro_expand(struct vtclog *vl, const char *text)
return (vsb); 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 * Execute a file
*/ */
...@@ -476,7 +534,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir, ...@@ -476,7 +534,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
{ {
unsigned old_err; unsigned old_err;
char *cwd, *p; char *cwd, *p;
char topbuild[BUFSIZ];
FILE *f; FILE *f;
struct extmacro *m; struct extmacro *m;
...@@ -491,14 +548,10 @@ exec_file(const char *fn, const char *script, const char *tmpdir, ...@@ -491,14 +548,10 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
VTAILQ_FOREACH(m, &extmacro_list, list) VTAILQ_FOREACH(m, &extmacro_list, list)
macro_def(vltop, NULL, m->name, m->val); 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); cwd = getcwd(NULL, PATH_MAX);
bprintf(topbuild, "%s/%s", cwd, TOP_BUILDDIR); macro_def(vltop, NULL, "pwd", cwd);
macro_def(vltop, NULL, "topbuild", topbuild); macro_def(vltop, NULL, "topbuild", "%s/%s", cwd, TOP_BUILDDIR);
AN(getcwd(topbuild, sizeof topbuild));
macro_def(vltop, NULL, "pwd", topbuild);
macro_def(vltop, NULL, "bad_ip", "10.255.255.255"); macro_def(vltop, NULL, "bad_ip", "10.255.255.255");
/* Move into our tmpdir */ /* Move into our tmpdir */
......
...@@ -49,15 +49,6 @@ struct cmds { ...@@ -49,15 +49,6 @@ struct cmds {
cmd_f *cmd; 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, void parse_string(char *buf, const struct cmds *cmd, void *priv,
struct vtclog *vl); struct vtclog *vl);
...@@ -92,3 +83,6 @@ int exec_file(const char *fn, const char *script, const char *tmpdir, ...@@ -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, void macro_def(struct vtclog *vl, const char *instance, const char *name,
const char *fmt, ...); const char *fmt, ...);
struct vsb *macro_expand(struct vtclog *vl, const char *text); 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 ...@@ -97,18 +97,13 @@ static int
parse_D_opt(char *arg) parse_D_opt(char *arg)
{ {
char *p, *q; char *p, *q;
struct extmacro *m;
p = arg; p = arg;
q = strchr(p, '='); q = strchr(p, '=');
if (!q) if (!q)
return (0); return (0);
*q++ = '\0'; *q++ = '\0';
m = calloc(sizeof *m, 1); extmacro_def(p, "%s", q);
AN(m);
REPLACE(m->name, p);
REPLACE(m->val, q);
VTAILQ_INSERT_TAIL(&extmacro_list, m, list);
return (1); return (1);
} }
...@@ -153,6 +148,7 @@ usage(void) ...@@ -153,6 +148,7 @@ usage(void)
fprintf(stderr, "usage: varnishtest [options] file ...\n"); fprintf(stderr, "usage: varnishtest [options] file ...\n");
#define FMT " %-28s # %s\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 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, "-j jobs", "Run this many tests in parallel");
fprintf(stderr, FMT, "-k", "Continue on test failure"); fprintf(stderr, FMT, "-k", "Continue on test failure");
fprintf(stderr, FMT, "-l", "Leave /tmp/vtc.* if test fails"); fprintf(stderr, FMT, "-l", "Leave /tmp/vtc.* if test fails");
...@@ -161,6 +157,9 @@ usage(void) ...@@ -161,6 +157,9 @@ usage(void)
fprintf(stderr, FMT, "-q", "Quiet mode: report only failues"); fprintf(stderr, FMT, "-q", "Quiet mode: report only failues");
fprintf(stderr, FMT, "-t duration", "Time tests out after this long"); fprintf(stderr, FMT, "-t duration", "Time tests out after this long");
fprintf(stderr, FMT, "-v", "Verbose mode: always report test log"); 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); exit(1);
} }
...@@ -331,9 +330,11 @@ main(int argc, char * const *argv) ...@@ -331,9 +330,11 @@ main(int argc, char * const *argv)
struct vtc_tst *tp; struct vtc_tst *tp;
char *p; char *p;
extmacro_def("varnishd", "varnishd"); /* Default to path lookup */
setbuf(stdout, NULL); setbuf(stdout, NULL);
setbuf(stderr, 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) { switch (ch) {
case 'D': case 'D':
if (!parse_D_opt(optarg)) { if (!parse_D_opt(optarg)) {
...@@ -342,6 +343,10 @@ main(int argc, char * const *argv) ...@@ -342,6 +343,10 @@ main(int argc, char * const *argv)
exit(2); exit(2);
} }
break; break;
case 'i':
/* Look for varnishd relative to varnishtest */
extmacro_def("varnishd", "../varnishd/varnishd");
break;
case 'j': case 'j':
npar = strtoul(optarg, NULL, 0); npar = strtoul(optarg, NULL, 0);
break; break;
......
...@@ -251,8 +251,8 @@ varnish_launch(struct varnish *v) ...@@ -251,8 +251,8 @@ varnish_launch(struct varnish *v)
vtc_log(v->vl, 2, "Launch"); vtc_log(v->vl, 2, "Launch");
vsb = VSB_new_auto(); vsb = VSB_new_auto();
AN(vsb); AN(vsb);
VSB_printf(vsb, "cd ${topbuild}/bin/varnishd &&"); VSB_printf(vsb, "cd ${pwd} &&");
VSB_printf(vsb, " ./varnishd -d -d -n %s", v->workdir); VSB_printf(vsb, " ${varnishd} -d -d -n %s", v->workdir);
VSB_printf(vsb, " -l 10m,1m,-"); VSB_printf(vsb, " -l 10m,1m,-");
VSB_printf(vsb, " -p auto_restart=off"); VSB_printf(vsb, " -p auto_restart=off");
VSB_printf(vsb, " -p syslog_cli_traffic=off"); VSB_printf(vsb, " -p syslog_cli_traffic=off");
......
...@@ -123,12 +123,12 @@ read_tmo(int fd, char *ptr, unsigned len, double tmo) ...@@ -123,12 +123,12 @@ read_tmo(int fd, char *ptr, unsigned len, double tmo)
pfd.fd = fd; pfd.fd = fd;
pfd.events = POLLIN; pfd.events = POLLIN;
i = poll(&pfd, 1, (int)(tmo * 1e3));
if (i == 0) {
errno = ETIMEDOUT;
return (-1);
}
for (j = 0; len > 0; ) { for (j = 0; len > 0; ) {
i = poll(&pfd, 1, (int)(tmo * 1e3));
if (i == 0) {
errno = ETIMEDOUT;
return (-1);
}
i = read(fd, ptr, len); i = read(fd, ptr, len);
if (i < 0) if (i < 0)
return (i); return (i);
......
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