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"
12 #include "qemu-common.h"
14 #include "qapi/qmp/types.h"
18 const char *cpu_model
;
24 typedef struct PCTestData PCTestData
;
26 static void test_pc_with_cpu_add(gconstpointer data
)
28 const PCTestData
*s
= data
;
33 args
= g_strdup_printf("-machine %s -cpu %s "
34 "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
35 s
->machine
, s
->cpu_model
,
36 s
->sockets
, s
->cores
, s
->threads
, s
->maxcpus
);
39 for (i
= s
->sockets
* s
->cores
* s
->threads
; i
< s
->maxcpus
; i
++) {
40 response
= qmp("{ 'execute': 'cpu-add',"
41 " 'arguments': { 'id': %d } }", i
);
43 g_assert(!qdict_haskey(response
, "error"));
51 static void test_pc_without_cpu_add(gconstpointer data
)
53 const PCTestData
*s
= data
;
57 args
= g_strdup_printf("-machine %s -cpu %s "
58 "-smp sockets=%u,cores=%u,threads=%u,maxcpus=%u",
59 s
->machine
, s
->cpu_model
,
60 s
->sockets
, s
->cores
, s
->threads
, s
->maxcpus
);
63 response
= qmp("{ 'execute': 'cpu-add',"
64 " 'arguments': { 'id': %d } }",
65 s
->sockets
* s
->cores
* s
->threads
);
67 g_assert(qdict_haskey(response
, "error"));
74 static void test_data_free(gpointer data
)
76 PCTestData
*pc
= data
;
82 static void add_pc_test_case(const char *mname
)
87 if (!g_str_has_prefix(mname
, "pc-")) {
90 data
= g_new(PCTestData
, 1);
91 data
->machine
= g_strdup(mname
);
92 data
->cpu_model
= "Haswell"; /* 1.3+ theoretically */
96 data
->maxcpus
= data
->sockets
* data
->cores
* data
->threads
* 2;
97 if (g_str_has_suffix(mname
, "-1.4") ||
98 (strcmp(mname
, "pc-1.3") == 0) ||
99 (strcmp(mname
, "pc-1.2") == 0) ||
100 (strcmp(mname
, "pc-1.1") == 0) ||
101 (strcmp(mname
, "pc-1.0") == 0) ||
102 (strcmp(mname
, "pc-0.15") == 0) ||
103 (strcmp(mname
, "pc-0.14") == 0) ||
104 (strcmp(mname
, "pc-0.13") == 0) ||
105 (strcmp(mname
, "pc-0.12") == 0) ||
106 (strcmp(mname
, "pc-0.11") == 0) ||
107 (strcmp(mname
, "pc-0.10") == 0)) {
108 path
= g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
109 mname
, data
->sockets
, data
->cores
,
110 data
->threads
, data
->maxcpus
);
111 qtest_add_data_func_full(path
, data
, test_pc_without_cpu_add
,
115 path
= g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
116 mname
, data
->sockets
, data
->cores
,
117 data
->threads
, data
->maxcpus
);
118 qtest_add_data_func_full(path
, data
, test_pc_with_cpu_add
,
124 int main(int argc
, char **argv
)
126 const char *arch
= qtest_get_arch();
128 g_test_init(&argc
, &argv
, NULL
);
130 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
131 qtest_cb_for_every_machine(add_pc_test_case
);