Commit 5b90693a authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added pure-NA test

parent 50576b4a
#include <mpi.h>
#include <mona.h>
#include <stdlib.h>
#define ASSERT_MESSAGE(__cond__, __msg__) \
if(!(__cond__)) { \
......
......@@ -6,10 +6,7 @@
#ifndef __MONA_H
#define __MONA_H
#include <mercury.h>
#include <mercury_types.h>
#include <mercury_bulk.h>
#include <mercury_macros.h>
#include <na.h>
#include <abt.h>
#ifdef __cplusplus
......
......@@ -4,6 +4,7 @@
* See COPYRIGHT in top-level directory.
*/
#include "mona.h"
#include <stdlib.h>
typedef struct cached_op_id* cached_op_id_t;
typedef struct cached_op_id {
......
......@@ -22,8 +22,15 @@ target_include_directories (test-put-get PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries (test-put-get mona)
add_executable (test-na test-na.c munit/munit.c)
target_include_directories (test-na PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/munit
${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries (test-na mona)
add_test (NAME TestInit COMMAND ./test-init)
add_test (NAME TestSendRecvUnexpected COMMAND mpirun -np 2 ./test-send-recv-unexpected)
add_test (NAME TestSendRecvExpected COMMAND mpirun -np 2 ./test-send-recv-expected)
add_test (NAME TestPutGet COMMAND mpirun -np 2 ./test-put-get)
add_test (NAME TestNA COMMAND mpirun -np 2 ./test-na)
#include <mpi.h>
#include "munit/munit.h"
#include <na.h>
#include <stdio.h>
#define MIN(a,b) ((a) < (b) ? (a) : (b))
typedef struct {
na_class_t* na_class;
na_context_t* na_context;
int rank;
na_addr_t self_addr;
na_addr_t other_addr;
na_op_id_t op_id;
na_size_t msg_len;
char* buf;
void* plugin_data;
int stop;
} test_context;
static void* test_context_setup(const MunitParameter params[], void* user_data)
{
(void)params;
(void)user_data;
na_return_t ret;
MPI_Init(NULL, NULL);
test_context* context = (test_context*)calloc(1, sizeof(*context));
context->na_class = NA_Initialize_opt("ofi+tcp", NA_TRUE, NULL);
context->na_context = NA_Context_create(context->na_class);
MPI_Comm_rank(MPI_COMM_WORLD, &(context->rank));
ret = NA_Addr_self(context->na_class, &(context->self_addr));
munit_assert_int(ret, ==, NA_SUCCESS);
char self_addr_str[128];
na_size_t self_addr_size = 128;
ret = NA_Addr_to_string(context->na_class, self_addr_str, &self_addr_size, context->self_addr);
munit_assert_int(ret, ==, NA_SUCCESS);
char other_addr_str[128];
MPI_Sendrecv(self_addr_str, 128, MPI_BYTE, (context->rank + 1) % 2, 0,
other_addr_str, 128, MPI_BYTE, (context->rank + 1) % 2, 0,
MPI_COMM_WORLD, MPI_STATUS_IGNORE);
ret = NA_Addr_lookup(context->na_class, other_addr_str, &(context->other_addr));
munit_assert_int(ret, ==, NA_SUCCESS);
context->msg_len = MIN(NA_Msg_get_max_expected_size(context->na_class),
2*NA_Msg_get_max_unexpected_size(context->na_class));
context->buf = (char*)NA_Msg_buf_alloc(context->na_class,
context->msg_len, &(context->plugin_data));
context->op_id = NA_Op_create(context->na_class);
return context;
}
static void test_context_tear_down(void* fixture)
{
MPI_Barrier(MPI_COMM_WORLD);
test_context* context = (test_context*)fixture;
NA_Addr_free(context->na_class, context->self_addr);
NA_Addr_free(context->na_class, context->other_addr);
NA_Msg_buf_free(context->na_class, context->buf, context->plugin_data);
NA_Op_destroy(context->na_class, context->op_id);
NA_Context_destroy(context->na_class, context->na_context);
NA_Finalize(context->na_class);
free(context);
MPI_Finalize();
}
static int sender_callback(const struct na_cb_info *info) {
test_context* context = (test_context*)(info->arg);
context->stop = 1;
return NA_SUCCESS;
}
static int receiver_callback(const struct na_cb_info *info) {
test_context* context = (test_context*)(info->arg);
context->stop = 1;
return NA_SUCCESS;
}
static MunitResult test_send_recv_expected(const MunitParameter params[], void* data)
{
(void)params;
test_context* context = (test_context*)data;
na_return_t ret;
if(context->rank == 0) { // sender
int i;
for(i = NA_Msg_get_expected_header_size(context->na_class); i < (int)context->msg_len; i++) {
context->buf[i] = i % 32;
}
ret = NA_Msg_init_expected(context->na_class, context->buf, context->msg_len);
munit_assert_int(ret, ==, NA_SUCCESS);
MPI_Barrier(MPI_COMM_WORLD);
ret = NA_Msg_send_expected(
context->na_class,
context->na_context,
sender_callback,
context,
context->buf,
context->msg_len,
context->plugin_data,
context->other_addr,
0, 0, &(context->op_id));
munit_assert_int(ret, ==, NA_SUCCESS);
} else { // receiver
ret = NA_Msg_recv_expected(
context->na_class,
context->na_context,
receiver_callback,
context,
context->buf,
context->msg_len,
context->plugin_data,
context->other_addr,
0, 0, &(context->op_id));
munit_assert_int(ret, ==, NA_SUCCESS);
MPI_Barrier(MPI_COMM_WORLD);
}
// progress loop
while(!context->stop) {
unsigned int actual_count = 0;
na_return_t trigger_ret;
do {
trigger_ret = NA_Trigger(context->na_context, 0, 1, NULL, &actual_count);
} while ((trigger_ret == NA_SUCCESS) && actual_count && !context->stop);
ret = NA_Progress(context->na_class, context->na_context, 0);
if (ret != NA_SUCCESS && ret != NA_TIMEOUT) {
fprintf(stderr, "WARNING: unexpected return value from NA_Progress (%d)\n", ret);
}
}
return MUNIT_OK;
}
static MunitTest test_suite_tests[] = {
{ (char*) "/expected", test_send_recv_expected, test_context_setup, test_context_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
static const MunitSuite test_suite = {
(char*) "/mona/na", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
return munit_suite_main(&test_suite, (void*) "mona", argc, argv);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment