@samitouri / QOSamiQemu / commits / f670b177af

tests/qtest/numa-test: replace HMP "info numa" with QMP query-cpus-fast

Convert the three test functions that relied on HMP "info numa" to use QMP "query-cpus-fast" instead, verifying each CPU's node-id through the structured response. Add a check_cpu_node() helper for the per-CPU assertions. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-14-9227de146347@redhat.com>

Marc-André Lureau committed Aug 28, 2026 at 16:04 UTC f670b177af5aaa2a86589c9ec652f7acfe4e2334
1 file changed +51 -12
tests/qtest/numa-test.c
+51 -12
@@ -19,19 +19,50 @@ static char *make_cli(const GString *generic_cli, const char *test_cli)
19 return g_strdup_printf("%s %s", generic_cli->str, test_cli);
20 }
21
22 +static void check_cpu_node(QTestState *qts, int cpu_idx, int expected_node)
23 +{
24 + QDict *resp;
25 + QList *cpus;
26 + QListEntry *e;
27 + bool found = false;
28 +
29 + resp = qtest_qmp(qts, "{ 'execute': 'query-cpus-fast' }");
30 + g_assert(resp);
31 + g_assert(qdict_haskey(resp, "return"));
32 + cpus = qdict_get_qlist(resp, "return");
33 + g_assert(cpus);
34 +
35 + QLIST_FOREACH_ENTRY(cpus, e) {
36 + QDict *cpu = qobject_to(QDict, qlist_entry_obj(e));
37 + int64_t idx = qdict_get_int(cpu, "cpu-index");
38 + if (idx == cpu_idx) {
39 + QDict *props = qdict_get_qdict(cpu, "props");
40 + g_assert(qdict_haskey(props, "node-id"));
41 + g_assert_cmpint(qdict_get_int(props, "node-id"), ==, expected_node);
42 + found = true;
43 + break;
44 + }
45 + }
46 + g_assert(found);
47 + qobject_unref(resp);
48 +}
49 +
50 static void test_mon_explicit(const void *data)
51 {
52 QTestState *qts;
25 - g_autofree char *s = NULL;
53 g_autofree char *cli = NULL;
54 + int i;
55
56 cli = make_cli(data, "-machine smp.cpus=8 -numa node,nodeid=0,memdev=ram,cpus=0-3 "
57 "-numa node,nodeid=1,cpus=4-7");
58 qts = qtest_init(cli);
59
32 - s = qtest_hmp(qts, "info numa");
33 - g_assert(strstr(s, "node 0 cpus: 0 1 2 3"));
34 - g_assert(strstr(s, "node 1 cpus: 4 5 6 7"));
60 + for (i = 0; i < 4; i++) {
61 + check_cpu_node(qts, i, 0);
62 + }
63 + for (i = 4; i < 8; i++) {
64 + check_cpu_node(qts, i, 1);
65 + }
66
67 qtest_quit(qts);
68 }
@@ -39,16 +70,19 @@ static void test_mon_explicit(const void *data)
70 static void test_def_cpu_split(const void *data)
71 {
72 QTestState *qts;
42 - g_autofree char *s = NULL;
73 g_autofree char *cli = NULL;
74 + int even_cpus[] = {0, 2, 4, 6};
75 + int odd_cpus[] = {1, 3, 5, 7};
76 + int i;
77
78 cli = make_cli(data, "-machine smp.cpus=8,smp.sockets=8 "
79 "-numa node,memdev=ram -numa node");
80 qts = qtest_init(cli);
81
49 - s = qtest_hmp(qts, "info numa");
50 - g_assert(strstr(s, "node 0 cpus: 0 2 4 6"));
51 - g_assert(strstr(s, "node 1 cpus: 1 3 5 7"));
82 + for (i = 0; i < 4; i++) {
83 + check_cpu_node(qts, even_cpus[i], 0);
84 + check_cpu_node(qts, odd_cpus[i], 1);
85 + }
86
87 qtest_quit(qts);
88 }
@@ -56,17 +90,22 @@ static void test_def_cpu_split(const void *data)
90 static void test_mon_partial(const void *data)
91 {
92 QTestState *qts;
59 - g_autofree char *s = NULL;
93 g_autofree char *cli = NULL;
94 + int node0_cpus[] = {0, 1, 2, 3, 6, 7};
95 + int node1_cpus[] = {4, 5};
96 + int i;
97
98 cli = make_cli(data, "-machine smp.cpus=8 "
99 "-numa node,nodeid=0,memdev=ram,cpus=0-1 "
100 "-numa node,nodeid=1,cpus=4-5 ");
101 qts = qtest_init(cli);
102
67 - s = qtest_hmp(qts, "info numa");
68 - g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7"));
69 - g_assert(strstr(s, "node 1 cpus: 4 5"));
103 + for (i = 0; i < 6; i++) {
104 + check_cpu_node(qts, node0_cpus[i], 0);
105 + }
106 + for (i = 0; i < 2; i++) {
107 + check_cpu_node(qts, node1_cpus[i], 1);
108 + }
109
110 qtest_quit(qts);
111 }