提交 086f37e9 编写于 作者: M Michal Privoznik

tests: Avoid use of virQEMUDriverCreateXMLConf(NULL)

We use the function to create a virDomainXMLOption object that is
required for some functions. However, we don't pass the driver
pointer to the object anywhere - rather than pass NULL. This
causes trouble later when parsing a domain XML and calling post
parse callbacks:

  Program received signal SIGSEGV, Segmentation fault.
  0x000000000043fa3e in qemuDomainDefPostParse (def=0x7d36c0, caps=0x7caf10, opaque=0x0) at qemu/qemu_domain.c:1043
  1043        qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator);
  (gdb) bt
  #0  0x000000000043fa3e in qemuDomainDefPostParse (def=0x7d36c0, caps=0x7caf10, opaque=0x0) at qemu/qemu_domain.c:1043
  #1  0x00007ffff2928bf9 in virDomainDefPostParse (def=0x7d36c0, caps=0x7caf10, xmlopt=0x7c82c0) at conf/domain_conf.c:4269
  #2  0x00007ffff294de04 in virDomainDefParseXML (xml=0x7da8c0, root=0x7dab80, ctxt=0x7da980, caps=0x7caf10, xmlopt=0x7c82c0, flags=0) at conf/domain_conf.c:16400
  #3  0x00007ffff294e5b5 in virDomainDefParseNode (xml=0x7da8c0, root=0x7dab80, caps=0x7caf10, xmlopt=0x7c82c0, flags=0) at conf/domain_conf.c:16582
  #4  0x00007ffff294e424 in virDomainDefParse (xmlStr=0x0, filename=0x7c7ef0 "/home/zippy/work/libvirt/libvirt.git/tests/securityselinuxlabeldata/disks.xml", caps=0x7caf10, xmlopt=0x7c82c0, flags=0) at conf/domain_conf.c:16529
  #5  0x00007ffff294e4b2 in virDomainDefParseFile (filename=0x7c7ef0 "/home/zippy/work/libvirt/libvirt.git/tests/securityselinuxlabeldata/disks.xml", caps=0x7caf10, xmlopt=0x7c82c0, flags=0) at conf/domain_conf.c:16553
  #6  0x00000000004303ca in testSELinuxLoadDef (testname=0x53c929 "disks") at securityselinuxlabeltest.c:192
  #7  0x00000000004309e8 in testSELinuxLabeling (opaque=0x53c929) at securityselinuxlabeltest.c:313
  #8  0x0000000000431207 in virtTestRun (title=0x53c92f "Labelling \"disks\"", body=0x430964 <testSELinuxLabeling>, data=0x53c929) at testutils.c:211
  #9  0x0000000000430c5d in mymain () at securityselinuxlabeltest.c:373
  #10 0x00000000004325c2 in virtTestMain (argc=1, argv=0x7fffffffd7e8, func=0x430b4a <mymain>) at testutils.c:863
  #11 0x0000000000430deb in main (argc=1, argv=0x7fffffffd7e8) at securityselinuxlabeltest.c:381
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 b1dc59b3
......@@ -160,7 +160,7 @@ static int
mymain(void)
{
int ret = 0;
virDomainXMLOptionPtr xmlopt;
virQEMUDriver driver;
testQemuData data;
#if !WITH_YAJL
......@@ -169,12 +169,12 @@ mymain(void)
#endif
if (virThreadInitialize() < 0 ||
!(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
virEventRegisterDefaultImpl();
data.xmlopt = xmlopt;
data.xmlopt = driver.xmlopt;
#define DO_TEST(name) \
do { \
......@@ -191,7 +191,8 @@ mymain(void)
DO_TEST("caps_1.6.50-1");
DO_TEST("caps_2.1.1-1");
virObjectUnref(xmlopt);
qemuTestDriverFree(&driver);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
......@@ -2238,7 +2238,7 @@ static int
mymain(void)
{
int ret = 0;
virDomainXMLOptionPtr xmlopt;
virQEMUDriver driver;
testQemuMonitorJSONSimpleFuncData simpleFunc;
#if !WITH_YAJL
......@@ -2247,29 +2247,30 @@ mymain(void)
#endif
if (virThreadInitialize() < 0 ||
!(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
virEventRegisterDefaultImpl();
#define DO_TEST(name) \
if (virtTestRun(# name, testQemuMonitorJSON ## name, xmlopt) < 0) \
#define DO_TEST(name) \
if (virtTestRun(# name, testQemuMonitorJSON ## name, driver.xmlopt) < 0) \
ret = -1
#define DO_TEST_SIMPLE(CMD, FNC, ...) \
simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.cmd = CMD, .func = FNC, \
.xmlopt = xmlopt, __VA_ARGS__ }; \
.xmlopt = driver.xmlopt, __VA_ARGS__ }; \
if (virtTestRun(# FNC, testQemuMonitorJSONSimpleFunc, &simpleFunc) < 0) \
ret = -1
#define DO_TEST_GEN(name, ...) \
simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.xmlopt = xmlopt, __VA_ARGS__ }; \
if (virtTestRun(# name, testQemuMonitorJSON ## name, &simpleFunc) < 0) \
simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.xmlopt = driver.xmlopt, \
__VA_ARGS__ }; \
if (virtTestRun(# name, testQemuMonitorJSON ## name, &simpleFunc) < 0) \
ret = -1
#define DO_TEST_CPU_DATA(name) \
do { \
struct testCPUData data = { name, xmlopt }; \
struct testCPUData data = { name, driver.xmlopt }; \
const char *label = "GetCPUData(" name ")"; \
if (virtTestRun(label, testQemuMonitorJSONGetCPUData, &data) < 0) \
ret = -1; \
......@@ -2347,7 +2348,7 @@ mymain(void)
DO_TEST_CPU_DATA("host");
DO_TEST_CPU_DATA("full");
virObjectUnref(xmlopt);
qemuTestDriverFree(&driver);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
......@@ -14,6 +14,7 @@
# include "qemu/qemu_monitor.h"
# include "qemu/qemu_monitor_text.h"
# include "qemumonitortestutils.h"
# include "testutilsqemu.h"
# define VIR_FROM_THIS VIR_FROM_NONE
......@@ -164,11 +165,11 @@ testMonitorTextBlockInfo(const void *opaque)
static int
mymain(void)
{
virDomainXMLOptionPtr xmlopt;
virQEMUDriver driver;
int result = 0;
if (virThreadInitialize() < 0 ||
!(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
virEventRegisterDefaultImpl();
......@@ -176,7 +177,7 @@ mymain(void)
# define DO_TEST(_name) \
do { \
if (virtTestRun("qemu monitor "#_name, test##_name, \
xmlopt) < 0) { \
driver.xmlopt) < 0) { \
result = -1; \
} \
} while (0)
......@@ -185,7 +186,7 @@ mymain(void)
DO_TEST(UnescapeArg);
DO_TEST(MonitorTextBlockInfo);
virObjectUnref(xmlopt);
qemuTestDriverFree(&driver);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
......@@ -46,7 +46,7 @@
VIR_LOG_INIT("tests.securityselinuxlabeltest");
static virCapsPtr caps;
static virDomainXMLOptionPtr xmlopt;
static virQEMUDriver driver;
static virSecurityManagerPtr mgr;
......@@ -189,7 +189,7 @@ testSELinuxLoadDef(const char *testname)
abs_srcdir, testname) < 0)
goto cleanup;
if (!(def = virDomainDefParseFile(xmlfile, caps, xmlopt, 0)))
if (!(def = virDomainDefParseFile(xmlfile, caps, driver.xmlopt, 0)))
goto cleanup;
for (i = 0; i < def->ndisks; i++) {
......@@ -361,7 +361,7 @@ mymain(void)
if ((caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
if (!(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
#define DO_TEST_LABELING(name) \
......@@ -375,6 +375,8 @@ mymain(void)
DO_TEST_LABELING("chardev");
DO_TEST_LABELING("nfs");
qemuTestDriverFree(&driver);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册