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

phk at varnish-cache.org phk at varnish-cache.org
Mon Jan 3 15:56:17 CET 2011


Author: phk
Date: 2011-01-03 15:56:17 +0100 (Mon, 03 Jan 2011)
New Revision: 5676

Added:
   trunk/varnish-cache/bin/varnishtest/tests/a00011.vtc
Modified:
   trunk/varnish-cache/bin/varnishtest/Makefile.am
   trunk/varnish-cache/bin/varnishtest/flint.sh
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/bin/varnishtest/vtc.h
   trunk/varnish-cache/bin/varnishtest/vtc_http.c
   trunk/varnish-cache/bin/varnishtest/vtc_log.c
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
Log:
First cut at gzip support in varnishtest.



Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishtest/Makefile.am	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/Makefile.am	2011-01-03 14:56:17 UTC (rev 5676)
@@ -9,7 +9,7 @@
 
 DISTCLEANFILES = _.ok
 
-INCLUDES = -I$(top_srcdir)/include
+INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib/libvgz
 
 bin_PROGRAMS =	varnishtest
 
@@ -30,6 +30,7 @@
 		$(top_builddir)/lib/libvarnish/libvarnish.la \
 		$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 		$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
+		$(top_builddir)/lib/libvgz/libvgz.la \
 		${LIBM} ${PTHREAD_LIBS}
 
 varnishtest_CFLAGS = \

Modified: trunk/varnish-cache/bin/varnishtest/flint.sh
===================================================================
--- trunk/varnish-cache/bin/varnishtest/flint.sh	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/flint.sh	2011-01-03 14:56:17 UTC (rev 5676)
@@ -5,6 +5,7 @@
 	-I/usr/include \
 	-I. \
 	-I../../include \
+	-I../../lib/libvgz \
 	-I../.. \
 	../flint.lnt \
 	flint.lnt \

Added: trunk/varnish-cache/bin/varnishtest/tests/a00011.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/a00011.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/a00011.vtc	2011-01-03 14:56:17 UTC (rev 5676)
@@ -0,0 +1,17 @@
+# $Id$
+
+test "test vtc gzip support"
+
+server s1 {
+	rxreq
+	txresp -gzipbody FOO
+} -start
+
+client c1 -connect ${s1_sock} {
+	txreq 
+	rxresp
+	expect resp.bodylen == "26"
+	gunzip
+	expect resp.bodylen == "3"
+	expect resp.http.content-encoding == "gzip"
+} -run

Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2011-01-03 14:56:17 UTC (rev 5676)
@@ -355,7 +355,7 @@
 		return;
 	AN(av[1]);
 	AZ(av[2]);
-	vtc_dump(vl, 4, "shell", av[1]);
+	vtc_dump(vl, 4, "shell", av[1], -1);
 	r = system(av[1]);
 	assert(WEXITSTATUS(r) == 0);
 }

Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h	2011-01-03 14:56:17 UTC (rev 5676)
@@ -73,7 +73,7 @@
 void vtc_logclose(struct vtclog *vl);
 void vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...);
 void vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx,
-    const char *str);
+    const char *str, int len);
 
 int exec_file(const char *fn, const char *script, const char *tmpdir,
     char *logbuf, unsigned loglen);

Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c	2011-01-03 14:56:17 UTC (rev 5676)
@@ -49,6 +49,8 @@
 
 #include "vtc.h"
 
+#include "zlib.h"
+
 #define MAX_HDR		50
 
 struct http {
@@ -65,6 +67,7 @@
 	char			*rxbuf;
 	int			prxbuf;
 	char			*body;
+	unsigned		bodyl;
 	char			bodylen[20];
 
 	char			*req[MAX_HDR];
@@ -135,7 +138,7 @@
 
 	vsb_finish(hp->vsb);
 	AZ(vsb_overflowed(hp->vsb));
-	vtc_dump(hp->vl, lvl, pfx, vsb_data(hp->vsb));
+	vtc_dump(hp->vl, lvl, pfx, vsb_data(hp->vsb), vsb_len(hp->vsb));
 	l = write(hp->fd, vsb_data(hp->vsb), vsb_len(hp->vsb));
 	if (l != vsb_len(hp->vsb))
 		vtc_log(hp->vl, 0, "Write failed: %s", strerror(errno));
@@ -315,7 +318,7 @@
 
 	for (n = 0; n < 3 || hh[n] != NULL; n++) {
 		sprintf(buf, "http[%2d] ", n);
-		vtc_dump(hp->vl, 4, buf, hh[n]);
+		vtc_dump(hp->vl, 4, buf, hh[n], -1);
 	}
 }
 
