r4595 - trunk/varnish-cache/bin/varnishtest

phk at projects.linpro.no phk at projects.linpro.no
Fri Feb 26 20:16:39 CET 2010


Author: phk
Date: 2010-02-26 20:16:39 +0100 (Fri, 26 Feb 2010)
New Revision: 4595

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
Log:
Use -S with varnishtest



Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2010-02-26 19:16:06 UTC (rev 4594)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2010-02-26 19:16:39 UTC (rev 4595)
@@ -88,13 +88,14 @@
 macro_def(struct vtclog *vl, const char *instance, const char *name,
     const char *fmt, ...)
 {
-	char buf[256];
+	char buf1[256];
+	char buf2[256];
 	struct macro *m;
 	va_list ap;
 
 	if (instance != NULL) {
-		bprintf(buf, "%s_%s", instance, name);
-		name = buf;
+		bprintf(buf1, "%s_%s", instance, name);
+		name = buf1;
 	}
 
 	AZ(pthread_mutex_lock(&macro_mtx));
@@ -112,9 +113,9 @@
 		va_start(ap, fmt);
 		free(m->val);
 		m->val = NULL;
-		vbprintf(buf, fmt, ap);
+		vbprintf(buf2, fmt, ap);
 		va_end(ap);
-		m->val = strdup(buf);
+		m->val = strdup(buf2);
 		AN(m->val);
 		vtc_log(vl, 4, "macro def %s=%s", name, m->val);
 	} else if (m != NULL) {

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-02-26 19:16:06 UTC (rev 4594)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-02-26 19:16:39 UTC (rev 4595)
@@ -34,6 +34,7 @@
 #include <stdio.h>
 
 #include <ctype.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -92,11 +93,13 @@
 	unsigned retval;
 	char *r;
 
-	vtc_dump(v->vl, 4, "CLI TX", cmd);
-	i = write(v->cli_fd, cmd, strlen(cmd));
-	assert(i == strlen(cmd));
-	i = write(v->cli_fd, "\n", 1);
-	assert(i == 1);
+	if (cmd != NULL) {
+		vtc_dump(v->vl, 4, "CLI TX", cmd);
+		i = write(v->cli_fd, cmd, strlen(cmd));
+		assert(i == strlen(cmd));
+		i = write(v->cli_fd, "\n", 1);
+		assert(i == 1);
+	}
 	i = cli_readres(v->cli_fd, &retval, &r, 20.0);
 	if (i != 0) {
 		vtc_log(v->vl, 0, "CLI failed (%s) = %d %u %s",
@@ -104,8 +107,8 @@
 		return ((enum cli_status_e)retval);
 	}
 	assert(i == 0);
+	vtc_log(v->vl, 3, "CLI RX  %u", retval);
 	vtc_dump(v->vl, 4, "CLI RX", r);
-	vtc_log(v->vl, 3, "CLI STATUS (%s) %u", cmd, retval);
 	if (repl != NULL)
 		*repl = r;
 	else
@@ -154,7 +157,8 @@
 	v->workdir = strdup(buf);
 	AN(v->workdir);
 
-	bprintf(buf, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir);
+	bprintf(buf, "rm -rf %s ; mkdir -p %s ; echo ' %ld' > %s/_S",
+	    v->workdir, v->workdir, random(), v->workdir);
 	AZ(system(buf));
 
 	v->vl = vtc_logopen(name);
@@ -241,9 +245,9 @@
 	struct vsb *vsb;
 	int i, nfd, nap;
 	struct vss_addr **ap;
-	char abuf[128],pbuf[128];
+	char abuf[128], pbuf[128];
 	struct pollfd fd;
-	unsigned retval;
+	enum cli_status_e u;
 	char *r;
 
 	/* Create listener socket */
@@ -262,6 +266,7 @@
 	vsb_printf(vsb, " -p auto_restart=off");
 	vsb_printf(vsb, " -p syslog_cli_traffic=off");
 	vsb_printf(vsb, " -a '%s'", "127.0.0.1:0");
+	vsb_printf(vsb, " -S %s/_S", v->workdir);
 	vsb_printf(vsb, " -M %s:%s", abuf, pbuf);
 	vsb_printf(vsb, " -P %s/varnishd.pid", v->workdir);
 	vsb_printf(vsb, " %s", vsb_data(v->args));
@@ -312,16 +317,37 @@
 
 	AZ(close(v->cli_fd));
 	v->cli_fd = nfd;
+	nfd = -1;
 
 	vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd);
 	assert(v->cli_fd >= 0);
 
-	i = cli_readres(v->cli_fd, &retval, &r, 20.0);
-	if (i != 0 || retval != CLIS_OK)
-		vtc_log(v->vl, 0, "CLI banner fail", v->cli_fd);
-	vtc_log(v->vl, 4, "CLI banner %03u", retval);
+
+	/* Receive the banner or auth response */
+	u = varnish_ask_cli(v, NULL, &r);
+	if (vtc_error)
+		return;
+	if (u != CLIS_AUTH)
+		vtc_log(v->vl, 0, "CLI auth demand expected: %u %s", u, r);
+
+	bprintf(abuf, "%s/_S", v->workdir);
+	nfd = open(abuf, O_RDONLY);
+	assert(nfd >= 0);
+
+	assert(sizeof abuf >= CLI_AUTH_RESPONSE_LEN + 6);
+	strcpy(abuf, "auth ");
+	CLI_response(nfd, r, abuf + 5);
+	AZ(close(nfd));
 	free(r);
+	strcat(abuf, "\n");
 
+	u = varnish_ask_cli(v, abuf, &r);
+	if (vtc_error)
+		return;
+	if (u != CLIS_OK)
+		vtc_log(v->vl, 0, "CLI auth command failed: %u %s", u, r);
+	free(r);
+
 	if (v->stats != NULL)
 		VSL_Close();
 	v->stats = VSL_OpenStats(v->workdir);



More information about the varnish-commit mailing list