]> git.proxmox.com Git - mirror_qemu.git/blob - tests/boot-serial-test.c
tests/boot-serial-test: Add tests for microblaze boards
[mirror_qemu.git] / tests / boot-serial-test.c
1 /*
2 * Test serial output of some machines.
3 *
4 * Copyright 2016 Thomas Huth, Red Hat Inc.
5 *
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.
8 *
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.
14 */
15
16 #include "qemu/osdep.h"
17 #include "libqtest.h"
18
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 */
25 };
26
27 static const uint8_t kernel_pls3adsp1800[] = {
28 0xb0, 0x00, 0x84, 0x00, /* imm 0x8400 */
29 0x30, 0x60, 0x00, 0x04, /* addik r3,r0,4 */
30 0x30, 0x80, 0x00, 0x54, /* addik r4,r0,'T' */
31 0xf0, 0x83, 0x00, 0x00, /* sbi r4,r3,0 */
32 0xb8, 0x00, 0xff, 0xfc /* bri -4 loop */
33 };
34
35 static const uint8_t kernel_plml605[] = {
36 0xe0, 0x83, 0x00, 0xb0, /* imm 0x83e0 */
37 0x00, 0x10, 0x60, 0x30, /* addik r3,r0,0x1000 */
38 0x54, 0x00, 0x80, 0x30, /* addik r4,r0,'T' */
39 0x00, 0x00, 0x83, 0xf0, /* sbi r4,r3,0 */
40 0xfc, 0xff, 0x00, 0xb8 /* bri -4 loop */
41 };
42
43 typedef struct testdef {
44 const char *arch; /* Target architecture */
45 const char *machine; /* Name of the machine */
46 const char *extra; /* Additional parameters */
47 const char *expect; /* Expected string in the serial output */
48 size_t codesize; /* Size of the kernel or bios data */
49 const uint8_t *kernel; /* Set in case we use our own mini kernel */
50 const uint8_t *bios; /* Set in case we use our own mini bios */
51 } testdef_t;
52
53 static testdef_t tests[] = {
54 { "alpha", "clipper", "", "PCI:" },
55 { "ppc", "ppce500", "", "U-Boot" },
56 { "ppc", "prep", "", "Open Hack'Ware BIOS" },
57 { "ppc64", "ppce500", "", "U-Boot" },
58 { "ppc64", "prep", "", "Open Hack'Ware BIOS" },
59 { "ppc64", "pseries", "", "Open Firmware" },
60 { "ppc64", "powernv", "-cpu POWER8", "SkiBoot" },
61 { "i386", "isapc", "-cpu qemu32 -device sga", "SGABIOS" },
62 { "i386", "pc", "-device sga", "SGABIOS" },
63 { "i386", "q35", "-device sga", "SGABIOS" },
64 { "x86_64", "isapc", "-cpu qemu32 -device sga", "SGABIOS" },
65 { "x86_64", "q35", "-device sga", "SGABIOS" },
66 { "s390x", "s390-ccw-virtio",
67 "-nodefaults -device sclpconsole,chardev=serial0", "virtio device" },
68 { "m68k", "mcf5208evb", "", "TT", sizeof(kernel_mcf5208), kernel_mcf5208 },
69 { "microblaze", "petalogix-s3adsp1800", "", "TT",
70 sizeof(kernel_pls3adsp1800), kernel_pls3adsp1800 },
71 { "microblazeel", "petalogix-ml605", "", "TT",
72 sizeof(kernel_plml605), kernel_plml605 },
73
74 { NULL }
75 };
76
77 static void check_guest_output(const testdef_t *test, int fd)
78 {
79 bool output_ok = false;
80 int i, nbr, pos = 0, ccnt;
81 char ch;
82
83 /* Poll serial output... Wait at most 60 seconds */
84 for (i = 0; i < 6000; ++i) {
85 ccnt = 0;
86 while ((nbr = read(fd, &ch, 1)) == 1 && ccnt++ < 512) {
87 if (ch == test->expect[pos]) {
88 pos += 1;
89 if (test->expect[pos] == '\0') {
90 /* We've reached the end of the expected string! */
91 output_ok = true;
92 goto done;
93 }
94 } else {
95 pos = 0;
96 }
97 }
98 g_assert(nbr >= 0);
99 g_usleep(10000);
100 }
101
102 done:
103 g_assert(output_ok);
104 }
105
106 static void test_machine(const void *data)
107 {
108 const testdef_t *test = data;
109 char serialtmp[] = "/tmp/qtest-boot-serial-sXXXXXX";
110 char codetmp[] = "/tmp/qtest-boot-serial-cXXXXXX";
111 const char *codeparam = "";
112 const uint8_t *code = NULL;
113 int ser_fd;
114
115 ser_fd = mkstemp(serialtmp);
116 g_assert(ser_fd != -1);
117
118 if (test->kernel) {
119 code = test->kernel;
120 codeparam = "-kernel";
121 } else if (test->bios) {
122 code = test->bios;
123 codeparam = "-bios";
124 }
125
126 if (code) {
127 ssize_t wlen;
128 int code_fd;
129
130 code_fd = mkstemp(codetmp);
131 g_assert(code_fd != -1);
132 wlen = write(code_fd, code, test->codesize);
133 g_assert(wlen == test->codesize);
134 close(code_fd);
135 }
136
137 /*
138 * Make sure that this test uses tcg if available: It is used as a
139 * fast-enough smoketest for that.
140 */
141 global_qtest = qtest_startf("%s %s -M %s,accel=tcg:kvm "
142 "-chardev file,id=serial0,path=%s "
143 "-no-shutdown -serial chardev:serial0 %s",
144 codeparam, code ? codetmp : "",
145 test->machine, serialtmp, test->extra);
146 unlink(serialtmp);
147 if (code) {
148 unlink(codetmp);
149 }
150
151 check_guest_output(test, ser_fd);
152 qtest_quit(global_qtest);
153
154 close(ser_fd);
155 }
156
157 int main(int argc, char *argv[])
158 {
159 const char *arch = qtest_get_arch();
160 int i;
161
162 g_test_init(&argc, &argv, NULL);
163
164 for (i = 0; tests[i].arch != NULL; i++) {
165 if (strcmp(arch, tests[i].arch) == 0) {
166 char *name = g_strdup_printf("boot-serial/%s", tests[i].machine);
167 qtest_add_data_func(name, &tests[i], test_machine);
168 g_free(name);
169 }
170 }
171
172 return g_test_run();
173 }