Commit 41261961 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added test for comm-based send/recv

parent e1986e10
......@@ -11,7 +11,7 @@ typedef struct mona_comm {
mona_instance_t mona;
na_size_t size;
na_size_t rank;
na_addr_t addrs[1];
na_addr_t* addrs;
} mona_comm;
#define NB_OP_INIT(__argtype__) \
......@@ -44,15 +44,20 @@ na_return_t mona_comm_create(
{
na_return_t na_ret;
unsigned i = 0, j = 0, k = 0;
if(count == 0)
if(count == 0) {
return NA_INVALID_ARG;
na_size_t s = sizeof(mona_comm) - 1 + count*sizeof(na_addr_t);
mona_comm_t tmp = calloc(1, s);
}
mona_comm_t tmp = calloc(1, sizeof(mona_comm));
if(!tmp)
return NA_NOMEM;
tmp->mona = mona;
tmp->size = count;
tmp->rank = count;
tmp->addrs = calloc(sizeof(na_addr_t), count);
if(!tmp->addrs) {
na_ret = NA_NOMEM;
goto error;
}
// copy array of addresses and find rank of self
for(i = 0; i < count; i++) {
na_ret = mona_addr_dup(mona, peers[i], tmp->addrs + i);
......@@ -89,6 +94,7 @@ error:
for(j = 0; j < i; j++) {
mona_addr_free(mona, tmp->addrs[i]);
}
free(tmp->addrs);
free(tmp);
goto finish;
}
......@@ -102,6 +108,7 @@ na_return_t mona_comm_free(mona_comm_t comm)
if(na_ret != NA_SUCCESS)
return na_ret;
}
free(comm->addrs);
free(comm);
return na_ret;
}
......
......@@ -298,7 +298,16 @@ na_bool_t mona_addr_cmp(
na_addr_t addr1,
na_addr_t addr2)
{
return NA_Addr_cmp(mona->na_class, addr1, addr2);
if(addr1 == NA_ADDR_NULL && addr2 == NA_ADDR_NULL)
return NA_TRUE;
if(addr1 == NA_ADDR_NULL || addr2 == NA_ADDR_NULL)
return NA_FALSE;
char str1[256], str2[256];
na_size_t s = 256;
mona_addr_to_string(mona, str1, &s, addr1);
s = 256;
mona_addr_to_string(mona, str2, &s, addr2);
return strcmp(str1, str2) == 0 ? NA_TRUE : NA_FALSE;
}
na_bool_t mona_addr_is_self(
......@@ -774,7 +783,6 @@ na_return_t mona_recv(
na_tag_t recv_tag = 0;
// wait for a matching unexpected message to come around
msg = wait_for_matching_unexpected_message(mona, src, tag, &recv_size, &recv_addr, &recv_tag);
if(!msg) return NA_PROTOCOL_ERROR;
......
......@@ -52,13 +52,20 @@ target_include_directories (test-na PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries (test-na mona)
add_executable (test-send-recv-coll test-send-recv-coll.c munit/munit.c)
target_include_directories (test-send-recv-coll PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/munit
${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries (test-send-recv-coll mona)
add_test (NAME TestInit COMMAND ./test-init)
add_test (NAME TestSendRecv COMMAND mpirun -np 2 ./test-send-recv)
add_test (NAME TestSendRecvSelf COMMAND mpirun -np 2 ./test-send-recv-self)
add_test (NAME TestISendIRecv COMMAND mpirun -np 2 ./test-isend-irecv)
add_test (NAME TestISendIRecvMulti COMMAND mpirun -np 2 ./test-isend-irecv-multi)
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)
add_test (NAME TestSendRecv COMMAND mpirun -np 2 ./test-send-recv --no-fork)
add_test (NAME TestSendRecvSelf COMMAND mpirun -np 2 ./test-send-recv-self --no-fork)
add_test (NAME TestISendIRecv COMMAND mpirun -np 2 ./test-isend-irecv --no-fork)
add_test (NAME TestISendIRecvMulti COMMAND mpirun -np 2 ./test-isend-irecv-multi --no-fork)
add_test (NAME TestSendRecvUnexpected COMMAND mpirun -np 2 ./test-send-recv-unexpected --no-fork)
add_test (NAME TestSendRecvExpected COMMAND mpirun -np 2 ./test-send-recv-expected --no-fork)
add_test (NAME TestPutGet COMMAND mpirun -np 2 ./test-put-get --no-fork)
add_test (NAME TestNA COMMAND mpirun -np 2 ./test-na --no-fork)
add_test (NAME TestSendRecvColl COMMAND mpirun -np 2 ./test-send-recv-coll --no-fork)
#include <mpi.h>
#include "munit/munit.h"
#include "mona.h"
#include "mona-coll.h"
typedef struct {
mona_instance_t mona;
int rank;
na_addr_t self_addr;
na_addr_t other_addr;
} test_context;
static void* test_context_setup(const MunitParameter params[], void* user_data)
{
(void)params;
(void)user_data;
int ret;
MPI_Init(NULL, NULL);
ABT_init(0, NULL);
mona_instance_t mona = mona_init("ofi+tcp", NA_TRUE, NULL);
test_context* context = (test_context*)calloc(1, sizeof(*context));
context->mona = mona;
MPI_Comm_rank(MPI_COMM_WORLD, &(context->rank));
ret = mona_addr_self(mona, &(context->self_addr));
munit_assert_int(ret, ==, NA_SUCCESS);
char self_addr_str[128];
na_size_t self_addr_size = 128;
ret = mona_addr_to_string(mona, 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 = mona_addr_lookup(mona, other_addr_str, &(context->other_addr));
munit_assert_int(ret, ==, NA_SUCCESS);
return context;
}
static void test_context_tear_down(void* fixture)
{
MPI_Barrier(MPI_COMM_WORLD);
test_context* context = (test_context*)fixture;
mona_addr_free(context->mona, context->self_addr);
mona_addr_free(context->mona, context->other_addr);
mona_finalize(context->mona);
free(context);
ABT_finalize();
MPI_Finalize();
}
static MunitResult test_send_recv(const MunitParameter params[], void* data)
{
(void)params;
test_context* context = (test_context*)data;
na_return_t ret;
mona_instance_t mona = context->mona;
char* buf = malloc(8192);
na_size_t msg_len = 8192;
mona_comm_t comm;
na_addr_t comm_addrs[2];
comm_addrs[0] = context->rank == 0 ? context->self_addr : context->other_addr;
comm_addrs[1] = context->rank == 0 ? context->other_addr : context->self_addr;
ret = mona_comm_create(mona, 2, comm_addrs, &comm);
munit_assert_int(ret, ==, NA_SUCCESS);
if(context->rank == 0) { // sender
int i;
for(i = 0; i < (int)msg_len; i++) {
buf[i] = i % 32;
}
ret = mona_comm_send(comm, buf, msg_len, 1, 1234);
munit_assert_int(ret, ==, NA_SUCCESS);
na_size_t recv_size;
ret = mona_comm_recv(comm, buf, 64, 1, 1234, &recv_size, NULL, NULL);
munit_assert_int(ret, ==, NA_SUCCESS);
for(i = 0; i < 64; i++) {
munit_assert_int(buf[i], ==, (i+1) % 32);
}
} else { // receiver
int i;
na_size_t recv_size;
ret = mona_comm_recv(comm, buf, msg_len, 0, 1234, &recv_size, NULL, NULL);
munit_assert_int(ret, ==, NA_SUCCESS);
for(i = 0; i < (int)msg_len; i++) {
munit_assert_int(buf[i], ==, i % 32);
}
for(i=0; i < 64; i++) {
buf[i] = (i+1) % 32;
}
ret = mona_comm_send(comm, buf, 64, 0, 1234);
munit_assert_int(ret, ==, NA_SUCCESS);
}
ret = mona_comm_free(comm);
munit_assert_int(ret, ==, NA_SUCCESS);
return MUNIT_OK;
}
static MunitTest test_suite_tests[] = {
{ (char*) "/comm", test_send_recv, 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/send-recv", 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