[libvirt] PATCH: Reset global error object at end of test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There statstest test case is expected to raise a number of libvirt
errors. Since these are now stored in thread locals, it is expected
that this won't be free'd automatically at system shutdown. This 
patch adds a call to virResetError() at the end to release the memory
associated with the stored error object. There is still one block of
memory alocated though, which is the thread local error error object
itself. We can't free this easily, so I just add a valgrind suppression
rule instead. This lets 'make valgrind' pass again

Also since the test case doesn't call virInitialize()as a normal
app would do, we need to explicitly initialize the thread local storage
to ensure things work correctly.

Daniel

diff -r 93337ec227d6 tests/.valgrind.supp
--- a/tests/.valgrind.supp	Mon Jan 26 15:25:53 2009 +0000
+++ b/tests/.valgrind.supp	Tue Jan 27 11:15:47 2009 +0000
@@ -238,3 +238,18 @@
    fun:virtTestRun
    fun:mymain
 }
+{
+   ignoreThreadLocalErrorObject
+   Memcheck:Leak
+   fun:calloc
+   fun:virAlloc
+   fun:virLastErrorObject
+   fun:virRaiseError
+   fun:statsErrorFunc
+   fun:xenLinuxDomainDeviceID
+   fun:testDeviceHelper
+   fun:virtTestRun
+   fun:mymain
+   fun:virtTestMain
+   fun:main
+}
diff -r 93337ec227d6 tests/testutils.c
--- a/tests/testutils.c	Mon Jan 26 15:25:53 2009 +0000
+++ b/tests/testutils.c	Tue Jan 27 11:15:47 2009 +0000
@@ -26,6 +26,8 @@
 #include "internal.h"
 #include "memory.h"
 #include "util.h"
+#include "threads.h"
+#include "virterror_internal.h"
 
 #if TEST_OOM_TRACE
 #include <execinfo.h>
@@ -319,8 +321,8 @@ int virtTestMain(int argc,
                  int (*func)(int, char **))
 {
     char *debugStr;
+    int ret;
 #if TEST_OOM
-    int ret;
     int approxAlloc = 0;
     int n;
     char *oomStr = NULL;
@@ -330,6 +332,10 @@ int virtTestMain(int argc,
     int worker = 0;
 #endif
 
+    if (virThreadInitialize() < 0 ||
+        virErrorInitialize() < 0)
+        return 1;
+
     if ((debugStr = getenv("VIR_TEST_DEBUG")) != NULL) {
         if (virStrToLong_ui(debugStr, NULL, 10, &testDebug) < 0)
             testDebug = 0;
@@ -349,8 +355,10 @@ int virtTestMain(int argc,
     if (getenv("VIR_TEST_MP") != NULL) {
         mp = sysconf(_SC_NPROCESSORS_ONLN);
         fprintf(stderr, "Using %d worker processes\n", mp);
-        if (VIR_ALLOC_N(workers, mp) < 0)
-            return EXIT_FAILURE;
+        if (VIR_ALLOC_N(workers, mp) < 0) {
+            ret = EXIT_FAILURE;
+            goto cleanup;
+        }
     }
 
     if (testOOM)
@@ -359,7 +367,7 @@ int virtTestMain(int argc,
     /* Run once to count allocs, and ensure it passes :-) */
     ret = (func)(argc, argv);
     if (ret != EXIT_SUCCESS)
-        return EXIT_FAILURE;
+        goto cleanup;
 
 #if TEST_OOM_TRACE
     if (testDebug)
@@ -431,9 +439,11 @@ int virtTestMain(int argc,
         else
             fprintf(stderr, " FAILED\n");
     }
+cleanup:
+#else
+    ret = (func)(argc, argv);
+#endif
+
+    virResetLastError();
     return ret;
-
-#else
-    return (func)(argc, argv);
-#endif
 }


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]