2 * QTest testcase for PC CPUs
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.
13 #include "qemu-common.h"
15 #include "qemu/osdep.h"
16 #include "qapi/qmp/types.h"
20 const char *cpu_model
;
26 typedef struct PCTestData PCTestData
;
28 static void test_pc_with_cpu_add(gconstpointer data
)
30 const PCTestData
*s
= data
;
35 args
= g_strdup_printf("-machine %s -cpu %s "
36 "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
37 s
->machine
, s
->cpu_model
,
38 s
->sockets
, s
->cores
, s
->threads
, s
->maxcpus
);
41 for (i
= s
->sockets
* s
->cores
* s
->threads
; i
< s
->maxcpus
; i
++) {
42 response
= qmp("{ 'execute': 'cpu-add',"
43 " 'arguments': { 'id': %d } }", i
);
45 g_assert(!qdict_haskey(response
, "error"));
53 static void test_pc_without_cpu_add(gconstpointer data
)
55 const PCTestData
*s
= data
;
59 args
= g_strdup_printf("-machine %s -cpu %s "
60 "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
61 s
->machine
, s
->cpu_model
,
62 s
->sockets
, s
->cores
, s
->threads
, s
->maxcpus
);
65 response
= qmp("{ 'execute': 'cpu-add',"
66 " 'arguments': { 'id': %d } }",
67 s
->sockets
* s
->cores
* s
->threads
);
69 g_assert(qdict_haskey(response
, "error"));
76 static void add_pc_test_cases(void)
78 const char *arch
= qtest_get_arch();
79 QDict
*response
, *minfo
;
84 const char *mname
, *path
;
87 qtest_start("-machine none");
88 response
= qmp("{ 'execute': 'query-machines' }");
90 list
= qdict_get_qlist(response
, "return");
93 for (p
= qlist_first(list
); p
; p
= qlist_next(p
)) {
94 minfo
= qobject_to_qdict(qlist_entry_obj(p
));
96 qobj
= qdict_get(minfo
, "name");
98 qstr
= qobject_to_qstring(qobj
);
100 mname
= qstring_get_str(qstr
);
101 if (!g_str_has_prefix(mname
, "pc-")) {
104 data
= g_malloc(sizeof(PCTestData
));
105 data
->machine
= mname
;
106 data
->cpu_model
= "Haswell"; /* 1.3+ theoretically */
110 data
->maxcpus
= data
->sockets
* data
->cores
* data
->threads
* 2;
111 if (g_str_has_suffix(mname
, "-1.4") ||
112 (strcmp(mname
, "pc-1.3") == 0) ||
113 (strcmp(mname
, "pc-1.2") == 0) ||
114 (strcmp(mname
, "pc-1.1") == 0) ||
115 (strcmp(mname
, "pc-1.0") == 0) ||
116 (strcmp(mname
, "pc-0.15") == 0) ||
117 (strcmp(mname
, "pc-0.14") == 0) ||
118 (strcmp(mname
, "pc-0.13") == 0) ||
119 (strcmp(mname
, "pc-0.12") == 0) ||
120 (strcmp(mname
, "pc-0.11") == 0) ||
121 (strcmp(mname
, "pc-0.10") == 0)) {
122 path
= g_strdup_printf("/%s/cpu/%s/init/%ux%ux%u&maxcpus=%u",
123 arch
, mname
, data
->sockets
, data
->cores
,
124 data
->threads
, data
->maxcpus
);
125 g_test_add_data_func(path
, data
, test_pc_without_cpu_add
);
127 path
= g_strdup_printf("/%s/cpu/%s/add/%ux%ux%u&maxcpus=%u",
128 arch
, mname
, data
->sockets
, data
->cores
,
129 data
->threads
, data
->maxcpus
);
130 g_test_add_data_func(path
, data
, test_pc_with_cpu_add
);
136 int main(int argc
, char **argv
)
138 const char *arch
= qtest_get_arch();
140 g_test_init(&argc
, &argv
, NULL
);
142 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {