File: test_dlopen_cfg_print.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (64 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * 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)

typedef struct ucs_list_link {
    struct ucs_list_link *prev;
    struct ucs_list_link *next;
} ucs_list_link_t;

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)
{
    typedef void (*print_all_opts_func_t)(FILE*, const char *, int,
                                          ucs_list_link_t *);

    const char *ucs_filename = QUOTE(UCS_LIB_PATH);
    const char *uct_filename = QUOTE(UCT_LIB_PATH);
    void *ucs_handle, *uct_handle;
    ucs_list_link_t *config_list;
    int i;
    print_all_opts_func_t print_all_opts;

    /* 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 */
    print_all_opts =
        (print_all_opts_func_t)dlsym(ucs_handle, "ucs_config_parser_print_all_opts");
    config_list = (ucs_list_link_t*)dlsym(ucs_handle, "ucs_config_global_list");
    print_all_opts(stdout, "TEST_", 0, config_list);
    dlclose(ucs_handle);

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