]> Git Repo - qemu.git/blob - tests/numa-test.c
Merge remote-tracking branch 'kraxel/tags/pull-ui-20170512-1' into staging
[qemu.git] / tests / numa-test.c
1 /*
2  * NUMA configuration test cases
3  *
4  * Copyright (c) 2017 Red Hat Inc.
5  * Authors:
6  *  Igor Mammedov <[email protected]>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or later.
9  * See the COPYING file in the top-level directory.
10  */
11
12 #include "qemu/osdep.h"
13 #include "libqtest.h"
14
15 static char *make_cli(const char *generic_cli, const char *test_cli)
16 {
17     return g_strdup_printf("%s %s", generic_cli ? generic_cli : "", test_cli);
18 }
19
20 static char *hmp_info_numa(void)
21 {
22     QDict *resp;
23     char *s;
24
25     resp = qmp("{ 'execute': 'human-monitor-command', 'arguments': "
26                       "{ 'command-line': 'info numa '} }");
27     g_assert(resp);
28     g_assert(qdict_haskey(resp, "return"));
29     s = g_strdup(qdict_get_str(resp, "return"));
30     g_assert(s);
31     QDECREF(resp);
32     return s;
33 }
34
35 static void test_mon_explicit(const void *data)
36 {
37     char *s;
38     char *cli;
39
40     cli = make_cli(data, "-smp 8 "
41                    "-numa node,nodeid=0,cpus=0-3 "
42                    "-numa node,nodeid=1,cpus=4-7 ");
43     qtest_start(cli);
44
45     s = hmp_info_numa();
46     g_assert(strstr(s, "node 0 cpus: 0 1 2 3"));
47     g_assert(strstr(s, "node 1 cpus: 4 5 6 7"));
48     g_free(s);
49
50     qtest_end();
51     g_free(cli);
52 }
53
54 static void test_mon_default(const void *data)
55 {
56     char *s;
57     char *cli;
58
59     cli = make_cli(data, "-smp 8 -numa node -numa node");
60     qtest_start(cli);
61
62     s = hmp_info_numa();
63     g_assert(strstr(s, "node 0 cpus: 0 2 4 6"));
64     g_assert(strstr(s, "node 1 cpus: 1 3 5 7"));
65     g_free(s);
66
67     qtest_end();
68     g_free(cli);
69 }
70
71 static void test_mon_partial(const void *data)
72 {
73     char *s;
74     char *cli;
75
76     cli = make_cli(data, "-smp 8 "
77                    "-numa node,nodeid=0,cpus=0-1 "
78                    "-numa node,nodeid=1,cpus=4-5 ");
79     qtest_start(cli);
80
81     s = hmp_info_numa();
82     g_assert(strstr(s, "node 0 cpus: 0 1 2 3 6 7"));
83     g_assert(strstr(s, "node 1 cpus: 4 5"));
84     g_free(s);
85
86     qtest_end();
87     g_free(cli);
88 }
89
90 static QList *get_cpus(QDict **resp)
91 {
92     *resp = qmp("{ 'execute': 'query-cpus' }");
93     g_assert(*resp);
94     g_assert(qdict_haskey(*resp, "return"));
95     return  qdict_get_qlist(*resp, "return");
96 }
97
98 static void test_query_cpus(const void *data)
99 {
100     char *cli;
101     QDict *resp;
102     QList *cpus;
103     const QObject *e;
104
105     cli = make_cli(data, "-smp 8 -numa node,cpus=0-3 -numa node,cpus=4-7");
106     qtest_start(cli);
107     cpus = get_cpus(&resp);
108     g_assert(cpus);
109
110     while ((e = qlist_pop(cpus))) {
111         QDict *cpu, *props;
112         int64_t cpu_idx, node;
113
114         cpu = qobject_to_qdict(e);
115         g_assert(qdict_haskey(cpu, "CPU"));
116         g_assert(qdict_haskey(cpu, "props"));
117
118         cpu_idx = qdict_get_int(cpu, "CPU");
119         props = qdict_get_qdict(cpu, "props");
120         g_assert(qdict_haskey(props, "node-id"));
121         node = qdict_get_int(props, "node-id");
122         if (cpu_idx >= 0 && cpu_idx < 4) {
123             g_assert_cmpint(node, ==, 0);
124         } else {
125             g_assert_cmpint(node, ==, 1);
126         }
127     }
128
129     QDECREF(resp);
130     qtest_end();
131     g_free(cli);
132 }
133
134 static void pc_numa_cpu(const void *data)
135 {
136     char *cli;
137     QDict *resp;
138     QList *cpus;
139     const QObject *e;
140
141     cli = make_cli(data, "-cpu pentium -smp 8,sockets=2,cores=2,threads=2 "
142         "-numa node,nodeid=0 -numa node,nodeid=1 "
143         "-numa cpu,node-id=1,socket-id=0 "
144         "-numa cpu,node-id=0,socket-id=1,core-id=0 "
145         "-numa cpu,node-id=0,socket-id=1,core-id=1,thread-id=0 "
146         "-numa cpu,node-id=1,socket-id=1,core-id=1,thread-id=1");
147     qtest_start(cli);
148     cpus = get_cpus(&resp);
149     g_assert(cpus);
150
151     while ((e = qlist_pop(cpus))) {
152         QDict *cpu, *props;
153         int64_t socket, core, thread, node;
154
155         cpu = qobject_to_qdict(e);
156         g_assert(qdict_haskey(cpu, "props"));
157         props = qdict_get_qdict(cpu, "props");
158
159         g_assert(qdict_haskey(props, "node-id"));
160         node = qdict_get_int(props, "node-id");
161         g_assert(qdict_haskey(props, "socket-id"));
162         socket = qdict_get_int(props, "socket-id");
163         g_assert(qdict_haskey(props, "core-id"));
164         core = qdict_get_int(props, "core-id");
165         g_assert(qdict_haskey(props, "thread-id"));
166         thread = qdict_get_int(props, "thread-id");
167
168         if (socket == 0) {
169             g_assert_cmpint(node, ==, 1);
170         } else if (socket == 1 && core == 0) {
171             g_assert_cmpint(node, ==, 0);
172         } else if (socket == 1 && core == 1 && thread == 0) {
173             g_assert_cmpint(node, ==, 0);
174         } else if (socket == 1 && core == 1 && thread == 1) {
175             g_assert_cmpint(node, ==, 1);
176         } else {
177             g_assert(false);
178         }
179     }
180
181     QDECREF(resp);
182     qtest_end();
183     g_free(cli);
184 }
185
186 static void spapr_numa_cpu(const void *data)
187 {
188     char *cli;
189     QDict *resp;
190     QList *cpus;
191     const QObject *e;
192
193     cli = make_cli(data, "-smp 4,cores=4 "
194         "-numa node,nodeid=0 -numa node,nodeid=1 "
195         "-numa cpu,node-id=0,core-id=0 "
196         "-numa cpu,node-id=0,core-id=1 "
197         "-numa cpu,node-id=0,core-id=2 "
198         "-numa cpu,node-id=1,core-id=3");
199     qtest_start(cli);
200     cpus = get_cpus(&resp);
201     g_assert(cpus);
202
203     while ((e = qlist_pop(cpus))) {
204         QDict *cpu, *props;
205         int64_t core, node;
206
207         cpu = qobject_to_qdict(e);
208         g_assert(qdict_haskey(cpu, "props"));
209         props = qdict_get_qdict(cpu, "props");
210
211         g_assert(qdict_haskey(props, "node-id"));
212         node = qdict_get_int(props, "node-id");
213         g_assert(qdict_haskey(props, "core-id"));
214         core = qdict_get_int(props, "core-id");
215
216         if (core >= 0 && core < 3) {
217             g_assert_cmpint(node, ==, 0);
218         } else if (core == 3) {
219             g_assert_cmpint(node, ==, 1);
220         } else {
221             g_assert(false);
222         }
223     }
224
225     QDECREF(resp);
226     qtest_end();
227     g_free(cli);
228 }
229
230 static void aarch64_numa_cpu(const void *data)
231 {
232     char *cli;
233     QDict *resp;
234     QList *cpus;
235     const QObject *e;
236
237     cli = make_cli(data, "-smp 2 "
238         "-numa node,nodeid=0 -numa node,nodeid=1 "
239         "-numa cpu,node-id=1,thread-id=0 "
240         "-numa cpu,node-id=0,thread-id=1");
241     qtest_start(cli);
242     cpus = get_cpus(&resp);
243     g_assert(cpus);
244
245     while ((e = qlist_pop(cpus))) {
246         QDict *cpu, *props;
247         int64_t thread, node;
248
249         cpu = qobject_to_qdict(e);
250         g_assert(qdict_haskey(cpu, "props"));
251         props = qdict_get_qdict(cpu, "props");
252
253         g_assert(qdict_haskey(props, "node-id"));
254         node = qdict_get_int(props, "node-id");
255         g_assert(qdict_haskey(props, "thread-id"));
256         thread = qdict_get_int(props, "thread-id");
257
258         if (thread == 0) {
259             g_assert_cmpint(node, ==, 1);
260         } else if (thread == 1) {
261             g_assert_cmpint(node, ==, 0);
262         } else {
263             g_assert(false);
264         }
265     }
266
267     QDECREF(resp);
268     qtest_end();
269     g_free(cli);
270 }
271
272 int main(int argc, char **argv)
273 {
274     const char *args = NULL;
275     const char *arch = qtest_get_arch();
276
277     if (strcmp(arch, "aarch64") == 0) {
278         args = "-machine virt";
279     }
280
281     g_test_init(&argc, &argv, NULL);
282
283     qtest_add_data_func("/numa/mon/default", args, test_mon_default);
284     qtest_add_data_func("/numa/mon/cpus/explicit", args, test_mon_explicit);
285     qtest_add_data_func("/numa/mon/cpus/partial", args, test_mon_partial);
286     qtest_add_data_func("/numa/qmp/cpus/query-cpus", args, test_query_cpus);
287
288     if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) {
289         qtest_add_data_func("/numa/pc/cpu/explicit", args, pc_numa_cpu);
290     }
291
292     if (!strcmp(arch, "ppc64")) {
293         qtest_add_data_func("/numa/spapr/cpu/explicit", args, spapr_numa_cpu);
294     }
295
296     if (!strcmp(arch, "aarch64")) {
297         qtest_add_data_func("/numa/aarch64/cpu/explicit", args,
298                             aarch64_numa_cpu);
299     }
300
301     return g_test_run();
302 }
This page took 0.040588 seconds and 4 git commands to generate.