]> git.ipfire.org Git - ipfire-3.x.git/blob - sssd/patches/0010-dlopen-test-Add-check-for-untested-libraries.patch
kernel: Drop ld.so placeholder files
[ipfire-3.x.git] / sssd / patches / 0010-dlopen-test-Add-check-for-untested-libraries.patch
1 From 916065cfed5ceccfd2ee4127a460b47161c2efd7 Mon Sep 17 00:00:00 2001
2 From: Lukas Slebodnik <lslebodn@redhat.com>
3 Date: Mon, 17 Oct 2016 21:44:18 +0200
4 Subject: [PATCH 10/39] dlopen-test: Add check for untested libraries
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Reviewed-by: Petr Čech <pcech@redhat.com>
10 (cherry picked from commit c7b3c43cf669e39f7ce5f4ef1a2e939b31a8b7b9)
11 (cherry picked from commit 7251859d8cdb2fc57c969f67ac76904fea331cd0)
12 ---
13 src/tests/dlopen-tests.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
14 1 file changed, 69 insertions(+)
15
16 diff --git a/src/tests/dlopen-tests.c b/src/tests/dlopen-tests.c
17 index c857dff73..520c91f63 100644
18 --- a/src/tests/dlopen-tests.c
19 +++ b/src/tests/dlopen-tests.c
20 @@ -30,6 +30,7 @@
21 #include <stdlib.h>
22 #include <limits.h>
23 #include <check.h>
24 +#include <dirent.h>
25 #include "tests/common.h"
26
27 #define LIBPFX ABS_BUILD_DIR "/" LT_OBJDIR
28 @@ -154,16 +155,84 @@ static bool recursive_dlopen(const char **name, int round, char **errmsg)
29 return ok;
30 }
31
32 +static int file_so_filter(const struct dirent *ent)
33 +{
34 + char *suffix;
35 +
36 + suffix = rindex(ent->d_name, '.');
37 + if (suffix != NULL
38 + && strcmp(suffix, ".so") == 0
39 + && suffix[3] == '\0') {
40 + return 1;
41 + }
42 +
43 + return 0;
44 +}
45 +
46 +static char **get_so_files(size_t *_list_size)
47 +{
48 + int n;
49 + struct dirent **namelist;
50 + char **libraries;
51 +
52 + n = scandir(LIBPFX, &namelist, file_so_filter, alphasort);
53 + fail_unless(n > 0);
54 +
55 + libraries = calloc(n + 1, sizeof(char *));
56 +
57 + for (int i = 0; i < n; ++i) {
58 + libraries[i] = strdup(namelist[i]->d_name);
59 + fail_if(libraries[i] == NULL);
60 +
61 + free(namelist[i]);
62 + }
63 + free(namelist);
64 +
65 + *_list_size = (size_t)n;
66 + return libraries;
67 +}
68 +
69 +static void remove_library_from_list(const char *library, char **list,
70 + size_t list_size)
71 +{
72 + for (size_t i = 0; i < list_size; ++i) {
73 + if (list[i] != NULL && strcmp(library, list[i]) == 0) {
74 + /* found library need to be removed from list */
75 + free(list[i]);
76 + list[i] = NULL;
77 + return;
78 + }
79 + }
80 +
81 + ck_abort_msg("Cannot find expected library: %s", library);
82 +}
83 +
84 START_TEST(test_dlopen_base)
85 {
86 char *errmsg;
87 bool ok;
88 int i;
89 + size_t found_libraries_size;
90 + char **found_libraries = get_so_files(&found_libraries_size);
91 + bool unchecked_library = false;
92
93 for (i = 0; so[i].name != NULL; i++) {
94 ok = recursive_dlopen(so[i].libs, 0, &errmsg);
95 fail_unless(ok, "Error opening %s: [%s]", so[i].name, errmsg);
96 +
97 + remove_library_from_list(so[i].name, found_libraries,
98 + found_libraries_size);
99 }
100 +
101 + for (i = 0; i < found_libraries_size; ++i) {
102 + if (found_libraries[i] != NULL) {
103 + printf("Unchecked library found: %s\n", found_libraries[i]);
104 + unchecked_library = true;
105 + }
106 + }
107 + free(found_libraries);
108 +
109 + fail_if(unchecked_library);
110 }
111 END_TEST
112
113 --
114 2.11.0
115