ppc: Remove MMU_MODEn_SUFFIX definitions
[qemu/kevin.git] / tests / pc-cpu-test.c
blob6b34ca588b108a70b7771cd91ea33cc4b9b755fe
1 /*
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.
8 */
10 #include "qemu/osdep.h"
11 #include <glib.h>
13 #include "qemu-common.h"
14 #include "libqtest.h"
15 #include "qapi/qmp/types.h"
17 struct PCTestData {
18 const char *machine;
19 const char *cpu_model;
20 unsigned sockets;
21 unsigned cores;
22 unsigned threads;
23 unsigned maxcpus;
25 typedef struct PCTestData PCTestData;
27 static void test_pc_with_cpu_add(gconstpointer data)
29 const PCTestData *s = data;
30 char *args;
31 QDict *response;
32 unsigned int i;
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);
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);
48 qtest_end();
49 g_free(args);
52 static void test_pc_without_cpu_add(gconstpointer data)
54 const PCTestData *s = data;
55 char *args;
56 QDict *response;
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);
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);
71 qtest_end();
72 g_free(args);
75 static void add_pc_test_cases(void)
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;
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);
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;
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)) {
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);
124 } else {
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);
131 qtest_end();
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) {
141 add_pc_test_cases();
144 return g_test_run();