net: make iov_to_buf take right size argument in nc_sendv_compat()
[qemu/ar7.git] / tests / boot-order-test.c
blob360a6911ebfe8573cdfef54a8ab76adbdb8d3e9b
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 <string.h>
14 #include <glib.h>
15 #include "libqos/fw_cfg.h"
16 #include "libqtest.h"
18 #define NO_QEMU_PROTOS
19 #include "hw/nvram/fw_cfg.h"
20 #undef NO_QEMU_PROTOS
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 char *args;
35 uint64_t actual;
37 args = g_strdup_printf("-nodefaults%s%s %s",
38 machine ? " -M " : "",
39 machine ?: "",
40 test_args);
41 qtest_start(args);
42 actual = read_boot_order();
43 g_assert_cmphex(actual, ==, expected_boot);
44 qmp_discard_response("{ '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_discard_response(""); /* HACK: wait for event */
50 actual = read_boot_order();
51 g_assert_cmphex(actual, ==, expected_reboot);
52 qtest_quit(global_qtest);
53 g_free(args);
56 static void test_boot_orders(const char *machine,
57 uint64_t (*read_boot_order)(void),
58 const boot_order_test *tests)
60 int i;
62 for (i = 0; tests[i].args; i++) {
63 test_a_boot_order(machine, tests[i].args,
64 read_boot_order,
65 tests[i].expected_boot,
66 tests[i].expected_reboot);
70 static uint8_t read_mc146818(uint16_t port, uint8_t reg)
72 outb(port, reg);
73 return inb(port + 1);
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[] = {
85 { "",
86 0x1230, 0x1230 },
87 { "-no-fd-bootchk",
88 0x1231, 0x1231 },
89 { "-boot c",
90 0x0200, 0x0200 },
91 { "-boot nda",
92 0x3410, 0x3410 },
93 { "-boot order=",
94 0, 0 },
95 { "-boot order= -boot order=c",
96 0x0200, 0x0200 },
97 { "-boot once=a",
98 0x0100, 0x1230 },
99 { "-boot once=a -no-fd-bootchk",
100 0x0101, 0x1231 },
101 { "-boot once=a,order=c",
102 0x0100, 0x0200 },
103 { "-boot once=d -boot order=nda",
104 0x0300, 0x3410 },
105 { "-boot once=a -boot once=b -boot once=c",
106 0x0200, 0x1230 },
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[] = {
128 { "", 'c', 'c' },
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[] = {
147 { "", 'c', 'c' },
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);
208 return g_test_run();