@samitouri / QOSamiQemu / commits / c31b39063f

tests/qtest: cover sp-mem SOFT_RESERVED e820 entry

Boot one sp-mem device and assert the guest's e820 table gains exactly one E820_SOFT_RESERVED range whose length matches the device's backend size. Signed-off-by: FangSheng Huang <FangSheng.Huang@amd.com> Acked-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-ID: <20260623075051.3797975-11-FangSheng.Huang@amd.com>

fanhuang committed Jun 23, 2026 at 15:50 UTC c31b39063fe9af23ba78dd15155f73ef8f51e8ac
1 file changed +34
tests/qtest/e820-test.c
+34
@@ -16,6 +16,7 @@
16 #include "libqtest.h"
17 #include "libqos/fw_cfg.h"
18 #include "qemu/bswap.h"
19 +#include "qemu/units.h"
20
21 /* e820 entry layout and types (cf. hw/i386/e820_memory_layout.h) */
22 #define E820_RAM 1
@@ -85,11 +86,44 @@ static void test_e820_basic(void)
86 qtest_quit(s);
87 }
88
89 +static void test_e820_sp_mem(void)
90 +{
91 + struct e820_entry table[E820_MAX_ENTRIES];
92 + QFWCFG *fw_cfg;
93 + QTestState *s;
94 + size_t n, i;
95 + int soft_reserved = 0;
96 + uint64_t soft_reserved_len = 0;
97 +
98 + s = qtest_init("-machine q35 -m 256M,slots=2,maxmem=2G "
99 + "-object memory-backend-ram,id=ram0,size=256M "
100 + "-numa node,nodeid=0,memdev=ram0 "
101 + "-object memory-backend-ram,id=spm0,size=128M "
102 + "-device sp-mem,id=sp0,memdev=spm0,node=0");
103 + fw_cfg = pc_fw_cfg_init(s);
104 +
105 + n = get_e820_table(fw_cfg, table);
106 + for (i = 0; i < n; i++) {
107 + if (le32_to_cpu(table[i].type) == E820_SOFT_RESERVED) {
108 + soft_reserved++;
109 + soft_reserved_len = le64_to_cpu(table[i].length);
110 + }
111 + }
112 +
113 + /* exactly one SOFT_RESERVED range, sized to the backend */
114 + g_assert_cmpint(soft_reserved, ==, 1);
115 + g_assert_cmpint(soft_reserved_len, ==, 128 * MiB);
116 +
117 + pc_fw_cfg_uninit(fw_cfg);
118 + qtest_quit(s);
119 +}
120 +
121 int main(int argc, char **argv)
122 {
123 g_test_init(&argc, &argv, NULL);
124
125 qtest_add_func("e820/basic", test_e820_basic);
126 + qtest_add_func("e820/sp-mem", test_e820_sp_mem);
127
128 return g_test_run();
129 }