Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20150702-v3' into staging
[qemu.git] / tests / pc-cpu-test.c
blob3505c7c43fa4cd78dcc0613c7f4b4e46fee30291
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 QDict *response, *minfo;
79 QList *list;
80 const QListEntry *p;
81 QObject *qobj;
82 QString *qstr;
83 const char *mname, *path;
84 PCTestData *data;
86 qtest_start("-machine none");
87 response = qmp("{ 'execute': 'query-machines' }");
88 g_assert(response);
89 list = qdict_get_qlist(response, "return");
90 g_assert(list);
92 for (p = qlist_first(list); p; p = qlist_next(p)) {
93 minfo = qobject_to_qdict(qlist_entry_obj(p));
94 g_assert(minfo);
95 qobj = qdict_get(minfo, "name");
96 g_assert(qobj);
97 qstr = qobject_to_qstring(qobj);
98 g_assert(qstr);
99 mname = qstring_get_str(qstr);
100 if (!g_str_has_prefix(mname, "pc-")) {
101 continue;
103 data = g_malloc(sizeof(PCTestData));
104 data->machine = mname;
105 data->cpu_model = "Haswell"; /* 1.3+ theoretically */
106 data->sockets = 1;
107 data->cores = 3;
108 data->threads = 2;
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);
125 } else {
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);
132 qtest_end();
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) {
142 add_pc_test_cases();
145 return g_test_run();