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.
10 #include "qemu/osdep.h"
13 #include "qemu-common.h"
15 #include "qapi/qmp/types.h"
19 const char *cpu_model
;
25 typedef struct PCTestData PCTestData
;
27 static void test_pc_with_cpu_add(gconstpointer data
)
29 const PCTestData
*s
= data
;
34 args
= g_strdup_printf("-machine %s -cpu %s "
35 "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
36 s
->machine
, s
->cpu_model
,
37 s
->sockets
, s
->cores
, s
->threads
, s
->maxcpus
);
40 for (i
= s
->sockets
* s
->cores
* s
->threads
; i
< s
->maxcpus
; i
++) {
41 response
= qmp("{ 'execute': 'cpu-add',"
42 " 'arguments': { 'id': %d } }", i
);
44 g_assert(!qdict_haskey(response
, "error"));
52 static void test_pc_without_cpu_add(gconstpointer data
)
54 const PCTestData
*s
= data
;
58 args
= g_strdup_printf("-machine %s -cpu %s "
59 "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
60 s
->machine
, s
->cpu_model
,
61 s
->sockets
, s
->cores
, s
->threads
, s
->maxcpus
);
64 response
= qmp("{ 'execute': 'cpu-add',"
65 " 'arguments': { 'id': %d } }",
66 s
->sockets
* s
->cores
* s
->threads
);
68 g_assert(qdict_haskey(response
, "error"));
75 static void add_pc_test_cases(void)
77 QDict
*response
, *minfo
;
82 const char *mname
, *path
;
85 qtest_start("-machine none");
86 response
= qmp("{ 'execute': 'query-machines' }");
88 list
= qdict_get_qlist(response
, "return");
91 for (p
= qlist_first(list
); p
; p
= qlist_next(p
)) {
92 minfo
= qobject_to_qdict(qlist_entry_obj(p
));
94 qobj
= qdict_get(minfo
, "name");
96 qstr
= qobject_to_qstring(qobj
);
98 mname
= qstring_get_str(qstr
);
99 if (!g_str_has_prefix(mname
, "pc-")) {
102 data
= g_malloc(sizeof(PCTestData
));
103 data
->machine
= mname
;
104 data
->cpu_model
= "Haswell"; /* 1.3+ theoretically */
108 data
->maxcpus
= data
->sockets
* data
->cores
* data
->threads
* 2;
109 if (g_str_has_suffix(mname
, "-1.4") ||
110 (strcmp(mname
, "pc-1.3") == 0) ||
111 (strcmp(mname
, "pc-1.2") == 0) ||
112 (strcmp(mname
, "pc-1.1") == 0) ||
113 (strcmp(mname
, "pc-1.0") == 0) ||
114 (strcmp(mname
, "pc-0.15") == 0) ||
115 (strcmp(mname
, "pc-0.14") == 0) ||
116 (strcmp(mname
, "pc-0.13") == 0) ||
117 (strcmp(mname
, "pc-0.12") == 0) ||
118 (strcmp(mname
, "pc-0.11") == 0) ||
119 (strcmp(mname
, "pc-0.10") == 0)) {
120 path
= g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
121 mname
, data
->sockets
, data
->cores
,
122 data
->threads
, data
->maxcpus
);
123 qtest_add_data_func(path
, data
, test_pc_without_cpu_add
);
125 path
= g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
126 mname
, data
->sockets
, data
->cores
,
127 data
->threads
, data
->maxcpus
);
128 qtest_add_data_func(path
, data
, test_pc_with_cpu_add
);
134 int main(int argc
, char **argv
)
136 const char *arch
= qtest_get_arch();
138 g_test_init(&argc
, &argv
, NULL
);
140 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {