[libvirt] [PATCH] fix virDomainMigrateToURI doc
by Dan Kenigsberg
---
src/libvirt.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 92a1eaa..d2a0d7a 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3279,7 +3279,7 @@ error:
* @bandwidth: (optional) specify migration bandwidth limit in Mbps
*
* Migrate the domain object from its current host to the destination
- * host given by dconn (a connection to the destination host).
+ * host given by duri.
*
* Flags may be one of more of the following:
* VIR_MIGRATE_LIVE Do not pause the VM during migration
--
1.6.2.5
15 years, 1 month
[libvirt] [PATCH 00/10] tests: More XML 2 XML tests and cleanups
by Cole Robinson
In attempting to refactor some storage pool XML parsing, I wanted some unit
tests to ensure I wasn't causing regressions. So, the following series adds
XML 2 XML tests for storage pools (and virtual networks and storage vols).
Also included are several cleanups in tests/, and bug fixes needed to make
the new tests actually pass.
Cole Robinson (10):
tests: Fix text output for interface XML 2 XML
tests: Document VIR_TEST_DEBUG environment variable.
tests: Break out duplicate schema verification functionality.
storage: Fix generating iscsi 'auth' xml
schema: Update storage pool schema.
tests: Add XML 2 XML tests for storage pools.
network: Fix reading 'forwardDelay' attribute.
schema: Update network schema.
tests: Add network XML to XML tests.
tests: Add storage volume XML 2 XML tests.
HACKING | 10 ++
docs/schemas/network.rng | 41 ++++++-
docs/schemas/storagepool.rng | 51 ++++++++-
src/conf/network_conf.c | 10 ++-
src/conf/storage_conf.c | 2 +-
tests/.gitignore | 3 +
tests/Makefile.am | 33 +++++-
tests/capabilityschematest | 34 +-----
tests/domainschematest | 33 +-----
tests/interfaceschematest | 31 +-----
tests/interfacexml2xmltest.c | 4 +-
tests/networkschemadata/netboot-network.xml | 12 --
tests/networkschematest | 33 +-----
tests/networkxml2xmlin/forward-delay-network.xml | 13 ++
tests/networkxml2xmlin/isolated-network.xml | 10 ++
tests/networkxml2xmlin/nat-network.xml | 13 ++
tests/networkxml2xmlin/netboot-network.xml | 14 +++
tests/networkxml2xmlin/routed-network.xml | 11 ++
tests/networkxml2xmlout/forward-delay-network.xml | 13 ++
tests/networkxml2xmlout/isolated-network.xml | 10 ++
tests/networkxml2xmlout/nat-network.xml | 13 ++
tests/networkxml2xmlout/netboot-network.xml | 14 +++
tests/networkxml2xmlout/routed-network.xml | 11 ++
tests/networkxml2xmltest.c | 97 +++++++++++++++
tests/nodedevschematest | 31 +-----
tests/schematestutils.sh | 39 ++++++
tests/statstest.c | 2 +-
tests/storagepoolschemadata/pool-dir.xml | 17 ---
tests/storagepoolschemadata/pool-disk.xml | 22 ----
tests/storagepoolschemadata/pool-fs.xml | 19 ---
tests/storagepoolschemadata/pool-iscsi.xml | 10 --
tests/storagepoolschemadata/pool-logical.xml | 19 ---
tests/storagepoolschemadata/pool-netfs.xml | 20 ---
tests/storagepoolschematest | 33 +-----
tests/storagepoolxml2xmlin/pool-dir.xml | 18 +++
tests/storagepoolxml2xmlin/pool-disk.xml | 22 ++++
tests/storagepoolxml2xmlin/pool-fs.xml | 19 +++
tests/storagepoolxml2xmlin/pool-iscsi-auth.xml | 17 +++
tests/storagepoolxml2xmlin/pool-iscsi.xml | 16 +++
tests/storagepoolxml2xmlin/pool-logical-create.xml | 20 +++
tests/storagepoolxml2xmlin/pool-logical.xml | 19 +++
tests/storagepoolxml2xmlin/pool-mpath.xml | 12 ++
tests/storagepoolxml2xmlin/pool-netfs.xml | 20 +++
tests/storagepoolxml2xmlin/pool-scsi.xml | 15 +++
tests/storagepoolxml2xmlout/pool-dir.xml | 18 +++
tests/storagepoolxml2xmlout/pool-disk.xml | 19 +++
tests/storagepoolxml2xmlout/pool-fs.xml | 19 +++
tests/storagepoolxml2xmlout/pool-iscsi-auth.xml | 20 +++
tests/storagepoolxml2xmlout/pool-iscsi.xml | 19 +++
.../storagepoolxml2xmlout/pool-logical-create.xml | 22 ++++
tests/storagepoolxml2xmlout/pool-logical.xml | 19 +++
tests/storagepoolxml2xmlout/pool-mpath.xml | 17 +++
tests/storagepoolxml2xmlout/pool-netfs.xml | 20 +++
tests/storagepoolxml2xmlout/pool-scsi.xml | 18 +++
tests/storagepoolxml2xmltest.c | 102 ++++++++++++++++
tests/storagevolschemadata/vol-logical.xml | 20 ---
tests/storagevolschemadata/vol-partition.xml | 21 ----
tests/storagevolschemadata/vol-qcow2.xml | 31 -----
tests/storagevolschematest | 33 +-----
tests/storagevolxml2xmlin/vol-file-backing.xml | 24 ++++
tests/storagevolxml2xmlin/vol-file.xml | 15 +++
tests/storagevolxml2xmlin/vol-logical-backing.xml | 29 +++++
tests/storagevolxml2xmlin/vol-logical.xml | 20 +++
tests/storagevolxml2xmlin/vol-partition.xml | 21 ++++
tests/storagevolxml2xmlin/vol-qcow2.xml | 31 +++++
tests/storagevolxml2xmlout/vol-file-backing.xml | 27 +++++
tests/storagevolxml2xmlout/vol-file.xml | 18 +++
tests/storagevolxml2xmlout/vol-logical-backing.xml | 26 ++++
tests/storagevolxml2xmlout/vol-logical.xml | 17 +++
tests/storagevolxml2xmlout/vol-partition.xml | 18 +++
tests/storagevolxml2xmlout/vol-qcow2.xml | 31 +++++
tests/storagevolxml2xmltest.c | 123 ++++++++++++++++++++
72 files changed, 1291 insertions(+), 413 deletions(-)
delete mode 100644 tests/networkschemadata/netboot-network.xml
create mode 100644 tests/networkxml2xmlin/forward-delay-network.xml
create mode 100644 tests/networkxml2xmlin/isolated-network.xml
create mode 100644 tests/networkxml2xmlin/nat-network.xml
create mode 100644 tests/networkxml2xmlin/netboot-network.xml
create mode 100644 tests/networkxml2xmlin/routed-network.xml
create mode 100644 tests/networkxml2xmlout/forward-delay-network.xml
create mode 100644 tests/networkxml2xmlout/isolated-network.xml
create mode 100644 tests/networkxml2xmlout/nat-network.xml
create mode 100644 tests/networkxml2xmlout/netboot-network.xml
create mode 100644 tests/networkxml2xmlout/routed-network.xml
create mode 100644 tests/networkxml2xmltest.c
create mode 100644 tests/schematestutils.sh
delete mode 100644 tests/storagepoolschemadata/pool-dir.xml
delete mode 100644 tests/storagepoolschemadata/pool-disk.xml
delete mode 100644 tests/storagepoolschemadata/pool-fs.xml
delete mode 100644 tests/storagepoolschemadata/pool-iscsi.xml
delete mode 100644 tests/storagepoolschemadata/pool-logical.xml
delete mode 100644 tests/storagepoolschemadata/pool-netfs.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-dir.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-disk.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-fs.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-iscsi.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-logical-create.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-logical.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-mpath.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-netfs.xml
create mode 100644 tests/storagepoolxml2xmlin/pool-scsi.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-dir.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-disk.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-fs.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-iscsi.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-logical-create.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-logical.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-mpath.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-netfs.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-scsi.xml
create mode 100644 tests/storagepoolxml2xmltest.c
delete mode 100644 tests/storagevolschemadata/vol-logical.xml
delete mode 100644 tests/storagevolschemadata/vol-partition.xml
delete mode 100644 tests/storagevolschemadata/vol-qcow2.xml
create mode 100644 tests/storagevolxml2xmlin/vol-file-backing.xml
create mode 100644 tests/storagevolxml2xmlin/vol-file.xml
create mode 100644 tests/storagevolxml2xmlin/vol-logical-backing.xml
create mode 100644 tests/storagevolxml2xmlin/vol-logical.xml
create mode 100644 tests/storagevolxml2xmlin/vol-partition.xml
create mode 100644 tests/storagevolxml2xmlin/vol-qcow2.xml
create mode 100644 tests/storagevolxml2xmlout/vol-file-backing.xml
create mode 100644 tests/storagevolxml2xmlout/vol-file.xml
create mode 100644 tests/storagevolxml2xmlout/vol-logical-backing.xml
create mode 100644 tests/storagevolxml2xmlout/vol-logical.xml
create mode 100644 tests/storagevolxml2xmlout/vol-partition.xml
create mode 100644 tests/storagevolxml2xmlout/vol-qcow2.xml
create mode 100644 tests/storagevolxml2xmltest.c
15 years, 1 month
[libvirt] [PATCH] do not bother rotating short qemu logs
by Dan Kenigsberg
without this, after few weeks without use, each defined domain grows a
tail of empty gzipped logs, instead of keeping just the last log of
interest.
---
daemon/libvirtd.logrotate.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/daemon/libvirtd.logrotate.in b/daemon/libvirtd.logrotate.in
index 093651c..0c51fd3 100644
--- a/daemon/libvirtd.logrotate.in
+++ b/daemon/libvirtd.logrotate.in
@@ -5,4 +5,5 @@
compress
delaycompress
copytruncate
+ minsize 100k
}
--
1.6.2.5
15 years, 1 month
[libvirt] [PATCH] LXC fix virCgroupGetValueStr on handling a string terminated with '\n'
by Ryota Ozaki
Hi there,
A cgroup file returns integer value terminated with '\n' and remaining
it has sometimes harmful effects, for example it leads virStrToLong_ull
failed.
The fix just gets rid of '\n' if included. It first has been in
virCgroupGetFreezerState, but now merged in virCgroupGetValueStr to cover
every functions using virCgroupGetValueStr.
I'm not sure that that behavior is from the beginning or changed in a
recent kernel, but the fix should work even though anyway.
BTW, by the defect I first got the following error and it made me confused.
# virsh -c lxc:/// dominfo 4930
Id: 4930
Name: lxc
UUID: 084369a0-956a-3010-fc37-ddeb4d627e69
OS Type: exe
Autostart: disable
error: this function is not supported by the hypervisor: virNodeGetSecurityModel
The really error happens in lxcDomainGetInfo, so I guess something is wrong
with internal error propagation. Anyone know this unexpected behavior?
Thanks,
ozaki-r
>From 667efde6ad165479817975c6544f6784e1177a32 Mon Sep 17 00:00:00 2001
From: Ryota Ozaki <ozaki.ryota(a)gmail.com>
Date: Fri, 16 Oct 2009 00:13:41 +0900
Subject: [PATCH] LXC fix virCgroupGetValueStr on handling a string
terminated with '\n'
* src/util/cgroup.c: get rid of '\n' from the return value
of virCgroupGetValueStr
---
src/util/cgroup.c | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index f728a2f..f0e2960 100644
--- a/src/util/cgroup.c+++ b/src/util/cgroup.c
@@ -309,6 +309,10 @@ static int virCgroupGetValueStr(virCgroupPtr group,
DEBUG("Failed to read %s: %m\n", keypath);
rc = -errno;
} else {
+ /* Terminated with '\n' has sometimes harmful effects to the caller */
+ char *p = strchr((const char *)value, '\n');
+ if (p) *p = '\0';
+
rc = 0;
}
@@ -969,13 +973,7 @@ int virCgroupSetFreezerState(virCgroupPtr group, const char
*state)
int virCgroupGetFreezerState(virCgroupPtr group, char **state)
{
- int ret;
- ret = virCgroupGetValueStr(group,
+ return virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_CPU,
"freezer.state", state);
- if (ret == 0) {
- char *p = strchr(*state, '\n');
- if (p) *p = '\0';
- }
- return ret;
}
--
1.6.2.5
15 years, 1 month
[libvirt] [PATCH] 528575 avoid libvirtd crash on LCX domain autostart
by Daniel Veillard
https://bugzilla.redhat.com/show_bug.cgi?id=528575
virsh -c lxc:/// autostart vm1
crash the daemon because the driver autostartDir is never initialized
and we do a NULL dereference. The enclosed patch is trivial and avoid
the crash, but ...
[root@paphio ~]# virsh -c lxc:/// dominfo vm1
Id: -
Name: vm1
UUID: d320f760-7541-6633-fd42-4f984fca9f51
OS Type: exe
State: shut off
CPU(s): 1
Max memory: 500000 kB
Used memory: 500000 kB
Autostart: enable
while the domain is properly flagged as autostarting it doesn't seem to
actually autostart, and the driver->autostartDir directory is not
created on the fly as I would expect, i.e.
/etc/libvirt/lxc/autostart/
still doesn't exist and the domain is marked as off and Autostart: enable
I think it would be good to ACK the patch to avoid the crash but we also
need to have someone look at the autostart of LXC domains and double
check what is going on, maybe I missed something :-)
Ozaki, any chance you could look at this ?
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
15 years, 1 month
[libvirt] Re: [virt-tools-list] libvirt 0.7.2 linker issues
by Cole Robinson
On 10/19/2009 08:54 AM, Laurent Léonard wrote:
> Hi,
>
> I'm trying to package libvirt 0.7.2 for Debian and get some linker issues :
>
> make[3]: Entering directory `/home/user/debian/libvirt/libvirt-0.7.2/tools'
> CC virsh-console.o
> CC virsh-virsh.o
> CCLD virsh
> ../src/.libs/libvirt.so: undefined reference to `security_getenforce'
> ../src/.libs/libvirt.so: undefined reference to `freecon'
> ../src/.libs/libvirt.so: undefined reference to `setexeccon'
> ../src/.libs/libvirt.so: undefined reference to
> `selinux_virtual_domain_context_path'
> ../src/.libs/libvirt.so: undefined reference to `context_str'
> ../src/.libs/libvirt.so: undefined reference to `context_range_set'
> ../src/.libs/libvirt.so: undefined reference to `is_selinux_enabled'
> ../src/.libs/libvirt.so: undefined reference to `setfilecon'
> ../src/.libs/libvirt.so: undefined reference to `context_new'
> ../src/.libs/libvirt.so: undefined reference to `getfilecon'
> ../src/.libs/libvirt.so: undefined reference to `getpidcon'
> ../src/.libs/libvirt.so: undefined reference to `context_free'
> ../src/.libs/libvirt.so: undefined reference to `context_range_get'
> ../src/.libs/libvirt.so: undefined reference to `matchpathcon'
> ../src/.libs/libvirt.so: undefined reference to
> `selinux_virtual_image_context_path'
> ../src/.libs/libvirt.so: undefined reference to `security_check_context'
> collect2: ld returned 1 exit status
> make[3]: *** [virsh] Error 1
> make[3]: Leaving directory `/home/user/debian/libvirt/libvirt-0.7.2/tools'
> make[2]: *** [all] Error 2
> make[2]: Leaving directory `/home/user/debian/libvirt/libvirt-0.7.2/tools'
> make[1]: *** [all-recursive] Error 1
> make[1]: Leaving directory `/home/user/debian/libvirt/libvirt-0.7.2'
> make: *** [all] Error 2
>
> Any idea what's wrong ?
>
> Thank you,
Libvirt questions should go to libvirt-list(a)redhat.com (cc'd now).
You should pass --with-selinux=no to configure, since those are all
libselinux functions. Do you have libselinux installed? If not, there's
probably an error in configure.in selinux autodetection.
- Cole
15 years, 1 month
[libvirt] LXC implement missing macaddr assignment feature
by Ryota Ozaki
Hi,
Currently MAC address configuration of container veth is just ignored.
This patch implements the missing feature.
* src/lxc/veth.c, src/lxc/veth.h: add setMacAddr
* src/lxc/lxc_driver.c: set macaddr of container veth if specified
ozaki-r
>From 38ccccf09526bdd125c717beb13769aa2904e751 Mon Sep 17 00:00:00 2001
From: Ryota Ozaki <ozaki.ryota(a)gmail.com>
Date: Mon, 19 Oct 2009 22:13:18 +0900
Subject: [PATCH] LXC implement missing macaddr assignment feature
Currently MAC address configuration of container veth is just ignored.
This patch implements the missing feature.
* src/lxc/veth.c, src/lxc/veth.h: add setMacAddr
* src/lxc/lxc_driver.c: set macaddr of container veth if specified
---
src/lxc/lxc_driver.c | 11 +++++++++++
src/lxc/veth.c | 31 +++++++++++++++++++++++++++++++
src/lxc/veth.h | 1 +
3 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 783dfcc..ef97364 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -786,6 +786,17 @@ static int lxcSetupInterfaces(virConnectPtr conn,
goto error_exit;
}
+ if (def->nets[i]->mac) {
+ char macaddr[VIR_MAC_STRING_BUFLEN];
+ virFormatMacAddr(def->nets[i]->mac, macaddr);
+ if (0 != (rc = setMacAddr(containerVeth, macaddr))) {
+ virReportSystemError(conn, rc,
+ _("failed to set %s to %s"),
+ macaddr, containerVeth);
+ goto error_exit;
+ }
+ }
+
if (0 != (rc = brAddInterface(brctl, bridge, parentVeth))) {
virReportSystemError(conn, rc,
_("failed to add %s device to %s"),
diff --git a/src/lxc/veth.c b/src/lxc/veth.c
index 71d7de6..b15df8d 100644
--- a/src/lxc/veth.c
+++ b/src/lxc/veth.c
@@ -216,3 +216,34 @@ error_out:
VIR_FREE(pid);
return rc;
}
+
+/**
+ * setMacAddr
+ * @iface: name of device
+ * @macaddr: MAC address to be assigned
+ *
+ * Changes the MAC address of the given device with the
+ * given address using this command:
+ * ip link set @iface address @macaddr
+ *
+ * Returns 0 on success or -1 in case of error
+ */
+int setMacAddr(const char* iface, const char* macaddr)
+{
+ int rc = -1;
+ const char *argv[] = {
+ "ip", "link", "set", iface, "address", macaddr, NULL
+ };
+ int cmdResult;
+
+ if (NULL == iface) {
+ goto error_out;
+ }
+
+ rc = virRun(NULL, argv, &cmdResult);
+ if (0 == rc)
+ rc = cmdResult;
+
+error_out:
+ return rc;
+}
diff --git a/src/lxc/veth.h b/src/lxc/veth.h
index 429eb3d..8f2f514 100644
--- a/src/lxc/veth.h
+++ b/src/lxc/veth.h
@@ -20,5 +20,6 @@ int vethCreate(char* veth1, int veth1MaxLen, char* veth2,
int vethDelete(const char* veth);
int vethInterfaceUpOrDown(const char* veth, int upOrDown);
int moveInterfaceToNetNs(const char *iface, int pidInNs);
+int setMacAddr(const char* iface, const char* macaddr);
#endif /* VETH_H */
--
1.6.2.5
15 years, 1 month
[libvirt] Using libvirt to obtain mac address of virtual domain
by Carlen, Devin C. (ARC-A)[PEROT SYSTEMS]
Greetings, I am new to libvirt and am looking for the most efficient
way to programmatically obtain the mac address from a virtual domain.
Libvirt is providing access to xen and kvm in my case. A nudge in the
right direction would be appreciated!
Best Regards,
Devin Carlen
15 years, 1 month
[libvirt] [PATCH] tests: Centralize VIR_TEST_DEBUG lookup, and document it
by Cole Robinson
Provide a simple interface for other tests to lookup the testDebug variable.
Also remove a redundant error message in interface tests.
If anyone feels inclined to change this env variable to match the existing
LIBVIRT_* format, it should now be easier to do so.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
HACKING | 10 ++++++++++
tests/interfacexml2xmltest.c | 2 --
tests/statstest.c | 4 ++--
tests/testutils.c | 38 ++++++++++++++++++++++++++------------
tests/testutils.h | 4 ++--
tests/testutilsqemu.c | 2 +-
6 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/HACKING b/HACKING
index bcff8c6..fba7778 100644
--- a/HACKING
+++ b/HACKING
@@ -37,6 +37,16 @@ and run the tests:
The latter test checks for memory leaks.
+If you encounter any failing tests, the VIR_TEST_DEBUG environment variable
+may help:
+
+ VIR_TEST_DEBUG=1 make check (or)
+ VIR_TEST_DEBUG=2 make check
+
+Also, individual tests can be run from inside the 'tests/' directory, like:
+
+ ./qemuxml2xmltest
+
(6) Update tests and/or documentation, particularly if you are adding
a new feature or changing the output of a program.
diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c
index 5ffebad..ed3093c 100644
--- a/tests/interfacexml2xmltest.c
+++ b/tests/interfacexml2xmltest.c
@@ -43,8 +43,6 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0;
fail:
- if (ret != 0)
- fprintf(stderr, "expected: -------\n%s", actual);
free(actual);
virInterfaceDefFree(dev);
return ret;
diff --git a/tests/statstest.c b/tests/statstest.c
index 82c0daa..4c2ea7f 100644
--- a/tests/statstest.c
+++ b/tests/statstest.c
@@ -25,7 +25,7 @@ static int testDevice(const char *path, int expect)
if (actual == expect) {
return 0;
} else {
- if (getenv("DEBUG_TESTS"))
+ if (virtTestGetDebug())
fprintf(stderr, "Expect %-6d Actual %-6d\n", expect, actual);
return -1;
}
@@ -55,7 +55,7 @@ mymain(int argc ATTRIBUTE_UNUSED,
* register a handler to stop error messages cluttering
* up display
*/
- if (!getenv("VIR_TEST_DEBUG"))
+ if (!virtTestGetDebug())
virSetErrorFunc(NULL, testQuietError);
#define DO_TEST(dev, num) \
diff --git a/tests/testutils.c b/tests/testutils.c
index e6f5e61..9daec6d 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -45,7 +45,7 @@
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
-unsigned int testDebug = 0;
+unsigned int testDebug = -1;
static unsigned int testOOM = 0;
static unsigned int testCounter = 0;
@@ -255,10 +255,10 @@ int virtTestDifference(FILE *stream,
const char *actualStart = actual;
const char *actualEnd = actual + (strlen(actual)-1);
- if (!testDebug)
+ if (!virtTestGetDebug())
return 0;
- if (testDebug < 2) {
+ if (virtTestGetDebug() < 2) {
/* Skip to first character where they differ */
while (*expectStart && *actualStart &&
*actualStart == *expectStart) {
@@ -322,12 +322,30 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED)
}
#endif
+unsigned int
+virtTestGetDebug() {
+ char *debugStr;
+ unsigned int debug;
+
+ if (testDebug != -1)
+ return testDebug;
+
+ testDebug = 0;
+
+ if ((debugStr = getenv("VIR_TEST_DEBUG")) == NULL)
+ return 0;
+
+ if (virStrToLong_ui(debugStr, NULL, 10, &debug) < 0)
+ return 0;
+
+ testDebug = debug;
+ return testDebug;
+}
int virtTestMain(int argc,
char **argv,
int (*func)(int, char **))
{
- char *debugStr;
int ret;
#if TEST_OOM
int approxAlloc = 0;
@@ -344,10 +362,6 @@ int virtTestMain(int argc,
virRandomInitialize(time(NULL) ^ getpid()))
return 1;
- if ((debugStr = getenv("VIR_TEST_DEBUG")) != NULL) {
- if (virStrToLong_ui(debugStr, NULL, 10, &testDebug) < 0)
- testDebug = 0;
- }
#if TEST_OOM
if ((oomStr = getenv("VIR_TEST_OOM")) != NULL) {
@@ -375,7 +389,7 @@ int virtTestMain(int argc,
goto cleanup;
#if TEST_OOM_TRACE
- if (testDebug)
+ if (virtTestGetDebug())
virAllocTestHook(virtTestErrorHook, NULL);
#endif
@@ -393,7 +407,7 @@ int virtTestMain(int argc,
approxAlloc = virAllocTestCount();
testCounter++;
- if (testDebug)
+ if (virtTestGetDebug())
fprintf(stderr, "%d) OOM...\n", testCounter);
else
fprintf(stderr, "%d) OOM of %d allocs ", testCounter, approxAlloc);
@@ -415,7 +429,7 @@ int virtTestMain(int argc,
if (mp &&
(n % mp) != (worker - 1))
continue;
- if (!testDebug) {
+ if (!virtTestGetDebug()) {
if (mp)
fprintf(stderr, "%d", worker);
else
@@ -444,7 +458,7 @@ int virtTestMain(int argc,
}
}
- if (testDebug)
+ if (virtTestGetDebug())
fprintf(stderr, " ... OOM of %d allocs", approxAlloc);
if (ret == EXIT_SUCCESS)
diff --git a/tests/testutils.h b/tests/testutils.h
index f036e0f..aef1179 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -34,6 +34,8 @@ int virtTestDifference(FILE *stream,
const char *expect,
const char *actual);
+unsigned int virtTestGetDebug(void);
+
int virtTestMain(int argc,
char **argv,
int (*func)(int, char **));
@@ -43,6 +45,4 @@ int virtTestMain(int argc,
return virtTestMain(argc,argv, func); \
}
-extern unsigned int testDebug;
-
#endif /* __VIT_TEST_UTILS_H__ */
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 9269f5c..eeeb5ec 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -132,7 +132,7 @@ virCapsPtr testQemuCapsInit(void) {
NULL) == NULL)
goto cleanup;
- if (testDebug) {
+ if (virtTestGetDebug()) {
char *caps_str;
caps_str = virCapabilitiesFormatXML(caps);
--
1.6.0.6
15 years, 1 month