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"
17 #define NO_QEMU_PROTOS
18 #include "hw/nvram/fw_cfg.h"
19 #include "libqos/fw_cfg.h"
21 static uint64_t ram_size
= 128 << 20;
22 static uint16_t nb_cpus
= 1;
23 static uint16_t max_cpus
= 1;
24 static uint64_t nb_nodes
= 0;
25 static uint16_t boot_menu
= 0;
26 static QFWCFG
*fw_cfg
= NULL
;
28 static void test_fw_cfg_signature(void)
32 qfw_cfg_get(fw_cfg
, FW_CFG_SIGNATURE
, buf
, 4);
35 g_assert_cmpstr(buf
, ==, "QEMU");
38 static void test_fw_cfg_id(void)
40 uint32_t id
= qfw_cfg_get_u32(fw_cfg
, FW_CFG_ID
);
45 static void test_fw_cfg_uuid(void)
48 static const uint8_t uuid
[16] = {
49 0x46, 0x00, 0xcb, 0x32, 0x38, 0xec, 0x4b, 0x2f,
50 0x8a, 0xcb, 0x81, 0xc6, 0xea, 0x54, 0xf2, 0xd8,
53 qfw_cfg_get(fw_cfg
, FW_CFG_UUID
, buf
, 16);
54 g_assert(memcmp(buf
, uuid
, sizeof(buf
)) == 0);
57 static void test_fw_cfg_ram_size(void)
59 g_assert_cmpint(qfw_cfg_get_u64(fw_cfg
, FW_CFG_RAM_SIZE
), ==, ram_size
);
62 static void test_fw_cfg_nographic(void)
64 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_NOGRAPHIC
), ==, 0);
67 static void test_fw_cfg_nb_cpus(void)
69 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_NB_CPUS
), ==, nb_cpus
);
72 static void test_fw_cfg_max_cpus(void)
74 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_MAX_CPUS
), ==, max_cpus
);
77 static void test_fw_cfg_numa(void)
82 g_assert_cmpint(qfw_cfg_get_u64(fw_cfg
, FW_CFG_NUMA
), ==, nb_nodes
);
84 cpu_mask
= g_malloc0(sizeof(uint64_t) * max_cpus
);
85 node_mask
= g_malloc0(sizeof(uint64_t) * nb_nodes
);
87 qfw_cfg_read_data(fw_cfg
, cpu_mask
, sizeof(uint64_t) * max_cpus
);
88 qfw_cfg_read_data(fw_cfg
, node_mask
, sizeof(uint64_t) * nb_nodes
);
91 g_assert(cpu_mask
[0] & 0x01);
92 g_assert_cmpint(node_mask
[0], ==, ram_size
);
99 static void test_fw_cfg_boot_menu(void)
101 g_assert_cmpint(qfw_cfg_get_u16(fw_cfg
, FW_CFG_BOOT_MENU
), ==, boot_menu
);
104 int main(int argc
, char **argv
)
110 g_test_init(&argc
, &argv
, NULL
);
112 fw_cfg
= pc_fw_cfg_init();
114 qtest_add_func("fw_cfg/signature", test_fw_cfg_signature
);
115 qtest_add_func("fw_cfg/id", test_fw_cfg_id
);
116 qtest_add_func("fw_cfg/uuid", test_fw_cfg_uuid
);
117 qtest_add_func("fw_cfg/ram_size", test_fw_cfg_ram_size
);
118 qtest_add_func("fw_cfg/nographic", test_fw_cfg_nographic
);
119 qtest_add_func("fw_cfg/nb_cpus", test_fw_cfg_nb_cpus
);
121 qtest_add_func("fw_cfg/machine_id", test_fw_cfg_machine_id
);
122 qtest_add_func("fw_cfg/kernel", test_fw_cfg_kernel
);
123 qtest_add_func("fw_cfg/initrd", test_fw_cfg_initrd
);
124 qtest_add_func("fw_cfg/boot_device", test_fw_cfg_boot_device
);
126 qtest_add_func("fw_cfg/max_cpus", test_fw_cfg_max_cpus
);
127 qtest_add_func("fw_cfg/numa", test_fw_cfg_numa
);
128 qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu
);
130 cmdline
= g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
131 s
= qtest_start(cmdline
);