feafcbc
From 916065cfed5ceccfd2ee4127a460b47161c2efd7 Mon Sep 17 00:00:00 2001
feafcbc
From: Lukas Slebodnik <lslebodn@redhat.com>
feafcbc
Date: Mon, 17 Oct 2016 21:44:18 +0200
feafcbc
Subject: [PATCH 10/39] dlopen-test: Add check for untested libraries
feafcbc
MIME-Version: 1.0
feafcbc
Content-Type: text/plain; charset=UTF-8
feafcbc
Content-Transfer-Encoding: 8bit
feafcbc
feafcbc
Reviewed-by: Petr Čech <pcech@redhat.com>
feafcbc
(cherry picked from commit c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9)
feafcbc
(cherry picked from commit 7251859d8cdb2fc57c969f67ac76904fea331cd0)
feafcbc
---
feafcbc
 src/tests/dlopen-tests.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
feafcbc
 1 file changed, 69 insertions(+)
feafcbc
feafcbc
diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
feafcbc
index c857dff73..520c91f63 100644
feafcbc
--- a/src/tests/dlopen-tests.c
feafcbc
+++ b/src/tests/dlopen-tests.c
feafcbc
@@ -30,6 +30,7 @@
feafcbc
 #include <stdlib.h>
feafcbc
 #include <limits.h>
feafcbc
 #include <check.h>
feafcbc
+#include <dirent.h>
feafcbc
 #include "tests/common.h"
feafcbc
 
feafcbc
 #define LIBPFX ABS_BUILD_DIR "/" LT_OBJDIR
feafcbc
@@ -154,16 +155,84 @@ static bool recursive_dlopen(const char **name, int round, char **errmsg)
feafcbc
     return ok;
feafcbc
 }
feafcbc
 
feafcbc
+static int file_so_filter(const struct dirent *ent)
feafcbc
+{
feafcbc
+    char *suffix;
feafcbc
+
feafcbc
+    suffix = rindex(ent->d_name, '.');
feafcbc
+    if (suffix != NULL
feafcbc
+            && strcmp(suffix, ".so") == 0
feafcbc
+            && suffix[3] == '\0') {
feafcbc
+        return 1;
feafcbc
+    }
feafcbc
+
feafcbc
+    return 0;
feafcbc
+}
feafcbc
+
feafcbc
+static char **get_so_files(size_t *_list_size)
feafcbc
+{
feafcbc
+    int n;
feafcbc
+    struct dirent **namelist;
feafcbc
+    char **libraries;
feafcbc
+
feafcbc
+    n = scandir(LIBPFX, &namelist, file_so_filter, alphasort);
feafcbc
+    fail_unless(n > 0);
feafcbc
+
feafcbc
+    libraries = calloc(n + 1, sizeof(char *));
feafcbc
+
feafcbc
+    for (int i = 0; i < n; ++i) {
feafcbc
+        libraries[i] = strdup(namelist[i]->d_name);
feafcbc
+        fail_if(libraries[i] == NULL);
feafcbc
+
feafcbc
+        free(namelist[i]);
feafcbc
+    }
feafcbc
+    free(namelist);
feafcbc
+
feafcbc
+    *_list_size = (size_t)n;
feafcbc
+    return libraries;
feafcbc
+}
feafcbc
+
feafcbc
+static void remove_library_from_list(const char *library, char **list,
feafcbc
+                                     size_t list_size)
feafcbc
+{
feafcbc
+    for (size_t i = 0; i < list_size; ++i) {
feafcbc
+        if (list[i] != NULL && strcmp(library, list[i]) == 0) {
feafcbc
+            /* found library need to be removed from list */
feafcbc
+            free(list[i]);
feafcbc
+            list[i] = NULL;
feafcbc
+            return;
feafcbc
+        }
feafcbc
+    }
feafcbc
+
feafcbc
+    ck_abort_msg("Cannot find expected library: %s", library);
feafcbc
+}
feafcbc
+
feafcbc
 START_TEST(test_dlopen_base)
feafcbc
 {
feafcbc
     char *errmsg;
feafcbc
     bool ok;
feafcbc
     int i;
feafcbc
+    size_t found_libraries_size;
feafcbc
+    char **found_libraries = get_so_files(&found_libraries_size);
feafcbc
+    bool unchecked_library = false;
feafcbc
 
feafcbc
     for (i = 0; so[i].name != NULL; i++) {
feafcbc
         ok = recursive_dlopen(so[i].libs, 0, &errmsg);
feafcbc
         fail_unless(ok, "Error opening %s: [%s]", so[i].name, errmsg);
feafcbc
+
feafcbc
+        remove_library_from_list(so[i].name, found_libraries,
feafcbc
+                                 found_libraries_size);
feafcbc
     }
feafcbc
+
feafcbc
+    for (i = 0; i < found_libraries_size; ++i) {
feafcbc
+        if (found_libraries[i] != NULL) {
feafcbc
+            printf("Unchecked library found: %s\n", found_libraries[i]);
feafcbc
+            unchecked_library = true;
feafcbc
+        }
feafcbc
+    }
feafcbc
+    free(found_libraries);
feafcbc
+
feafcbc
+    fail_if(unchecked_library);
feafcbc
 }
feafcbc
 END_TEST
feafcbc
 
feafcbc
-- 
feafcbc
2.11.0
feafcbc