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 typedef struct testdef
{
20 const char *arch
; /* Target architecture */
21 const char *machine
; /* Name of the machine */
22 const char *extra
; /* Additional parameters */
23 const char *expect
; /* Expected string in the serial output */
24 size_t codesize
; /* Size of the kernel or bios data */
25 const uint8_t *kernel
; /* Set in case we use our own mini kernel */
26 const uint8_t *bios
; /* Set in case we use our own mini bios */
29 static testdef_t tests
[] = {
30 { "alpha", "clipper", "", "PCI:" },
31 { "ppc", "ppce500", "", "U-Boot" },
32 { "ppc", "prep", "", "Open Hack'Ware BIOS" },
33 { "ppc64", "ppce500", "", "U-Boot" },
34 { "ppc64", "prep", "", "Open Hack'Ware BIOS" },
35 { "ppc64", "pseries", "", "Open Firmware" },
36 { "ppc64", "powernv", "-cpu POWER8", "SkiBoot" },
37 { "i386", "isapc", "-cpu qemu32 -device sga", "SGABIOS" },
38 { "i386", "pc", "-device sga", "SGABIOS" },
39 { "i386", "q35", "-device sga", "SGABIOS" },
40 { "x86_64", "isapc", "-cpu qemu32 -device sga", "SGABIOS" },
41 { "x86_64", "q35", "-device sga", "SGABIOS" },
42 { "s390x", "s390-ccw-virtio",
43 "-nodefaults -device sclpconsole,chardev=serial0", "virtio device" },
47 static void check_guest_output(const testdef_t
*test
, int fd
)
49 bool output_ok
= false;
50 int i
, nbr
, pos
= 0, ccnt
;
53 /* Poll serial output... Wait at most 60 seconds */
54 for (i
= 0; i
< 6000; ++i
) {
56 while ((nbr
= read(fd
, &ch
, 1)) == 1 && ccnt
++ < 512) {
57 if (ch
== test
->expect
[pos
]) {
59 if (test
->expect
[pos
] == '\0') {
60 /* We've reached the end of the expected string! */
76 static void test_machine(const void *data
)
78 const testdef_t
*test
= data
;
79 char serialtmp
[] = "/tmp/qtest-boot-serial-sXXXXXX";
80 char codetmp
[] = "/tmp/qtest-boot-serial-cXXXXXX";
81 const char *codeparam
= "";
82 const uint8_t *code
= NULL
;
85 ser_fd
= mkstemp(serialtmp
);
86 g_assert(ser_fd
!= -1);
90 codeparam
= "-kernel";
91 } else if (test
->bios
) {
100 code_fd
= mkstemp(codetmp
);
101 g_assert(code_fd
!= -1);
102 wlen
= write(code_fd
, code
, test
->codesize
);
103 g_assert(wlen
== test
->codesize
);
108 * Make sure that this test uses tcg if available: It is used as a
109 * fast-enough smoketest for that.
111 global_qtest
= qtest_startf("%s %s -M %s,accel=tcg:kvm "
112 "-chardev file,id=serial0,path=%s "
113 "-no-shutdown -serial chardev:serial0 %s",
114 codeparam
, code
? codetmp
: "",
115 test
->machine
, serialtmp
, test
->extra
);
121 check_guest_output(test
, ser_fd
);
122 qtest_quit(global_qtest
);
127 int main(int argc
, char *argv
[])
129 const char *arch
= qtest_get_arch();
132 g_test_init(&argc
, &argv
, NULL
);
134 for (i
= 0; tests
[i
].arch
!= NULL
; i
++) {
135 if (strcmp(arch
, tests
[i
].arch
) == 0) {
136 char *name
= g_strdup_printf("boot-serial/%s", tests
[i
].machine
);
137 qtest_add_data_func(name
, &tests
[i
], test_machine
);