Skip to contentSkip to conversation

consoled regression test

PATCH New Anthony Liguori 1 participant 1 message Aug 4, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 consoled regression test

Attached is a randomized tester for consoled. It's a patch against xen-unstable.hg but it doesn't add itself to any of the Makefiles but just as a subdirectory of consoled. There's a README in the directory that should be read otherwise you won't be able to do anything useful with it :-)

Right now, we can get pretty far before seeing data corruption. Previously, we'd see it almost immediately (after ~600 bytes, which is the max the control channel can hold before filling up).

It's actual general enough that it could be also used to test network traffic corruption but there are certainly better tools for that.

Regards,

Anthony Liguori

tools/consoled/testsuite/console-dom0.c +117 -0
diff -urN xen-unstable-20050804/tools/consoled/testsuite/console-dom0.c xen-unstable.hg/tools/consoled/testsuite/console-dom0.c
@@ -0,0 +1,117 @@
+/* Written by Anthony Liguori <[email protected]> */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <unistd.h>
+#include <termios.h>
+
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+
+static void generate_random_buffer(char *buffer, size_t size)
+{
+	int i;
+
+	for (i = 0; i < size; i++) {
+		buffer[i] = random() & 0xFF;
+	}
+}
+
+static void canonicalize(char *buffer)
+{
+	char *reader, *writer;
+
+	reader = writer = buffer;
+
+	while (*reader) {
+		*writer = *reader;
+		if (*reader != '\r') writer++;
+		reader++;
+	}
+	*writer = *reader;
+}
+
+int main(int argc, char **argv)
+{
+	char buffer[4096];
+	char *line;
+	unsigned int seed;
+	size_t size;
+	int runs;
+	unsigned long long total_bytes = 0;
+	struct termios term;
+
+	tcgetattr(STDIN_FILENO, &term);
+	cfmakeraw(&term);
+	tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
+
+	tcgetattr(STDOUT_FILENO, &term);
+	cfmakeraw(&term);
+	tcsetattr(STDOUT_FILENO, TCSAFLUSH, &term);
+
+	while ((line = fgets(buffer, sizeof(buffer), stdin))) {
+		canonicalize(line);
+
+		if (strcmp(line, "!!!XEN Test Begin!!!\n") == 0) {
+			break;
+		} else {
+			fprintf(stderr, "%s", line);
+		}
+	}
+
+	if (line == NULL) {
+		fprintf(stderr, "Client never sent start string.\n");
+		return 1;
+	}
+
+	seed = time(0);
+
+	printf("%u\n", seed); fflush(stdout);
+
+	fprintf(stderr, "Waiting for seed acknowledgement\n");
+	line = fgets(buffer, sizeof(buffer), stdin);
+	if (line == NULL) {
+		fprintf(stderr, "Client never acknowledge seed.\n");
+		return 1;
+	}
+
+	canonicalize(line);
+	if (strcmp(line, "Seed Okay.\n") != 0) {
+		fprintf(stderr, "Incorrect seed acknowledgement.\n");
+		fprintf(stderr, "[%s]", line);
+		return 1;
+	} else {
+		fprintf(stderr, "Processed seed.\n");
+	}
+
+	srandom(seed);
+
+	for (runs = (random() % 100000) + 4096; runs > 0; runs--) {
+
+		size = random() % 4096;
+
+		fprintf(stderr, "Writing %d bytes.\n", size);
+
+		generate_random_buffer(buffer, size);
+		fwrite(buffer, size, 1, stdout);
+		fflush(stdout);
+
+		do {
+			line = fgets(buffer, sizeof(buffer), stdin);
+			if (line == NULL) {
+				fprintf(stderr, "Premature EOF from client.\n");
+				return 1;
+			}
+
+			canonicalize(line);
+			fprintf(stderr, "%s", line);
+		} while (strcmp(line, "Okay.\n") != 0);
+
+		total_bytes += size;
+	}
+
+	fprintf(stderr, "PASS: processed %llu byte(s).\n", total_bytes);
+
+	return 0;
+}
tools/consoled/testsuite/console-domU.c +76 -0

76 lines not on this page · raw message

tools/consoled/testsuite/Makefile +11 -0
diff -urN xen-unstable-20050804/tools/consoled/testsuite/Makefile xen-unstable.hg/tools/consoled/testsuite/Makefile
@@ -0,0 +1,11 @@
+CFLAGS=-g -Wall
+CC=gcc
+LDFLAGS=-static
+
+all: console-dom0 console-domU procpipe
+
+console-dom0: console-dom0.o
+console-domU: console-domU.o
+procpipe: procpipe.o
+
+clean:; $(RM) *.o console-domU console-dom0 procpipe
tools/consoled/testsuite/procpipe.c +133 -0

133 lines not on this page · raw message

tools/consoled/testsuite/README +29 -0
diff -urN xen-unstable-20050804/tools/consoled/testsuite/README xen-unstable.hg/tools/consoled/testsuite/README
@@ -0,0 +1,29 @@
+ABOUT
+
+This tool uses two programs, one that lives in dom0 and one that lives in domU
+to verify that no data is lost.  dom0 and domU share a handshake with each
+other that they use to exchange a random seed.
+
+Both programs then generate a series of random numbers and then writes and
+reads the numbers via the console.  Because each side starts with the same seed
+they know what data the other side is generating and therefore what should be
+expected.
+
+RUNNNING
+
+console-domU should be installed within the guest image.  It must be launched
+from the client automatically.  I use a custom initrd image and put it in the
+/linuxrc.
+
+console-dom0 and console-domU will communicate with each other and stress the
+console code.  You can verify it at various levels by invoking it in different
+ways.  procpipe is used to connect the two.  I use the following command for
+testing:
+
+./procpipe ./console-dom0 'xm create -c /etc/xen/xmexample1'
+
+xmexample1 has no devices and no root set (this is what triggers /linuxrc).
+
+If it freezes, it probably means that console-domU is expecting more data from
+console-dom0 (which means that some data got dropped).  I'd like to add
+timeouts in the future to handle this more gracefully.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel