tests: add CPUs to numa node mapping test
[qemu/kevin.git] / tests / numa-test.c
blobf5da0c845b640fce014c03ab00a88f421b680119
1 /*
2 * NUMA configuration test cases
4 * Copyright (c) 2017 Red Hat Inc.
5 * Authors:
6 * Igor Mammedov <imammedo@redhat.com>
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.
12 #include "qemu/osdep.h"
13 #include "libqtest.h"
15 static char *make_cli(const char *generic_cli, const char *test_cli)
17 return g_strdup_printf("%s %s", generic_cli ? generic_cli : "", test_cli);
20 static char *hmp_info_numa(void)
22 QDict *resp;
23 char *s;
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;
35 static void test_mon_explicit(const void *data)
37 char *s;
38 char *cli;
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);
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);
50 qtest_end();
51 g_free(cli);
54 static void test_mon_default(const void *data)
56 char *s;
57 char *cli;
59 cli = make_cli(data, "-smp 8 -numa node -numa node");
60 qtest_start(cli);
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);
67 qtest_end();
68 g_free(cli);
71 static void test_mon_partial(const void *data)
73 char *s;
74 char *cli;
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);
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);
86 qtest_end();
87 g_free(cli);
90 int main(int argc, char **argv)
92 const char *args = NULL;
93 const char *arch = qtest_get_arch();
95 if (strcmp(arch, "aarch64") == 0) {
96 args = "-machine virt";
99 g_test_init(&argc, &argv, NULL);
101 qtest_add_data_func("/numa/mon/default", args, test_mon_default);
102 qtest_add_data_func("/numa/mon/cpus/explicit", args, test_mon_explicit);
103 qtest_add_data_func("/numa/mon/cpus/partial", args, test_mon_partial);
105 return g_test_run();