r3911 - trunk/varnish-cache/bin/varnishtest

phk at projects.linpro.no phk at projects.linpro.no
Wed Mar 11 14:15:09 CET 2009


Author: phk
Date: 2009-03-11 14:15:09 +0100 (Wed, 11 Mar 2009)
New Revision: 3911

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
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
Log:
Try to improve the way we deal with a test that errors out, in the hope
that varnishd panic messages do not get quenched on the way down.



Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2009-03-11 13:15:09 UTC (rev 3911)
@@ -48,9 +48,9 @@
 
 const char	*vtc_file;
 char		*vtc_desc;
+int		vtc_error;		/* Error encountered */
+int		vtc_stop;		/* Stops current test without error */
 
-static int	stop;
-
 /**********************************************************************
  * Read a file into memory
  */
@@ -64,17 +64,13 @@
 	int fd;
 
 	fd = open(fn, O_RDONLY);
-	if (fd < 0) {
-		fprintf(stderr, "Cannot open %s: %s", fn, strerror(errno));
-		exit (1);
-	}
+	if (fd < 0)
+		return (NULL);
 	buf = malloc(sz);
 	assert(buf != NULL);
 	s = read(fd, buf, sz - 1);
-	if (s <= 0) {
-		fprintf(stderr, "Cannot read %s: %s", fn, strerror(errno));
-		exit (1);
-	}
+	if (s <= 0)
+		return (NULL);
 	AZ(close (fd));
 	assert(s < sz);		/* XXX: increase MAX_FILESIZE */
 	buf[s] = '\0';
@@ -98,6 +94,8 @@
 
 	assert(buf != NULL);
 	for (p = buf; *p != '\0'; p++) {
+		if (vtc_error || vtc_stop)
+			break;
 		/* Start of line */
 		if (isspace(*p))
 			continue;
@@ -183,18 +181,11 @@
 		for (cp = cmd; cp->name != NULL; cp++)
 			if (!strcmp(token_s[0], cp->name))
 				break;
-		if (cp->name == NULL) {
-			for (tn = 0; token_s[tn] != NULL; tn++)
-				fprintf(stderr, "%s ", token_s[tn]);
-			fprintf(stderr, "\n");
-			fprintf(stderr, "Unknown command: \"%s\"", token_s[0]);
-			exit (1);
-		}
+		if (cp->name == NULL)
+			vtc_log(vl, 0, "Unknown command: \"%s\"", token_s[0]);
 
 		assert(cp->cmd != NULL);
 		cp->cmd(token_s, priv, cmd, vl);
-		if (stop)
-			break;
 	}
 }
 
@@ -323,7 +314,7 @@
 		vtc_log(vl, 4, "random[%d] = 0x%x (expect 0x%x)",
 		    i, l, random_expect[i]);
 		vtc_log(vl, 1, "SKIPPING test: unknown srandom(1) sequence.");
-		stop = 1;
+		vtc_stop = 1;
 		break;
 	}
 	l = 0;
@@ -334,7 +325,7 @@
 		    NRNDEXPECT, NRNDEXPECT + 1000,
 		    l, RND_NEXT_1K);
 		vtc_log(vl, 1, "SKIPPING test: unknown srandom(1) sequence.");
-		stop = 1;
+		vtc_stop = 1;
 	}
 }
 
@@ -359,15 +350,21 @@
 {
 	char *buf;
 
-	stop = 0;
+	vtc_stop = 0;
 	vtc_file = fn;
 	vtc_desc = NULL;
 	vtc_log(vl, 1, "TEST %s starting", fn);
 	buf = read_file(fn);
+	if (buf == NULL)
+		vtc_log(vl, 0, "Cannot read file '%s': %s",
+		    fn, strerror(errno));
 	parse_string(buf, cmds, NULL, vl);
 	vtc_log(vl, 1, "RESETTING after %s", fn);
 	reset_cmds(cmds);
-	vtc_log(vl, 1, "TEST %s completed", fn);
+	if (vtc_error)
+		vtc_log(vl, 1, "TEST %s FAILED", fn);
+	else
+		vtc_log(vl, 1, "TEST %s completed", fn);
 	vtc_file = NULL;
 	free(vtc_desc);
 }
@@ -421,9 +418,18 @@
 
 	init_sema();
 	for (i = 0; i < ntest; i++) {
-		for (ch = 0; ch < argc; ch++)
+		for (ch = 0; ch < argc; ch++) {
 			exec_file(argv[ch], vl);
+			if (vtc_error)
+				break;
+		}
+		if (vtc_error)
+			break;
 	}
