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>
|
|
|
|
|
2013-04-16 13:41:44 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
|
2011-10-18 19:16:01 +00:00
|
|
|
#ifdef WITH_QEMU
|
|
|
|
|
|
|
|
# include "internal.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"
|
2013-04-03 10:36:23 +00:00
|
|
|
# include "virstring.h"
|
2011-10-18 19:16:01 +00:00
|
|
|
|
2013-05-03 12:52:21 +00:00
|
|
|
# define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2011-10-18 19:16:01 +00:00
|
|
|
static const char *abs_top_srcdir;
|
2012-11-28 16:43:10 +00:00
|
|
|
static virQEMUDriver driver;
|
2011-10-18 19:16:01 +00:00
|
|
|
|
|
|
|
static int testCompareXMLToArgvFiles(const char *xml,
|
|
|
|
const char *cmdline,
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr extraFlags,
|
2011-10-18 19:16:01 +00:00
|
|
|
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';
|
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
|
2011-10-18 19:16:01 +00:00
|
|
|
QEMU_EXPECTED_VIRT_TYPES,
|
2014-11-18 16:44:00 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2011-10-18 19:16:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
2014-01-10 17:18:03 +00:00
|
|
|
if (!virDomainDefCheckABIStability(vmdef, vmdef)) {
|
|
|
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-10-18 19:16:01 +00:00
|
|
|
/*
|
|
|
|
* 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, "/.")) {
|
2013-05-03 12:52:21 +00:00
|
|
|
if (VIR_STRDUP(emulator, vmdef->emulator + 1) < 0)
|
2011-10-18 19:16:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-02-18 15:33:50 +00:00
|
|
|
vmdef->id = -1;
|
2011-10-18 19:16:01 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSetList(extraFlags,
|
|
|
|
QEMU_CAPS_VNC_COLON,
|
|
|
|
QEMU_CAPS_NO_REBOOT,
|
|
|
|
QEMU_CAPS_NO_ACPI,
|
|
|
|
QEMU_CAPS_LAST);
|
2011-10-18 19:16:01 +00:00
|
|
|
|
2013-02-01 13:48:58 +00:00
|
|
|
if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DEVICE))
|
2012-06-29 15:02:04 +00:00
|
|
|
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();
|
|
|
|
|
2012-12-18 19:32:23 +00:00
|
|
|
if (vmdef->os.arch == VIR_ARCH_X86_64 ||
|
|
|
|
vmdef->os.arch == VIR_ARCH_I686) {
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSet(extraFlags, QEMU_CAPS_PCI_MULTIBUS);
|
2011-10-18 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2013-05-17 10:34:24 +00:00
|
|
|
VIR_NETDEV_VPORT_PROFILE_OP_NO_OP,
|
2015-01-16 11:25:50 +00:00
|
|
|
&testCallbacks, false, false, NULL,
|
2015-02-20 19:52:37 +00:00
|
|
|
NULL, NULL)))
|
2011-10-18 19:16:01 +00:00
|
|
|
goto fail;
|
|
|
|
|
Introduce new OOM testing support
The previous OOM testing support would re-run the entire "main"
method each iteration, failing a different malloc each time.
When a test suite has 'n' allocations, the number of repeats
requires is (n * (n + 1) ) / 2. This gets very large, very
quickly.
This new OOM testing support instead integrates at the
virtTestRun level, so each individual test case gets repeated,
instead of the entire test suite. This means the values of
'n' are orders of magnitude smaller.
The simple usage is
$ VIR_TEST_OOM=1 ./qemuxml2argvtest
...
29) QEMU XML-2-ARGV clock-utc ... OK
Test OOM for nalloc=36 .................................... OK
30) QEMU XML-2-ARGV clock-localtime ... OK
Test OOM for nalloc=36 .................................... OK
31) QEMU XML-2-ARGV clock-france ... OK
Test OOM for nalloc=38 ...................................... OK
...
the second lines reports how many mallocs have to be failed, and thus
how many repeats of the test will be run.
If it crashes, then running under valgrind will often show the problem
$ VIR_TEST_OOM=1 ../run valgrind ./qemuxml2argvtest
When debugging problems it is also helpful to select an individual
test case
$ VIR_TEST_RANGE=30 VIR_TEST_OOM=1 ../run valgrind ./qemuxml2argvtest
When things get really tricky, it is possible to request that just
specific allocs are failed. eg to fail allocs 5 -> 12, use
$ VIR_TEST_RANGE=30 VIR_TEST_OOM=1:5-12 ../run valgrind ./qemuxml2argvtest
In the worse case, you might want to know the stack trace of the
alloc which was failed then VIR_TEST_OOM_TRACE can be set. If it
is set to 1 then it will only print if it thinks a mistake happened.
This is often not reliable, so setting it to 2 will make it print
the stack trace for every alloc that is failed.
$ VIR_TEST_OOM_TRACE=2 VIR_TEST_RANGE=30 VIR_TEST_OOM=1:5-5 ../run valgrind ./qemuxml2argvtest
30) QEMU XML-2-ARGV clock-localtime ... OK
Test OOM for nalloc=36 !virAllocN
/home/berrange/src/virt/libvirt/src/util/viralloc.c:180
virHashCreateFull
/home/berrange/src/virt/libvirt/src/util/virhash.c:144
virDomainDefParseXML
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11745
virDomainDefParseNode
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12646
virDomainDefParse
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12590
testCompareXMLToArgvFiles
/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:106
virtTestRun
/home/berrange/src/virt/libvirt/tests/testutils.c:250
mymain
/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:418 (discriminator 2)
virtTestMain
/home/berrange/src/virt/libvirt/tests/testutils.c:750
??
??:0
_start
??:?
FAILED
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-09-23 13:21:52 +00:00
|
|
|
if (!virtTestOOMActive()) {
|
|
|
|
if (!!virGetLastError() != expectError) {
|
|
|
|
if (virTestGetDebug() && (log = virtTestLogContentAndReset()))
|
|
|
|
fprintf(stderr, "\n%s", log);
|
|
|
|
goto fail;
|
|
|
|
}
|
2011-10-18 19:16:01 +00:00
|
|
|
|
Introduce new OOM testing support
The previous OOM testing support would re-run the entire "main"
method each iteration, failing a different malloc each time.
When a test suite has 'n' allocations, the number of repeats
requires is (n * (n + 1) ) / 2. This gets very large, very
quickly.
This new OOM testing support instead integrates at the
virtTestRun level, so each individual test case gets repeated,
instead of the entire test suite. This means the values of
'n' are orders of magnitude smaller.
The simple usage is
$ VIR_TEST_OOM=1 ./qemuxml2argvtest
...
29) QEMU XML-2-ARGV clock-utc ... OK
Test OOM for nalloc=36 .................................... OK
30) QEMU XML-2-ARGV clock-localtime ... OK
Test OOM for nalloc=36 .................................... OK
31) QEMU XML-2-ARGV clock-france ... OK
Test OOM for nalloc=38 ...................................... OK
...
the second lines reports how many mallocs have to be failed, and thus
how many repeats of the test will be run.
If it crashes, then running under valgrind will often show the problem
$ VIR_TEST_OOM=1 ../run valgrind ./qemuxml2argvtest
When debugging problems it is also helpful to select an individual
test case
$ VIR_TEST_RANGE=30 VIR_TEST_OOM=1 ../run valgrind ./qemuxml2argvtest
When things get really tricky, it is possible to request that just
specific allocs are failed. eg to fail allocs 5 -> 12, use
$ VIR_TEST_RANGE=30 VIR_TEST_OOM=1:5-12 ../run valgrind ./qemuxml2argvtest
In the worse case, you might want to know the stack trace of the
alloc which was failed then VIR_TEST_OOM_TRACE can be set. If it
is set to 1 then it will only print if it thinks a mistake happened.
This is often not reliable, so setting it to 2 will make it print
the stack trace for every alloc that is failed.
$ VIR_TEST_OOM_TRACE=2 VIR_TEST_RANGE=30 VIR_TEST_OOM=1:5-5 ../run valgrind ./qemuxml2argvtest
30) QEMU XML-2-ARGV clock-localtime ... OK
Test OOM for nalloc=36 !virAllocN
/home/berrange/src/virt/libvirt/src/util/viralloc.c:180
virHashCreateFull
/home/berrange/src/virt/libvirt/src/util/virhash.c:144
virDomainDefParseXML
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11745
virDomainDefParseNode
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12646
virDomainDefParse
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12590
testCompareXMLToArgvFiles
/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:106
virtTestRun
/home/berrange/src/virt/libvirt/tests/testutils.c:250
mymain
/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:418 (discriminator 2)
virtTestMain
/home/berrange/src/virt/libvirt/tests/testutils.c:750
??
??:0
_start
??:?
FAILED
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-09-23 13:21:52 +00:00
|
|
|
if (expectError) {
|
|
|
|
/* need to suppress the errors */
|
|
|
|
virResetLastError();
|
|
|
|
}
|
2011-10-18 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsPtr extraFlags;
|
2011-10-18 19:16:01 +00:00
|
|
|
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);
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
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;
|
|
|
|
bool json = false;
|
|
|
|
|
|
|
|
abs_top_srcdir = getenv("abs_top_srcdir");
|
|
|
|
if (!abs_top_srcdir)
|
2013-11-27 21:31:53 +00:00
|
|
|
abs_top_srcdir = abs_srcdir "/..";
|
2011-10-18 19:16:01 +00:00
|
|
|
|
2015-01-26 16:09:36 +00:00
|
|
|
if (!(driver.config = virQEMUDriverConfigNew(false)))
|
|
|
|
return EXIT_FAILURE;
|
2011-10-18 19:16:01 +00:00
|
|
|
if ((driver.caps = testQemuCapsInit()) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
2013-03-11 09:24:29 +00:00
|
|
|
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
|
2013-03-05 15:17:24 +00:00
|
|
|
return EXIT_FAILURE;
|
2011-10-18 19:16:01 +00:00
|
|
|
|
|
|
|
# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info = { \
|
|
|
|
name, NULL, migrateFrom, migrateFd, json, expectError \
|
|
|
|
}; \
|
2013-02-01 13:48:58 +00:00
|
|
|
if (!(info.extraFlags = virQEMUCapsNew())) \
|
2011-10-18 19:16:01 +00:00
|
|
|
return EXIT_FAILURE; \
|
2013-02-01 13:48:58 +00:00
|
|
|
virQEMUCapsSetList(info.extraFlags, __VA_ARGS__, QEMU_CAPS_LAST);\
|
2011-10-18 19:16:01 +00:00
|
|
|
if (virtTestRun("QEMU XML-2-ARGV " name, \
|
2013-09-20 18:13:35 +00:00
|
|
|
testCompareXMLToArgvHelper, &info) < 0) \
|
2011-10-18 19:16:01 +00:00
|
|
|
ret = -1; \
|
2012-08-20 16:44:14 +00:00
|
|
|
virObjectUnref(info.extraFlags); \
|
2011-10-18 19:16:01 +00:00
|
|
|
} 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);
|
|
|
|
|
2013-01-10 21:03:14 +00:00
|
|
|
virObjectUnref(driver.config);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(driver.caps);
|
2013-03-31 18:03:42 +00:00
|
|
|
virObjectUnref(driver.xmlopt);
|
2011-10-18 19:16:01 +00:00
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2011-10-18 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_QEMU */
|