2011-10-18 19:16:01 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#ifdef WITH_QEMU
|
|
|
|
|
|
|
|
# include "internal.h"
|
|
|
|
# include "testutils.h"
|
|
|
|
# include "qemu/qemu_capabilities.h"
|
|
|
|
# include "qemu/qemu_command.h"
|
|
|
|
# include "qemu/qemu_domain.h"
|
|
|
|
# include "datatypes.h"
|
|
|
|
# include "cpu/cpu_map.h"
|
|
|
|
|
|
|
|
# include "testutilsqemu.h"
|
|
|
|
|
|
|
|
static const char *abs_top_srcdir;
|
|
|
|
static struct qemud_driver driver;
|
|
|
|
|
|
|
|
static int testCompareXMLToArgvFiles(const char *xml,
|
|
|
|
const char *cmdline,
|
|
|
|
virBitmapPtr extraFlags,
|
|
|
|
const char *migrateFrom,
|
|
|
|
int migrateFd,
|
|
|
|
bool json,
|
|
|
|
bool expectError)
|
|
|
|
{
|
|
|
|
char *expectargv = NULL;
|
|
|
|
int len;
|
|
|
|
char *actualargv = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainChrSourceDef monitor_chr;
|
|
|
|
virConnectPtr conn;
|
|
|
|
char *log = NULL;
|
|
|
|
char *emulator = NULL;
|
|
|
|
virCommandPtr cmd = NULL;
|
|
|
|
|
|
|
|
if (!(conn = virGetConnect()))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
len = virtTestLoadFile(cmdline, &expectargv);
|
|
|
|
if (len < 0)
|
|
|
|
goto fail;
|
|
|
|
if (len && expectargv[len - 1] == '\n')
|
|
|
|
expectargv[len - 1] = '\0';
|
|
|
|
|
|
|
|
if (!(vmdef = virDomainDefParseFile(driver.caps, xml,
|
|
|
|
QEMU_EXPECTED_VIRT_TYPES,
|
|
|
|
VIR_DOMAIN_XML_INACTIVE)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For test purposes, we may want to fake emulator's output by providing
|
|
|
|
* our own script instead of a real emulator. For this to work we need to
|
|
|
|
* specify a relative path in <emulator/> element, which, however, is not
|
|
|
|
* allowed by RelaxNG schema for domain XML. To work around it we add an
|
|
|
|
* extra '/' at the beginning of relative emulator path so that it looks
|
|
|
|
* like, e.g., "/./qemu.sh" or "/../emulator/qemu.sh" instead of
|
|
|
|
* "./qemu.sh" or "../emulator/qemu.sh" respectively. The following code
|
|
|
|
* detects such paths, strips the extra '/' and makes the path absolute.
|
|
|
|
*/
|
|
|
|
if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
|
|
|
|
if (!(emulator = strdup(vmdef->emulator + 1)))
|
|
|
|
goto fail;
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(vmdef->emulator);
|
2011-10-18 19:16:01 +00:00
|
|
|
vmdef->emulator = NULL;
|
|
|
|
if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
|
|
|
|
abs_srcdir, emulator) < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuCapsGet(extraFlags, QEMU_CAPS_DOMID))
|
|
|
|
vmdef->id = 6;
|
|
|
|
else
|
|
|
|
vmdef->id = -1;
|
|
|
|
|
|
|
|
memset(&monitor_chr, 0, sizeof(monitor_chr));
|
|
|
|
monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
|
|
|
monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
|
|
|
|
monitor_chr.data.nix.listen = true;
|
|
|
|
|
|
|
|
qemuCapsSetList(extraFlags,
|
|
|
|
QEMU_CAPS_VNC_COLON,
|
|
|
|
QEMU_CAPS_NO_REBOOT,
|
2011-12-20 01:08:29 +00:00
|
|
|
QEMU_CAPS_NO_ACPI,
|
2011-10-18 19:16:01 +00:00
|
|
|
QEMU_CAPS_LAST);
|
|
|
|
|
|
|
|
if (qemudCanonicalizeMachine(&driver, vmdef) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2012-06-29 15:02:04 +00:00
|
|
|
if (qemuCapsGet(extraFlags, QEMU_CAPS_DEVICE))
|
|
|
|
qemuDomainAssignAddresses(vmdef, extraFlags, NULL);
|
2011-10-18 19:16:01 +00:00
|
|
|
|
2012-02-02 23:16:43 +00:00
|
|
|
log = virtTestLogContentAndReset();
|
|
|
|
VIR_FREE(log);
|
2011-10-18 19:16:01 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
|
|
|
/* We do not call qemuCapsExtractVersionInfo() before calling
|
|
|
|
* qemuBuildCommandLine(), so we should set QEMU_CAPS_PCI_MULTIBUS for
|
|
|
|
* x86_64 and i686 architectures here.
|
|
|
|
*/
|
|
|
|
if (STREQLEN(vmdef->os.arch, "x86_64", 6) ||
|
|
|
|
STREQLEN(vmdef->os.arch, "i686", 4)) {
|
|
|
|
qemuCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS);
|
|
|
|
}
|
|
|
|
|
2011-10-20 12:45:12 +00:00
|
|
|
if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2011-10-18 19:16:01 +00:00
|
|
|
if (!(cmd = qemuBuildCommandLine(conn, &driver,
|
|
|
|
vmdef, &monitor_chr, json, extraFlags,
|
|
|
|
migrateFrom, migrateFd, NULL,
|
Rename Macvtap management APIs
In preparation for code re-organization, rename the Macvtap
management APIs to have the following patterns
virNetDevMacVLanXXXXX - macvlan/macvtap interface management
virNetDevVPortProfileXXXX - virtual port profile management
* src/util/macvtap.c, src/util/macvtap.h: Rename APIs
* src/conf/domain_conf.c, src/network/bridge_driver.c,
src/qemu/qemu_command.c, src/qemu/qemu_command.h,
src/qemu/qemu_driver.c, src/qemu/qemu_hotplug.c,
src/qemu/qemu_migration.c, src/qemu/qemu_process.c,
src/qemu/qemu_process.h: Update for renamed APIs
2011-11-02 16:51:01 +00:00
|
|
|
VIR_NETDEV_VPORT_PROFILE_OP_NO_OP)))
|
2011-10-18 19:16:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!!virGetLastError() != expectError) {
|
|
|
|
if (virTestGetDebug() && (log = virtTestLogContentAndReset()))
|
|
|
|
fprintf(stderr, "\n%s", log);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectError) {
|
|
|
|
/* need to suppress the errors */
|
|
|
|
virResetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(actualargv = virCommandToString(cmd)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (emulator) {
|
|
|
|
/* Skip the abs_srcdir portion of replacement emulator. */
|
|
|
|
char *start_skip = strstr(actualargv, abs_srcdir);
|
|
|
|
char *end_skip = strstr(actualargv, emulator);
|
|
|
|
if (!start_skip || !end_skip)
|
|
|
|
goto fail;
|
|
|
|
memmove(start_skip, end_skip, strlen(end_skip) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ(expectargv, actualargv)) {
|
|
|
|
virtTestDifference(stderr, expectargv, actualargv);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(log);
|
|
|
|
VIR_FREE(emulator);
|
|
|
|
VIR_FREE(expectargv);
|
|
|
|
VIR_FREE(actualargv);
|
2011-10-18 19:16:01 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
virDomainDefFree(vmdef);
|
Convert public datatypes to inherit from virObject
This converts the following public API datatypes to use the
virObject infrastructure:
virConnectPtr
virDomainPtr
virDomainSnapshotPtr
virInterfacePtr
virNetworkPtr
virNodeDevicePtr
virNWFilterPtr
virSecretPtr
virStreamPtr
virStorageVolPtr
virStoragePoolPtr
The code is significantly simplified, since the mutex in the
virConnectPtr object now only needs to be held when accessing
the per-connection virError object instance. All other operations
are completely lock free.
* src/datatypes.c, src/datatypes.h, src/libvirt.c: Convert
public datatypes to use virObject
* src/conf/domain_event.c, src/phyp/phyp_driver.c,
src/qemu/qemu_command.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c, src/storage/storage_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xend_internal.c,
tests/qemuxml2argvtest.c, tests/qemuxmlnstest.c,
tests/sexpr2xmltest.c, tests/xmconfigtest.c: Convert
to use virObjectUnref/virObjectRef
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-07-31 16:55:36 +00:00
|
|
|
virObjectUnref(conn);
|
2011-10-18 19:16:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
virBitmapPtr extraFlags;
|
|
|
|
const char *migrateFrom;
|
|
|
|
int migrateFd;
|
|
|
|
bool json;
|
|
|
|
bool expectError;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char *xml = NULL;
|
|
|
|
char *args = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/qemuxmlnsdata/qemuxmlns-%s.xml",
|
|
|
|
abs_srcdir, info->name) < 0 ||
|
|
|
|
virAsprintf(&args, "%s/qemuxmlnsdata/qemuxmlns-%s.args",
|
|
|
|
abs_srcdir, info->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = testCompareXMLToArgvFiles(xml, args, info->extraFlags,
|
|
|
|
info->migrateFrom, info->migrateFd,
|
|
|
|
info->json, info->expectError);
|
|
|
|
|
|
|
|
cleanup:
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(args);
|
2011-10-18 19:16:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char *map = NULL;
|
|
|
|
bool json = false;
|
|
|
|
|
|
|
|
abs_top_srcdir = getenv("abs_top_srcdir");
|
|
|
|
if (!abs_top_srcdir)
|
|
|
|
abs_top_srcdir = "..";
|
|
|
|
|
|
|
|
if ((driver.caps = testQemuCapsInit()) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
if ((driver.stateDir = strdup("/nowhere")) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
if ((driver.hugetlbfs_mount = strdup("/dev/hugepages")) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
if ((driver.hugepage_path = strdup("/dev/hugepages/libvirt/qemu")) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
driver.spiceTLS = 1;
|
|
|
|
if (!(driver.spiceTLSx509certdir = strdup("/etc/pki/libvirt-spice")))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
if (!(driver.spicePassword = strdup("123456")))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
|
|
|
|
cpuMapOverride(map) < 0) {
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(map);
|
2011-10-18 19:16:01 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info = { \
|
|
|
|
name, NULL, migrateFrom, migrateFd, json, expectError \
|
|
|
|
}; \
|
|
|
|
if (!(info.extraFlags = qemuCapsNew())) \
|
|
|
|
return EXIT_FAILURE; \
|
|
|
|
qemuCapsSetList(info.extraFlags, __VA_ARGS__, QEMU_CAPS_LAST); \
|
|
|
|
if (virtTestRun("QEMU XML-2-ARGV " name, \
|
|
|
|
1, testCompareXMLToArgvHelper, &info) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
qemuCapsFree(info.extraFlags); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
# define DO_TEST(name, expectError, ...) \
|
|
|
|
DO_TEST_FULL(name, NULL, -1, expectError, __VA_ARGS__)
|
|
|
|
|
|
|
|
# define NONE QEMU_CAPS_LAST
|
|
|
|
|
|
|
|
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
|
|
|
|
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
|
|
|
|
* values for these envvars */
|
|
|
|
setenv("PATH", "/bin", 1);
|
|
|
|
setenv("USER", "test", 1);
|
|
|
|
setenv("LOGNAME", "test", 1);
|
|
|
|
setenv("HOME", "/home/test", 1);
|
|
|
|
unsetenv("TMPDIR");
|
|
|
|
unsetenv("LD_PRELOAD");
|
|
|
|
unsetenv("LD_LIBRARY_PATH");
|
|
|
|
unsetenv("QEMU_AUDIO_DRV");
|
|
|
|
unsetenv("SDL_AUDIODRIVER");
|
|
|
|
|
|
|
|
DO_TEST("qemu-ns-domain", false, NONE);
|
|
|
|
DO_TEST("qemu-ns-domain-ns0", false, NONE);
|
|
|
|
DO_TEST("qemu-ns-domain-commandline", false, NONE);
|
|
|
|
DO_TEST("qemu-ns-domain-commandline-ns0", false, NONE);
|
|
|
|
DO_TEST("qemu-ns-commandline", false, NONE);
|
|
|
|
DO_TEST("qemu-ns-commandline-ns0", false, NONE);
|
|
|
|
DO_TEST("qemu-ns-commandline-ns1", false, NONE);
|
|
|
|
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(driver.stateDir);
|
2011-10-18 19:16:01 +00:00
|
|
|
virCapabilitiesFree(driver.caps);
|
2012-02-02 23:16:43 +00:00
|
|
|
VIR_FREE(map);
|
2011-10-18 19:16:01 +00:00
|
|
|
|
2012-03-22 11:33:35 +00:00
|
|
|
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2011-10-18 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|
|
|
|
|
|
|
|
#else
|
2011-12-01 20:47:34 +00:00
|
|
|
# include "testutils.h"
|
2011-10-18 19:16:01 +00:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_QEMU */
|