bhyve: add xml2args unittest

At this point unittest covers 4 basic cases:

 - minimal working XML for bhyve
 - same as above, but with virtio disk
 - ACPI and APIC args test
 - MAC address test
This commit is contained in:
Roman Bogorodskiy 2014-03-26 20:53:49 +04:00
parent a1bd8d2546
commit 1994d2dddb
11 changed files with 323 additions and 0 deletions

View File

@ -64,6 +64,7 @@ LDADDS = \
../src/libvirt.la
EXTRA_DIST = \
bhyvexml2argvdata \
capabilityschemadata \
capabilityschematest \
commanddata \
@ -233,6 +234,10 @@ if WITH_VMWARE
test_programs += vmwarevertest
endif WITH_VMWARE
if WITH_BHYVE
test_programs += bhyvexml2argvtest
endif WITH_BHYVE
if WITH_CIL
test_programs += objectlocking
endif WITH_CIL
@ -354,6 +359,10 @@ test_libraries += libqemumonitortestutils.la \
$(NULL)
endif WITH_QEMU
if WITH_BHYVE
test_libraries += bhyvexml2argvmock.la
endif WITH_BHYVE
if WITH_DBUS
test_libraries += virsystemdmock.la
endif WITH_DBUS
@ -610,6 +619,23 @@ else ! WITH_VMWARE
EXTRA_DIST += vmwarevertest.c
endif ! WITH_VMWARE
if WITH_BHYVE
bhyvexml2argvmock_la_SOURCES = \
bhyvexml2argvmock.c
bhyvexml2argvmock_la_CFLAGS = $(AM_CFLAGS)
bhyvexml2argvmock_la_LDFLAGS = -module -avoid-version \
-rpath /evil/libtool/hack/to/force/shared/lib/creation
bhyve_LDADDS = ../src/libvirt_driver_bhyve_impl.la
bhyve_LDADDS += $(LDADDS)
bhyvexml2argvtest_SOURCES = \
bhyvexml2argvtest.c \
testutils.c testutils.h
bhyvexml2argvtest_LDADD = $(bhyve_LDADDS)
else ! WITH_BHYVE
EXTRA_DIST += bhyvexml2argvtest.c bhyvexml2argvmock.c
endif ! WITH_BHYVE
networkxml2xmltest_SOURCES = \
networkxml2xmltest.c \
testutils.c testutils.h

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyve -c 1 -m 214 -A -I -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve

View File

@ -0,0 +1,24 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
<memory>219136</memory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
</os>
<features>
<apic/>
<acpi/>
</features>
<devices>
<disk type='file'>
<driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/>
</disk>
<interface type='bridge'>
<model type='virtio'/>
<source bridge="virbr0"/>
</interface>
</devices>
</domain>

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve

View File

@ -0,0 +1,20 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
<memory>219136</memory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
</os>
<devices>
<disk type='file'>
<driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/>
</disk>
<interface type='bridge'>
<model type='virtio'/>
<source bridge="virbr0"/>
</interface>
</devices>
</domain>

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
-s 2:0,virtio-blk,/tmp/freebsd.img bhyve

View File

@ -0,0 +1,20 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
<memory>219136</memory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
</os>
<devices>
<disk type='file'>
<driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/>
<target dev='vda' bus='virtio'/>
</disk>
<interface type='bridge'>
<model type='virtio'/>
<source bridge="virbr0"/>
</interface>
</devices>
</domain>

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
-s 1:0,virtio-net,faketapdev,mac=52:54:00:22:ee:11 \
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve

View File

@ -0,0 +1,21 @@
<domain type='bhyve'>
<name>bhyve</name>
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
<memory>219136</memory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
</os>
<devices>
<disk type='file'>
<driver name='file' type='raw'/>
<source file='/tmp/freebsd.img'/>
<target dev='hda' bus='sata'/>
</disk>
<interface type='bridge'>
<mac address="52:54:00:22:ee:11"/>
<model type='virtio'/>
<source bridge="virbr0"/>
</interface>
</devices>
</domain>

49
tests/bhyvexml2argvmock.c Normal file
View File

