URL: https://github.com/SSSD/sssd/pull/56
Author: lslebodn
 Title: #56: Update dlopen test
Action: opened

PR body:
"""

"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/56/head:pr56
git checkout pr56
From 2de9b6598b1589a7cc37107ed7fa5ad5ac814665 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lsleb...@redhat.com>
Date: Mon, 17 Oct 2016 21:39:57 +0200
Subject: [PATCH 1/4] dlopen-test: Use portable macro for location of .libs

---
 src/tests/dlopen-tests.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
index 96cc4db..6e37dbe 100644
--- a/src/tests/dlopen-tests.c
+++ b/src/tests/dlopen-tests.c
@@ -22,7 +22,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#define _GNU_SOURCE
+#include "config.h"
+
 #include <stdbool.h>
 #include <dlfcn.h>
 #include <stdio.h>
@@ -31,7 +32,7 @@
 #include <check.h>
 #include "tests/common.h"
 
-#define LIBPFX ABS_BUILD_DIR"/.libs/"
+#define LIBPFX ABS_BUILD_DIR "/" LT_OBJDIR
 
 struct so {
     const char *name;

From 7f2d46f517cef9d969135e28052821e19d8feb2e Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lsleb...@redhat.com>
Date: Mon, 17 Oct 2016 21:59:18 +0200
Subject: [PATCH 2/4] dlopen-test: Add missing libraries to the check list

nfsidmap plugin(sss.so) and libsss_cert.so were not checked.
Few libraries which are build for testing purposes were added to the list
otherwise we would not be able to detect unchecked libraries.
---
 src/tests/dlopen-tests.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
index 6e37dbe..c980ab9 100644
--- a/src/tests/dlopen-tests.c
+++ b/src/tests/dlopen-tests.c
@@ -78,6 +78,7 @@ struct so {
     { "libsss_child.so", { LIBPFX"libsss_util.so",
                            LIBPFX"libsss_child.so", NULL } },
     { "libsss_crypt.so", { LIBPFX"libsss_crypt.so", NULL } },
+    { "libsss_cert.so", { LIBPFX"libsss_cert.so", NULL } },
     { "libsss_util.so", { LIBPFX"libsss_util.so", NULL } },
     { "libsss_simple.so", { LIBPFX"libdlopen_test_providers.so",
                             LIBPFX"libsss_simple.so", NULL } },
@@ -114,6 +115,18 @@ struct so {
 #ifdef HAVE_CONFIG_LIB
     { "libsss_config.so", { LIBPFX"libsss_config.so", NULL } },
 #endif
+#ifdef BUILD_NFS_IDMAP
+    { "sss.so", { LIBPFX"sss.so", NULL } },
+#endif
+    /* for testing purposes */
+    { "libsss_nss_idmap_tests.so", { LIBPFX"libsss_nss_idmap_tests.so",
+                                     NULL } },
+#ifdef BUILD_SAMBA
+    { "libdlopen_test_winbind_idmap.so",
+      { LIBPFX"libdlopen_test_winbind_idmap.so", NULL } },
+    { "libsss_ad_tests.so", { LIBPFX"libdlopen_test_providers.so",
+                              LIBPFX"libsss_ad_tests.so", NULL } },
+#endif
     { NULL }
 };
 

From 7c1dc0acae9513772f6a020301c0483c1c4f309b Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lsleb...@redhat.com>
Date: Mon, 17 Oct 2016 22:17:27 +0200
Subject: [PATCH 3/4] dlopen-test: Move libraries to the right "sections"

The library winbind_idmap_sss.so is build only when building
with samba. The library libdlopen_test_providers.so was moved
to the group of libraries build for testing purposes.
---
 src/tests/dlopen-tests.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
index c980ab9..c857dff 100644
--- a/src/tests/dlopen-tests.c
+++ b/src/tests/dlopen-tests.c
@@ -71,9 +71,6 @@ struct so {
 #ifdef HAVE_CIFS_IDMAP_PLUGIN
     { "cifs_idmap_sss.so", { LIBPFX"cifs_idmap_sss.so", NULL } },
 #endif
-    { "winbind_idmap_sss.so", { LIBPFX"libdlopen_test_winbind_idmap.so",
-                                LIBPFX"winbind_idmap_sss.so",
-                                NULL } },
     { "memberof.so", { LIBPFX"memberof.so", NULL } },
     { "libsss_child.so", { LIBPFX"libsss_util.so",
                            LIBPFX"libsss_child.so", NULL } },
@@ -87,6 +84,8 @@ struct so {
                         LIBPFX"libsss_ad.so", NULL } },
     { "libsss_ipa.so", { LIBPFX"libdlopen_test_providers.so",
                          LIBPFX"libsss_ipa.so", NULL } },
+    { "winbind_idmap_sss.so", { LIBPFX"libdlopen_test_winbind_idmap.so",
+                                LIBPFX"winbind_idmap_sss.so", NULL } },
 #endif /* BUILD_SAMBA */
     { "libsss_krb5.so", { LIBPFX"libdlopen_test_providers.so",
                           LIBPFX"libsss_krb5.so", NULL } },
@@ -98,8 +97,6 @@ struct so {
                                  LIBPFX"libsss_ldap_common.so", NULL } },
     { "libsss_proxy.so", { LIBPFX"libdlopen_test_providers.so",
                            LIBPFX"libsss_proxy.so", NULL } },
-    { "libdlopen_test_providers.so", { LIBPFX"libdlopen_test_providers.so",
-                                       NULL } },
 #ifdef HAVE_PYTHON2_BINDINGS
     { "_py2hbac.so", { LIBPFX"_py2hbac.so", NULL } },
     { "_py2sss.so", { LIBPFX"_py2sss.so", NULL } },
@@ -119,6 +116,8 @@ struct so {
     { "sss.so", { LIBPFX"sss.so", NULL } },
 #endif
     /* for testing purposes */
+    { "libdlopen_test_providers.so", { LIBPFX"libdlopen_test_providers.so",
+                                       NULL } },
     { "libsss_nss_idmap_tests.so", { LIBPFX"libsss_nss_idmap_tests.so",
                                      NULL } },
 #ifdef BUILD_SAMBA

From 45338375ed45e3241718eb23cfe66595cf4d4b7c Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lsleb...@redhat.com>
Date: Mon, 17 Oct 2016 21:44:18 +0200
Subject: [PATCH 4/4] dlopen-test: Add check for untested libraries

---
 src/tests/dlopen-tests.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
index c857dff..520c91f 100644
--- a/src/tests/dlopen-tests.c
+++ b/src/tests/dlopen-tests.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <check.h>
+#include <dirent.h>
 #include "tests/common.h"
 
 #define LIBPFX ABS_BUILD_DIR "/" LT_OBJDIR
@@ -154,16 +155,84 @@ static bool recursive_dlopen(const char **name, int round, char **errmsg)
     return ok;
 }
 
+static int file_so_filter(const struct dirent *ent)
+{
+    char *suffix;
+
+    suffix = rindex(ent->d_name, '.');
+    if (suffix != NULL
+            && strcmp(suffix, ".so") == 0
+            && suffix[3] == '\0') {
+        return 1;
+    }
+
+    return 0;
+}
+
+static char **get_so_files(size_t *_list_size)
+{
+    int n;
+    struct dirent **namelist;
+    char **libraries;
+
+    n = scandir(LIBPFX, &namelist, file_so_filter, alphasort);
+    fail_unless(n > 0);
+
+    libraries = calloc(n + 1, sizeof(char *));
+
+    for (int i = 0; i < n; ++i) {
+        libraries[i] = strdup(namelist[i]->d_name);
+        fail_if(libraries[i] == NULL);
+
+        free(namelist[i]);
+    }
+    free(namelist);
+
+    *_list_size = (size_t)n;
+    return libraries;
+}
+
+static void remove_library_from_list(const char *library, char **list,
+                                     size_t list_size)
+{
+    for (size_t i = 0; i < list_size; ++i) {
+        if (list[i] != NULL && strcmp(library, list[i]) == 0) {
+            /* found library need to be removed from list */
+            free(list[i]);
+            list[i] = NULL;
+            return;
+        }
+    }
+
+    ck_abort_msg("Cannot find expected library: %s", library);
+}
+
 START_TEST(test_dlopen_base)
 {
     char *errmsg;
     bool ok;
     int i;
+    size_t found_libraries_size;
+    char **found_libraries = get_so_files(&found_libraries_size);
+    bool unchecked_library = false;
 
     for (i = 0; so[i].name != NULL; i++) {
         ok = recursive_dlopen(so[i].libs, 0, &errmsg);
         fail_unless(ok, "Error opening %s: [%s]", so[i].name, errmsg);
+
+        remove_library_from_list(so[i].name, found_libraries,
+                                 found_libraries_size);
     }
+
+    for (i = 0; i < found_libraries_size; ++i) {
+        if (found_libraries[i] != NULL) {
+            printf("Unchecked library found: %s\n", found_libraries[i]);
+            unchecked_library = true;
+        }
+    }
+    free(found_libraries);
+
+    fail_if(unchecked_library);
 }
 END_TEST
 
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org

Reply via email to