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.
13 #include "qemu/osdep.h"
14 #include "libqos/fw_cfg.h"
16 #include "qapi/qmp/qdict.h"
17 #include "standard-headers/linux/qemu_fw_cfg.h"
19 /* TODO actually test the results and get rid of this */
20 #define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))
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
)(QTestState
*),
31 uint64_t expected_boot
,
32 uint64_t expected_reboot
)
37 qts
= qtest_initf("-nodefaults%s%s %s", machine
? " -M " : "",
38 machine
?: "", test_args
);
39 actual
= read_boot_order(qts
);
40 g_assert_cmphex(actual
, ==, expected_boot
);
41 qmp_discard_response(qts
, "{ 'execute': 'system_reset' }");
43 * system_reset only requests reset. We get a RESET event after
44 * the actual reset completes. Need to wait for that.
46 qtest_qmp_eventwait(qts
, "RESET");
47 actual
= read_boot_order(qts
);
48 g_assert_cmphex(actual
, ==, expected_reboot
);
52 static void test_boot_orders(const char *machine
,
53 uint64_t (*read_boot_order
)(QTestState
*),
54 const boot_order_test
*tests
)
58 for (i
= 0; tests
[i
].args
; i
++) {
59 test_a_boot_order(machine
, tests
[i
].args
,
61 tests
[i
].expected_boot
,
62 tests
[i
].expected_reboot
);
66 static uint8_t read_mc146818(QTestState
*qts
, uint16_t port
, uint8_t reg
)
68 qtest_outb(qts
, port
, reg
);
69 return qtest_inb(qts
, port
+ 1);
72 static uint64_t read_boot_order_pc(QTestState
*qts
)
74 uint8_t b1
= read_mc146818(qts
, 0x70, 0x38);
75 uint8_t b2
= read_mc146818(qts
, 0x70, 0x3d);
77 return b1
| (b2
<< 8);
80 static const boot_order_test test_cases_pc
[] = {
91 { "-boot order= -boot order=c",
95 { "-boot once=a -no-fd-bootchk",
97 { "-boot once=a,order=c",
99 { "-boot once=d -boot order=nda",
101 { "-boot once=a -boot once=b -boot once=c",
106 static void test_pc_boot_order(void)
108 test_boot_orders(NULL
, read_boot_order_pc
, test_cases_pc
);
111 static uint8_t read_m48t59(QTestState
*qts
, uint64_t addr
, uint16_t reg
)
113 qtest_writeb(qts
, addr
, reg
& 0xff);
114 qtest_writeb(qts
, addr
+ 1, reg
>> 8);
115 return qtest_readb(qts
, addr
+ 3);
118 static uint64_t read_boot_order_prep(QTestState
*qts
)
120 return read_m48t59(qts
, 0x80000000 + 0x74, 0x34);
123 static const boot_order_test test_cases_prep
[] = {
125 { "-boot c", 'c', 'c' },
126 { "-boot d", 'd', 'd' },
130 static void test_prep_boot_order(void)
132 test_boot_orders("prep", read_boot_order_prep
, test_cases_prep
);
135 static uint64_t read_boot_order_pmac(QTestState
*qts
)
137 QFWCFG
*fw_cfg
= mm_fw_cfg_init(qts
, 0xf0000510);
139 return qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_DEVICE
);
142 static const boot_order_test test_cases_fw_cfg
[] = {
144 { "-boot c", 'c', 'c' },
145 { "-boot d", 'd', 'd' },
146 { "-boot once=d,order=c", 'd', 'c' },
150 static void test_pmac_oldworld_boot_order(void)
152 test_boot_orders("g3beige", read_boot_order_pmac
, test_cases_fw_cfg
);
155 static void test_pmac_newworld_boot_order(void)
157 test_boot_orders("mac99", read_boot_order_pmac
, test_cases_fw_cfg
);
160 static uint64_t read_boot_order_sun4m(QTestState
*qts
)
162 QFWCFG
*fw_cfg
= mm_fw_cfg_init(qts
, 0xd00000510ULL
);
164 return qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_DEVICE
);
167 static void test_sun4m_boot_order(void)
169 test_boot_orders("SS-5", read_boot_order_sun4m
, test_cases_fw_cfg
);
172 static uint64_t read_boot_order_sun4u(QTestState
*qts
)
174 QFWCFG
*fw_cfg
= io_fw_cfg_init(qts
, 0x510);
176 return qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_DEVICE
);
179 static void test_sun4u_boot_order(void)
181 test_boot_orders("sun4u", read_boot_order_sun4u
, test_cases_fw_cfg
);
184 int main(int argc
, char *argv
[])
186 const char *arch
= qtest_get_arch();
188 g_test_init(&argc
, &argv
, NULL
);
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) {
193 qtest_add_func("boot-order/prep", test_prep_boot_order
);
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
);
198 } else if (strcmp(arch
, "sparc") == 0) {
199 qtest_add_func("boot-order/sun4m", test_sun4m_boot_order
);
200 } else if (strcmp(arch
, "sparc64") == 0) {
201 qtest_add_func("boot-order/sun4u", test_sun4u_boot_order
);