Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
hg_return_t
hg_test_drc_acquire(int argc, char *argv[], struct hg_test_info *hg_test_info)
{
    struct hg_test_info hg_test_drc_info = { 0 };
    struct hg_init_info hg_test_drc_init_info = { 0 };
    hg_return_t ret = HG_SUCCESS;

    if (!hg_test_info->credential) {
    /* Create an NA class with "tcp" protocol */
    hg_test_drc_info.na_test_info.extern_init = NA_TRUE;
    hg_test_drc_info.na_test_info.protocol = strdup("tcp");
    hg_test_drc_info.na_test_info.listen = hg_test_info->na_test_info.listen;
    if (NA_Test_init(argc, argv, &hg_test_drc_info.na_test_info) != NA_SUCCESS) {
        HG_LOG_ERROR("Could not initialize NA test layer");
        ret = HG_NA_ERROR;
        goto done;
    }

    /* Assign NA class */
    hg_test_drc_init_info.na_class = hg_test_drc_info.na_test_info.na_class;

    /* Init HG HL with init options */
    ret = HG_Hl_init_opt(NULL, hg_test_drc_info.na_test_info.listen,
        &hg_test_drc_init_info);
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not initialize HG HL");
        goto done;
    }
    hg_test_drc_info.hg_class = HG_CLASS_DEFAULT;
    hg_test_drc_info.context = HG_CONTEXT_DEFAULT;
    hg_test_drc_info.request_class = HG_REQUEST_CLASS_DEFAULT;

    /* Attach test info to class */
    HG_Class_set_data(hg_test_drc_info.hg_class, &hg_test_drc_info, NULL);

    /* Register routines */
    hg_test_drc_register(hg_test_drc_info.hg_class);

    /* Acquire DRC token */
    if (hg_test_drc_info.na_test_info.listen) {
        char addr_string[NA_TEST_MAX_ADDR_NAME];
        na_size_t addr_string_len = NA_TEST_MAX_ADDR_NAME;
        hg_addr_t self_addr;

        ret = hg_test_drc_token_acquire(&hg_test_drc_info);
        if (ret != HG_SUCCESS) {
            HG_LOG_ERROR("Could not acquire DRC token");
            goto done;
        }

        /* TODO only rank 0 */
        ret = HG_Addr_self(hg_test_drc_info.hg_class, &self_addr);
        if (ret != HG_SUCCESS) {
            HG_LOG_ERROR("Could not get self addr");
            goto done;
        }

        ret = HG_Addr_to_string(hg_test_drc_info.hg_class, addr_string,
            &addr_string_len, self_addr);
        if (ret != HG_SUCCESS) {
            HG_LOG_ERROR("Could not convert addr to string");
            goto done;
        }
        HG_Addr_free(hg_test_drc_info.hg_class, self_addr);

        na_test_set_config(addr_string);

        /* Used by CTest Test Driver to know when to launch clients */
        MERCURY_TESTING_READY_MSG();

        /* Progress */
        do {
            unsigned int total_count = 0;
            unsigned int actual_count = 0;

            do {
                ret = HG_Trigger(hg_test_drc_info.context, 0, 1, &actual_count);
                total_count += actual_count;
            } while ((ret == HG_SUCCESS) && actual_count);

            /* Break as soon as something was triggered */
            if (total_count)
                break;

            ret = HG_Progress(hg_test_drc_info.context, HG_MAX_IDLE_TIME);
        } while (ret == HG_SUCCESS || ret == HG_TIMEOUT);
    } else {
        char test_addr_name[NA_TEST_MAX_ADDR_NAME] = { '\0' };

        if (hg_test_drc_info.na_test_info.mpi_comm_rank == 0)
            na_test_get_config(test_addr_name, NA_TEST_MAX_ADDR_NAME);

        /* Broadcast addr name */
        NA_Test_bcast(test_addr_name, NA_TEST_MAX_ADDR_NAME, 0,
            &hg_test_drc_info.na_test_info);

        hg_test_drc_info.na_test_info.target_name = strdup(test_addr_name);
        printf("# Target name read: %s\n",
            hg_test_drc_info.na_test_info.target_name);

        ret = hg_test_drc_token_request(&hg_test_drc_info);
        if (ret != HG_SUCCESS) {
            HG_LOG_ERROR("Could not request DRC token");
            goto done;
        }
    }

#ifdef MERCURY_HAS_PARALLEL_TESTING
    /* TODO bcast cookie when parallel mode */
#endif

    /* Finalize HG HL interface */
    ret = HG_Hl_finalize();
    if (ret != HG_SUCCESS) {
        HG_LOG_ERROR("Could not finalize HG HL");
        goto done;
    }

    /* Finalize NA test class interface */
#ifdef MERCURY_HAS_PARALLEL_TESTING
    hg_test_drc_info.na_test_info.mpi_no_finalize = NA_TRUE;
#endif
    if (NA_Test_finalize(&hg_test_drc_info.na_test_info) != NA_SUCCESS) {
        HG_LOG_ERROR("Could not finalize NA test interface");
        ret = HG_NA_ERROR;
        goto done;
    }
    hg_test_info->credential = hg_test_drc_info.credential;
    } else {
        hg_test_drc_info.credential = hg_test_info->credential;
        ret = hg_test_drc_token_acquire(&hg_test_drc_info);
        if (ret != HG_SUCCESS) {
            HG_LOG_ERROR("Could not acquire DRC token");
            goto done;
        }
    }

    /* Copy cookie/credential info */
    hg_test_info->wlm_id = hg_test_drc_info.wlm_id;
    hg_test_info->credential_info = hg_test_drc_info.credential_info;
    hg_test_info->cookie = hg_test_drc_info.cookie;

    /* Sleep a few seconds to make sure listener is initialized */
    if (!hg_test_drc_info.na_test_info.listen) {
        unsigned int sleep_sec = 5;

        printf("# Sleeping now for %d seconds...\n", sleep_sec);
        fflush(stdout);
        sleep(sleep_sec);
    }

