r2816 - in trunk/varnish-cache/bin/varnishtest: . tests

phk at projects.linpro.no phk at projects.linpro.no
Thu Jun 26 10:53:52 CEST 2008


Author: phk
Date: 2008-06-26 10:53:51 +0200 (Thu, 26 Jun 2008)
New Revision: 2816

Modified:
   trunk/varnish-cache/bin/varnishtest/flint.lnt
   trunk/varnish-cache/bin/varnishtest/flint.sh
   trunk/varnish-cache/bin/varnishtest/tests/b00007.vtc
   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:
Add -chunked primitive for easier message composition.

Go over varnishtest with FlexeLint



Modified: trunk/varnish-cache/bin/varnishtest/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishtest/flint.lnt	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/flint.lnt	2008-06-26 08:53:51 UTC (rev 2816)
@@ -7,38 +7,44 @@
                         // 796 and 797 (out-of-bounds errors).
 -elib(123)  // size is both a variable and a macro with args
 -emacro(736, isnan)  // isnanf
+-efile(766, ../../config.h)
 
 
+// -header(../../config.h)
+
+// Fix strchr() semtics, it can only return NULL if arg2 != 0
 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 ))
-
--sem(vsb_new, @p == malloc(1))
--sem(vsb_delete, custodial(1))
+// 
+// -sem(vsb_new, @p == malloc(1))
+// -sem(vsb_delete, custodial(1))
 -sem(lbv_assert, r_no)
 -sem(lbv_xxxassert, r_no)
-
--ffc	// No automatic custody
-
+// -sem(WS_Init, custodial(2))
+// -sem(http_Setup, custodial(2))
+// 
+// -ffc	// No automatic custody
+// 
 -e763	// Redundant declaration for symbol '...' previously declared
--e726	// Extraneous comma ignored
--e728	// Symbol ... not explicitly initialized
+// -e726	// Extraneous comma ignored
+// -e728	// Symbol ... not explicitly initialized
 -e716	// while(1) ... 
--e785	// Too few initializers for aggregate 
--e786	// String concatenation within initializer
-
--emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types)
--emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types)
--emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small)
--emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small)
+// -e785	// Too few initializers for aggregate 
+// -e786	// String concatenation within initializer
+// 
+// -emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types)
+// -emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types)
+// -emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small)
+// -emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small)
 -emacro(506, VTAILQ_FOREACH_SAFE) // constant value boolean
-
+// 
 -esym(534, sprintf)	// Ignoring return value of function
--esym(534, asprintf)	// Ignoring return value of function
+// -esym(534, asprintf)	// Ignoring return value of function
 -esym(534, printf)	// Ignoring return value of function
 -esym(534, fprintf)	// Ignoring return value of function
 -esym(534, memset)	// Ignoring return value of function
--esym(534, memcpy)	// Ignoring return value of function
--esym(534, memmove)	// Ignoring return value of function
--esym(534, strcpy)	// Ignoring return value of function
+// -esym(534, memcpy)	// Ignoring return value of function
+// -esym(534, memmove)	// Ignoring return value of function
+// -esym(534, strcpy)	// Ignoring return value of function
 -esym(534, vsb_printf)	// Ignoring return value of function
 -esym(534, vsb_cat)	// Ignoring return value of function
 -esym(534, vsb_bcat)	// Ignoring return value of function
@@ -46,33 +52,44 @@
 -esym(534, strcat)	// Ignoring return value of function
 -esym(534, strcpy)	// Ignoring return value of function
 -esym(534, strlcpy)	// Ignoring return value of function
