summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2016-10-17 21:44:18 +0200
committerLukas Slebodnik <lslebodn@redhat.com>2016-10-25 10:33:41 +0200
commitc7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9 (patch)
tree11c6fe2b7ae93d3039d38bab57a591d9a9ff3bb0
parentd708e53d0df0c1ed4cc0097bebfa2a84d7b20fad (diff)
downloadsssd-c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9.tar.gz
sssd-c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9.tar.xz
sssd-c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9.zip
dlopen-test: Add check for untested libraries
Reviewed-by: Petr Čech <pcech@redhat.com>
-rw-r--r--src/tests/dlopen-tests.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
index c857dff73..520c91f63 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