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 QDict
*response
, *minfo
;
83 const char *mname
, *path
;
86 qtest_start("-machine none");
87 response
= qmp("{ 'execute': 'query-machines' }");
89 list
= qdict_get_qlist(response
, "return");
92 for (p
= qlist_first(list
); p
; p
= qlist_next(p
)) {
93 minfo
= qobject_to_qdict(qlist_entry_obj(p
));
95 qobj
= qdict_get(minfo
, "name");
97 qstr
= qobject_to_qstring(qobj
);
99 mname
= qstring_get_str(qstr
);
100 if (!g_str_has_prefix(mname
, "pc-")) {
103 data
= g_malloc(sizeof(PCTestData
));
104 data
->machine
= mname
;
105 data
->cpu_model
= "Haswell"; /* 1.3+ theoretically */
109 data
->maxcpus
= data
->sockets
* data
->cores
* data
->threads
* 2;
110 if (g_str_has_suffix(mname
, "-1.4") ||
111 (strcmp(mname
, "pc-1.3") == 0) ||
112 (strcmp(mname
, "pc-1.2") == 0) ||
113 (strcmp(mname
, "pc-1.1") == 0) ||
114 (strcmp(mname
, "pc-1.0") == 0) ||
115 (strcmp(mname
, "pc-0.15") == 0) ||
116 (strcmp(mname
, "pc-0.14") == 0) ||
117 (strcmp(mname
, "pc-0.13") == 0) ||
118 (strcmp(mname
, "pc-0.12") == 0) ||
119 (strcmp(mname
, "pc-0.11") == 0) ||
120 (strcmp(mname
, "pc-0.10") == 0)) {
121 path
= g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
122 mname
, data
->sockets
, data
->cores
,
123 data
->threads
, data
->maxcpus
);
124 qtest_add_data_func(path
, data
, test_pc_without_cpu_add
);
126 path
= g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
127 mname
, data
->sockets
, data
->cores
,
128 data
->threads
, data
->maxcpus
);
129 qtest_add_data_func(path
, data
, test_pc_with_cpu_add
);
135 int main(int argc
, char **argv
)
137 const char *arch
= qtest_get_arch();
139 g_test_init(&argc
, &argv
, NULL
);
141 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {