tests: Use the new DO_TEST_CAPS_*() macros
[libvirt/ericb.git] / tests / vircapstest.c
blob7fc0ebe4f6a4cf96167c0eefc374b8d8949a6ae5
1 /*
2 * Copyright (C) IBM Corp 2014
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
20 #include <config.h>
22 #include "testutils.h"
23 #include "testutilslxc.h"
24 #include "testutilsqemu.h"
25 #include "capabilities.h"
26 #include "virbitmap.h"
29 #define VIR_FROM_THIS VIR_FROM_NONE
32 static int
33 test_virCapabilitiesGetCpusForNodemask(const void *data ATTRIBUTE_UNUSED)
35 const char *nodestr = "3,4,5,6";
36 virBitmapPtr nodemask = NULL;
37 virBitmapPtr cpumap = NULL;
38 virCapsPtr caps = NULL;
39 int mask_size = 8;
40 int ret = -1;
43 if (!(caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false)))
44 goto error;
46 if (virTestCapsBuildNUMATopology(caps, 3) < 0)
47 goto error;
49 if (virBitmapParse(nodestr, &nodemask, mask_size) < 0)
50 goto error;
52 if (!(cpumap = virCapabilitiesGetCpusForNodemask(caps, nodemask)))
53 goto error;
55 ret = 0;
57 error:
58 virObjectUnref(caps);
59 virBitmapFree(nodemask);
60 virBitmapFree(cpumap);
61 return ret;
66 static bool ATTRIBUTE_UNUSED
67 doCapsExpectFailure(virCapsPtr caps,
68 int ostype,
69 virArch arch,
70 int domaintype,
71 const char *emulator,
72 const char *machinetype)
74 virCapsDomainDataPtr data = virCapabilitiesDomainDataLookup(caps, ostype,
75 arch, domaintype, emulator, machinetype);
77 if (data) {
78 VIR_FREE(data);
79 return false;
82 return true;
85 static bool ATTRIBUTE_UNUSED
86 doCapsCompare(virCapsPtr caps,
87 int ostype,
88 virArch arch,
89 int domaintype,
90 const char *emulator,
91 const char *machinetype,
92 int expect_ostype,
93 virArch expect_arch,
94 int expect_domaintype,
95 const char *expect_emulator,
96 const char *expect_machinetype)
98 bool ret = false;
99 virCapsDomainDataPtr data = virCapabilitiesDomainDataLookup(caps, ostype,
100 arch, domaintype, emulator, machinetype);
102 if (!data)
103 goto error;
105 if (data->ostype != expect_ostype) {
106 fprintf(stderr, "data->ostype=%s doesn't match expect_ostype=%s\n",
107 virDomainOSTypeToString(data->ostype),
108 virDomainOSTypeToString(expect_ostype));
109 goto error;
112 if (data->arch != expect_arch) {
113 fprintf(stderr, "data->arch=%s doesn't match expect_arch=%s\n",
114 virArchToString(data->arch),
115 virArchToString(expect_arch));
116 goto error;
119 if (data->domaintype != expect_domaintype) {
120 fprintf(stderr, "data->domaintype=%s doesn't match "
121 "expect_domaintype=%s\n",
122 virDomainVirtTypeToString(data->domaintype),
123 virDomainVirtTypeToString(expect_domaintype));
124 goto error;
127 if (STRNEQ(data->emulator, expect_emulator)) {
128 fprintf(stderr, "data->emulator=%s doesn't match expect_emulator=%s\n",
129 data->emulator, expect_emulator);
130 goto error;
133 if (STRNEQ_NULLABLE(data->machinetype, expect_machinetype)) {
134 fprintf(stderr, "data->machinetype=%s doesn't match "
135 "expect_machinetype=%s\n",
136 NULLSTR(data->machinetype), NULLSTR(expect_machinetype));
137 goto error;
140 ret = true;
141 error:
142 VIR_FREE(data);
143 return ret;
146 #define CAPSCOMP(o, a, d, e, m, fo, fa, fd, fe, fm) \
147 if (!doCapsCompare(caps, o, a, d, e, m, fo, fa, fd, fe, fm)) \
148 ret = -1;
150 #define CAPS_EXPECT_ERR(o, a, d, e, m) \
151 if (!doCapsExpectFailure(caps, o, a, d, e, m)) \
152 ret = -1;
154 #ifdef WITH_QEMU
155 static int
156 test_virCapsDomainDataLookupQEMU(const void *data ATTRIBUTE_UNUSED)
158 int ret = 0;
159 virCapsPtr caps = NULL;
161 if (!(caps = testQemuCapsInit())) {
162 ret = -1;
163 goto out;
166 /* Checking each parameter individually */
167 CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
168 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
169 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-x86_64", "pc-0.11");
170 CAPSCOMP(VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
171 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
172 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-x86_64", "pc-0.11");
173 CAPSCOMP(-1, VIR_ARCH_AARCH64, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
174 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_AARCH64,
175 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-aarch64", "virt");
176 CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_KVM, NULL, NULL,
177 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64,
178 VIR_DOMAIN_VIRT_KVM, "/usr/bin/qemu-system-x86_64", "pc");
179 CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, "/usr/bin/qemu-system-ppc64", NULL,
180 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64,
181 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-ppc64", "pseries");
182 CAPSCOMP(-1, VIR_ARCH_RISCV32, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
183 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_RISCV32,
184 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-riscv32", "spike_v1.10");
185 CAPSCOMP(-1, VIR_ARCH_RISCV64, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
186 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_RISCV64,
187 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-riscv64", "spike_v1.10");
188 CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, "s390-virtio",
189 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_S390X,
190 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-s390x",
191 "s390-virtio");
193 CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, "pseries",
194 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64,
195 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-ppc64", "pseries");
196 CAPSCOMP(-1, VIR_ARCH_PPC64LE, VIR_DOMAIN_VIRT_NONE, NULL, "pseries",
197 VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_PPC64LE,
198 VIR_DOMAIN_VIRT_QEMU, "/usr/bin/qemu-system-ppc64", "pseries");
200 CAPS_EXPECT_ERR(VIR_DOMAIN_OSTYPE_LINUX, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL);
201 CAPS_EXPECT_ERR(-1, VIR_ARCH_PPC64LE, VIR_DOMAIN_VIRT_NONE, NULL, "pc");
202 CAPS_EXPECT_ERR(-1, VIR_ARCH_MIPS, VIR_DOMAIN_VIRT_NONE, NULL, NULL);
203 CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE,
204 "/usr/bin/qemu-system-aarch64", "pc");
205 CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc");
207 out:
208 virObjectUnref(caps);
209 return ret;
211 #endif /* WITH_QEMU */
213 #ifdef WITH_LXC
214 static int
215 test_virCapsDomainDataLookupLXC(const void *data ATTRIBUTE_UNUSED)
217 int ret = 0;
218 virCapsPtr caps = NULL;
220 if (!(caps = testLXCCapsInit())) {
221 ret = -1;
222 goto out;
225 CAPSCOMP(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
226 VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64,
227 VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);
228 CAPSCOMP(-1, VIR_ARCH_X86_64, VIR_DOMAIN_VIRT_NONE, NULL, NULL,
229 VIR_DOMAIN_OSTYPE_EXE, VIR_ARCH_X86_64,
230 VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);
232 out:
233 virObjectUnref(caps);
234 return ret;
236 #endif /* WITH_LXC */
238 static int
239 mymain(void)
241 int ret = 0;
243 if (virTestRun("virCapabilitiesGetCpusForNodemask",
244 test_virCapabilitiesGetCpusForNodemask, NULL) < 0)
245 ret = -1;
246 #ifdef WITH_QEMU
247 if (virTestRun("virCapsDomainDataLookupQEMU",
248 test_virCapsDomainDataLookupQEMU, NULL) < 0)
249 ret = -1;
250 #endif
251 #ifdef WITH_LXC
252 if (virTestRun("virCapsDomainDataLookupLXC",
253 test_virCapsDomainDataLookupLXC, NULL) < 0)
254 ret = -1;
255 #endif /* WITH_LXC */
257 return ret;
260 VIR_TEST_MAIN(mymain)