@ -0,0 +1,49 @@
#include <config.h>
#include "virstring.h"
#include "virnetdev.h"
#include "virnetdevtap.h"
#include "internal.h"
#define VIR_FROM_THIS VIR_FROM_BHYVE
void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
virMacAddrPtr addr)
{
addr->addr[0] = prefix[0];
addr->addr[1] = prefix[1];
addr->addr[2] = prefix[2];
addr->addr[3] = 0;
addr->addr[4] = 0;
addr->addr[5] = 0;
}
int virNetDevTapCreateInBridgePort(const char *brname ATTRIBUTE_UNUSED,
char **ifname,
const virMacAddr *macaddr ATTRIBUTE_UNUSED,
const unsigned char *vmuuid ATTRIBUTE_UNUSED,
int *tapfd ATTRIBUTE_UNUSED,
int tapfdSize ATTRIBUTE_UNUSED,
virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
virNetDevVlanPtr virtVlan ATTRIBUTE_UNUSED,
unsigned int fakeflags ATTRIBUTE_UNUSED)
{
if (VIR_STRDUP(*ifname, "vnet0") < 0)
return -1;
return 0;
}
char *virNetDevTapGetRealDeviceName(char *name ATTRIBUTE_UNUSED)
{
char *fakename;
if (VIR_STRDUP(fakename, "faketapdev") < 0)
return NULL;
return fakename;
}
int virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED,
bool online ATTRIBUTE_UNUSED)
{
return 0;
}

151
tests/bhyvexml2argvtest.c Normal file
View File

@ -0,0 +1,151 @@
#include <config.h>
#include "testutils.h"
#ifdef WITH_BHYVE
# include "datatypes.h"
# include "bhyve/bhyve_utils.h"
# include "bhyve/bhyve_command.h"
# define VIR_FROM_THIS VIR_FROM_BHYVE
static bhyveConn driver;
static virCapsPtr
testBhyveBuildCapabilities(void)
{
virCapsPtr caps;
virCapsGuestPtr guest;
if ((caps = virCapabilitiesNew(virArchFromHost(),
0, 0)) == NULL)
return NULL;
if ((guest = virCapabilitiesAddGuest(caps, "hvm",
VIR_ARCH_X86_64,
"bhyve",
NULL, 0, NULL)) == NULL)
goto error;
if (virCapabilitiesAddGuestDomain(guest,
"bhyve", NULL, NULL, 0, NULL) == NULL)
goto error;
return caps;
error:
virObjectUnref(caps);
return NULL;
}
static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdline)
{
char *expectargv = NULL;
int len;
char *actualargv = NULL;
virDomainDefPtr vmdef = NULL;
virDomainObj vm;
virCommandPtr cmd = NULL;
int ret = -1;
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
1 << VIR_DOMAIN_VIRT_BHYVE,
VIR_DOMAIN_XML_INACTIVE)))
goto out;
vm.def = vmdef;
if (!(cmd = virBhyveProcessBuildBhyveCmd(&driver, &vm)))
goto out;
if (!(actualargv = virCommandToString(cmd)))
goto out;
len = virtTestLoadFile(cmdline, &expectargv);
if (len < 0)
goto out;
if (len && expectargv[len - 1] == '\n')
expectargv[len - 1] = '\0';
if (STRNEQ(expectargv, actualargv)) {
virtTestDifference(stderr, expectargv, actualargv);
goto out;
}
ret = 0;
out:
VIR_FREE(expectargv);
VIR_FREE(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
return ret;
}
static int
testCompareXMLToArgvHelper(const void *data)
{
int ret = -1;
const char *name = data;
char *xml = NULL;
char *args = NULL;
if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
abs_srcdir, name) < 0 ||
virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
abs_srcdir, name) < 0)
goto cleanup;
ret = testCompareXMLToArgvFiles(xml, args);
cleanup:
VIR_FREE(xml);
VIR_FREE(args);
return ret;
}
static int
mymain(void)
{
int ret = 0;
if ((driver.caps = testBhyveBuildCapabilities()) == NULL)
return EXIT_FAILURE;
if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)) == NULL)
return EXIT_FAILURE;
# define DO_TEST(name) \
do { \
if (virtTestRun("BHYVE XML-2-ARGV " name, \
testCompareXMLToArgvHelper, name) < 0) \
ret = -1; \
} while (0)
DO_TEST("base");
DO_TEST("acpiapic");
DO_TEST("disk-virtio");
DO_TEST("macaddr");
virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyvexml2argvmock.so")
#else
int main(void)
{
return EXIT_AM_SKIP;
}
#endif /* WITH_BHYVE */