]> Git Repo - qemu.git/blob - tests/boot-order-test.c
iotests: Add preallocated growth test for qcow2
[qemu.git] / tests / boot-order-test.c
1 /*
2  * Boot order test cases.
3  *
4  * Copyright (c) 2013 Red Hat Inc.
5  *
6  * Authors:
7  *  Markus Armbruster <[email protected]>,
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12
13 #include "qemu/osdep.h"
14 #include "libqos/fw_cfg.h"
15 #include "libqtest.h"
16
17 #include "hw/nvram/fw_cfg_keys.h"
18
19 typedef struct {
20     const char *args;
21     uint64_t expected_boot;
22     uint64_t expected_reboot;
23 } boot_order_test;
24
25 static void test_a_boot_order(const char *machine,
26                               const char *test_args,
27                               uint64_t (*read_boot_order)(void),
28                               uint64_t expected_boot,
29                               uint64_t expected_reboot)
30 {
31     char *args;
32     uint64_t actual;
33
34     args = g_strdup_printf("-nodefaults%s%s %s",
35                            machine ? " -M " : "",
36                            machine ?: "",
37                            test_args);
38     qtest_start(args);
39     actual = read_boot_order();
40     g_assert_cmphex(actual, ==, expected_boot);
41     qmp_discard_response("{ 'execute': 'system_reset' }");
42     /*
43      * system_reset only requests reset.  We get a RESET event after
44      * the actual reset completes.  Need to wait for that.
45      */
46     qmp_discard_response("");   /* HACK: wait for event */
47     actual = read_boot_order();
48     g_assert_cmphex(actual, ==, expected_reboot);
49     qtest_quit(global_qtest);
50     g_free(args);
51 }
52
53 static void test_boot_orders(const char *machine,
54                              uint64_t (*read_boot_order)(void),
55                              const boot_order_test *tests)
56 {
57     int i;
58
59     for (i = 0; tests[i].args; i++) {
60         test_a_boot_order(machine, tests[i].args,
61                           read_boot_order,
62                           tests[i].expected_boot,
63                           tests[i].expected_reboot);
64     }
65 }
66
67 static uint8_t read_mc146818(uint16_t port, uint8_t reg)
68 {
69     outb(port, reg);
70     return inb(port + 1);
71 }
72
73 static uint64_t read_boot_order_pc(void)
74 {
75     uint8_t b1 = read_mc146818(0x70, 0x38);
76     uint8_t b2 = read_mc146818(0x70, 0x3d);
77
78     return b1 | (b2 << 8);
79 }
80
81 static const boot_order_test test_cases_pc[] = {
82     { "",
83       0x1230, 0x1230 },
84     { "-no-fd-bootchk",
85       0x1231, 0x1231 },
86     { "-boot c",
87       0x0200, 0x0200 },
88     { "-boot nda",
89       0x3410, 0x3410 },
90     { "-boot order=",
91       0, 0 },
92     { "-boot order= -boot order=c",
93       0x0200, 0x0200 },
94     { "-boot once=a",
95       0x0100, 0x1230 },
96     { "-boot once=a -no-fd-bootchk",
97       0x0101, 0x1231 },
98     { "-boot once=a,order=c",
99       0x0100, 0x0200 },
100     { "-boot once=d -boot order=nda",
101       0x0300, 0x3410 },
102     { "-boot once=a -boot once=b -boot once=c",
103       0x0200, 0x1230 },
104     {}
105 };
106
107 static void test_pc_boot_order(void)
108 {
109     test_boot_orders(NULL, read_boot_order_pc, test_cases_pc);
110 }
111
112 static uint8_t read_m48t59(uint64_t addr, uint16_t reg)
113 {
114     writeb(addr, reg & 0xff);
115     writeb(addr + 1, reg >> 8);
116     return readb(addr + 3);
117 }
118
119 static uint64_t read_boot_order_prep(void)
120 {
121     return read_m48t59(0x80000000 + 0x74, 0x34);
122 }
123
124 static const boot_order_test test_cases_prep[] = {
125     { "", 'c', 'c' },
126     { "-boot c", 'c', 'c' },
127     { "-boot d", 'd', 'd' },
128     {}
129 };
130
131 static void test_prep_boot_order(void)
132 {
133     test_boot_orders("prep", read_boot_order_prep, test_cases_prep);
134 }
135
136 static uint64_t read_boot_order_pmac(void)
137 {
138     QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
139
140     return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
141 }
142
143 static const boot_order_test test_cases_fw_cfg[] = {
144     { "", 'c', 'c' },
145     { "-boot c", 'c', 'c' },
146     { "-boot d", 'd', 'd' },
147     { "-boot once=d,order=c", 'd', 'c' },
148     {}
149 };
150
151 static void test_pmac_oldworld_boot_order(void)
152 {
153     test_boot_orders("g3beige", read_boot_order_pmac, test_cases_fw_cfg);
154 }
155
156 static void test_pmac_newworld_boot_order(void)
157 {
158     test_boot_orders("mac99", read_boot_order_pmac, test_cases_fw_cfg);
159 }
160
161 static uint64_t read_boot_order_sun4m(void)
162 {
163     QFWCFG *fw_cfg = mm_fw_cfg_init(0xd00000510ULL);
164
165     return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
166 }
167
168 static void test_sun4m_boot_order(void)
169 {
170     test_boot_orders("SS-5", read_boot_order_sun4m, test_cases_fw_cfg);
171 }
172
173 static uint64_t read_boot_order_sun4u(void)
174 {
175     QFWCFG *fw_cfg = io_fw_cfg_init(0x510);
176
177     return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
178 }
179
180 static void test_sun4u_boot_order(void)
181 {
182     test_boot_orders("sun4u", read_boot_order_sun4u, test_cases_fw_cfg);
183 }
184
185 int main(int argc, char *argv[])
186 {
187     const char *arch = qtest_get_arch();
188
189     g_test_init(&argc, &argv, NULL);
190
191     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
192         qtest_add_func("boot-order/pc", test_pc_boot_order);
193     } else if (strcmp(arch, "ppc") == 0 || strcmp(arch, "ppc64") == 0) {
194         qtest_add_func("boot-order/prep", test_prep_boot_order);
195         qtest_add_func("boot-order/pmac_oldworld",
196                        test_pmac_oldworld_boot_order);
197         qtest_add_func("boot-order/pmac_newworld",
198                        test_pmac_newworld_boot_order);
199     } else if (strcmp(arch, "sparc") == 0) {
200         qtest_add_func("boot-order/sun4m", test_sun4m_boot_order);
201     } else if (strcmp(arch, "sparc64") == 0) {
202         qtest_add_func("boot-order/sun4u", test_sun4u_boot_order);
203     }
204
205     return g_test_run();
206 }
This page took 0.034438 seconds and 4 git commands to generate.