]>
Commit | Line | Data |
---|---|---|
7fe55c3c AF |
1 | /* |
2 | * QTest testcase for PC CPUs | |
3 | * | |
4 | * Copyright (c) 2015 SUSE Linux GmbH | |
5 | * | |
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 | */ | |
9 | ||
681c28a3 | 10 | #include "qemu/osdep.h" |
7fe55c3c | 11 | #include <glib.h> |
7fe55c3c AF |
12 | |
13 | #include "qemu-common.h" | |
14 | #include "libqtest.h" | |
7fe55c3c AF |
15 | #include "qapi/qmp/types.h" |
16 | ||
17 | struct PCTestData { | |
18 | const char *machine; | |
19 | const char *cpu_model; | |
20 | unsigned sockets; | |
21 | unsigned cores; | |
22 | unsigned threads; | |
23 | unsigned maxcpus; | |
24 | }; | |
25 | typedef struct PCTestData PCTestData; | |
26 | ||
27 | static void test_pc_with_cpu_add(gconstpointer data) | |
28 | { | |
29 | const PCTestData *s = data; | |
30 | char *args; | |
31 | QDict *response; | |
32 | unsigned int i; | |
33 | ||
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); | |
38 | qtest_start(args); | |
39 | ||
40 | for (i = s->sockets * s->cores * s->threads; 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 | QDECREF(response); | |
46 | } | |
47 | ||
48 | qtest_end(); | |
49 | g_free(args); | |
50 | } | |
51 | ||
52 | static void test_pc_without_cpu_add(gconstpointer data) | |
53 | { | |
54 | const PCTestData *s = data; | |
55 | char *args; | |
56 | QDict *response; | |
57 | ||
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); | |
62 | qtest_start(args); | |
63 | ||
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 | QDECREF(response); | |
70 | ||
71 | qtest_end(); | |
72 | g_free(args); | |
73 | } | |
74 | ||
75 | static void add_pc_test_cases(void) | |
76 | { | |
7fe55c3c AF |
77 | QDict *response, *minfo; |
78 | QList *list; | |
79 | const QListEntry *p; | |
80 | QObject *qobj; | |
81 | QString *qstr; | |
82 | const char *mname, *path; | |
83 | PCTestData *data; | |
84 | ||
85 | qtest_start("-machine none"); | |
86 | response = qmp("{ 'execute': 'query-machines' }"); | |
87 | g_assert(response); | |
88 | list = qdict_get_qlist(response, "return"); | |
89 | g_assert(list); | |
90 | ||
91 | for (p = qlist_first(list); p; p = qlist_next(p)) { | |
92 | minfo = qobject_to_qdict(qlist_entry_obj(p)); | |
93 | g_assert(minfo); | |
94 | qobj = qdict_get(minfo, "name"); | |
95 | g_assert(qobj); | |
96 | qstr = qobject_to_qstring(qobj); | |
97 | g_assert(qstr); | |
98 | mname = qstring_get_str(qstr); | |
99 | if (!g_str_has_prefix(mname, "pc-")) { | |
100 | continue; | |
101 | } | |
102 | data = g_malloc(sizeof(PCTestData)); | |
103 | data->machine = mname; | |
104 | data->cpu_model = "Haswell"; /* 1.3+ theoretically */ | |
105 | data->sockets = 1; | |
106 | data->cores = 3; | |
107 | data->threads = 2; | |
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)) { | |
53f77e45 AF |
120 | path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u", |
121 | mname, data->sockets, data->cores, | |
7fe55c3c | 122 | data->threads, data->maxcpus); |
53f77e45 | 123 | qtest_add_data_func(path, data, test_pc_without_cpu_add); |
7fe55c3c | 124 | } else { |
53f77e45 AF |
125 | path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u", |
126 | mname, data->sockets, data->cores, | |
7fe55c3c | 127 | data->threads, data->maxcpus); |
53f77e45 | 128 | qtest_add_data_func(path, data, test_pc_with_cpu_add); |
7fe55c3c AF |
129 | } |
130 | } | |
131 | qtest_end(); | |
132 | } | |
133 | ||
134 | int main(int argc, char **argv) | |
135 | { | |
136 | const char *arch = qtest_get_arch(); | |
137 | ||
138 | g_test_init(&argc, &argv, NULL); | |
139 | ||
140 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { | |
141 | add_pc_test_cases(); | |
142 | } | |
143 | ||
144 | return g_test_run(); | |
145 | } |