-
--emacro(506, isnan)	// constant value boolean
--emacro(747, isnan)	// significant coersion
--emacro(506, assert)	// constant value boolean
--emacro(827, assert)	// loop not reachable
--emacro(774, assert)	// booelan always true
-
-// cache.h
--emacro(506, INCOMPL) // Constant value Boolean
-
-// Review all below this line ///////////////////////////////////////////////
-
+// 
+// -emacro(506, isnan)	// constant value boolean
+// -emacro(747, isnan)	// significant coersion
+// -emacro(506, assert)	// constant value boolean
+// -emacro(827, assert)	// loop not reachable
+// -emacro(774, assert)	// booelan always true
+// -emacro(774, HTTPH)	// always false
+// 
+// // cache.h
+// -emacro(506, INCOMPL) // Constant value Boolean
+// 
+// // cache_center.c
+// -efunc(525, CNT_Session)	// Negative indentation from line
+// -efunc(525, http_FilterFields)	// Negative indentation from line
+// -efunc(539, http_FilterFields)	// Positive indentation from line
+// 
+// // cache_vcl.c
+// -efunc(525, vcl_handlingname)	// Negative indentation from line
+// -esym(528, vcl_handlingname)	// Not referenced
+// -e641	// Converting enum 'cli_status_e' to int
+// 
+// // Review all below this line ///////////////////////////////////////////////
+// 
 -e732   // Loss of sign (arg. no. 2) (int to unsigned
 -e737	// [45]  Loss of sign in promotion from int to unsigned
 -e713	// Loss of precision (assignment) (unsigned long long to long long)
 -e574	// Signed-unsigned mix with relational
--e712	// Loss of precision (assignment) (long long to
--e747	// Significant prototype coercion (arg. no. 2) long
-
-/*
-
--e767	// Macro redef (system queue.h vs ours )
-
--e506	// Constant value boolean
--e818	// Pointer parameter '...' could be declared as pointing to const
--e774	// Boolean within 'if' always evaluates to False
--e534	// Ignoring return value of function
--e557	// unrecog format
-
-*/
+// -e712	// Loss of precision (assignment) (long long to
+// -e747	// Significant prototype coercion (arg. no. 2) long
+// 
+// /*
+// 
+// -e767	// Macro redef (system queue.h vs ours )
+// 
+// -e506	// Constant value boolean
+// -e818	// Pointer parameter '...' could be declared as pointing to const
+// -e774	// Boolean within 'if' always evaluates to False
+// -e534	// Ignoring return value of function
+// -e557	// unrecog format
+// 
+// */

Modified: trunk/varnish-cache/bin/varnishtest/flint.sh
===================================================================
--- trunk/varnish-cache/bin/varnishtest/flint.sh	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/flint.sh	2008-06-26 08:53:51 UTC (rev 2816)
@@ -6,11 +6,10 @@
 	-I. \
 	-I../../include \
 	-I../.. \
-	-DVARNISH_STATE_DIR=\"foo\" \
 	flint.lnt \
 	*.c > $T 2>&1
 
-for t in Error Warning Info
+for t in Error Warning Info Note
 do
 	sed -n "/$t [0-9][0-9][0-9]:/s/.*\($t [0-9][0-9][0-9]\).*/\1/p" $T
 done | awk '

Modified: trunk/varnish-cache/bin/varnishtest/tests/b00007.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/b00007.vtc	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/tests/b00007.vtc	2008-06-26 08:53:51 UTC (rev 2816)
@@ -19,8 +19,8 @@
 	send "Transfer-encoding: chunked\r\n"
 	send "\r\n"
 	send "00000004\r\n1234\r\n"
-	send "00000004\r\n1234\r\n"
-	send "00000000\r\n"
+	chunked "1234"
+	chunked ""
 }
 
 server s1 -start 

Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2008-06-26 08:53:51 UTC (rev 2816)
@@ -61,11 +61,11 @@
 		err(1, "Cannot open %s", fn);
 	buf = malloc(sz);
 	assert(buf != NULL);
-	s = read(fd, buf, sz);
+	s = read(fd, buf, sz - 1);
 	if (s <= 0) 
 		err(1, "Cannot read %s", fn);
+	AZ(close (fd));
 	assert(s < sz);		/* XXX: increase MAX_FILESIZE */
-	AZ(close (fd));
 	buf[s] = '\0';
 	buf = realloc(buf, s + 1);
 	assert(buf != NULL);
