2 * qtest fw_cfg test case
4 * Copyright IBM, Corp. 2012-2013
7 * Anthony Liguori <aliguori@us.ibm.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"
16 #include "standard-headers/linux/qemu_fw_cfg.h"
17 #include "libqos/fw_cfg.h"
18 #include "qemu/bswap.h"
20 static uint64_t ram_size
= 128 << 20;
21 static uint16_t nb_cpus
= 1;
22 static uint16_t max_cpus
= 1;
23 static uint64_t nb_nodes
= 0;
24 static uint16_t boot_menu
= 0;
26 static void test_fw_cfg_signature(void)
33 fw_cfg
= pc_fw_cfg_init(s
);
35 qfw_cfg_get(fw_cfg
, FW_CFG_SIGNATURE
, buf
, 4);
38 g_assert_cmpstr(buf
, ==, "QEMU");
39 pc_fw_cfg_uninit(fw_cfg
);
43 static void test_fw_cfg_id(void)
50 fw_cfg
= pc_fw_cfg_init(s
);
52 id
= qfw_cfg_get_u32(fw_cfg
, FW_CFG_ID
);
55 pc_fw_cfg_uninit(fw_cfg
);
59 static void test_fw_cfg_uuid(void)
65 static const uint8_t uuid
[16] = {
66 0x46, 0x00, 0xcb, 0x32, 0x38, 0xec, 0x4b, 0x2f,
67 0x8a, 0xcb, 0x81, 0xc6, 0xea, 0x54, 0xf2, 0xd8,
70 s
= qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
71 fw_cfg
= pc_fw_cfg_init(s
);
73 qfw_cfg_get(fw_cfg
, FW_CFG_UUID
, buf
, 16);
74 g_assert(memcmp(buf
, uuid
, sizeof(buf
)) == 0);
76 pc_fw_cfg_uninit(fw_cfg
);
81 static void test_fw_cfg_ram_size(void)
87 fw_cfg
= pc_fw_cfg_init(s
);
89 g_assert_cmpint(qfw_cfg_get_u64(fw_cfg
, FW_CFG_RAM_SIZE
), ==, ram_size
);
91 pc_fw_cfg_uninit(fw_cfg
);
95 static void test_fw_cfg_nographic(void)
101 fw_cfg
= pc_fw_cfg_init(s
);
103 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_NOGRAPHIC
), ==, 0);
105 pc_fw_cfg_uninit(fw_cfg
);
109 static void test_fw_cfg_nb_cpus(void)
115 fw_cfg
= pc_fw_cfg_init(s
);
117 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_NB_CPUS
), ==, nb_cpus
);
119 pc_fw_cfg_uninit(fw_cfg
);
123 static void test_fw_cfg_max_cpus(void)
129 fw_cfg
= pc_fw_cfg_init(s
);
131 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_MAX_CPUS
), ==, max_cpus
);
132 pc_fw_cfg_uninit(fw_cfg
);
136 static void test_fw_cfg_numa(void)
144 fw_cfg
= pc_fw_cfg_init(s
);
146 g_assert_cmpint(qfw_cfg_get_u64(fw_cfg
, FW_CFG_NUMA
), ==, nb_nodes
);
148 cpu_mask
= g_new0(uint64_t, max_cpus
);
149 node_mask
= g_new0(uint64_t, nb_nodes
);
151 qfw_cfg_read_data(fw_cfg
, cpu_mask
, sizeof(uint64_t) * max_cpus
);
152 qfw_cfg_read_data(fw_cfg
, node_mask
, sizeof(uint64_t) * nb_nodes
);
155 g_assert(cpu_mask
[0] & 0x01);
156 g_assert_cmpint(node_mask
[0], ==, ram_size
);
161 pc_fw_cfg_uninit(fw_cfg
);
165 static void test_fw_cfg_boot_menu(void)
171 fw_cfg
= pc_fw_cfg_init(s
);
173 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_MENU
), ==, boot_menu
);
174 pc_fw_cfg_uninit(fw_cfg
);
178 static void test_fw_cfg_reboot_timeout(void)
182 uint32_t reboot_timeout
= 0;
185 s
= qtest_init("-boot reboot-timeout=15");
186 fw_cfg
= pc_fw_cfg_init(s
);
188 filesize
= qfw_cfg_get_file(fw_cfg
, "etc/boot-fail-wait",
189 &reboot_timeout
, sizeof(reboot_timeout
));
190 g_assert_cmpint(filesize
, ==, sizeof(reboot_timeout
));
191 reboot_timeout
= le32_to_cpu(reboot_timeout
);
192 g_assert_cmpint(reboot_timeout
, ==, 15);
193 pc_fw_cfg_uninit(fw_cfg
);
197 static void test_fw_cfg_splash_time(void)
201 uint16_t splash_time
= 0;
204 s
= qtest_init("-boot splash-time=12");
205 fw_cfg
= pc_fw_cfg_init(s
);
207 filesize
= qfw_cfg_get_file(fw_cfg
, "etc/boot-menu-wait",
208 &splash_time
, sizeof(splash_time
));
209 g_assert_cmpint(filesize
, ==, sizeof(splash_time
));
210 splash_time
= le16_to_cpu(splash_time
);
211 g_assert_cmpint(splash_time
, ==, 12);
212 pc_fw_cfg_uninit(fw_cfg
);
216 int main(int argc
, char **argv
)
218 g_test_init(&argc
, &argv
, NULL
);
220 qtest_add_func("fw_cfg/signature", test_fw_cfg_signature
);
221 qtest_add_func("fw_cfg/id", test_fw_cfg_id
);
222 qtest_add_func("fw_cfg/uuid", test_fw_cfg_uuid
);
223 qtest_add_func("fw_cfg/ram_size", test_fw_cfg_ram_size
);
224 qtest_add_func("fw_cfg/nographic", test_fw_cfg_nographic
);
225 qtest_add_func("fw_cfg/nb_cpus", test_fw_cfg_nb_cpus
);
227 qtest_add_func("fw_cfg/machine_id", test_fw_cfg_machine_id
);
228 qtest_add_func("fw_cfg/kernel", test_fw_cfg_kernel
);
229 qtest_add_func("fw_cfg/initrd", test_fw_cfg_initrd
);
230 qtest_add_func("fw_cfg/boot_device", test_fw_cfg_boot_device
);
232 qtest_add_func("fw_cfg/max_cpus", test_fw_cfg_max_cpus
);
233 qtest_add_func("fw_cfg/numa", test_fw_cfg_numa
);
234 qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu
);
235 qtest_add_func("fw_cfg/reboot_timeout", test_fw_cfg_reboot_timeout
);
236 qtest_add_func("fw_cfg/splash_time", test_fw_cfg_splash_time
);