aboutsummaryrefslogtreecommitdiffstats
path: root/tools/console/testsuite/console-domU.c
blob: 3a9c508a6a0447f94b1069012d79023fd0874a7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Written by Anthony Liguori <aliguori@us.ibm.com> */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <termios.h>
#include <unistd.h>

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 i;
	int runs;
	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);

	printf("!!!XEN Test Begin!!!\n"); fflush(stdout);
	line = fgets(buffer, sizeof(buffer), stdin);
	if (line == NULL) {
		printf("Failure\n"); fflush(stdout);
		return 1;
	}

	canonicalize(line);
	seed = strtoul(line, 0, 0);

	printf("Seed Okay.\n"); fflush(stdout);

	srandom(seed);

	for (runs = (random() % 100000) + 4096; runs > 0; runs--) {
		size = random() % 4096;

		for (i = 0; i < size; i++) {
			int ch;
			int exp;

			ch = fgetc(stdin);
			exp = random() & 0xFF;
			if (ch != exp) {
				printf("Expected %d got %d\n",
				       exp, ch);
				fflush(stdout);
			}
			printf("Got %d/%d good bytes\n", i, size);
		}
		
		printf("Okay.\n"); fflush(stdout);
	}

	return 0;
}