r3533 - branches/2.0/varnish-cache/bin/varnishtest

tfheen at projects.linpro.no tfheen at projects.linpro.no
Mon Jan 19 14:45:10 CET 2009


Author: tfheen
Date: 2009-01-19 14:45:10 +0100 (Mon, 19 Jan 2009)
New Revision: 3533

Modified:
   branches/2.0/varnish-cache/bin/varnishtest/vtc.c
Log:
Merge r3367:

Add a toplevel word which examines the sequence returned by
srandom(1) and stops the test if we do not get the same sequence
as we expect.

The Open Group does not define which deterministic sequence srandom(1)
should result in, on that it be deterministic, but I have high hopes
in the general sanity and expect that UNIX people across the board
have realized that for portability the same sequence should be
returned on all platforms.

At the very least FreeBSD and Linux/GLIBC, as seen on projects.linpro.no,
agree.


Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/vtc.c	2009-01-19 13:28:59 UTC (rev 3532)
+++ branches/2.0/varnish-cache/bin/varnishtest/vtc.c	2009-01-19 13:45:10 UTC (rev 3533)
@@ -44,6 +44,8 @@
 const char	*vtc_file;
 char		*vtc_desc;
 
+static int	stop;
+
 /**********************************************************************
  * Read a file into memory
  */
@@ -185,6 +187,8 @@
 	
 		assert(cp->cmd != NULL);
 		cp->cmd(token_s, priv, cmd, vl);
+		if (stop)
+			break;
 	}
 }
 
@@ -282,6 +286,52 @@
 }
 
 /**********************************************************************
+ * Check random generator
+ */
+
+#define NRNDEXPECT	12
+static const unsigned long random_expect[NRNDEXPECT] = {
+	1804289383,	846930886,	1681692777,	1714636915,
+	1957747793,	424238335,	719885386,	1649760492,
+	 596516649,	1189641421,	1025202362,	1350490027
+};
+
+#define RND_NEXT_1K	0x3bdcbe30
+
+static void
+cmd_random(CMD_ARGS)
+{
+	unsigned long l;
+	int i;
+
+	(void)cmd;
+	(void)priv;
+	if (av == NULL)
+		return;
+	srandom(1);
+	for (i = 0; i < NRNDEXPECT; i++) {
+		l = random();
+		if (l == random_expect[i])
+			continue;
+		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;
+		break;
+	}
+	l = 0;
+	for (i = 0; i < 1000; i++) 
+		l += random();
+	if (l != RND_NEXT_1K) {
+		vtc_log(vl, 4, "sum(random[%d...%d]) = 0x%x (expect 0x%x)",
+		    NRNDEXPECT, NRNDEXPECT + 1000,
+		    l, RND_NEXT_1K);
+		vtc_log(vl, 1, "SKIPPING test: unknown srandom(1) sequence.");
+		stop = 1;
+	}
+}
+
+/**********************************************************************
  * Execute a file
  */
 
@@ -293,6 +343,7 @@
 	{ "test", 	cmd_test },
 	{ "shell", 	cmd_shell },
 	{ "sema", 	cmd_sema },
+	{ "random",	cmd_random },
 	{ NULL, 	NULL }
 };
 
@@ -301,6 +352,7 @@
 {
 	char *buf;
 
+	stop = 0;
 	vtc_file = fn;
 	vtc_desc = NULL;
 	vtc_log(vl, 1, "TEST %s starting", fn);



More information about the varnish-commit mailing list