Commit 9aff778c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a '-L' flag for running varnishtest in "Learner mode", this will

be used for the examples in the tutorial.

The argument is the base port TCP number for the examples.

Servers listen on ports starting 10 above the base.

Server -listen oand client -connect arguments are numeric offsets to
the base TCP port number.

Polish the log-message output a bit, both with and without -L.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4753 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8244c49a
......@@ -64,6 +64,8 @@ static struct vtclog *vltop;
static pthread_mutex_t vtc_mtx;
static pthread_cond_t vtc_cond;
int vtc_learn = 0;
/**********************************************************************
* Macro facility
*/
......@@ -117,9 +119,11 @@ macro_def(struct vtclog *vl, const char *instance, const char *name,
va_end(ap);
m->val = strdup(buf2);
AN(m->val);
vtc_log(vl, 4, "macro def %s=%s", name, m->val);
if (!vtc_learn)
vtc_log(vl, 4, "macro def %s=%s", name, m->val);
} else if (m != NULL) {
vtc_log(vl, 4, "macro undef %s", name);
if (!vtc_learn)
vtc_log(vl, 4, "macro undef %s", name);
VTAILQ_REMOVE(&macro_list, m, list);
free(m->name);
free(m->val);
......@@ -305,8 +309,11 @@ parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl)
for (cp = cmd; cp->name != NULL; cp++)
if (!strcmp(token_s[0], cp->name))
break;
if (cp->name == NULL)
if (cp->name == NULL) {
vtc_log(vl, 0, "Unknown command: \"%s\"", token_s[0]);
return;
}
vtc_log(vl, 3, "%s", token_s[0]);
assert(cp->cmd != NULL);
cp->cmd(token_s, priv, cmd, vl);
......@@ -618,8 +625,19 @@ main(int argc, char * const *argv)
vtc_loginit();
vltop = vtc_logopen("top");
AN(vltop);
while ((ch = getopt(argc, argv, "n:qt:v")) != -1) {
while ((ch = getopt(argc, argv, "L:n:qt:v")) != -1) {
switch (ch) {
case 'L':
/* XXX: append "/tutorial" to default search path */
vtc_learn = strtoul(optarg, NULL, 0);
if (vtc_learn > 65000) {
fprintf(stderr,
"-L argument must be 1...65000\n");
exit(1);
}
vtc_verbosity += 2;
dur = 60 * 3; /* seconds */
break;
case 'n':
ntest = strtoul(optarg, NULL, 0);
break;
......
......@@ -54,6 +54,7 @@ cmd_f cmd_client;
cmd_f cmd_varnish;
cmd_f cmd_sema;
extern int vtc_learn; /* Non-zero in Learners mode */
extern int vtc_verbosity;
extern int vtc_error; /* Error, bail out */
extern int vtc_stop; /* Abandon current test, no error */
......
......@@ -58,7 +58,7 @@ struct client {
char *spec;
char *connect;
char connect[256];
unsigned repeat;
......@@ -84,7 +84,7 @@ client_thread(void *priv)
char *p;
CAST_OBJ_NOTNULL(c, priv, CLIENT_MAGIC);
AN(c->connect);
AN(*c->connect);
p = strdup(c->connect);
vsb = macro_expand(p);
......@@ -106,9 +106,9 @@ client_thread(void *priv)
if (fd < 0)
vtc_log(c->vl, 0, "Failed to open %s", vsb_data(vsb));
assert(fd >= 0);
vtc_log(vl, 3, "Connected to %s fd is %d", vsb_data(vsb), fd);
vtc_log(vl, 3, "connected fd %d", fd);
http_process(vl, c->spec, fd, -1);
vtc_log(vl, 3, "Closing fd %d", fd);
vtc_log(vl, 3, "closing fd %d", fd);
TCP_close(&fd);
}
vtc_log(vl, 2, "Ending");
......@@ -135,7 +135,10 @@ client_new(const char *name)
if (*c->name != 'c')
vtc_log(c->vl, 0, "Client name must start with 'c'");
REPLACE(c->connect, "${v1_sock}");
if (vtc_learn)
bprintf(c->connect, "127.0.0.1:%d", vtc_learn);
else
bprintf(c->connect, "%s", "${v1_sock}");
VTAILQ_INSERT_TAIL(&clients, c, list);
return (c);
}
......@@ -152,7 +155,6 @@ client_delete(struct client *c)
vtc_logclose(c->vl);
free(c->spec);
free(c->name);
free(c->connect);
/* XXX: MEMLEAK (?)*/
FREE_OBJ(c);
}
......@@ -180,7 +182,8 @@ client_wait(struct client *c)
void *res;
CHECK_OBJ_NOTNULL(c, CLIENT_MAGIC);
vtc_log(c->vl, 2, "Waiting for client");
if (!vtc_learn)
vtc_log(c->vl, 2, "Waiting for client");
AZ(pthread_join(c->tp, &res));
if (res != NULL)
vtc_log(c->vl, 0, "Client returned \"%s\"", (char *)res);
......@@ -238,7 +241,11 @@ cmd_client(CMD_ARGS)
if (vtc_error)
break;
if (!strcmp(*av, "-connect")) {
REPLACE(c->connect, av[1]);
if (vtc_learn)
bprintf(c->connect, "127.0.0.1:%d",
vtc_learn + atoi(av[1]));
else
bprintf(c->connect, "%s", av[1]);
av++;
continue;
}
......
......@@ -483,7 +483,6 @@ cmd_http_rxresp(CMD_ARGS)
else
vtc_log(hp->vl, 0,
"Unknown http rxresp spec: %s\n", *av);
vtc_log(hp->vl, 3, "rxresp");
http_rxhdr(hp);
http_splitheader(hp, 0);
if (!has_obj)
......@@ -596,7 +595,6 @@ cmd_http_rxreq(CMD_ARGS)
for(; *av != NULL; av++)
vtc_log(hp->vl, 0, "Unknown http rxreq spec: %s\n", *av);
vtc_log(hp->vl, 3, "rxreq");
http_rxhdr(hp);
http_splitheader(hp, 1);
http_swallow_body(hp, hp->req, 0);
......@@ -617,7 +615,6 @@ cmd_http_rxhdrs(CMD_ARGS)
for(; *av != NULL; av++)
vtc_log(hp->vl, 0, "Unknown http rxreq spec: %s\n", *av);
vtc_log(hp->vl, 3, "rxhdrs");
http_rxhdr(hp);
http_splitheader(hp, 1);
}
......@@ -636,7 +633,6 @@ cmd_http_rxbody(CMD_ARGS)
for(; *av != NULL; av++)
vtc_log(hp->vl, 0, "Unknown http rxreq spec: %s\n", *av);
vtc_log(hp->vl, 3, "rxbody");
http_swallow_body(hp, hp->req, 0);
vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen);
}
......@@ -887,7 +883,10 @@ http_process(struct vtclog *vl, const char *spec, int sock, int sfd)
ALLOC_OBJ(hp, HTTP_MAGIC);
AN(hp);
hp->fd = sock;
hp->timeout = 3000;
if (vtc_learn)
hp->timeout = 120 * 1000;
else
hp->timeout = 3000;
hp->nrxbuf = 640*1024;
hp->vsb = vsb_newauto();
hp->rxbuf = malloc(hp->nrxbuf); /* XXX */
......
......@@ -113,10 +113,10 @@ vtc_logclose(struct vtclog *vl)
static const char * const lead[] = {
"----",
"# ",
"## ",
"### ",
"####"
"* ",
"** ",
"*** ",
"****"
};
#define NLEAD (sizeof(lead)/sizeof(lead[0]))
......
......@@ -63,7 +63,7 @@ struct server {
int depth;
int sock;
char *listen;
char listen[256];
struct vss_addr **vss_addr;
char *addr;
char *port;
......@@ -104,6 +104,7 @@ server_thread(void *priv)
fd = accept(s->sock, addr, &l);
if (fd < 0)
vtc_log(vl, 0, "Accepted failed: %s", strerror(errno));
vtc_log(vl, 3, "accepted fd %d", fd);
http_process(vl, s->spec, fd, s->sock);
vtc_log(vl, 3, "shutting fd %d", fd);
assert((shutdown(fd, SHUT_WR) == 0)
......@@ -135,7 +136,10 @@ server_new(const char *name)
if (*s->name != 's')
vtc_log(s->vl, 0, "Server name must start with 's'");
REPLACE(s->listen, "127.0.0.1:0");
if (vtc_learn)
bprintf(s->listen, "127.0.0.1:%d", vtc_learn + 10);
else
bprintf(s->listen, "127.0.0.1:%d", 0);
AZ(VSS_parse(s->listen, &s->addr, &s->port));
s->repeat = 1;
s->depth = 1;
......@@ -154,7 +158,6 @@ server_delete(struct server *s)
CHECK_OBJ_NOTNULL(s, SERVER_MAGIC);
vtc_logclose(s->vl);
free(s->listen);
free(s->name);
/* XXX: MEMLEAK (?) (VSS ??) */
FREE_OBJ(s);
......@@ -170,7 +173,8 @@ server_start(struct server *s)
int naddr;
CHECK_OBJ_NOTNULL(s, SERVER_MAGIC);
vtc_log(s->vl, 2, "Starting server");
if (!vtc_learn)
vtc_log(s->vl, 2, "Starting server");
if (s->sock < 0) {
naddr = VSS_resolve(s->addr, s->port, &s->vss_addr);
if (naddr != 1)
......@@ -189,7 +193,8 @@ server_start(struct server *s)
if (!strcmp(s->port, "0"))
REPLACE(s->port, s->aport);
}
vtc_log(s->vl, 1, "Listen on %s:%s", s->addr, s->port);
if (!vtc_learn)
vtc_log(s->vl, 1, "Listen on %s:%s", s->addr, s->port);
s->run = 1;
AZ(pthread_create(&s->tp, NULL, server_thread, s));
}
......@@ -204,7 +209,8 @@ server_wait(struct server *s)
void *res;
CHECK_OBJ_NOTNULL(s, SERVER_MAGIC);
vtc_log(s->vl, 2, "Waiting for server");
if (!vtc_learn)
vtc_log(s->vl, 2, "Waiting for server");
AZ(pthread_join(s->tp, &res));
if (res != NULL && !vtc_stop)
vtc_log(s->vl, 0, "Server returned \"%p\"",
......@@ -293,7 +299,11 @@ cmd_server(CMD_ARGS)
continue;
}
if (!strcmp(*av, "-listen")) {
REPLACE(s->listen, av[1]);
if (vtc_learn)
bprintf(s->listen, "127.0.0.1:%d",
vtc_learn + 10 + atoi(av[1]));
else
bprintf(s->listen, "%s", av[1]);
AZ(VSS_parse(s->listen, &s->addr, &s->port));
av++;
continue;
......
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