ui: add trace events related to VNC client throttling
[qemu/ar7.git] / tests / boot-serial-test.c
blobdd3828c49b38d5beb8569c35ea3604bbf3d0a1f7
1 /*
2 * Test serial output of some machines.
4 * Copyright 2016 Thomas Huth, Red Hat Inc.
6 * This work is licensed under the terms of the GNU GPL, version 2
7 * or later. See the COPYING file in the top-level directory.
9 * This test is used to check that the serial output of the firmware
10 * (that we provide for some machines) or some small mini-kernels that
11 * we provide here contains an expected string. Thus we check that the
12 * firmware/kernel still boots at least to a certain point and so we
13 * know that the machine is not completely broken.
16 #include "qemu/osdep.h"
17 #include "libqtest.h"
19 static const uint8_t kernel_mcf5208[] = {
20 0x41, 0xf9, 0xfc, 0x06, 0x00, 0x00, /* lea 0xfc060000,%a0 */
21 0x10, 0x3c, 0x00, 0x54, /* move.b #'T',%d0 */
22 0x11, 0x7c, 0x00, 0x04, 0x00, 0x08, /* move.b #4,8(%a0) Enable TX */
23 0x11, 0x40, 0x00, 0x0c, /* move.b %d0,12(%a0) Print 'T' */
24 0x60, 0xfa /* bra.s loop */
27 typedef struct testdef {
28 const char *arch; /* Target architecture */
29 const char *machine; /* Name of the machine */
30 const char *extra; /* Additional parameters */
31 const char *expect; /* Expected string in the serial output */
32 size_t codesize; /* Size of the kernel or bios data */
33 const uint8_t *kernel; /* Set in case we use our own mini kernel */
34 const uint8_t *bios; /* Set in case we use our own mini bios */
35 } testdef_t;
37 static testdef_t tests[] = {
38 { "alpha", "clipper", "", "PCI:" },
39 { "ppc", "ppce500", "", "U-Boot" },
40 { "ppc", "prep", "", "Open Hack'Ware BIOS" },
41 { "ppc64", "ppce500", "", "U-Boot" },
42 { "ppc64", "prep", "", "Open Hack'Ware BIOS" },
43 { "ppc64", "pseries", "", "Open Firmware" },
44 { "ppc64", "powernv", "-cpu POWER8", "SkiBoot" },
45 { "i386", "isapc", "-cpu qemu32 -device sga", "SGABIOS" },
46 { "i386", "pc", "-device sga", "SGABIOS" },
47 { "i386", "q35", "-device sga", "SGABIOS" },
48 { "x86_64", "isapc", "-cpu qemu32 -device sga", "SGABIOS" },
49 { "x86_64", "q35", "-device sga", "SGABIOS" },
50 { "s390x", "s390-ccw-virtio",
51 "-nodefaults -device sclpconsole,chardev=serial0", "virtio device" },
52 { "m68k", "mcf5208evb", "", "TT", sizeof(kernel_mcf5208), kernel_mcf5208 },
54 { NULL }
57 static void check_guest_output(const testdef_t *test, int fd)
59 bool output_ok = false;
60 int i, nbr, pos = 0, ccnt;
61 char ch;
63 /* Poll serial output... Wait at most 60 seconds */
64 for (i = 0; i < 6000; ++i) {
65 ccnt = 0;
66 while ((nbr = read(fd, &ch, 1)) == 1 && ccnt++ < 512) {
67 if (ch == test->expect[pos]) {
68 pos += 1;
69 if (test->expect[pos] == '\0') {
70 /* We've reached the end of the expected string! */
71 output_ok = true;
72 goto done;
74 } else {
75 pos = 0;
78 g_assert(nbr >= 0);
79 g_usleep(10000);
82 done:
83 g_assert(output_ok);
86 static void test_machine(const void *data)
88 const testdef_t *test = data;
89 char serialtmp[] = "/tmp/qtest-boot-serial-sXXXXXX";
90 char codetmp[] = "/tmp/qtest-boot-serial-cXXXXXX";
91 const char *codeparam = "";
92 const uint8_t *code = NULL;
93 int ser_fd;
95 ser_fd = mkstemp(serialtmp);
96 g_assert(ser_fd != -1);
98 if (test->kernel) {
99 code = test->kernel;
100 codeparam = "-kernel";
101 } else if (test->bios) {
102 code = test->bios;
103 codeparam = "-bios";
106 if (code) {
107 ssize_t wlen;
108 int code_fd;
110 code_fd = mkstemp(codetmp);
111 g_assert(code_fd != -1);
112 wlen = write(code_fd, code, test->codesize);
113 g_assert(wlen == test->codesize);
114 close(code_fd);
118 * Make sure that this test uses tcg if available: It is used as a
119 * fast-enough smoketest for that.
121 global_qtest = qtest_startf("%s %s -M %s,accel=tcg:kvm "
122 "-chardev file,id=serial0,path=%s "
123 "-no-shutdown -serial chardev:serial0 %s",
124 codeparam, code ? codetmp : "",
125 test->machine, serialtmp, test->extra);
126 unlink(serialtmp);
127 if (code) {
128 unlink(codetmp);
131 check_guest_output(test, ser_fd);
132 qtest_quit(global_qtest);
134 close(ser_fd);
137 int main(int argc, char *argv[])
139 const char *arch = qtest_get_arch();
140 int i;
142 g_test_init(&argc, &argv, NULL);
144 for (i = 0; tests[i].arch != NULL; i++) {
145 if (strcmp(arch, tests[i].arch) == 0) {
146 char *name = g_strdup_printf("boot-serial/%s", tests[i].machine);
147 qtest_add_data_func(name, &tests[i], test_machine);
148 g_free(name);
152 return g_test_run();