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