@@ -381,7 +384,8 @@
 		l = strtoul(p, NULL, 0);
 		hp->body = hp->rxbuf + hp->prxbuf;
 		http_rxchar(hp, l);
-		vtc_dump(hp->vl, 4, "body", hp->body);
+		vtc_dump(hp->vl, 4, "body", hp->body, l);
+		hp->bodyl = l;
 		sprintf(hp->bodylen, "%d", l);
 		return;
 	}
@@ -393,7 +397,7 @@
 			do
 				http_rxchar(hp, 1);
 			while (hp->rxbuf[hp->prxbuf - 1] != '\n');
-			vtc_dump(hp->vl, 4, "len", hp->rxbuf + l);
+			vtc_dump(hp->vl, 4, "len", hp->rxbuf + l, -1);
 			i = strtoul(hp->rxbuf + l, &q, 16);
 			assert(q != hp->rxbuf + l);
 			assert(*q == '\0' || vct_islws(*q));
@@ -401,7 +405,7 @@
 			if (i > 0) {
 				ll += i;
 				http_rxchar(hp, i);
-				vtc_dump(hp->vl, 4, "chunk", hp->rxbuf + l);
+				vtc_dump(hp->vl, 4, "chunk", hp->rxbuf + l, -1);
 			}
 			l = hp->prxbuf;
 			http_rxchar(hp, 2);
@@ -412,7 +416,8 @@
 			if (i == 0)
 				break;
 		}
-		vtc_dump(hp->vl, 4, "body", hp->body);
+		vtc_dump(hp->vl, 4, "body", hp->body, ll);
+		hp->bodyl = ll;
 		sprintf(hp->bodylen, "%d", ll);
 		return;
 	}
@@ -422,8 +427,9 @@
 			i = http_rxchar_eof(hp, 1);
 			ll += i;
 		} while (i > 0);
-		vtc_dump(hp->vl, 4, "rxeof", hp->body);
+		vtc_dump(hp->vl, 4, "rxeof", hp->body, ll);
 	}
+	hp->bodyl = ll;
 	sprintf(hp->bodylen, "%d", ll);
 }
 
@@ -454,7 +460,7 @@
 		if (i == 2)
 			break;
 	}
-	vtc_dump(hp->vl, 4, "rxhdr", hp->rxbuf);
+	vtc_dump(hp->vl, 4, "rxhdr", hp->rxbuf, -1);
 }
 
 
@@ -493,6 +499,82 @@
 }
 
 /**********************************************************************
+ * Ungzip rx'ed body
+ */
+
+#define TRUST_ME(ptr)   ((void*)(uintptr_t)(ptr))
+
+#define OVERHEAD 31
+
+
+static void
+cmd_http_gunzip_body(CMD_ARGS)
+{
+	int i;
+	z_stream vz;
+	struct http *hp;
+	char *p;
+	unsigned l;
+
+	(void)cmd;
+	(void)vl;
+	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+	ONLY_CLIENT(hp, av);
+
+	memset(&vz, 0, sizeof vz);
+
+	vz.next_in = TRUST_ME(hp->body);
+	vz.avail_in = hp->bodyl;
+
+	l = hp->bodyl;
+	p = calloc(l, 1);
+	AN(p);
+
+	vz.next_out = TRUST_ME(p);
+	vz.avail_out = l;
+
+	assert(Z_OK == inflateInit2(&vz, 31));
+	i = inflate(&vz, Z_FINISH);
+	if (i != Z_STREAM_END)
+		vtc_log(hp->vl, 0, "Gunzip error = %d", i);
+	hp->bodyl = vz.total_out;
+	memcpy(hp->body, p, hp->bodyl);
+	free(p);
+	vtc_dump(hp->vl, 4, "body", hp->body, hp->bodyl);
+	bprintf(hp->bodylen, "%u", hp->bodyl);
+	assert(Z_OK == inflateEnd(&vz));
+}
+
+/**********************************************************************
+ * Create a gzip'ed body
+ */
+
+static void
+gzip_body(const char *txt, char **body, int *bodylen)
+{
+	int l;
+	z_stream vz;
+
+	memset(&vz, 0, sizeof vz);
+
+	l = strlen(txt);
+	*body = calloc(l + OVERHEAD, 1);
+	AN(*body);
+
+	vz.next_in = TRUST_ME(txt);
+	vz.avail_in = l;
+
+	vz.next_out = TRUST_ME(*body);
+	vz.avail_out = l + OVERHEAD;
+
+	assert(Z_OK == deflateInit2(&vz,
+	    Z_NO_COMPRESSION, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY));
+	assert(Z_STREAM_END == deflate(&vz, Z_FINISH));
+	*bodylen = vz.total_out;
+	assert(Z_OK == deflateEnd(&vz));
+}
+
+/**********************************************************************
  * Transmit a response
  */
 
