[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, 6 months
[libvirt] [PATCH] tests: Initialize virRandom in for test suite.
by Cole Robinson
Otherwise any virRandom calls will result in a segfault.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
tests/testutils.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tests/testutils.c b/tests/testutils.c
index 536441a..e6f5e61 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -340,7 +340,8 @@ int virtTestMain(int argc,
#endif
if (virThreadInitialize() < 0 ||
- virErrorInitialize() < 0)
+ virErrorInitialize() < 0 ||
+ virRandomInitialize(time(NULL) ^ getpid()))
return 1;
if ((debugStr = getenv("VIR_TEST_DEBUG")) != NULL) {
--
1.6.0.6
15 years, 6 months
[libvirt] error: unable to connect to '/usr/local/var/run/libvirt/libvirt-sock': Connection refused
by Liu, Zhentao
Hello,
I updated libvirt-bin to version 0.7.0. I still got a error:
-------------------------------------------------------------------------------------------
root@forest:/tmp/libvirt-0.7.0# virsh -c qemu:///system list
error: unable to connect to '/usr/local/var/run/libvirt/libvirt-sock': Connection refused
error: failed to connect to the hypervisor
-------------------------------------------------------------------------------------------
Any helps?
Regards
Zhentao
15 years, 6 months
[libvirt] [PATCH] Better error reporting for failed migration.
by Chris Lalancette
The comment in the code says most of it, but when the destination
hostname resolution is screwed up, print a proper error instead
of the very unhelpful "unknown error".
Note that I'm not overly fond of the wording in the error message,
so I'm open to suggestions.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/qemu/qemu_driver.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d37b184..02bb5cb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6288,6 +6288,22 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn,
goto cleanup;
}
+ /* Remember that we are running on the destination. The hostname that
+ * we resolve here will be used on the source machine in the "migrate"
+ * monitor command. Because of that, localhost is almost always the
+ * wrong thing. Adding this check explicitly breaks localhost
+ * migration, but only for those machines that have improperly
+ * configured hostname resolution.
+ */
+ if (STREQ(hostname, "localhost")) {
+ VIR_FREE(hostname);
+ qemudReportError(dconn, NULL, NULL, VIR_ERR_INVALID_ARG, "%s",
+ _("Could not resolve destination hostname; "
+ "either fix destination to resolve hostname, "
+ "or use the optional URI migration parameter"));
+ goto cleanup;
+ }
+
/* XXX this really should have been a properly well-formed
* URI, but we can't add in tcp:// now without breaking
* compatability with old targets. We at least make the
--
1.6.0.6
15 years, 6 months
[libvirt] error: failed to connect to the hypervisor
by Liu, Zhentao
Hello,
I have reinstalled libvirt-bin on ubuntu 9.04. Then I got a error:
------------------------------------------------------------------------
root@forest:/usr/local/etc/logrotate.d# virsh -c qemu:///system list
error: failed to connect to the hypervisor
-----------------------------------------------------------------------
ps: I have installed kvm on ubuntu.
Any ideas?
Regards
Zhentao
15 years, 6 months
[libvirt] error: failed to connect to the hypervisor
by Liu, Zhentao
Hello,
I have installed libvirt-bin 0.6.1 on the ubuntu 9.04. When I run "virsh -c qemu:///system list", I get this error:
----------------------------------------------------------------------------
unable to connect to '/var/run/libvirt/libvirt-sock': Permission denied
failed to connect to the hypervisor
-----------------------------------------------------------------------------
Then I search in the Internet, it may be a bug of version 0.6.1. So I update libvirt-bin to version 0.6.3, but I still get
a error:
---------------------------------------------------------------------------------
root@forest:/home/zli# virsh -c qemu:///system list
error: failed to connect to the hypervisor
----------------------------------------------------------------------------------
I have no idea about the reason. Any helps?
Regards
Zhentao
15 years, 6 months
[libvirt] [PATCH] util: Make sure random data is initialized when in virRandom
by Cole Robinson
When writing some tests, I mistakenly attempted to auto-generate a UUID,
which caused a segfault: virRandom was being used without calling
virRandomInitialize. Make sure this case can't happen.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/util/util.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index e5135fc..1554097 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1910,6 +1910,7 @@ int virKillProcess(pid_t pid, int sig)
}
+static int random_initialized = 0;
static char randomState[128];
static struct random_data randomData;
static virMutex randomLock;
@@ -1925,6 +1926,7 @@ int virRandomInitialize(unsigned int seed)
&randomData) < 0)
return -1;
+ random_initialized = 1;
return 0;
}
@@ -1932,6 +1934,12 @@ int virRandom(int max)
{
int32_t ret;
+ if (!random_initialized) {
+ /* This can error, but what's worse? Unnoticed bogus random data or
+ * a segfault? */
+ virRandomInitialize(time(NULL) ^ getpid());
+ }
+
virMutexLock(&randomLock);
random_r(&randomData, &ret);
virMutexUnlock(&randomLock);
--
1.6.5.rc2
15 years, 6 months