mips jazz: compile only in 64 bit
[qemu/ar7.git] / tests / pc-cpu-test.c
bloba0122d3d61d4b0984cba2803e330e4718dc576a5
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 <glib.h>
11 #include <string.h>
13 #include "qemu-common.h"
14 #include "libqtest.h"
15 #include "qemu/osdep.h"
16 #include "qapi/qmp/types.h"
18 struct PCTestData {
19 const char *machine;
20 const char *cpu_model;
21 unsigned sockets;
22 unsigned cores;
23 unsigned threads;
24 unsigned maxcpus;
26 typedef struct PCTestData PCTestData;
28 static void test_pc_with_cpu_add(gconstpointer data)
30 const PCTestData *s = data;
31 char *args;
32 QDict *response;
33 unsigned int i;
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);
39 qtest_start(args);
41 for (i = s->sockets * s->cores * s->threads; i < s->maxcpus; i++) {
42 response = qmp("{ 'execute': 'cpu-add',"
43 " 'arguments': { 'id': %d } }", i);
44 g_assert(response);
45 g_assert(!qdict_haskey(response, "error"));
46 QDECREF(response);
49 qtest_end();
50 g_free(args);
53 static void test_pc_without_cpu_add(gconstpointer data)
55 const PCTestData *s = data;
56 char *args;
57 QDict *response;
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);
63 qtest_start(args);
65 response = qmp("{ 'execute': 'cpu-add',"
66 " 'arguments': { 'id': %d } }",
67 s->sockets * s->cores * s->threads);
68 g_assert(response);
69 g_assert(qdict_haskey(response, "error"));
70 QDECREF(response);
72 qtest_end();
73 g_free(args);
76 static void add_pc_test_cases(void)
78 const char *arch = qtest_get_arch();
79 QDict *response, *minfo;
80 QList *list;
81 const QListEntry *p;
82 QObject *qobj;
83 QString *qstr;
84 const char *mname, *path;
85 PCTestData *data;
87 qtest_start("-machine none");
88 response = qmp("{ 'execute': 'query-machines' }");
89 g_assert(response);
90 list = qdict_get_qlist(response, "return");
91 g_assert(list);
93 for (p = qlist_first(list); p; p = qlist_next(p)) {
94 minfo = qobject_to_qdict(qlist_entry_obj(p));
95 g_assert(minfo);
96 qobj = qdict_get(minfo, "name");
97 g_assert(qobj);
98 qstr = qobject_to_qstring(qobj);
99 g_assert(qstr);
100 mname = qstring_get_str(qstr);
101 if (!g_str_has_prefix(mname, "pc-")) {
102 continue;
104 data = g_malloc(sizeof(PCTestData));
105 data->machine = mname;
106 data->cpu_model = "Haswell"; /* 1.3+ theoretically */
107 data->sockets = 1;
108 data->cores = 3;
109 data->threads = 2;
110 data->maxcpus = data->sockets * data->cores * data->threads * 2;
111 if (g_str_has_suffix(mname, "-1.4") ||
112 (strcmp(mname, "pc-1.3") == 0) ||
113 (strcmp(mname, "pc-1.2") == 0) ||
114 (strcmp(mname, "pc-1.1") == 0) ||
115 (strcmp(mname, "pc-1.0") == 0) ||
116 (strcmp(mname, "pc-0.15") == 0) ||
117 (strcmp(mname, "pc-0.14") == 0) ||
118 (strcmp(mname, "pc-0.13") == 0) ||
119 (strcmp(mname, "pc-0.12") == 0) ||
120 (strcmp(mname, "pc-0.11") == 0) ||
121 (strcmp(mname, "pc-0.10") == 0)) {
122 path = g_strdup_printf("/%s/cpu/%s/init/%ux%ux%u&maxcpus=%u",
123 arch, mname, data->sockets, data->cores,
124 data->threads, data->maxcpus);
125 g_test_add_data_func(path, data, test_pc_without_cpu_add);
126 } else {
127 path = g_strdup_printf("/%s/cpu/%s/add/%ux%ux%u&maxcpus=%u",
128 arch, mname, data->sockets, data->cores,
129 data->threads, data->maxcpus);
130 g_test_add_data_func(path, data, test_pc_with_cpu_add);
133 qtest_end();
136 int main(int argc, char **argv)
138 const char *arch = qtest_get_arch();
140 g_test_init(&argc, &argv, NULL);
142 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
143 add_pc_test_cases();
146 return g_test_run();