r4753 - trunk/varnish-cache/bin/varnishtest

phk at varnish-cache.org phk at varnish-cache.org
Mon May 3 11:49:32 CEST 2010


Author: phk
Date: 2010-05-03 11:49:32 +0200 (Mon, 03 May 2010)
New Revision: 4753

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/bin/varnishtest/vtc.h
   trunk/varnish-cache/bin/varnishtest/vtc_client.c
   trunk/varnish-cache/bin/varnishtest/vtc_http.c
   trunk/varnish-cache/bin/varnishtest/vtc_log.c
   trunk/varnish-cache/bin/varnishtest/vtc_server.c
Log:
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.



Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2010-04-30 08:16:11 UTC (rev 4752)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2010-05-03 09:49:32 UTC (rev 4753)
@@ -64,6 +64,8 @@
 static pthread_mutex_t	vtc_mtx;
 static pthread_cond_t	vtc_cond;
 
+int			vtc_learn = 0;
+
 /**********************************************************************
  * Macro facility
  */
@@ -117,9 +119,11 @@
 		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 @@
 		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 @@
 	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;

Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h	2010-04-30 08:16:11 UTC (rev 4752)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h	2010-05-03 09:49:32 UTC (rev 4753)
@@ -54,6 +54,7 @@
 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 */

Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_client.c	2010-04-30 08:16:11 UTC (rev 4752)
+++ trunk/varnish-cache/bin/varnishtest/vtc_client.c	2010-05-03 09:49:32 UTC (rev 4753)
@@ -58,7 +58,7 @@
 
 	char			*spec;
 
-	char			*connect;
+	char			connect[256];
 
 	unsigned		repeat;
 
@@ -84,7 +84,7 @@
 	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 @@
 		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 @@
 	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 @@
 	vtc_logclose(c->vl);
 	free(c->spec);
 	free(c->name);
-	free(c->connect);
 	/* XXX: MEMLEAK (?)*/
 	FREE_OBJ(c);
 }
@@ -180,7 +182,8 @@
 	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 @@
 		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;
 		}

Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c	2010-04-30 08:16:11 UTC (rev 4752)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c	2010-05-03 09:49:32 UTC (rev 4753)
@@ -483,7 +483,6 @@
 		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 @@
 
 	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 @@
 
 	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 @@
 
 	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 @@
 	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 */

Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_log.c	2010-04-30 08:16:11 UTC (rev 4752)
+++ trunk/varnish-cache/bin/varnishtest/vtc_log.c	2010-05-03 09:49:32 UTC (rev 4753)
@@ -113,10 +113,10 @@
 
 static const char * const lead[] = {
 	"----",
-	"#   ",
-	"##  ",
-	"### ",
-	"####"
+	"*   ",
+	"**  ",
+	"*** ",
+	"****"
 };
 
 #define NLEAD (sizeof(lead)/sizeof(lead[0]))

Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_server.c	2010-04-30 08:16:11 UTC (rev 4752)
+++ trunk/varnish-cache/bin/varnishtest/vtc_server.c	2010-05-03 09:49:32 UTC (rev 4753)
@@ -63,7 +63,7 @@
 
 	int			depth;
 	int			sock;
-	char			*listen;
+	char			listen[256];
 	struct vss_addr		**vss_addr;
 	char			*addr;
 	char			*port;
@@ -104,6 +104,7 @@
 		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 @@
 	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 @@
 
 	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 @@
 	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 @@
 		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 @@
 	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 @@
 			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;




More information about the varnish-commit mailing list