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/>.
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
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
;
43 if (!(caps
= virCapabilitiesNew(VIR_ARCH_X86_64
, false, false)))
46 if (virTestCapsBuildNUMATopology(caps
, 3) < 0)
49 if (virBitmapParse(nodestr
, &nodemask
, mask_size
) < 0)
52 if (!(cpumap
= virCapabilitiesGetCpusForNodemask(caps
, nodemask
)))
59 virBitmapFree(nodemask
);
60 virBitmapFree(cpumap
);
66 static bool ATTRIBUTE_UNUSED
67 doCapsExpectFailure(virCapsPtr caps
,
72 const char *machinetype
)
74 virCapsDomainDataPtr data
= virCapabilitiesDomainDataLookup(caps
, ostype
,
75 arch
, domaintype
, emulator
, machinetype
);
85 static bool ATTRIBUTE_UNUSED
86 doCapsCompare(virCapsPtr caps
,
91 const char *machinetype
,
94 int expect_domaintype
,
95 const char *expect_emulator
,
96 const char *expect_machinetype
)
99 virCapsDomainDataPtr data
= virCapabilitiesDomainDataLookup(caps
, ostype
,
100 arch
, domaintype
, emulator
, machinetype
);
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
));
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
));
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
));
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
);
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
));
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)) \
150 #define CAPS_EXPECT_ERR(o, a, d, e, m) \
151 if (!doCapsExpectFailure(caps, o, a, d, e, m)) \
156 test_virCapsDomainDataLookupQEMU(const void *data ATTRIBUTE_UNUSED
)
159 virCapsPtr caps
= NULL
;
161 if (!(caps
= testQemuCapsInit())) {
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",
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");
208 virObjectUnref(caps
);
211 #endif /* WITH_QEMU */
215 test_virCapsDomainDataLookupLXC(const void *data ATTRIBUTE_UNUSED
)
218 virCapsPtr caps
= NULL
;
220 if (!(caps
= testLXCCapsInit())) {
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
);
233 virObjectUnref(caps
);
236 #endif /* WITH_LXC */
243 if (virTestRun("virCapabilitiesGetCpusForNodemask",
244 test_virCapabilitiesGetCpusForNodemask
, NULL
) < 0)
247 if (virTestRun("virCapsDomainDataLookupQEMU",
248 test_virCapsDomainDataLookupQEMU
, NULL
) < 0)
252 if (virTestRun("virCapsDomainDataLookupLXC",
253 test_virCapsDomainDataLookupLXC
, NULL
) < 0)
255 #endif /* WITH_LXC */
260 VIR_TEST_MAIN(mymain
)