tests: fix valgrind issues
authorAlexander Kanavin <alexander.kanavin@intel.com>
Thu, 4 Jul 2013 17:13:50 +0000 (20:13 +0300)
committerAlexander Kanavin <alexander.kanavin@intel.com>
Wed, 17 Jul 2013 11:04:34 +0000 (14:04 +0300)
test/daemon/daemon-test.c
test/plugins/pluginproxytest.c
test/valgrind.supp
test/valgrind_common.mk

index 51ae1f4..3d5d396 100644 (file)
@@ -57,7 +57,6 @@ struct IdentityData {
     { "Secret", "s", "test_pass" },
     { "StoreSecret", "b", (void *)TRUE}
 };
-gchar *exe_name = 0;
 
 #if HAVE_GTESTDBUS
 GTestDBus *dbus = NULL;
@@ -65,9 +64,34 @@ GTestDBus *dbus = NULL;
 GPid daemon_pid = 0;
 #endif
 
+static gchar* _get_executable_name()
+{
+    gchar *procfname;
+    char *path;
+    ssize_t res;
+    pid_t pid = getpid();
+
+    //valgrind does some magic with tasks, so we read the executable name of
+    //the 'main' task, instead of the current task
+    procfname = g_strdup_printf ("/proc/%d/task/%d/exe", pid, pid);
+    path = g_malloc0 (PATH_MAX + 1);
+    res = readlink (procfname, path, PATH_MAX);
+    g_free (procfname);
+
+    if (res <= 0) {
+        WARN ("failed to follow link for pid %d", pid);
+        g_free (path);
+        return NULL;
+    }
+    return path;
+}
+
 static void
 setup_daemon (void)
 {
+    gchar* exe_name = _get_executable_name();
+    fail_if(exe_name == NULL);
+    
     fail_if (g_setenv ("G_MESSAGES_DEBUG", "all", TRUE) == FALSE);
     fail_if (g_setenv ("SSO_IDENTITY_TIMEOUT", "5", TRUE) == FALSE);
     fail_if (g_setenv ("SSO_DAEMON_TIMEOUT", "5", TRUE) == FALSE);
@@ -77,7 +101,8 @@ setup_daemon (void)
     fail_if (g_setenv ("SSO_KEYCHAIN_SYSCTX", exe_name, TRUE) == FALSE);
     fail_if (g_setenv ("SSO_PLUGIN_TIMEOUT", "5", TRUE) == FALSE);
 
-    DBG ("Programe name : %s\n", exe_name);
+    DBG ("Programe pid %d, name : %s\n", getpid(), exe_name);
+    free(exe_name);
 
     if (system("rm -rf /tmp/gsignond") != 0) {
         DBG("Failed to clean db path : %s\n", strerror(errno));
@@ -768,8 +793,6 @@ int main (int argc, char *argv[])
     g_type_init ();
 #endif
 
-    exe_name = argv[0];
-
     s = daemon_suite();
     sr = srunner_create(s);
 
index 113df32..811b541 100644 (file)
@@ -498,7 +498,8 @@ START_TEST (test_pluginproxyfactory_add)
     fail_if(gsignond_plugin_proxy_factory_add_plugin(factory, proxy) == TRUE);
     fail_if(gsignond_plugin_proxy_factory_get_plugin(factory, "password")
             != proxy);
-
+    g_object_unref(proxy);
+    
     g_object_unref(proxy);
     g_object_unref(factory);
     g_object_unref(config);
index e791e62..224006d 100644 (file)
@@ -52,5 +52,15 @@ Memcheck:Leak
 ...
 fun:g_resolver_lookup_by_name_async
 }
-
-
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   ...
+   fun:_dl_allocate_tls
+}
+{
+   <insert_a_suppression_name_here>
+   Memcheck:Leak
+   ...
+   fun:gdbus_shared_thread_func
+}
index 4b0cc5b..358fe3f 100644 (file)
@@ -2,14 +2,15 @@ SUPPRESSIONS = $(top_srcdir)/test/valgrind.supp
 
 %.valgrind: %
        @$(TESTS_ENVIRONMENT) \
+       RUNNING_VALGRIND=yes \
        CK_FORK=no \
-       CK_DEFAULT_TIMEOUT=120 \
+       CK_TIMEOUT_MULTIPLIER=10 \
        G_SLICE=always-malloc \
        $(LIBTOOL) --mode=execute \
        valgrind -q \
        $(foreach s,$(SUPPRESSIONS),--suppressions=$(s)) \
        --tool=memcheck --leak-check=full --trace-children=yes \
-       --leak-resolution=high --num-callers=20 \
+       --leak-resolution=high --num-callers=30 \
        --error-exitcode=1 \
        ./$*