2 * Boot order test cases.
4 * Copyright (c) 2013 Red Hat Inc.
7 * Markus Armbruster <armbru@redhat.com>,
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.
15 #include "libqos/fw_cfg.h"
18 #define NO_QEMU_PROTOS
19 #include "hw/nvram/fw_cfg.h"
24 uint64_t expected_boot
;
25 uint64_t expected_reboot
;
28 static void test_a_boot_order(const char *machine
,
29 const char *test_args
,
30 uint64_t (*read_boot_order
)(void),
31 uint64_t expected_boot
,
32 uint64_t expected_reboot
)
37 args
= g_strdup_printf("-nodefaults -display none%s%s %s",
38 machine
? " -M " : "",
42 actual
= read_boot_order();
43 g_assert_cmphex(actual
, ==, expected_boot
);
44 qmp("{ 'execute': 'system_reset' }");
46 * system_reset only requests reset. We get a RESET event after
47 * the actual reset completes. Need to wait for that.
49 qmp(""); /* HACK: wait for event */
50 actual
= read_boot_order();
51 g_assert_cmphex(actual
, ==, expected_reboot
);
52 qtest_quit(global_qtest
);
56 static void test_boot_orders(const char *machine
,
57 uint64_t (*read_boot_order
)(void),
58 const boot_order_test
*tests
)
62 for (i
= 0; tests
[i
].args
; i
++) {
63 test_a_boot_order(machine
, tests
[i
].args
,
65 tests
[i
].expected_boot
,
66 tests
[i
].expected_reboot
);
70 static uint8_t read_mc146818(uint16_t port
, uint8_t reg
)
76 static uint64_t read_boot_order_pc(void)
78 uint8_t b1
= read_mc146818(0x70, 0x38);
79 uint8_t b2
= read_mc146818(0x70, 0x3d);
81 return b1
| (b2
<< 8);
84 static const boot_order_test test_cases_pc
[] = {
95 { "-boot order= -boot order=c",
99 { "-boot once=a -no-fd-bootchk",
101 { "-boot once=a,order=c",
103 { "-boot once=d -boot order=nda",
105 { "-boot once=a -boot once=b -boot once=c",
110 static void test_pc_boot_order(void)
112 test_boot_orders(NULL
, read_boot_order_pc
, test_cases_pc
);
115 static uint8_t read_m48t59(uint64_t addr
, uint16_t reg
)
117 writeb(addr
, reg
& 0xff);
118 writeb(addr
+ 1, reg
>> 8);
119 return readb(addr
+ 3);
122 static uint64_t read_boot_order_prep(void)
124 return read_m48t59(0x80000000 + 0x74, 0x34);
127 static const boot_order_test test_cases_prep
[] = {
129 { "-boot c", 'c', 'c' },
130 { "-boot d", 'd', 'd' },
134 static void test_prep_boot_order(void)
136 test_boot_orders("prep", read_boot_order_prep
, test_cases_prep
);
139 static uint64_t read_boot_order_pmac(void)
141 QFWCFG
*fw_cfg
= mm_fw_cfg_init(0xf0000510);
143 return qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_DEVICE
);
146 static const boot_order_test test_cases_fw_cfg
[] = {
148 { "-boot c", 'c', 'c' },
149 { "-boot d", 'd', 'd' },
150 { "-boot once=d,order=c", 'd', 'c' },
154 static void test_pmac_oldworld_boot_order(void)
156 test_boot_orders("g3beige", read_boot_order_pmac
, test_cases_fw_cfg
);
159 static void test_pmac_newworld_boot_order(void)
161 test_boot_orders("mac99", read_boot_order_pmac
, test_cases_fw_cfg
);
164 static uint64_t read_boot_order_sun4m(void)
166 QFWCFG
*fw_cfg
= mm_fw_cfg_init(0xd00000510ULL
);
168 return qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_DEVICE
);
171 static void test_sun4m_boot_order(void)
173 test_boot_orders("SS-5", read_boot_order_sun4m
, test_cases_fw_cfg
);
176 static uint64_t read_boot_order_sun4u(void)
178 QFWCFG
*fw_cfg
= io_fw_cfg_init(0x510);
180 return qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_DEVICE
);
183 static void test_sun4u_boot_order(void)
185 test_boot_orders("sun4u", read_boot_order_sun4u
, test_cases_fw_cfg
);
188 int main(int argc
, char *argv
[])
190 const char *arch
= qtest_get_arch();
192 g_test_init(&argc
, &argv
, NULL
);
194 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
195 qtest_add_func("boot-order/pc", test_pc_boot_order
);
196 } else if (strcmp(arch
, "ppc") == 0 || strcmp(arch
, "ppc64") == 0) {
197 qtest_add_func("boot-order/prep", test_prep_boot_order
);
198 qtest_add_func("boot-order/pmac_oldworld",
199 test_pmac_oldworld_boot_order
);
200 qtest_add_func("boot-order/pmac_newworld",
201 test_pmac_newworld_boot_order
);
202 } else if (strcmp(arch
, "sparc") == 0) {
203 qtest_add_func("boot-order/sun4m", test_sun4m_boot_order
);
204 } else if (strcmp(arch
, "sparc64") == 0) {
205 qtest_add_func("boot-order/sun4u", test_sun4u_boot_order
);