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