]>
git.proxmox.com Git - mirror_qemu.git/blob - tests/boot-serial-test.c
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"
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 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 */
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 */
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 */
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
},
77 static void check_guest_output(const testdef_t
*test
, int fd
)
79 bool output_ok
= false;
80 int i
, nbr
, pos
= 0, ccnt
;
83 /* Poll serial output... Wait at most 60 seconds */
84 for (i
= 0; i
< 6000; ++i
) {
86 while ((nbr
= read(fd
, &ch
, 1)) == 1 && ccnt
++ < 512) {
87 if (ch
== test
->expect
[pos
]) {
89 if (test
->expect
[pos
] == '\0') {
90 /* We've reached the end of the expected string! */
106 static void test_machine(const void *data
)
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
;
115 ser_fd
= mkstemp(serialtmp
);
116 g_assert(ser_fd
!= -1);
120 codeparam
= "-kernel";
121 } else if (test
->bios
) {
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
);
138 * Make sure that this test uses tcg if available: It is used as a
139 * fast-enough smoketest for that.
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
);
151 check_guest_output(test
, ser_fd
);
152 qtest_quit(global_qtest
);
157 int main(int argc
, char *argv
[])
159 const char *arch
= qtest_get_arch();
162 g_test_init(&argc
, &argv
, NULL
);
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
);