@@ -571,6 +653,11 @@
 			body = synth_body(av[1]);
 			bodylen = strlen(body);
 			av++;
+		} else if (!strcmp(*av, "-gzipbody")) {
+			assert(body == nullbody);
+			gzip_body(av[1], &body, &bodylen);
+			vsb_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
+			av++;
 		} else
 			break;
 	}
@@ -726,7 +813,7 @@
 	CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
 	AN(av[1]);
 	AZ(av[2]);
-	vtc_dump(hp->vl, 4, "send", av[1]);
+	vtc_dump(hp->vl, 4, "send", av[1], -1);
 	i = write(hp->fd, av[1], strlen(av[1]));
 	assert(i == strlen(av[1]));
 
@@ -900,6 +987,7 @@
 
 	{ "txresp",		cmd_http_txresp },
 	{ "rxresp",		cmd_http_rxresp },
+	{ "gunzip",		cmd_http_gunzip_body },
 	{ "expect",		cmd_http_expect },
 	{ "send",		cmd_http_send },
 	{ "chunked",		cmd_http_chunked },

Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_log.c	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/vtc_log.c	2011-01-03 14:56:17 UTC (rev 5676)
@@ -155,7 +155,7 @@
 
 //lint -e{818}
 void
-vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str)
+vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str, int len)
 {
 	int nl = 1;
 	unsigned l;
@@ -170,9 +170,10 @@
 		vsb_printf(vl->vsb, "%s %-4s %s(null)\n",
 		    lead[lvl], vl->id, pfx);
 	else {
-		l = 0;
-		for(; *str != '\0'; str++) {
-			if (++l > 512) {
+		if (len == -1)
+			len = strlen(str);
+		for (l = 0; l < len; l++, str++) {
+			if (l > 512) {
 				vsb_printf(vl->vsb, "...");
 				break;
 			}
@@ -189,7 +190,7 @@
 				vsb_printf(vl->vsb, "\\n\n");
 				nl = 1;
 			} else if (*str < 0x20 || *str > 0x7e)
-				vsb_printf(vl->vsb, "\\x%02x", *str);
+				vsb_printf(vl->vsb, "\\x%02x", (*str) & 0xff);
 			else
 				vsb_printf(vl->vsb, "%c", *str);
 		}

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2011-01-03 11:08:19 UTC (rev 5675)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2011-01-03 14:56:17 UTC (rev 5676)
@@ -96,7 +96,7 @@
 	char *r;
 
 	if (cmd != NULL) {
-		vtc_dump(v->vl, 4, "CLI TX", cmd);
+		vtc_dump(v->vl, 4, "CLI TX", cmd, -1);
 		i = write(v->cli_fd, cmd, strlen(cmd));
 		assert(i == strlen(cmd));
 		i = write(v->cli_fd, "\n", 1);
@@ -110,7 +110,7 @@
 	}
 	assert(i == 0);
 	vtc_log(v->vl, 3, "CLI RX  %u", retval);
-	vtc_dump(v->vl, 4, "CLI RX", r);
+	vtc_dump(v->vl, 4, "CLI RX", r, -1);
 	if (repl != NULL)
 		*repl = r;
 	else
@@ -221,7 +221,7 @@
 		if (i <= 0)
 			break;
 		buf[i] = '\0';
-		vtc_dump(v->vl1, 3, "debug", buf);
+		vtc_dump(v->vl1, 3, "debug", buf, -1);
 	}
 	return (NULL);
 }




More information about the varnish-commit mailing list