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

Add -D macro option to varnishtest

parent 7058d471
......@@ -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);
......
......@@ -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);
......
......@@ -91,6 +91,32 @@ static int vtc_good;
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;
......
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