tcg/i386: Propagate is64 to tcg_out_qemu_ld_direct
[qemu/ar7.git] / tests / cpu-plug-test.c
blobf4a677d23809c70627acaf31924cabce7401e8d0
1 /*
2 * QTest testcase for CPU plugging
4 * Copyright (c) 2015 SUSE Linux GmbH
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
10 #include "qemu/osdep.h"
12 #include "qemu-common.h"
13 #include "libqtest.h"
14 #include "qapi/qmp/qdict.h"
16 struct PlugTestData {
17 char *machine;
18 const char *cpu_model;
19 char *device_model;
20 unsigned sockets;
21 unsigned cores;
22 unsigned threads;
23 unsigned maxcpus;
25 typedef struct PlugTestData PlugTestData;
27 static void test_plug_with_cpu_add(gconstpointer data)
29 const PlugTestData *s = data;
30 char *args;
31 QDict *response;
32 unsigned int i;
34 args = g_strdup_printf("-machine %s -cpu %s "
35 "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
36 s->machine, s->cpu_model,
37 s->sockets, s->cores, s->threads, s->maxcpus);
38 qtest_start(args);
40 for (i = 1; i < s->maxcpus; i++) {
41 response = qmp("{ 'execute': 'cpu-add',"
42 " 'arguments': { 'id': %d } }", i);
43 g_assert(response);
44 g_assert(!qdict_haskey(response, "error"));
45 qobject_unref(response);
48 qtest_end();
49 g_free(args);
52 static void test_plug_without_cpu_add(gconstpointer data)
54 const PlugTestData *s = data;
55 char *args;
56 QDict *response;
58 args = g_strdup_printf("-machine %s -cpu %s "
59 "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
60 s->machine, s->cpu_model,
61 s->sockets, s->cores, s->threads, s->maxcpus);
62 qtest_start(args);
64 response = qmp("{ 'execute': 'cpu-add',"
65 " 'arguments': { 'id': %d } }",
66 s->sockets * s->cores * s->threads);
67 g_assert(response);
68 g_assert(qdict_haskey(response, "error"));
69 qobject_unref(response);
71 qtest_end();
72 g_free(args);
75 static void test_plug_with_device_add_x86(gconstpointer data)
77 const PlugTestData *td = data;
78 char *args;
79 unsigned int s, c, t;
81 args = g_strdup_printf("-machine %s -cpu %s "
82 "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
83 td->machine, td->cpu_model,
84 td->sockets, td->cores, td->threads, td->maxcpus);
85 qtest_start(args);
87 for (s = 1; s < td->sockets; s++) {
88 for (c = 0; c < td->cores; c++) {
89 for (t = 0; t < td->threads; t++) {
90 char *id = g_strdup_printf("id-%i-%i-%i", s, c, t);
91 qtest_qmp_device_add(td->device_model, id,
92 "{'socket-id':%u, 'core-id':%u,"
93 " 'thread-id':%u}",
94 s, c, t);
95 g_free(id);
100 qtest_end();
101 g_free(args);
104 static void test_plug_with_device_add_coreid(gconstpointer data)
106 const PlugTestData *td = data;
107 char *args;
108 unsigned int c;
110 args = g_strdup_printf("-machine %s -cpu %s "
111 "-smp 1,sockets=%u,cores=%u,threads=%u,maxcpus=%u",
112 td->machine, td->cpu_model,
113 td->sockets, td->cores, td->threads, td->maxcpus);
114 qtest_start(args);
116 for (c = 1; c < td->cores; c++) {
117 char *id = g_strdup_printf("id-%i", c);
118 qtest_qmp_device_add(td->device_model, id, "{'core-id':%u}", c);
119 g_free(id);
122 qtest_end();
123 g_free(args);
126 static void test_data_free(gpointer data)
128 PlugTestData *pc = data;
130 g_free(pc->machine);
131 g_free(pc->device_model);
132 g_free(pc);
135 static void add_pc_test_case(const char *mname)
137 char *path;
138 PlugTestData *data;
140 if (!g_str_has_prefix(mname, "pc-")) {
141 return;
143 data = g_new(PlugTestData, 1);
144 data->machine = g_strdup(mname);
145 data->cpu_model = "Haswell"; /* 1.3+ theoretically */
146 data->device_model = g_strdup_printf("%s-%s-cpu", data->cpu_model,
147 qtest_get_arch());
148 data->sockets = 1;
149 data->cores = 3;
150 data->threads = 2;
151 data->maxcpus = data->sockets * data->cores * data->threads;
152 if (g_str_has_suffix(mname, "-1.4") ||
153 (strcmp(mname, "pc-1.3") == 0) ||
154 (strcmp(mname, "pc-1.2") == 0) ||
155 (strcmp(mname, "pc-1.1") == 0) ||
156 (strcmp(mname, "pc-1.0") == 0) ||
157 (strcmp(mname, "pc-0.15") == 0) ||
158 (strcmp(mname, "pc-0.14") == 0) ||
159 (strcmp(mname, "pc-0.13") == 0) ||
160 (strcmp(mname, "pc-0.12") == 0) ||
161 (strcmp(mname, "pc-0.11") == 0) ||
162 (strcmp(mname, "pc-0.10") == 0)) {
163 path = g_strdup_printf("cpu-plug/%s/init/%ux%ux%u&maxcpus=%u",
164 mname, data->sockets, data->cores,
165 data->threads, data->maxcpus);
166 qtest_add_data_func_full(path, data, test_plug_without_cpu_add,
167 test_data_free);
168 g_free(path);
169 } else {
170 PlugTestData *data2 = g_memdup(data, sizeof(PlugTestData));
172 data2->machine = g_strdup(data->machine);
173 data2->device_model = g_strdup(data->device_model);
175 path = g_strdup_printf("cpu-plug/%s/cpu-add/%ux%ux%u&maxcpus=%u",
176 mname, data->sockets, data->cores,
177 data->threads, data->maxcpus);
178 qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
179 test_data_free);
180 g_free(path);
181 path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
182 mname, data2->sockets, data2->cores,
183 data2->threads, data2->maxcpus);
184 qtest_add_data_func_full(path, data2, test_plug_with_device_add_x86,
185 test_data_free);
186 g_free(path);
190 static void add_pseries_test_case(const char *mname)
192 char *path;
193 PlugTestData *data;
195 if (!g_str_has_prefix(mname, "pseries-") ||
196 (g_str_has_prefix(mname, "pseries-2.") && atoi(&mname[10]) < 7)) {
197 return;
199 data = g_new(PlugTestData, 1);
200 data->machine = g_strdup(mname);
201 data->cpu_model = "power8_v2.0";
202 data->device_model = g_strdup("power8_v2.0-spapr-cpu-core");
203 data->sockets = 2;
204 data->cores = 3;
205 data->threads = 1;
206 data->maxcpus = data->sockets * data->cores * data->threads;
208 path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
209 mname, data->sockets, data->cores,
210 data->threads, data->maxcpus);
211 qtest_add_data_func_full(path, data, test_plug_with_device_add_coreid,
212 test_data_free);
213 g_free(path);
216 static void add_s390x_test_case(const char *mname)
218 char *path;
219 PlugTestData *data, *data2;
221 if (!g_str_has_prefix(mname, "s390-ccw-virtio-")) {
222 return;
225 data = g_new(PlugTestData, 1);
226 data->machine = g_strdup(mname);
227 data->cpu_model = "qemu";
228 data->device_model = g_strdup("qemu-s390x-cpu");
229 data->sockets = 1;
230 data->cores = 3;
231 data->threads = 1;
232 data->maxcpus = data->sockets * data->cores * data->threads;
234 data2 = g_memdup(data, sizeof(PlugTestData));
235 data2->machine = g_strdup(data->machine);
236 data2->device_model = g_strdup(data->device_model);
238 path = g_strdup_printf("cpu-plug/%s/cpu-add/%ux%ux%u&maxcpus=%u",
239 mname, data->sockets, data->cores,
240 data->threads, data->maxcpus);
241 qtest_add_data_func_full(path, data, test_plug_with_cpu_add,
242 test_data_free);
243 g_free(path);
245 path = g_strdup_printf("cpu-plug/%s/device-add/%ux%ux%u&maxcpus=%u",
246 mname, data2->sockets, data2->cores,
247 data2->threads, data2->maxcpus);
248 qtest_add_data_func_full(path, data2, test_plug_with_device_add_coreid,
249 test_data_free);
250 g_free(path);
253 int main(int argc, char **argv)
255 const char *arch = qtest_get_arch();
257 g_test_init(&argc, &argv, NULL);
259 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
260 qtest_cb_for_every_machine(add_pc_test_case, g_test_quick());
261 } else if (g_str_equal(arch, "ppc64")) {
262 qtest_cb_for_every_machine(add_pseries_test_case, g_test_quick());
263 } else if (g_str_equal(arch, "s390x")) {
264 qtest_cb_for_every_machine(add_s390x_test_case, g_test_quick());
267 return g_test_run();