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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* Copyright (c) 2015-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "test_error.h"
#include "test_common.h"
#include <time.h>
#define MAX_ERR_HANDLERS 5
#define TEST_NOTIFY PMIX_ERR_TIMEOUT
static bool done;
static void comfail_errhandler(size_t evhdlr_registration_id, pmix_status_t status,
const pmix_proc_t *source, pmix_info_t info[], size_t ninfo,
pmix_info_t results[], size_t nresults,
pmix_event_notification_cbfunc_fn_t cbfunc, void *cbdata)
{
TEST_ERROR(("comfail errhandler called for error status = %d ninfo = %lu", status,
(unsigned long) ninfo));
PMIX_HIDE_UNUSED_PARAMS(evhdlr_registration_id, source, info, results, nresults);
if (NULL != cbfunc) {
cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
}
}
static void timeout_errhandler(size_t evhdlr_registration_id, pmix_status_t status,
const pmix_proc_t *source, pmix_info_t info[], size_t ninfo,
pmix_info_t results[], size_t nresults,
pmix_event_notification_cbfunc_fn_t cbfunc, void *cbdata)
{
TEST_ERROR(("timeout errhandler called for error status = %d ninfo = %d", status, (int) ninfo));
PMIX_HIDE_UNUSED_PARAMS(evhdlr_registration_id, source, info, results, nresults);
if (NULL != cbfunc) {
cbfunc(PMIX_SUCCESS, NULL, 0, NULL, NULL, cbdata);
}
}
static void op1_callbk(pmix_status_t status, void *cbdata)
{
TEST_VERBOSE(("op1_callbk CALLED WITH STATUS %d", status));
PMIX_HIDE_UNUSED_PARAMS(cbdata);
done = true;
}
static void errhandler_reg_callbk1(pmix_status_t status, size_t errhandler_ref, void *cbdata)
{
size_t *ref = (size_t *) cbdata;
*ref = errhandler_ref;
TEST_VERBOSE(("PMIX client ERRHANDLER REGISTRATION CALLED WITH STATUS %d, ref=%lu", status,
(unsigned long) errhandler_ref));
}
int test_error(char *my_nspace, int my_rank, test_params params)
{
size_t errhandler_refs[MAX_ERR_HANDLERS];
struct timespec ts;
pmix_status_t status;
pmix_proc_t source;
PMIX_HIDE_UNUSED_PARAMS(params);
TEST_VERBOSE(("test-error: running error handling test cases"));
/* register specific client error handlers and test their invocation
* by triggering events from server side*/
status = PMIX_ERR_TIMEOUT;
PMIx_Register_event_handler(&status, 1, NULL, 0, timeout_errhandler, errhandler_reg_callbk1,
&errhandler_refs[0]);
/* reg a handler for comm errors */
status = PMIX_ERR_LOST_PEER_CONNECTION;
PMIx_Register_event_handler(&status, 1, NULL, 0, comfail_errhandler, errhandler_reg_callbk1,
&errhandler_refs[1]);
/* inject error from client */
done = false;
pmix_strncpy(source.nspace, my_nspace, PMIX_MAX_NSLEN);
source.rank = my_rank;
/* change error value to test other error notifications */
PMIx_Notify_event(TEST_NOTIFY, &source, PMIX_RANGE_NAMESPACE, NULL, 0, op1_callbk, NULL);
while (!done) {
ts.tv_sec = 0;
ts.tv_nsec = 100000;
nanosleep(&ts, NULL);
}
done = false;
/* dereg all handlers*/
PMIx_Deregister_event_handler(errhandler_refs[0], op1_callbk, NULL);
/* loop until we get callback */
while (!done) {
ts.tv_sec = 0;
ts.tv_nsec = 100000;
nanosleep(&ts, NULL);
}
done = false;
PMIx_Deregister_event_handler(errhandler_refs[1], op1_callbk, NULL);
/* loop until we get callback */
while (!done) {
ts.tv_sec = 0;
ts.tv_nsec = 100000;
nanosleep(&ts, NULL);
}
return PMIX_SUCCESS;
}
|