2 * Test utility checking symbol versions in libcryptsetup.
4 * Copyright (C) 2021-2023 Red Hat, Inc. All rights reserved.
6 * This file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This file is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #define UNUSED(expr) do { (void)(expr); } while (0)
30 static const char *libfile = "libcryptsetup.so.12";
32 #define LOG_MAX_LEN 256
38 __attribute__((format(printf, 2, 3)))
39 static void test_logf(int level, const char *format, ...)
42 char target[LOG_MAX_LEN + 2];
45 va_start(argp, format);
47 len = vsnprintf(&target[0], LOG_MAX_LEN, format, argp);
48 if (len > 0 && len < LOG_MAX_LEN) {
55 fprintf(stdout, "%s", target);
60 fprintf(stderr, "%s", target);
67 #define log_dbg(x...) test_logf(LOG_DEBUG, x)
68 #define log_std(x...) test_logf(LOG_NORMAL, x)
69 #define log_err(x...) test_logf(LOG_ERROR, x)
71 static int check_dlvsym(void *h, const char *symbol, const char *version)
77 log_dbg("Checking %s@%s...", symbol, version);
78 sym = dlvsym(h, symbol, version);
92 static int check_dlsym(void *h, const char *symbol)
97 log_dbg("Checking %s...", symbol);
98 sym = dlsym(h, symbol);
111 static int check_all_symbols(void *h)
115 #define CHECK_SYMBOL(SYM, VER) \
117 if (check_dlvsym(h, #SYM, #VER)) \
119 if (check_dlsym(h, #SYM)) \
124 #include "test-symbols-list.h"
128 log_err("test-symbols-list.h file is probably empty.");
132 log_std("Performed %u symbol checks in total.\n", scount);
137 static void usage(const char *app)
139 log_std("usage:\n\t%s [-v|--verbose|--debug] [optional path to library so file]\n", app);
144 int main(int argc, char **argv)
149 for (i = 1; i < argc; i++) {
152 else if (!strcmp("-v", argv[i]) || !strcmp("--verbose", argv[i]) ||
153 !strcmp("--debug", argv[i]))
155 else if (!strcmp("-h", argv[i]) || !strcmp("--help", argv[i]))
159 log_std("Checking dlopen(%s)...", libfile);
161 h = dlopen(libfile, RTLD_NOW);
163 log_err("dlopen(): %s.", dlerror());
169 r = check_all_symbols(h);
172 log_err("Failed to dlclose %s: %s.", libfile, dlerror());
176 return r ? EXIT_FAILURE : EXIT_SUCCESS;