+
+	if (vtc_error)
+		return (2);
+
 	fok = fopen("_.ok", "w");
 	if (fok != NULL)
 		fclose(fok);

Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h	2009-03-11 13:15:09 UTC (rev 3911)
@@ -55,6 +55,8 @@
 extern const char *vtc_file;
 extern char *vtc_desc;
 extern int vtc_verbosity;
+extern int vtc_error;		/* Error, bail out */
+extern int vtc_stop;		/* Abandon current test, no error */
 
 void init_sema(void);
 

Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_client.c	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc_client.c	2009-03-11 13:15:09 UTC (rev 3911)
@@ -162,10 +162,8 @@
 	CHECK_OBJ_NOTNULL(c, CLIENT_MAGIC);
 	vtc_log(c->vl, 2, "Waiting for client");
 	AZ(pthread_join(c->tp, &res));
-	if (res != NULL) {
+	if (res != NULL)
 		vtc_log(c->vl, 0, "Client returned \"%s\"", (char *)res);
-		exit (1);
-	}
 	c->tp = 0;
 }
 
@@ -217,6 +215,8 @@
 	av++;
 
 	for (; *av != NULL; av++) {
+		if (vtc_error)
+			break;
 		if (!strcmp(*av, "-connect")) {
 			REPLACE(c->connect, av[1]);
 			av++;
@@ -234,10 +234,8 @@
 			client_run(c);
 			continue;
 		}
-		if (**av == '-') {
+		if (**av == '-')
 			vtc_log(c->vl, 0, "Unknown client argument: %s", *av);
-			exit (1);
-		}
 		REPLACE(c->spec, *av);
 	}
 }

Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c	2009-03-11 13:15:09 UTC (rev 3911)
@@ -203,27 +203,22 @@
 	cmp = av[1];
 	rhs = cmd_var_resolve(hp, av[2]);
 	if (!strcmp(cmp, "==")) {
-		if (strcmp(lhs, rhs)) {
+		if (strcmp(lhs, rhs))
 			vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
 			    av[0], lhs, av[1], av[2], rhs);
-			exit (1);
-		} else {
+		else
 			vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
 			    av[0], lhs, av[1], av[2], rhs);
-		}
 	} else if (!strcmp(cmp, "!=")) {
-		if (!strcmp(lhs, rhs)) {
+		if (!strcmp(lhs, rhs))
 			vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
 			    av[0], lhs, av[1], av[2], rhs);
-			exit (1);
-		} else {
+		else
 			vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
 			    av[0], lhs, av[1], av[2], rhs);
-		}
 	} else {
 		vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) not implemented",
 		    av[0], lhs, av[1], av[2], rhs);
-		exit (1);
 	}
 }
 
@@ -321,11 +316,9 @@
 		pfd[0].events = POLLIN;
 		pfd[0].revents = 0;
 		i = poll(pfd, 1, hp->timeout);
-		if (i <= 0) {
+		if (i <= 0)
 			vtc_log(hp->vl, 0, "HTTP rx failed (%s)",
 			    strerror(errno));
-			exit (1);
-		}
 		assert(i > 0);
 		assert(hp->prxbuf < hp->nrxbuf);
 		i = read(hp->fd, hp->rxbuf + hp->prxbuf, n);
@@ -345,10 +338,8 @@
 	int i;
 
 	i = http_rxchar_eof(hp, n);
-	if (i <= 0) {
+	if (i <= 0)
 		vtc_log(hp->vl, 0, "HTTP rx failed (%s)", strerror(errno));
-		exit (1);
-	}
 	assert(i > 0);
 }
 
@@ -463,10 +454,8 @@
 	assert(!strcmp(av[0], "rxresp"));
 	av++;
 
-	for(; *av != NULL; av++) {
-		fprintf(stderr, "Unknown http rxresp spec: %s\n", *av);
-		exit (1);
-	}
+	for(; *av != NULL; av++)
+		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);
@@ -535,10 +524,8 @@
 		} else
 			break;
 	}
-	if (*av != NULL) {
-		fprintf(stderr, "Unknown http txresp spec: %s\n", *av);
-		exit (1);
-	}
+	if (*av != NULL)
+		vtc_log(hp->vl, 0, "Unknown http txresp spec: %s\n", *av);
 	if (body != NULL)
 		vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl);
 	vsb_cat(hp->vsb, nl);
@@ -563,10 +550,8 @@
 	assert(!strcmp(av[0], "rxreq"));
 	av++;
 
-	for(; *av != NULL; av++) {
-		fprintf(stderr, "Unknown http rxreq spec: %s\n", *av);
-		exit (1);
-	}
+	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);
@@ -586,10 +571,8 @@
 	assert(!strcmp(av[0], "rxhdrs"));
 	av++;
 
