]>
Commit | Line | Data |
---|---|---|
bf2a38d4 AL |
1 | /* |
2 | * qtest fw_cfg test case | |
3 | * | |
4 | * Copyright IBM, Corp. 2012-2013 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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 | ||
13 | #define NO_QEMU_PROTOS | |
14 | ||
15 | #include "libqtest.h" | |
16 | #include "hw/nvram/fw_cfg.h" | |
26491a38 | 17 | #include "libqos/fw_cfg.h" |
bf2a38d4 AL |
18 | |
19 | #include <string.h> | |
20 | #include <glib.h> | |
21 | ||
22 | static uint64_t ram_size = 128 << 20; | |
23 | static uint16_t nb_cpus = 1; | |
24 | static uint16_t max_cpus = 1; | |
25 | static uint64_t nb_nodes = 0; | |
26 | static uint16_t boot_menu = 0; | |
27 | static QFWCFG *fw_cfg = NULL; | |
28 | ||
29 | static void test_fw_cfg_signature(void) | |
30 | { | |
31 | char buf[5]; | |
32 | ||
33 | qfw_cfg_get(fw_cfg, FW_CFG_SIGNATURE, buf, 4); | |
34 | buf[4] = 0; | |
35 | ||
36 | g_assert_cmpstr(buf, ==, "QEMU"); | |
37 | } | |
38 | ||
39 | static void test_fw_cfg_id(void) | |
40 | { | |
41 | g_assert_cmpint(qfw_cfg_get_u32(fw_cfg, FW_CFG_ID), ==, 1); | |
42 | } | |
43 | ||
44 | static void test_fw_cfg_uuid(void) | |
45 | { | |
46 | uint8_t buf[16]; | |
47 | static const uint8_t uuid[16] = { | |
48 | 0x46, 0x00, 0xcb, 0x32, 0x38, 0xec, 0x4b, 0x2f, | |
49 | 0x8a, 0xcb, 0x81, 0xc6, 0xea, 0x54, 0xf2, 0xd8, | |
50 | }; | |
51 | ||
52 | qfw_cfg_get(fw_cfg, FW_CFG_UUID, buf, 16); | |
53 | g_assert(memcmp(buf, uuid, sizeof(buf)) == 0); | |
54 | } | |
55 | ||
56 | static void test_fw_cfg_ram_size(void) | |
57 | { | |
58 | g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE), ==, ram_size); | |
59 | } | |
60 | ||
61 | static void test_fw_cfg_nographic(void) | |
62 | { | |
63 | g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NOGRAPHIC), ==, 0); | |
64 | } | |
65 | ||
66 | static void test_fw_cfg_nb_cpus(void) | |
67 | { | |
68 | g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NB_CPUS), ==, nb_cpus); | |
69 | } | |
70 | ||
71 | static void test_fw_cfg_max_cpus(void) | |
72 | { | |
73 | g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_MAX_CPUS), ==, max_cpus); | |
74 | } | |
75 | ||
76 | static void test_fw_cfg_numa(void) | |
77 | { | |
78 | uint64_t *cpu_mask; | |
79 | uint64_t *node_mask; | |
80 | ||
81 | g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes); | |
82 | ||
83 | cpu_mask = g_malloc0(sizeof(uint64_t) * max_cpus); | |
84 | node_mask = g_malloc0(sizeof(uint64_t) * nb_nodes); | |
85 | ||
86 | qfw_cfg_read_data(fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus); | |
87 | qfw_cfg_read_data(fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes); | |
88 | ||
89 | if (nb_nodes) { | |
90 | g_assert(cpu_mask[0] & 0x01); | |
91 | g_assert_cmpint(node_mask[0], ==, ram_size); | |
92 | } | |
93 | ||
94 | g_free(node_mask); | |
95 | g_free(cpu_mask); | |
96 | } | |
97 | ||
98 | static void test_fw_cfg_boot_menu(void) | |
99 | { | |
100 | g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==, boot_menu); | |
101 | } | |
102 | ||
103 | int main(int argc, char **argv) | |
104 | { | |
105 | QTestState *s; | |
106 | char *cmdline; | |
107 | int ret; | |
108 | ||
109 | g_test_init(&argc, &argv, NULL); | |
110 | ||
111 | fw_cfg = pc_fw_cfg_init(); | |
112 | ||
113 | g_test_add_func("/fw_cfg/signature", test_fw_cfg_signature); | |
114 | g_test_add_func("/fw_cfg/id", test_fw_cfg_id); | |
115 | g_test_add_func("/fw_cfg/uuid", test_fw_cfg_uuid); | |
116 | g_test_add_func("/fw_cfg/ram_size", test_fw_cfg_ram_size); | |
117 | g_test_add_func("/fw_cfg/nographic", test_fw_cfg_nographic); | |
118 | g_test_add_func("/fw_cfg/nb_cpus", test_fw_cfg_nb_cpus); | |
119 | #if 0 | |
120 | g_test_add_func("/fw_cfg/machine_id", test_fw_cfg_machine_id); | |
121 | g_test_add_func("/fw_cfg/kernel", test_fw_cfg_kernel); | |
122 | g_test_add_func("/fw_cfg/initrd", test_fw_cfg_initrd); | |
123 | g_test_add_func("/fw_cfg/boot_device", test_fw_cfg_boot_device); | |
124 | #endif | |
125 | g_test_add_func("/fw_cfg/max_cpus", test_fw_cfg_max_cpus); | |
126 | g_test_add_func("/fw_cfg/numa", test_fw_cfg_numa); | |
127 | g_test_add_func("/fw_cfg/boot_menu", test_fw_cfg_boot_menu); | |
128 | ||
2ad645d2 | 129 | cmdline = g_strdup_printf("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 "); |
bf2a38d4 AL |
130 | s = qtest_start(cmdline); |
131 | g_free(cmdline); | |
132 | ||
133 | ret = g_test_run(); | |
134 | ||
135 | if (s) { | |
136 | qtest_quit(s); | |
137 | } | |
138 | ||
139 | return ret; | |
140 | } |