]>
Commit | Line | Data |
---|---|---|
edbd790d MA |
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 | ||
681c28a3 | 13 | #include "qemu/osdep.h" |
530a7e48 | 14 | #include "libqos/fw_cfg.h" |
edbd790d | 15 | #include "libqtest.h" |
055a1efc | 16 | #include "qapi/qmp/qdict.h" |
5be5df72 | 17 | #include "standard-headers/linux/qemu_fw_cfg.h" |
aea6a169 | 18 | |
055a1efc | 19 | /* TODO actually test the results and get rid of this */ |
8173668c | 20 | #define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__)) |
055a1efc | 21 | |
484986e2 MA |
22 | typedef struct { |
23 | const char *args; | |
24 | uint64_t expected_boot; | |
25 | uint64_t expected_reboot; | |
26 | } boot_order_test; | |
edbd790d | 27 | |
aea6a169 MA |
28 | static void test_a_boot_order(const char *machine, |
29 | const char *test_args, | |
8173668c | 30 | uint64_t (*read_boot_order)(QTestState *), |
aea6a169 MA |
31 | uint64_t expected_boot, |
32 | uint64_t expected_reboot) | |
edbd790d | 33 | { |
aea6a169 | 34 | uint64_t actual; |
8173668c | 35 | QTestState *qts; |
edbd790d | 36 | |
8173668c TH |
37 | qts = qtest_initf("-nodefaults%s%s %s", machine ? " -M " : "", |
38 | machine ?: "", test_args); | |
39 | actual = read_boot_order(qts); | |
aea6a169 | 40 | g_assert_cmphex(actual, ==, expected_boot); |
8173668c | 41 | qmp_discard_response(qts, "{ 'execute': 'system_reset' }"); |
edbd790d MA |
42 | /* |
43 | * system_reset only requests reset. We get a RESET event after | |
44 | * the actual reset completes. Need to wait for that. | |
45 | */ | |
8173668c TH |
46 | qtest_qmp_eventwait(qts, "RESET"); |
47 | actual = read_boot_order(qts); | |
aea6a169 | 48 | g_assert_cmphex(actual, ==, expected_reboot); |
8173668c | 49 | qtest_quit(qts); |
edbd790d MA |
50 | } |
51 | ||
aea6a169 | 52 | static void test_boot_orders(const char *machine, |
8173668c | 53 | uint64_t (*read_boot_order)(QTestState *), |
aea6a169 | 54 | const boot_order_test *tests) |
edbd790d | 55 | { |
aea6a169 MA |
56 | int i; |
57 | ||
58 | for (i = 0; tests[i].args; i++) { | |
59 | test_a_boot_order(machine, tests[i].args, | |
60 | read_boot_order, | |
61 | tests[i].expected_boot, | |
62 | tests[i].expected_reboot); | |
63 | } | |
edbd790d MA |
64 | } |
65 | ||
8173668c | 66 | static uint8_t read_mc146818(QTestState *qts, uint16_t port, uint8_t reg) |
484986e2 | 67 | { |
8173668c TH |
68 | qtest_outb(qts, port, reg); |
69 | return qtest_inb(qts, port + 1); | |
484986e2 MA |
70 | } |
71 | ||
8173668c | 72 | static uint64_t read_boot_order_pc(QTestState *qts) |
484986e2 | 73 | { |
8173668c TH |
74 | uint8_t b1 = read_mc146818(qts, 0x70, 0x38); |
75 | uint8_t b2 = read_mc146818(qts, 0x70, 0x3d); | |
484986e2 MA |
76 | |
77 | return b1 | (b2 << 8); | |
78 | } | |
79 | ||
aea6a169 MA |
80 | static const boot_order_test test_cases_pc[] = { |
81 | { "", | |
82 | 0x1230, 0x1230 }, | |
83 | { "-no-fd-bootchk", | |
84 | 0x1231, 0x1231 }, | |
85 | { "-boot c", | |
86 | 0x0200, 0x0200 }, | |
87 | { "-boot nda", | |
88 | 0x3410, 0x3410 }, | |
89 | { "-boot order=", | |
90 | 0, 0 }, | |
91 | { "-boot order= -boot order=c", | |
92 | 0x0200, 0x0200 }, | |
93 | { "-boot once=a", | |
94 | 0x0100, 0x1230 }, | |
95 | { "-boot once=a -no-fd-bootchk", | |
96 | 0x0101, 0x1231 }, | |
97 | { "-boot once=a,order=c", | |
98 | 0x0100, 0x0200 }, | |
99 | { "-boot once=d -boot order=nda", | |
100 | 0x0300, 0x3410 }, | |
101 | { "-boot once=a -boot once=b -boot once=c", | |
102 | 0x0200, 0x1230 }, | |
103 | {} | |
104 | }; | |
105 | ||
106 | static void test_pc_boot_order(void) | |
107 | { | |
108 | test_boot_orders(NULL, read_boot_order_pc, test_cases_pc); | |
109 | } | |
530a7e48 | 110 | |
8173668c | 111 | static uint8_t read_m48t59(QTestState *qts, uint64_t addr, uint16_t reg) |
e99f87cc | 112 | { |
8173668c TH |
113 | qtest_writeb(qts, addr, reg & 0xff); |
114 | qtest_writeb(qts, addr + 1, reg >> 8); | |
115 | return qtest_readb(qts, addr + 3); | |
e99f87cc MA |
116 | } |
117 | ||
8173668c | 118 | static uint64_t read_boot_order_prep(QTestState *qts) |
e99f87cc | 119 | { |
8173668c | 120 | return read_m48t59(qts, 0x80000000 + 0x74, 0x34); |
e99f87cc MA |
121 | } |
122 | ||
123 | static const boot_order_test test_cases_prep[] = { | |
124 | { "", 'c', 'c' }, | |
125 | { "-boot c", 'c', 'c' }, | |
126 | { "-boot d", 'd', 'd' }, | |
127 | {} | |
128 | }; | |
129 | ||
130 | static void test_prep_boot_order(void) | |
131 | { | |
132 | test_boot_orders("prep", read_boot_order_prep, test_cases_prep); | |
133 | } | |
134 | ||
8173668c | 135 | static uint64_t read_boot_order_pmac(QTestState *qts) |
530a7e48 | 136 | { |
8173668c | 137 | QFWCFG *fw_cfg = mm_fw_cfg_init(qts, 0xf0000510); |
530a7e48 | 138 | |
aea6a169 | 139 | return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); |
530a7e48 AF |
140 | } |
141 | ||
aea6a169 MA |
142 | static const boot_order_test test_cases_fw_cfg[] = { |
143 | { "", 'c', 'c' }, | |
144 | { "-boot c", 'c', 'c' }, | |
145 | { "-boot d", 'd', 'd' }, | |
146 | { "-boot once=d,order=c", 'd', 'c' }, | |
147 | {} | |
148 | }; | |
530a7e48 | 149 | |
aea6a169 MA |
150 | static void test_pmac_oldworld_boot_order(void) |
151 | { | |
152 | test_boot_orders("g3beige", read_boot_order_pmac, test_cases_fw_cfg); | |
153 | } | |
530a7e48 | 154 | |
aea6a169 MA |
155 | static void test_pmac_newworld_boot_order(void) |
156 | { | |
157 | test_boot_orders("mac99", read_boot_order_pmac, test_cases_fw_cfg); | |
530a7e48 AF |
158 | } |
159 | ||
8173668c | 160 | static uint64_t read_boot_order_sun4m(QTestState *qts) |
f88dc7dd | 161 | { |
8173668c | 162 | QFWCFG *fw_cfg = mm_fw_cfg_init(qts, 0xd00000510ULL); |
f88dc7dd MA |
163 | |
164 | return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); | |
165 | } | |
166 | ||
167 | static void test_sun4m_boot_order(void) | |
168 | { | |
169 | test_boot_orders("SS-5", read_boot_order_sun4m, test_cases_fw_cfg); | |
170 | } | |
171 | ||
8173668c | 172 | static uint64_t read_boot_order_sun4u(QTestState *qts) |
24943978 | 173 | { |
8173668c | 174 | QFWCFG *fw_cfg = io_fw_cfg_init(qts, 0x510); |
24943978 MA |
175 | |
176 | return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE); | |
177 | } | |
178 | ||
179 | static void test_sun4u_boot_order(void) | |
180 | { | |
181 | test_boot_orders("sun4u", read_boot_order_sun4u, test_cases_fw_cfg); | |
182 | } | |
183 | ||
edbd790d MA |
184 | int main(int argc, char *argv[]) |
185 | { | |
530a7e48 AF |
186 | const char *arch = qtest_get_arch(); |
187 | ||
edbd790d MA |
188 | g_test_init(&argc, &argv, NULL); |
189 | ||
530a7e48 AF |
190 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
191 | qtest_add_func("boot-order/pc", test_pc_boot_order); | |
192 | } else if (strcmp(arch, "ppc") == 0 || strcmp(arch, "ppc64") == 0) { | |
e99f87cc | 193 | qtest_add_func("boot-order/prep", test_prep_boot_order); |
aea6a169 MA |
194 | qtest_add_func("boot-order/pmac_oldworld", |
195 | test_pmac_oldworld_boot_order); | |
196 | qtest_add_func("boot-order/pmac_newworld", | |
197 | test_pmac_newworld_boot_order); | |
f88dc7dd MA |
198 | } else if (strcmp(arch, "sparc") == 0) { |
199 | qtest_add_func("boot-order/sun4m", test_sun4m_boot_order); | |
24943978 MA |
200 | } else if (strcmp(arch, "sparc64") == 0) { |
201 | qtest_add_func("boot-order/sun4u", test_sun4u_boot_order); | |
530a7e48 | 202 | } |
edbd790d MA |
203 | |
204 | return g_test_run(); | |
205 | } |