]> Git Repo - qemu.git/blob - tests/pc-cpu-test.c
qapi: Plumb in 'boxed' to qapi generator lower levels
[qemu.git] / tests / pc-cpu-test.c
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
10 #include "qemu/osdep.h"
11
12 #include "qemu-common.h"
13 #include "libqtest.h"
14 #include "qapi/qmp/types.h"
15
16 struct PCTestData {
17     const char *machine;
18     const char *cpu_model;
19     unsigned sockets;
20     unsigned cores;
21     unsigned threads;
22     unsigned maxcpus;
23 };
24 typedef struct PCTestData PCTestData;
25
26 static void test_pc_with_cpu_add(gconstpointer data)
27 {
28     const PCTestData *s = data;
29     char *args;
30     QDict *response;
31     unsigned int i;
32
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);
37     qtest_start(args);
38
39     for (i = s->sockets * s->cores * s->threads; i < s->maxcpus; i++) {
40         response = qmp("{ 'execute': 'cpu-add',"
41                        "  'arguments': { 'id': %d } }", i);
42         g_assert(response);
43         g_assert(!qdict_haskey(response, "error"));
44         QDECREF(response);
45     }
46
47     qtest_end();
48     g_free(args);
49 }
50
51 static void test_pc_without_cpu_add(gconstpointer data)
52 {
53     const PCTestData *s = data;
54     char *args;
55     QDict *response;
56
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);
61     qtest_start(args);
62
63     response = qmp("{ 'execute': 'cpu-add',"
64                    "  'arguments': { 'id': %d } }",
65                    s->sockets * s->cores * s->threads);
66     g_assert(response);
67     g_assert(qdict_haskey(response, "error"));
68     QDECREF(response);
69
70     qtest_end();
71     g_free(args);
72 }
73
74 static void add_pc_test_cases(void)
75 {
76     QDict *response, *minfo;
77     QList *list;
78     const QListEntry *p;
79     QObject *qobj;
80     QString *qstr;
81     const char *mname, *path;
82     PCTestData *data;
83
84     qtest_start("-machine none");
85     response = qmp("{ 'execute': 'query-machines' }");
86     g_assert(response);
87     list = qdict_get_qlist(response, "return");
88     g_assert(list);
89
90     for (p = qlist_first(list); p; p = qlist_next(p)) {
91         minfo = qobject_to_qdict(qlist_entry_obj(p));
92         g_assert(minfo);
93         qobj = qdict_get(minfo, "name");
94         g_assert(qobj);
95         qstr = qobject_to_qstring(qobj);
96         g_assert(qstr);
97         mname = qstring_get_str(qstr);
98         if (!g_str_has_prefix(mname, "pc-")) {
99             continue;
100         }
101         data = g_malloc(sizeof(PCTestData));
102         data->machine = mname;
103         data->cpu_model = "Haswell"; /* 1.3+ theoretically */
104         data->sockets = 1;
105         data->cores = 3;
106         data->threads = 2;
107         data->maxcpus = data->sockets * data->cores * data->threads * 2;
108         if (g_str_has_suffix(mname, "-1.4") ||
109             (strcmp(mname, "pc-1.3") == 0) ||
110             (strcmp(mname, "pc-1.2") == 0) ||
111             (strcmp(mname, "pc-1.1") == 0) ||
112             (strcmp(mname, "pc-1.0") == 0) ||
113             (strcmp(mname, "pc-0.15") == 0) ||
114             (strcmp(mname, "pc-0.14") == 0) ||
115             (strcmp(mname, "pc-0.13") == 0) ||
116             (strcmp(mname, "pc-0.12") == 0) ||
117             (strcmp(mname, "pc-0.11") == 0) ||
118             (strcmp(mname, "pc-0.10") == 0)) {
119             path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
120                                    mname, data->sockets, data->cores,
121                                    data->threads, data->maxcpus);
122             qtest_add_data_func(path, data, test_pc_without_cpu_add);
123         } else {
124             path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
125                                    mname, data->sockets, data->cores,
126                                    data->threads, data->maxcpus);
127             qtest_add_data_func(path, data, test_pc_with_cpu_add);
128         }
129     }
130     qtest_end();
131 }
132
133 int main(int argc, char **argv)
134 {
135     const char *arch = qtest_get_arch();
136
137     g_test_init(&argc, &argv, NULL);
138
139     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
140         add_pc_test_cases();
141     }
142
143     return g_test_run();
144 }
This page took 0.037321 seconds and 4 git commands to generate.