1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "internal.h"
#include "xml.h"
#include "testutils.h"
#include "xen/xen_hypervisor.h"
#include "virfile.h"
static int
testCompareFiles(const char *hostmachine, const char *xml_rel,
const char *cpuinfo_rel, const char *capabilities_rel)
{
char *expectxml = NULL;
char *actualxml = NULL;
FILE *fp1 = NULL, *fp2 = NULL;
virCapsPtr caps = NULL;
int ret = -1;
char *xml = NULL;
char *cpuinfo = NULL;
char *capabilities = NULL;
if (virAsprintf(&xml, "%s/%s", abs_srcdir, xml_rel) < 0 ||
virAsprintf(&cpuinfo, "%s/%s", abs_srcdir, cpuinfo_rel) < 0 ||
virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0)
goto fail;
if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail;
if (!(fp1 = fopen(cpuinfo, "r")))
goto fail;
if (!(fp2 = fopen(capabilities, "r")))
goto fail;
if (!(caps = xenHypervisorMakeCapabilitiesInternal(NULL, hostmachine, fp1, fp2)))
goto fail;
if (!(actualxml = virCapabilitiesFormatXML(caps)))
goto fail;
if (STRNEQ(expectxml, actualxml)) {
virtTestDifference(stderr, expectxml, actualxml);
goto fail;
}
ret = 0;
fail:
VIR_FREE(expectxml);
VIR_FREE(actualxml);
VIR_FREE(xml);
VIR_FREE(cpuinfo);
VIR_FREE(capabilities);
VIR_FORCE_FCLOSE(fp1);
VIR_FORCE_FCLOSE(fp2);
virCapabilitiesFree(caps);
return ret;
}
static int testXeni686(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("i686",
"xencapsdata/xen-i686.xml",
"xencapsdata/xen-i686.cpuinfo",
"xencapsdata/xen-i686.caps");
}
static int testXeni686PAE(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("i686",
"xencapsdata/xen-i686-pae.xml",
"xencapsdata/xen-i686-pae.cpuinfo",
"xencapsdata/xen-i686-pae.caps");
}
static int testXeni686PAEHVM(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("i686",
"xencapsdata/xen-i686-pae-hvm.xml",
"xencapsdata/xen-i686-pae-hvm.cpuinfo",
"xencapsdata/xen-i686-pae-hvm.caps");
}
/* No PAE + HVM is non-sensical - all VMX capable
CPUs have PAE */
/*
static int testXeni686HVM(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("i686",
"xencapsdata/xen-i686-hvm.xml",
"xencapsdata/xen-i686.cpuinfo",
"xencapsdata/xen-i686-hvm.caps");
}
*/
static int testXenx86_64(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("x86_64",
"xencapsdata/xen-x86_64.xml",
"xencapsdata/xen-x86_64.cpuinfo",
"xencapsdata/xen-x86_64.caps");
}
static int testXenx86_64HVM(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("x86_64",
"xencapsdata/xen-x86_64-hvm.xml",
"xencapsdata/xen-x86_64-hvm.cpuinfo",
"xencapsdata/xen-x86_64-hvm.caps");
}
static int testXenia64(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("ia64",
"xencapsdata/xen-ia64.xml",
"xencapsdata/xen-ia64.cpuinfo",
"xencapsdata/xen-ia64.caps");
}
static int testXenia64BE(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("ia64",
"xencapsdata/xen-ia64-be.xml",
"xencapsdata/xen-ia64-be.cpuinfo",
"xencapsdata/xen-ia64-be.caps");
}
static int testXenia64HVM(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("ia64",
"xencapsdata/xen-ia64-hvm.xml",
"xencapsdata/xen-ia64-hvm.cpuinfo",
"xencapsdata/xen-ia64-hvm.caps");
}
static int testXenia64BEHVM(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("ia64",
"xencapsdata/xen-ia64-be-hvm.xml",
"xencapsdata/xen-ia64-be-hvm.cpuinfo",
"xencapsdata/xen-ia64-be-hvm.caps");
}
static int testXenppc64(const void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("ppc64",
"xencapsdata/xen-ppc64.xml",
"xencapsdata/xen-ppc64.cpuinfo",
"xencapsdata/xen-ppc64.caps");
}
/* Fake initialization data for xenHypervisorInit(). Must be initialized
* explicitly before the implicit call via virInitialize(). */
static struct xenHypervisorVersions hv_versions = {
.hv = 0,
.hypervisor = 2,
.sys_interface = -1,
.dom_interface = -1,
};
static int
mymain(void)
{
int ret = 0;
xenHypervisorInit(&hv_versions);
virInitialize();
if (virtTestRun("Capabilities for i686, no PAE, no HVM",
1, testXeni686, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for i686, PAE, no HVM",
1, testXeni686PAE, NULL) != 0)
ret = -1;
/* No PAE + HVM is non-sensical - all VMX capable
CPUs have PAE */
/*if (virtTestRun("Capabilities for i686, no PAE, HVM",
1, testXeni686HVM, NULL) != 0)
ret = -1;
*/
if (virtTestRun("Capabilities for i686, PAE, HVM",
1, testXeni686PAEHVM, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for x86_64, no HVM",
1, testXenx86_64, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for x86_64, HVM",
1, testXenx86_64HVM, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for ia64, no HVM, LE",
1, testXenia64, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for ia64, HVM, LE",
1, testXenia64HVM, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for ia64, no HVM, BE",
1, testXenia64BE, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for ia64, HVM, BE",
1, testXenia64BEHVM, NULL) != 0)
ret = -1;
if (virtTestRun("Capabilities for ppc64",
1, testXenppc64, NULL) != 0)
ret = -1;
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIRT_TEST_MAIN(mymain)
|