]>
Commit | Line | Data |
---|---|---|
d2ab58ff TH |
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) contains an expected string. | |
11 | * Thus we check that the firmware still boots at least to a certain | |
12 | * point and so we know that the machine is not completely broken. | |
13 | */ | |
14 | ||
15 | #include "qemu/osdep.h" | |
16 | #include "libqtest.h" | |
17 | ||
18 | typedef struct testdef { | |
19 | const char *arch; /* Target architecture */ | |
20 | const char *machine; /* Name of the machine */ | |
21 | const char *extra; /* Additional parameters */ | |
22 | const char *expect; /* Expected string in the serial output */ | |
23 | } testdef_t; | |
24 | ||
25 | static testdef_t tests[] = { | |
26 | { "alpha", "clipper", "", "PCI:" }, | |
27 | { "ppc", "ppce500", "", "U-Boot" }, | |
28 | { "ppc", "prep", "", "Open Hack'Ware BIOS" }, | |
29 | { "ppc64", "ppce500", "", "U-Boot" }, | |
30 | { "ppc64", "prep", "", "Open Hack'Ware BIOS" }, | |
31 | { "ppc64", "pseries", "", "Open Firmware" }, | |
859c397e | 32 | { "ppc64", "powernv", "-cpu POWER9", "SkiBoot" }, |
d2ab58ff TH |
33 | { "i386", "isapc", "-cpu qemu32 -device sga", "SGABIOS" }, |
34 | { "i386", "pc", "-device sga", "SGABIOS" }, | |
35 | { "i386", "q35", "-device sga", "SGABIOS" }, | |
36 | { "x86_64", "isapc", "-cpu qemu32 -device sga", "SGABIOS" }, | |
37 | { "x86_64", "q35", "-device sga", "SGABIOS" }, | |
38 | { "s390x", "s390-ccw-virtio", | |
39 | "-nodefaults -device sclpconsole,chardev=serial0", "virtio device" }, | |
40 | { NULL } | |
41 | }; | |
42 | ||
43 | static void check_guest_output(const testdef_t *test, int fd) | |
44 | { | |
45 | bool output_ok = false; | |
46 | int i, nbr, pos = 0; | |
47 | char ch; | |
48 | ||
49 | /* Poll serial output... Wait at most 60 seconds */ | |
50 | for (i = 0; i < 6000; ++i) { | |
51 | while ((nbr = read(fd, &ch, 1)) == 1) { | |
52 | if (ch == test->expect[pos]) { | |
53 | pos += 1; | |
54 | if (test->expect[pos] == '\0') { | |
55 | /* We've reached the end of the expected string! */ | |
56 | output_ok = true; | |
57 | goto done; | |
58 | } | |
59 | } else { | |
60 | pos = 0; | |
61 | } | |
62 | } | |
63 | g_assert(nbr >= 0); | |
64 | g_usleep(10000); | |
65 | } | |
66 | ||
67 | done: | |
68 | g_assert(output_ok); | |
69 | } | |
70 | ||
71 | static void test_machine(const void *data) | |
72 | { | |
73 | const testdef_t *test = data; | |
74 | char *args; | |
75 | char tmpname[] = "/tmp/qtest-boot-serial-XXXXXX"; | |
76 | int fd; | |
77 | ||
78 | fd = mkstemp(tmpname); | |
79 | g_assert(fd != -1); | |
80 | ||
81 | args = g_strdup_printf("-M %s,accel=tcg -chardev file,id=serial0,path=%s" | |
82 | " -serial chardev:serial0 %s", test->machine, | |
83 | tmpname, test->extra); | |
84 | ||
85 | qtest_start(args); | |
86 | unlink(tmpname); | |
87 | ||
88 | check_guest_output(test, fd); | |
89 | qtest_quit(global_qtest); | |
90 | ||
91 | g_free(args); | |
92 | close(fd); | |
93 | } | |
94 | ||
95 | int main(int argc, char *argv[]) | |
96 | { | |
97 | const char *arch = qtest_get_arch(); | |
98 | int i; | |
99 | ||
100 | g_test_init(&argc, &argv, NULL); | |
101 | ||
102 | for (i = 0; tests[i].arch != NULL; i++) { | |
103 | if (strcmp(arch, tests[i].arch) == 0) { | |
104 | char *name = g_strdup_printf("boot-serial/%s", tests[i].machine); | |
105 | qtest_add_data_func(name, &tests[i], test_machine); | |
106 | g_free(name); | |
107 | } | |
108 | } | |
109 | ||
110 | return g_test_run(); | |
111 | } |