Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCS/TEST: Remove entry from configuration list when library is unloaded - v1.5.x #3656

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contrib/test_jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,15 @@ test_dlopen() {
! grep '^socket' strace.log
}

test_dlopen_cfg_print() {
../contrib/configure-devel --prefix=$ucx_inst
$MAKE clean
$MAKE

echo "==== Running test_dlopen_cfg_print ===="
./test/apps/test_dlopen_cfg_print
}

test_memtrack() {
../contrib/configure-devel --prefix=$ucx_inst
$MAKE clean
Expand Down Expand Up @@ -930,6 +939,7 @@ run_tests() {
do_distributed_task 1 4 run_ucp_client_server
do_distributed_task 3 4 test_profiling
do_distributed_task 3 4 test_dlopen
do_distributed_task 2 4 test_dlopen_cfg_print
do_distributed_task 3 4 test_memtrack
do_distributed_task 0 4 test_unused_env_var
do_distributed_task 1 3 test_malloc_hook
Expand Down
17 changes: 11 additions & 6 deletions src/ucs/config/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ typedef struct ucs_config_global_list_entry {


#define UCS_CONFIG_REGISTER_TABLE(_fields, _name, _prefix, _type) \
static ucs_config_global_list_entry_t _fields##_config_entry; \
UCS_STATIC_INIT { \
ucs_config_global_list_entry_t *entry = &_fields##_config_entry; \
extern ucs_list_link_t ucs_config_global_list; \
static ucs_config_global_list_entry_t entry; \
entry.fields = _fields; \
entry.name = _name; \
entry.prefix = _prefix; \
entry.size = sizeof(_type); \
ucs_list_add_tail(&ucs_config_global_list, &entry.list); \
entry->fields = _fields; \
entry->name = _name; \
entry->prefix = _prefix; \
entry->size = sizeof(_type); \
ucs_list_add_tail(&ucs_config_global_list, &entry->list); \
} \
\
UCS_STATIC_CLEANUP { \
ucs_list_del(&_fields##_config_entry.list); \
}


Expand Down
11 changes: 9 additions & 2 deletions test/apps/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ SUBDIRS = sockaddr
endif

noinst_PROGRAMS = \
test_dlopen

test_dlopen \
test_dlopen_cfg_print

objdir = $(shell sed -n -e 's/^objdir=\(.*\)$$/\1/p' $(LIBTOOL))

Expand All @@ -21,6 +21,13 @@ test_dlopen_CPPFLAGS = $(BASE_CPPFLAGS) -g -DUCP_LIB_PATH=$(abs_top_builddir)/sr
test_dlopen_CFLAGS = $(BASE_CFLAGS)
test_dlopen_LDADD = -ldl

test_dlopen_cfg_print_SOURCES = test_dlopen_cfg_print.c
test_dlopen_cfg_print_CPPFLAGS = $(BASE_CPPFLAGS) -g \
-DUCS_LIB_PATH=$(abs_top_builddir)/src/ucs/$(objdir)/libucs.so \
-DUCT_LIB_PATH=$(abs_top_builddir)/src/uct/$(objdir)/libuct.so
test_dlopen_cfg_print_CFLAGS = $(BASE_CFLAGS)
test_dlopen_cfg_print_LDADD = -ldl

if HAVE_TCMALLOC
noinst_PROGRAMS += test_tcmalloc
test_tcmalloc_SOURCES = test_tcmalloc.c
Expand Down
54 changes: 54 additions & 0 deletions test/apps/test_dlopen_cfg_print.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (C) Mellanox Technologies Ltd. 2019. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/

#include <stdlib.h>
#include <dlfcn.h>
#include <stdio.h>

#define _QUOTE(x) #x
#define QUOTE(x) _QUOTE(x)


static void* do_dlopen_or_exit(const char *filename)
{
void *handle;

(void)dlerror();
printf("opening '%s'\n", filename);
handle = dlopen(filename, RTLD_LAZY);
if (handle == NULL) {
fprintf(stderr, "failed to open %s: %s\n", filename,
dlerror());
exit(1);
}

return handle;
}

int main(int argc, char **argv)
{
const char *ucs_filename = QUOTE(UCS_LIB_PATH);
const char *uct_filename = QUOTE(UCT_LIB_PATH);
void *ucs_handle, *uct_handle;
int i;

/* unload and reload uct while ucs is loaded
* would fail if uct global vars are kept on global lists in ucs */
ucs_handle = do_dlopen_or_exit(ucs_filename);
for (i = 0; i < 2; ++i) {
uct_handle = do_dlopen_or_exit(uct_filename);
dlclose(uct_handle);
}

/* print all config table, to force going over the global list in ucs */
void (*print_all_opts)(FILE*,int) = dlsym(ucs_handle,
"ucs_config_parser_print_all_opts");
print_all_opts(stdout, 0);
dlclose(ucs_handle);

printf("done\n");
return 0;
}