@@ -141,7 +141,7 @@
 				p++;
 			} else if (*p == '{') { /* Braces */
 				nest_brace = 0;
-				token_s[tn] = p;
+				token_s[tn] = p + 1;
 				for (; *p != '\0'; p++) {
 					if (*p == '{')
 						nest_brace++;
@@ -151,7 +151,7 @@
 					}
 				}
 				assert(*p == '}');
-				token_e[tn++] = ++p;
+				token_e[tn++] = p++;
 			} else { /* other tokens */
 				token_s[tn] = p;
 				for (; *p != '\0' && !isspace(*p); p++)
@@ -228,7 +228,7 @@
 	AN(av[1]);
 	AZ(av[2]);
 	vtc_dump(vl, 4, "shell", av[1]);
-	system(av[1]);
+	(void)system(av[1]);	/* XXX: assert ? */
 }
 
 /**********************************************************************
@@ -303,7 +303,7 @@
  */
 
 int
-main(int argc, char **argv)
+main(int argc, char * const *argv)
 {
 	int ch;
 

Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h	2008-06-26 08:53:51 UTC (rev 2816)
@@ -30,7 +30,7 @@
 struct vtclog;
 struct cmds;
 
-#define CMD_ARGS char **av, void *priv, const struct cmds *cmd
+#define CMD_ARGS char * const *av, void *priv, const struct cmds *cmd
 typedef void cmd_f(CMD_ARGS);
 
 struct cmds {

Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_client.c	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc_client.c	2008-06-26 08:53:51 UTC (rev 2816)
@@ -208,11 +208,10 @@
 			client_run(c);
 			continue;
 		}
-		if (**av == '{') {
-			c->spec = *av;
-			continue;
+		if (**av == '-') {
+			vtc_log(c->vl, 0, "Unknown client argument: %s", *av);
+			exit (1);
 		}
-		vtc_log(c->vl, 0, "Unknown client argument: %s", *av);
-		exit (1);
+		c->spec = *av;
 	}
 }

Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c	2008-06-26 08:53:51 UTC (rev 2816)
@@ -51,6 +51,8 @@
 	int			timeout;
 	struct vtclog		*vl;
 
+	struct vsb		*vsb;
+
 	int			nrxbuf;
 	char			*rxbuf;
 
@@ -58,12 +60,31 @@
 	char			*resp[MAX_HDR];
 };
 
+/* XXX: we may want to vary this */
+static const char *nl = "\r\n";
+
 /**********************************************************************
+ * Finish and write the vsb to the fd
+ */
+
+static void
+http_write(const struct http *hp, int lvl, const char *pfx)
+{
+	int l;
+
+	vsb_finish(hp->vsb);
+	AZ(vsb_overflowed(hp->vsb));
+	vtc_dump(hp->vl, lvl, pfx, vsb_data(hp->vsb));
+	l = write(hp->fd, vsb_data(hp->vsb), vsb_len(hp->vsb));
+	assert(l == vsb_len(hp->vsb));
+}
+
+/**********************************************************************
  * find header
  */
 
 static char *
