r3976 - trunk/varnish-cache/bin/varnishtest

phk at projects.linpro.no phk at projects.linpro.no
Sun Mar 22 14:35:39 CET 2009


Author: phk
Date: 2009-03-22 14:35:38 +0100 (Sun, 22 Mar 2009)
New Revision: 3976

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
Log:
Continue the civilization of varnishtest:

Unify the construction of the workdir name.

Append uid to the name if non-zero (as in: "/tmp/__v1.488") to avoid
multiple users stomping on each other.

Blow away and recreate the workdir at the creation of an instance.

Close and reopen the shmem for each launch, close during cleanup.

Fixes #13



Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2009-03-22 13:28:38 UTC (rev 3975)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2009-03-22 13:35:38 UTC (rev 3976)
@@ -76,6 +76,7 @@
 
 	int			cli_fd;
 	int			vcl_nbr;
+	char			*workdir;
 };
 
 static VTAILQ_HEAD(, varnish)	varnishes =
@@ -143,15 +144,28 @@
 varnish_new(const char *name)
 {
 	struct varnish *v;
+	char *c;
 
 	AN(name);
 	ALLOC_OBJ(v, VARNISH_MAGIC);
 	AN(v);
 	REPLACE(v->name, name);
+
+	if (getuid() == 0)
+		asprintf(&v->workdir, "/tmp/__%s", name);
+	else
+		asprintf(&v->workdir, "/tmp/__%s.%d", name, getuid());
+	AN(v->workdir);
+
+	asprintf(&c, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir);
+	AZ(system(c));
+
 	v->vl = vtc_logopen(name);
 	AN(v->vl);
+
 	v->vl1 = vtc_logopen(name);
 	AN(v->vl1);
+
 	if (*v->name != 'v')
 		vtc_log(v->vl, 0, "Varnish name must start with 'v'");
 
@@ -160,6 +174,7 @@
 	v->accept = "127.0.0.1:9081";
 	v->cli_fd = -1;
 	VTAILQ_INSERT_TAIL(&varnishes, v, list);
+
 	return (v);
 }
 
@@ -174,7 +189,17 @@
 	CHECK_OBJ_NOTNULL(v, VARNISH_MAGIC);
 	vtc_logclose(v->vl);
 	free(v->name);
-	/* XXX: MEMLEAK */
+	free(v->workdir);
+	VSL_Close();
+
+	/*
+	 * We do not delete the workdir, it may contain stuff people
+	 * want (coredumps, shmlog/stats etc), and trying to divine
+	 * "may want" is just too much trouble.  Leave it around and
+	 * nuke it at the start of the next test-run.
+	 */
+
+	/* XXX: MEMLEAK (?) */
 	FREE_OBJ(v);
 }
 
@@ -226,11 +251,11 @@
 	vsb = vsb_newauto();
 	AN(vsb);
 	vsb_printf(vsb, "cd ../varnishd &&");
-	vsb_printf(vsb, " ./varnishd -d -d -n /tmp/__%s", v->name);
+	vsb_printf(vsb, " ./varnishd -d -d -n %s", v->workdir);
 	vsb_printf(vsb, " -p cli_banner=off");
 	vsb_printf(vsb, " -p auto_restart=off");
 	vsb_printf(vsb, " -a '%s' -T %s", v->accept, v->telnet);
-	vsb_printf(vsb, " -P /tmp/__%s/varnishd.pid", v->name);
+	vsb_printf(vsb, " -P %s/varnishd.pid", v->workdir);
 	vsb_printf(vsb, " %s", vsb_data(v->args));
 	vsb_finish(vsb);
 	AZ(vsb_overflowed(vsb));
@@ -274,12 +299,9 @@
 	}
 	vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd);
 	assert(v->cli_fd >= 0);
-	vsb = vsb_newauto();
-	vsb_printf(vsb, "/tmp/__%s", v->name);
-	vsb_finish(vsb);
-	AZ(vsb_overflowed(vsb));
-	v->stats = VSL_OpenStats(vsb_data(vsb));
-	vsb_delete(vsb);
+	if (v->stats != NULL)
+		VSL_Close();
+	v->stats = VSL_OpenStats(v->workdir);
 }
 
 /**********************************************************************
@@ -514,12 +536,13 @@
 		if (good)
 			break;
 	}
-	if (good)
+	if (good) {
 		vtc_log(v->vl, 2, "as expected: %s (%ju) %s %s",
 		    av[0], val, av[1], av[2]);
-	else
-		vtc_log(v->vl, 0, "Not true: %s (%ju) %s %s (%ju)",
-		    av[0], val, av[1], av[2], ref);
+		return;
+	}
+	vtc_log(v->vl, 0, "Not true: %s (%ju) %s %s (%ju)",
+	    av[0], val, av[1], av[2], ref);
 }
 
 /**********************************************************************



More information about the varnish-commit mailing list