]> Git Repo - qemu.git/blame - tests/boot-serial-test.c
scsi-disk: release AioContext in unaligned WRITE SAME case
[qemu.git] / tests / boot-serial-test.c
CommitLineData
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
e12c08d3
TH
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.
d2ab58ff
TH
14 */
15
16#include "qemu/osdep.h"
17#include "libqtest.h"
18
598a29f3
TH
19static 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
d2ab58ff
TH
27typedef 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 */
e12c08d3
TH
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 */
d2ab58ff
TH
35} testdef_t;
36
37static 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" },
eaa477ca 44 { "ppc64", "powernv", "-cpu POWER8", "SkiBoot" },
d2ab58ff
TH
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" },
598a29f3
TH
52 { "m68k", "mcf5208evb", "", "TT", sizeof(kernel_mcf5208), kernel_mcf5208 },
53
d2ab58ff
TH
54 { NULL }
55};
56
57static void check_guest_output(const testdef_t *test, int fd)
58{
59 bool output_ok = false;
92b540da 60 int i, nbr, pos = 0, ccnt;
d2ab58ff
TH
61 char ch;
62
63 /* Poll serial output... Wait at most 60 seconds */
64 for (i = 0; i < 6000; ++i) {
92b540da
TH
65 ccnt = 0;
66 while ((nbr = read(fd, &ch, 1)) == 1 && ccnt++ < 512) {
d2ab58ff
TH
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;
73 }
74 } else {
75 pos = 0;
76 }
77 }
78 g_assert(nbr >= 0);
79 g_usleep(10000);
80 }
81
82done:
83 g_assert(output_ok);
84}
85
86static void test_machine(const void *data)
87{
88 const testdef_t *test = data;
e12c08d3
TH
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;
d2ab58ff 94
e12c08d3
TH
95 ser_fd = mkstemp(serialtmp);
96 g_assert(ser_fd != -1);
97
98 if (test->kernel) {
99 code = test->kernel;
100 codeparam = "-kernel";
101 } else if (test->bios) {
102 code = test->bios;
103 codeparam = "-bios";
104 }
105
106 if (code) {
107 ssize_t wlen;
108 int code_fd;
109
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);
115 }
d2ab58ff 116
b96919d7
CH
117 /*
118 * Make sure that this test uses tcg if available: It is used as a
119 * fast-enough smoketest for that.
120 */
e12c08d3 121 global_qtest = qtest_startf("%s %s -M %s,accel=tcg:kvm "
78b27bad
EB
122 "-chardev file,id=serial0,path=%s "
123 "-no-shutdown -serial chardev:serial0 %s",
e12c08d3
TH
124 codeparam, code ? codetmp : "",
125 test->machine, serialtmp, test->extra);
126 unlink(serialtmp);
127 if (code) {
128 unlink(codetmp);
129 }
d2ab58ff 130
e12c08d3 131 check_guest_output(test, ser_fd);
d2ab58ff
TH
132 qtest_quit(global_qtest);
133
e12c08d3 134 close(ser_fd);
d2ab58ff
TH
135}
136
137int main(int argc, char *argv[])
138{
139 const char *arch = qtest_get_arch();
140 int i;
141
142 g_test_init(&argc, &argv, NULL);
143
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);
149 }
150 }
151
152 return g_test_run();
153}
This page took 0.119358 seconds and 4 git commands to generate.