-http_find_header(char **hh, const char *hdr)
+http_find_header(char * const *hh, const char *hdr)
 {
 	int n, l;
 	char *r;
@@ -235,7 +256,7 @@
  */
 
 static void
-http_swallow_body(struct http *hp, char **hh)
+http_swallow_body(const struct http *hp, char * const *hh)
 {
 	char *p, b[BUFSIZ + 1];
 	int l, i;
@@ -334,14 +355,11 @@
 cmd_http_txresp(CMD_ARGS)
 {
 	struct http *hp;
-	struct vsb *vsb;
 	const char *proto = "HTTP/1.1";
 	const char *status = "200";
 	const char *msg = "Ok";
 	const char *body = NULL;
 	int dohdr = 0;
-	const char *nl = "\r\n";
-	int l;
 
 	(void)cmd;
 	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
@@ -349,7 +367,7 @@
 	assert(!strcmp(av[0], "txresp"));
 	av++;
 
-	vsb = vsb_newauto();
+	vsb_clear(hp->vsb);
 
 	for(; *av != NULL; av++) {
 		if (!strcmp(*av, "-proto")) {
@@ -377,11 +395,11 @@
 		}
 		if (!strcmp(*av, "-hdr")) {
 			if (dohdr == 0) {
-				vsb_printf(vsb, "%s %s %s%s", 
+				vsb_printf(hp->vsb, "%s %s %s%s", 
 				    proto, status, msg, nl);
 				dohdr = 1;
 			}
-			vsb_printf(vsb, "%s%s", av[1], nl);
+			vsb_printf(hp->vsb, "%s%s", av[1], nl);
 			av++;
 			continue;
 		}
@@ -389,21 +407,16 @@
 		exit (1);
 	}
 	if (dohdr == 0) {
-		vsb_printf(vsb, "%s %s %s%s", 
+		vsb_printf(hp->vsb, "%s %s %s%s", 
 		    proto, status, msg, nl);
 		dohdr = 1;
 	}
-	vsb_cat(vsb, nl);
+	vsb_cat(hp->vsb, nl);
 	if (body != NULL) {
-		vsb_cat(vsb, body);
-		vsb_cat(vsb, nl);
+		vsb_cat(hp->vsb, body);
+		vsb_cat(hp->vsb, nl);
 	}
-	vsb_finish(vsb);
-	AZ(vsb_overflowed(vsb));
-	vtc_dump(hp->vl, 4, NULL, vsb_data(vsb));
-	l = write(hp->fd, vsb_data(vsb), vsb_len(vsb));
-	assert(l == vsb_len(vsb));
-	vsb_delete(vsb);
+	http_write(hp, 4, "txresp");
 }
 
 /**********************************************************************
@@ -439,14 +452,11 @@
 cmd_http_txreq(CMD_ARGS)
 {
 	struct http *hp;
-	struct vsb *vsb;
 	const char *req = "GET";
 	const char *url = "/";
 	const char *proto = "HTTP/1.1";
 	const char *body = NULL;
 	int dohdr = 0;
-	const char *nl = "\r\n";
-	int l;
 
 	(void)cmd;
 	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
@@ -454,7 +464,7 @@
 	assert(!strcmp(av[0], "txreq"));
 	av++;
 
-	vsb = vsb_newauto();
+	vsb_clear(hp->vsb);
 
 	for(; *av != NULL; av++) {
 		if (!strcmp(*av, "-url")) {
@@ -477,11 +487,11 @@
 		}
 		if (!strcmp(*av, "-hdr")) {
 			if (dohdr == 0) {
-				vsb_printf(vsb, "%s %s %s%s", 
+				vsb_printf(hp->vsb, "%s %s %s%s", 
 				    req, url, proto, nl);
 				dohdr = 1;
 			}
-			vsb_printf(vsb, "%s%s", av[1], nl);
+			vsb_printf(hp->vsb, "%s%s", av[1], nl);
 			av++;
 			continue;
 		}
@@ -494,21 +504,16 @@
 		exit (1);
 	}
 	if (dohdr == 0) {
-		vsb_printf(vsb, "%s %s %s%s", 
+		vsb_printf(hp->vsb, "%s %s %s%s", 
 		    req, url, proto, nl);
 		dohdr = 1;
 	}
-	vsb_cat(vsb, nl);
+	vsb_cat(hp->vsb, nl);
 	if (body != NULL) {
-		vsb_cat(vsb, body);
-		vsb_cat(vsb, nl);
+		vsb_cat(hp->vsb, body);
+		vsb_cat(hp->vsb, nl);
 	}
-	vsb_finish(vsb);
-	AZ(vsb_overflowed(vsb));
-	vtc_dump(hp->vl, 4, NULL, vsb_data(vsb));
-	l = write(hp->fd, vsb_data(vsb), vsb_len(vsb));
-	assert(l == vsb_len(vsb));
-	vsb_delete(vsb);
+	http_write(hp, 4, "txreq");
 }
 
 /**********************************************************************
@@ -531,7 +536,25 @@
 
 }
 
+/**********************************************************************
+ * Send a string as chunked encoding
+ */
 
+static void
+cmd_http_chunked(CMD_ARGS)
+{
+	struct http *hp;
+
+	(void)cmd;
+	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+	AN(av[1]);
+	AZ(av[2]);
+	vsb_clear(hp->vsb);
+	vsb_printf(hp->vsb, "%x%s%s%s", strlen(av[1]), nl, av[1], nl);
+	http_write(hp, 4, "chunked");
+}
+
+
 /**********************************************************************
  * Execute HTTP specifications
  */
@@ -543,6 +566,7 @@
 	{ "rxresp",	cmd_http_rxresp },
 	{ "expect",	cmd_http_expect },
 	{ "send",	cmd_http_send },
+	{ "chunked",	cmd_http_chunked },
 	{ "delay",	cmd_delay },
 	{ NULL,		NULL }
 };
@@ -560,14 +584,14 @@
 	hp->client = client;
 	hp->timeout = 1000;
 	hp->nrxbuf = 8192;
+	hp->vsb = vsb_newauto();
+	AN(hp->vsb);
 
-	s = strdup(spec + 1);
+	s = strdup(spec);
 	q = strchr(s, '\0');
 	assert(q > s);
-	q--;
-	assert(*q == '}');
-	*q = '\0';
 	AN(s);
 	parse_string(s, http_cmds, hp);
+	vsb_delete(hp->vsb);
 	free(hp);
 }

Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_log.c	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc_log.c	2008-06-26 08:53:51 UTC (rev 2816)
@@ -73,6 +73,7 @@
 
 #define NLEAD (sizeof(lead)/sizeof(lead[0]))
 
+//lint -e{818}
 void
 vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...)
 {
@@ -98,6 +99,7 @@
  * Dump a string
  */
 
+//lint -e{818}
 void
 vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str)
 {

Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_server.c	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc_server.c	2008-06-26 08:53:51 UTC (rev 2816)
@@ -252,11 +252,10 @@
 			server_wait(s);
 			continue;
 		}
-		if (**av == '{') {
-			s->spec = *av;
-			continue;
+		if (**av == '-') {
+			vtc_log(s->vl, 0, "Unknown server argument: %s", *av);
+			exit (1);
 		}
-		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	2008-06-25 22:09:00 UTC (rev 2815)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2008-06-26 08:53:51 UTC (rev 2816)
@@ -29,19 +29,17 @@
 
 #include <stdio.h>
 
-#include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <pthread.h>
 #include <signal.h>
+#include <pthread.h>
 
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
 
-
 #include "vqueue.h"
 #include "miniobj.h"
 #include "libvarnish.h"
@@ -91,7 +89,7 @@
 	assert(i == strlen(cmd));
 	i = write(v->cli_fd, "\n", 1);
 	assert(i == 1);
-	i = cli_readres(v->cli_fd, &retval, &r, 1000);
+	i = cli_readres(v->cli_fd, &retval, &r, 1.0);
 	assert(i == 0);
 	vtc_dump(v->vl, 4, "CLI RX", r);
 	vtc_log(v->vl, 3, "CLI STATUS %u", retval);
@@ -358,10 +356,9 @@
  */
 
 static void
-varnish_vclbackend(struct varnish *v, char *vcl)
+varnish_vclbackend(struct varnish *v, const char *vcl)
 {
 	struct vsb *vsb, *vsb2;
-	char *p;
 	enum cli_status_e u;
 
 	if (v->cli_fd < 0)
@@ -381,11 +378,6 @@
 
 	varnish_cli_encode(vsb, vsb_data(vsb2));
 
-	if (*vcl == '{') {
-		p = strchr(++vcl, '\0');
-		if (p > vcl && p[-1] == '}')
-			p[-1] = '\0';
-	}
 	varnish_cli_encode(vsb, vcl);
 
 	vsb_printf(vsb, "\"", *vcl);




More information about the varnish-commit mailing list