done:
    return ret;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
hg_return_t
HG_Test_finalize(hg_class_t *hg_class)
{
    hg_return_t ret = HG_SUCCESS;
    na_return_t na_ret;

    NA_Test_barrier();

    (void)hg_class;
    if (hg_test_is_client_g) {
        /* Terminate server */
        if (hg_test_rank_g == 0) hg_test_finalize_rpc();

        /* Free addr id */
        ret = HG_Addr_free(HG_CLASS_DEFAULT, hg_test_addr_g);
        if (ret != HG_SUCCESS) {
            fprintf(stderr, "Could not free addr\n");
            goto done;
        }
        hg_test_addr_g = HG_ADDR_NULL;
    } else if (hg_test_addr_table_g) {
        unsigned int i;

        for (i = 0; i < hg_test_addr_table_size_g; i++)
            HG_Addr_free(HG_CLASS_DEFAULT, hg_test_addr_table_g[i]);
        free(hg_test_addr_table_g);
        hg_test_addr_table_g = NULL;
    }

    /* Destroy bulk handle */
    HG_Bulk_free(hg_test_local_bulk_handle_g);
    hg_test_local_bulk_handle_g = HG_BULK_NULL;

#ifdef MERCURY_TESTING_HAS_THREAD_POOL
    hg_thread_pool_destroy(hg_test_thread_pool_g);
    hg_thread_mutex_destroy(&hg_test_local_bulk_handle_mutex_g);
#endif

    /* Finalize interface */
    ret = HG_Hl_finalize();
    if (ret != HG_SUCCESS) {
        fprintf(stderr, "Could not finalize HG\n");
        goto done;
    }

    na_ret = NA_Context_destroy(hg_test_na_class_g, hg_test_na_context_g);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not destroy NA context\n");
        goto done;
    }
    hg_test_na_context_g = NULL;

    na_ret = NA_Test_finalize(hg_test_na_class_g);
    if (na_ret != NA_SUCCESS) {
        fprintf(stderr, "Could not finalize NA interface\n");
        goto done;
    }

done:
     return ret;
}