root/opal/mca/pmix/pmix4x/pmix/test/pmix_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  * Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2006-2013 Los Alamos National Security, LLC.
  13  *                         All rights reserved.
  14  * Copyright (c) 2009-2012 Cisco Systems, Inc.  All rights reserved.
  15  * Copyright (c) 2011      Oak Ridge National Labs.  All rights reserved.
  16  * Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
  17  * Copyright (c) 2015      Research Organization for Information Science
  18  *                         and Technology (RIST). All rights reserved.
  19  * Copyright (c) 2015-2018 Mellanox Technologies, Inc.
  20  *                         All rights reserved.
  21  *
  22  * $COPYRIGHT$
  23  *
  24  * Additional copyrights may follow
  25  *
  26  * $HEADER$
  27  *
  28  */
  29 
  30 #include <stdio.h>
  31 #include <stdlib.h>
  32 #include <unistd.h>
  33 
  34 #include "src/util/pmix_environ.h"
  35 #include "src/util/output.h"
  36 
  37 #include "server_callbacks.h"
  38 #include "utils.h"
  39 #include "test_server.h"
  40 #include "test_common.h"
  41 
  42 bool spawn_wait = false;
  43 
  44 int main(int argc, char **argv)
  45 {
  46     char **client_env=NULL;
  47     char **client_argv=NULL;
  48     int rc;
  49     struct stat stat_buf;
  50     struct timeval tv;
  51     double test_start;
  52     test_params params;
  53     INIT_TEST_PARAMS(params);
  54     int test_fail = 0;
  55     char *tmp;
  56     int ns_nprocs;
  57 
  58     gettimeofday(&tv, NULL);
  59     test_start = tv.tv_sec + 1E-6*tv.tv_usec;
  60 
  61     /* smoke test */
  62     if (PMIX_SUCCESS != 0) {
  63         TEST_ERROR(("ERROR IN COMPUTING CONSTANTS: PMIX_SUCCESS = %d", PMIX_SUCCESS));
  64         exit(1);
  65     }
  66 
  67     TEST_VERBOSE(("Testing version %s", PMIx_Get_version()));
  68 
  69     parse_cmd(argc, argv, &params);
  70     TEST_VERBOSE(("Start PMIx_lite smoke test (timeout is %d)", params.timeout));
  71 
  72     /* set common argv and env */
  73     client_env = pmix_argv_copy(environ);
  74     set_client_argv(&params, &client_argv);
  75 
  76     tmp = pmix_argv_join(client_argv, ' ');
  77     TEST_VERBOSE(("Executing test: %s", tmp));
  78     free(tmp);
  79 
  80     /* verify executable */
  81     if( 0 > ( rc = stat(params.binary, &stat_buf) ) ){
  82         TEST_ERROR(("Cannot stat() executable \"%s\": %d: %s", params.binary, errno, strerror(errno)));
  83         FREE_TEST_PARAMS(params);
  84         return 0;
  85     } else if( !S_ISREG(stat_buf.st_mode) ){
  86         TEST_ERROR(("Client executable \"%s\": is not a regular file", params.binary));
  87         FREE_TEST_PARAMS(params);
  88         return 0;
  89     }else if( !(stat_buf.st_mode & S_IXUSR) ){
  90         TEST_ERROR(("Client executable \"%s\": has no executable flag", params.binary));
  91         FREE_TEST_PARAMS(params);
  92         return 0;
  93     }
  94 
  95     if (PMIX_SUCCESS != (rc = server_init(&params))) {
  96         FREE_TEST_PARAMS(params);
  97         return rc;
  98     }
  99 
 100     cli_init(params.lsize);
 101 
 102     int launched = 0;
 103     /* set namespaces and fork clients */
 104     if (NULL == params.ns_dist) {
 105         uint32_t i;
 106         int base_rank = 0;
 107 
 108         /* compute my start counter */
 109         for(i = 0; i < (uint32_t)my_server_id; i++) {
 110             base_rank += (params.nprocs % params.nservers) > (uint32_t)i ?
 111                         params.nprocs / params.nservers + 1 :
 112                         params.nprocs / params.nservers;
 113         }
 114         /* we have a single namespace for all clients */
 115         ns_nprocs = params.nprocs;
 116         launched += server_launch_clients(params.lsize, params.nprocs, base_rank,
 117                                    &params, &client_env, &client_argv);
 118     } else {
 119         char *pch;
 120         pch = strtok(params.ns_dist, ":");
 121         while (NULL != pch) {
 122             ns_nprocs = (int)strtol(pch, NULL, 10);
 123             if (params.nprocs < (uint32_t)(launched+ns_nprocs)) {
 124                 TEST_ERROR(("Total number of processes doesn't correspond number specified by ns_dist parameter."));
 125                 FREE_TEST_PARAMS(params);
 126                 return PMIX_ERROR;
 127             }
 128             if (0 < ns_nprocs) {
 129                 launched += server_launch_clients(ns_nprocs, ns_nprocs, 0, &params,
 130                                            &client_env, &client_argv);
 131             }
 132             pch = strtok (NULL, ":");
 133         }
 134     }
 135     if (params.lsize != (uint32_t)launched) {
 136         TEST_ERROR(("Total number of processes doesn't correspond number specified by ns_dist parameter."));
 137         cli_kill_all();
 138         test_fail = 1;
 139     }
 140 
 141     /* hang around until the client(s) finalize */
 142     while (!test_terminated()) {
 143         // To avoid test hang we want to interrupt the loop each 0.1s
 144         double test_current;
 145 
 146         // check if we exceed the max time
 147         gettimeofday(&tv, NULL);
 148         test_current = tv.tv_sec + 1E-6*tv.tv_usec;
 149         if( (test_current - test_start) > params.timeout ){
 150             break;
 151         }
 152         cli_wait_all(0);
 153     }
 154 
 155     if( !test_terminated() ){
 156         TEST_ERROR(("Test exited by a timeout!"));
 157         cli_kill_all();
 158         test_fail = 1;
 159     }
 160 
 161     if( test_abort ){
 162         TEST_ERROR(("Test was aborted!"));
 163         /* do not simply kill the clients as that generates
 164          * event notifications which these tests then print
 165          * out, flooding the log */
 166       //  cli_kill_all();
 167         test_fail = 1;
 168     }
 169 
 170     if (0 != params.test_spawn) {
 171         PMIX_WAIT_FOR_COMPLETION(spawn_wait);
 172     }
 173 
 174     /* deregister the errhandler */
 175     PMIx_Deregister_event_handler(0, op_callbk, NULL);
 176 
 177     cli_wait_all(1.0);
 178 
 179     test_fail += server_finalize(&params);
 180 
 181     FREE_TEST_PARAMS(params);
 182     pmix_argv_free(client_argv);
 183     pmix_argv_free(client_env);
 184 
 185     return test_fail;
 186 }

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