root/opal/mca/btl/usnic/test/usnic_btl_run_tests.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  * Copyright (c) 2014      Cisco Systems, Inc.  All rights reserved.
   3  * Copyright (c) 2016      IBM Corporation.  All rights reserved.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  */
  10 
  11 /* A simple test runner program for the usnic BTL unit tests.  See README.test
  12  * for more information. */
  13 
  14 /* for dladdr() */
  15 #define _GNU_SOURCE
  16 
  17 #include <assert.h>
  18 #include <stdio.h>
  19 #include <stdlib.h>
  20 #include <string.h>
  21 #include <libgen.h> /* for dirname() */
  22 
  23 #include <dlfcn.h>
  24 
  25 #define MCA_BTL_USNIC_SO "mca_btl_usnic.so"
  26 
  27 typedef void (*run_tests_fn_t)(void);
  28 
  29 int main(int argc, char **argv)
  30 {
  31     void *mpi_handle;
  32     void *usnic_handle;
  33     void (*run_tests)(void);
  34     int (*init)(int *, char ***);
  35     int (*finalize)(void);
  36     Dl_info info;
  37     char *libmpi_path;
  38     char *path;
  39     char *to;
  40     int path_len;
  41 
  42     mpi_handle = dlopen("lib" OMPI_LIBMPI_NAME ".so", RTLD_NOW|RTLD_GLOBAL);
  43     if (mpi_handle == NULL) {
  44         fprintf(stderr, "mpi_handle=NULL dlerror()=%s\n", dlerror());
  45         abort();
  46     }
  47 
  48     /* casting awfulness needed for GCC's "-pedantic" option :( */
  49     *(void **)(&init) = dlsym(mpi_handle, "MPI_Init");
  50     if (init == NULL) {
  51         fprintf(stderr, "init=NULL dlerror()=%s\n", dlerror());
  52         abort();
  53     }
  54     /* casting awfulness needed for GCC's "-pedantic" option :( */
  55     *(void **)(&finalize) = dlsym(mpi_handle, "MPI_Finalize");
  56     if (finalize == NULL) {
  57         fprintf(stderr, "finalize=%p dlerror()=%s\n", *(void **)(&finalize), dlerror());
  58         abort();
  59     }
  60 
  61     /* call MPI_Init this way to avoid build-time dependency issues */
  62     init(&argc, &argv);
  63 
  64     /* figure out where the usnic BTL shared object is relative to libmpi.so */
  65     if (!dladdr(*(void **)(&init), &info)) {
  66         fprintf(stderr, "ERROR: unable to dladdr(init,...)\n");
  67         abort();
  68     }
  69     libmpi_path = strdup(info.dli_fname);
  70     assert(libmpi_path != NULL);
  71     path_len = strlen(libmpi_path) + strlen("/openmpi/") + strlen(MCA_BTL_USNIC_SO);
  72     path = calloc(path_len+1, 1);
  73     to = path;
  74     to = stpcpy(to, dirname(libmpi_path));
  75     to = stpcpy(to, "/openmpi/");
  76     to = stpcpy(to, MCA_BTL_USNIC_SO);
  77 
  78     usnic_handle = dlopen(path, RTLD_NOW|RTLD_LOCAL);
  79     if (usnic_handle == NULL) {
  80         fprintf(stderr, "usnic_handle=%p dlerror()=%s\n", (void *)usnic_handle, dlerror());
  81         abort();
  82     }
  83 
  84     free(libmpi_path);
  85     free(path);
  86 
  87     /* casting awfulness needed for GCC's "-pedantic" option :( */
  88     *(void **)(&run_tests) = dlsym(usnic_handle, BTL_USNIC_RUN_TESTS_SYMBOL);
  89     if (run_tests == NULL) {
  90         fprintf(stderr, "run_tests=%p dlerror()=%s\n",
  91                 *(void **)(&run_tests), dlerror());
  92         abort();
  93     }
  94     run_tests();
  95 
  96     finalize();
  97 
  98     /* deliberately do not dlclose() either handle so that any valgrind stack
  99      * traces are more useful */
 100 
 101     return 0;
 102 }

/* [<][>][^][v][top][bottom][index][help] */