-	for(; *av != NULL; av++) {
-		fprintf(stderr, "Unknown http rxreq spec: %s\n", *av);
-		exit (1);
-	}
+	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);
@@ -607,10 +590,8 @@
 	assert(!strcmp(av[0], "rxbody"));
 	av++;
 
-	for(; *av != NULL; av++) {
-		fprintf(stderr, "Unknown http rxreq spec: %s\n", *av);
-		exit (1);
-	}
+	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);
@@ -671,10 +652,8 @@
 		} else
 			break;
 	}
-	if (*av != NULL) {
-		fprintf(stderr, "Unknown http txreq spec: %s\n", *av);
-		exit (1);
-	}
+	if (*av != NULL)
+		vtc_log(hp->vl, 0, "Unknown http txreq spec: %s\n", *av);
 	if (body != NULL)
 		vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl);
 	vsb_cat(hp->vsb, nl);

Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_log.c	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc_log.c	2009-03-11 13:15:09 UTC (rev 3911)
@@ -108,7 +108,8 @@
 	if (lvl == 0) {
 		printf("---- TEST FILE: %s\n", vtc_file);
 		printf("---- TEST DESCRIPTION: %s\n", vtc_desc);
-		exit (1);
+		vtc_error = 1;
+		pthread_exit(NULL);
 	}
 }
 
@@ -157,6 +158,8 @@
 	AZ(vsb_overflowed(vl->vsb));
 	(void)fputs(vsb_data(vl->vsb), stdout);
 	vsb_clear(vl->vsb);
-	if (lvl == 0)
-		exit (1);
+	if (lvl == 0) {
+		vtc_error = 1;
+		pthread_exit(NULL);
+	}
 }

Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_server.c	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc_server.c	2009-03-11 13:15:09 UTC (rev 3911)
@@ -164,13 +164,11 @@
 	vtc_log(s->vl, 2, "Starting server");
 	if (s->sock < 0) {
 		naddr = VSS_resolve(s->addr, s->port, &s->vss_addr);
-		if (naddr != 1) {
+		if (naddr != 1)
 			vtc_log(s->vl, 0,
 			    "Server s listen address not unique"
 			    " \"%s\" resolves to (%d) sockets",
 			    s->listen, naddr);
-			exit (1);
-		}
 		s->sock = VSS_listen(s->vss_addr[0], s->depth);
 		assert(s->sock >= 0);
 	}
@@ -191,11 +189,9 @@
 	CHECK_OBJ_NOTNULL(s, SERVER_MAGIC);
 	vtc_log(s->vl, 2, "Waiting for server");
 	AZ(pthread_join(s->tp, &res));
-	if (res != NULL) {
+	if (res != NULL)
 		vtc_log(s->vl, 0, "Server returned \"%p\"",
 		    (char *)res);
-		exit (1);
-	}
 	s->tp = 0;
 	TCP_close(&s->sock);
 	s->sock = -1;
@@ -255,6 +251,8 @@
 	av++;
 
 	for (; *av != NULL; av++) {
+		if (vtc_error)
+			break;
 		if (!strcmp(*av, "-repeat")) {
 			s->repeat = atoi(av[1]);
 			av++;
@@ -274,10 +272,8 @@
 			server_wait(s);
 			continue;
 		}
-		if (**av == '-') {
+		if (**av == '-')
 			vtc_log(s->vl, 0, "Unknown server argument: %s", *av);
-			exit (1);
-		}
 		s->spec = *av;
 	}
 }

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2009-03-11 11:08:12 UTC (rev 3910)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2009-03-11 13:15:09 UTC (rev 3911)
@@ -249,9 +249,8 @@
 			break;
 	}
 	if (v->cli_fd < 0) {
+		(void)kill(v->pid, SIGKILL);
 		vtc_log(v->vl, 0, "FAIL no CLI connection");
-		(void)kill(v->pid, SIGKILL);
-		exit (1);
 	}
 	vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd);
 	assert(v->cli_fd >= 0);
@@ -522,6 +521,8 @@
 	av++;
 
 	for (; *av != NULL; av++) {
+		if (vtc_error)
+			break;
 		if (!strcmp(*av, "-telnet")) {
 			AN(av[1]);
 			v->telnet = av[1];
@@ -600,6 +601,5 @@
 			continue;
 		}
 		vtc_log(v->vl, 0, "Unknown varnish argument: %s", *av);
-		exit (1);
 	}
 }



More information about the varnish-commit mailing list