MAINTAINERS: Fix F: patterns that don't match anything
[qemu/ar7.git] / tests / boot-order-test.c
blobc60ebcf9d97a4833a45adaac3bbfc6a3988cd340
1 /*
2 * Boot order test cases.
4 * Copyright (c) 2013 Red Hat Inc.
6 * Authors:
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"
15 #include "libqtest.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(...) qobject_unref(qmp(__VA_ARGS__))
22 typedef struct {
23 const char *args;
24 uint64_t expected_boot;
25 uint64_t expected_reboot;
26 } boot_order_test;
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)
34 uint64_t actual;
36 global_qtest = qtest_initf("-nodefaults%s%s %s",
37 machine ? " -M " : "",
38 machine ?: "",
39 test_args);
40 actual = read_boot_order();
41 g_assert_cmphex(actual, ==, expected_boot);
42 qmp_discard_response("{ 'execute': 'system_reset' }");
44 * system_reset only requests reset. We get a RESET event after
45 * the actual reset completes. Need to wait for that.
47 qmp_eventwait("RESET");
48 actual = read_boot_order();
49 g_assert_cmphex(actual, ==, expected_reboot);
50 qtest_quit(global_qtest);
53 static void test_boot_orders(const char *machine,
54 uint64_t (*read_boot_order)(void),
55 const boot_order_test *tests)
57 int i;
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);
67 static uint8_t read_mc146818(uint16_t port, uint8_t reg)
69 outb(port, reg);
70 return inb(port + 1);
73 static uint64_t read_boot_order_pc(void)
75 uint8_t b1 = read_mc146818(0x70, 0x38);
76 uint8_t b2 = read_mc146818(0x70, 0x3d);
78 return b1 | (b2 << 8);
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 },
107 static void test_pc_boot_order(void)
109 test_boot_orders(NULL, read_boot_order_pc, test_cases_pc);
112 static uint8_t read_m48t59(uint64_t addr, uint16_t reg)
114 writeb(addr, reg & 0xff);
115 writeb(addr + 1, reg >> 8);
116 return readb(addr + 3);
119 static uint64_t read_boot_order_prep(void)
121 return read_m48t59(0x80000000 + 0x74, 0x34);
124 static const boot_order_test test_cases_prep[] = {
125 { "", 'c', 'c' },
126 { "-boot c", 'c', 'c' },
127 { "-boot d", 'd', 'd' },
131 static void test_prep_boot_order(void)
133 test_boot_orders("prep", read_boot_order_prep, test_cases_prep);
136 static uint64_t read_boot_order_pmac(void)
138 QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xf0000510);
140 return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
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' },
151 static void test_pmac_oldworld_boot_order(void)
153 test_boot_orders("g3beige", read_boot_order_pmac, test_cases_fw_cfg);
156 static void test_pmac_newworld_boot_order(void)
158 test_boot_orders("mac99", read_boot_order_pmac, test_cases_fw_cfg);
161 static uint64_t read_boot_order_sun4m(void)
163 QFWCFG *fw_cfg = mm_fw_cfg_init(global_qtest, 0xd00000510ULL);
165 return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
168 static void test_sun4m_boot_order(void)
170 test_boot_orders("SS-5", read_boot_order_sun4m, test_cases_fw_cfg);
173 static uint64_t read_boot_order_sun4u(void)
175 QFWCFG *fw_cfg = io_fw_cfg_init(global_qtest, 0x510);
177 return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
180 static void test_sun4u_boot_order(void)
182 test_boot_orders("sun4u", read_boot_order_sun4u, test_cases_fw_cfg);
185 int main(int argc, char *argv[])
187 const char *arch = qtest_get_arch();
189 g_test_init(&argc, &argv, NULL);
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);
205 return g_test_run();