Commit 80b736ae authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added put/get test

parent c39256e4
......@@ -16,7 +16,14 @@ target_include_directories (test-send-recv-expected PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries (test-send-recv-expected mona)
add_executable (test-put-get test-put-get.c munit/munit.c)
target_include_directories (test-put-get PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/munit
${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries (test-put-get 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)
#include <mpi.h>
#include "munit/munit.h"
#include "mona.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("na+sm", 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_put_get(const MunitParameter params[], void* data)
{
(void)params;
test_context* context = (test_context*)data;
na_return_t ret;
mona_instance_t mona = context->mona;
void* plugin_data = NULL;
size_t msg_len = mona_msg_get_max_unexpected_size(mona);
char* msg_buf = (char*)mona_msg_buf_alloc(mona, msg_len, &plugin_data);
char* bulk_buf = (char*)calloc(1024, 1);
na_mem_handle_t mem_handle = NA_MEM_HANDLE_NULL;
ret = mona_mem_handle_create(mona, bulk_buf, 1024, NA_MEM_READWRITE, &mem_handle);
munit_assert_int(ret, ==, NA_SUCCESS);
ret = mona_mem_register(mona, mem_handle);
munit_assert_int(ret, ==, NA_SUCCESS);
na_size_t mem_handle_size = mona_mem_handle_get_serialize_size(mona, mem_handle);
if(context->rank == 0) { // sender
// set the buffer content
int i;
for(i=0; i < 1024; i++) {
bulk_buf[i] = i % 32;
}
// initialize unexpected message
ret = mona_msg_init_unexpected(mona, msg_buf, msg_len);
munit_assert_int(ret, ==, NA_SUCCESS);
// serialize local memory handle into message
ret = mona_mem_handle_serialize(mona,
msg_buf + mona_msg_get_unexpected_header_size(mona),
mem_handle_size,
mem_handle);
munit_assert_int(ret, ==, NA_SUCCESS);
// send unexpected message
ret = mona_msg_send_unexpected(
mona, msg_buf, msg_len, plugin_data, context->other_addr, 0, 1234);
munit_assert_int(ret, ==, NA_SUCCESS);
// receive unexpected message
ret = mona_msg_recv_unexpected(
mona, msg_buf, msg_len, plugin_data,
NULL, NULL, NULL);
munit_assert_int(ret, ==, NA_SUCCESS);
// check the new content of the buffer
for(i=0; i < 1024; i++) {
munit_assert_int(bulk_buf[i], ==, (i+1) % 32);
}
} else { // receiver
// receive unexpected message
ret = mona_msg_recv_unexpected(
mona, msg_buf, msg_len, plugin_data,
NULL, NULL, NULL);
munit_assert_int(ret, ==, NA_SUCCESS);
// deserialize remote memory handle
na_mem_handle_t remote_mem_handle = NA_MEM_HANDLE_NULL;
ret = mona_mem_handle_deserialize(mona, &remote_mem_handle,
msg_buf + mona_msg_get_unexpected_header_size(mona),
mem_handle_size);
munit_assert_int(ret, ==, NA_SUCCESS);
// issue GET
ret = mona_get(mona, mem_handle, 0, remote_mem_handle, 0, 1024, context->other_addr, 0);
munit_assert_int(ret, ==, NA_SUCCESS);
// modify buffer
int i;
for(i=0; i < 1024; i++) {
bulk_buf[i] = (i+1) % 32;
}
// issue PUT
ret = mona_put(mona, mem_handle, 0, remote_mem_handle, 0, 1024, context->other_addr, 0);
munit_assert_int(ret, ==, NA_SUCCESS);
// initialize unexpected message
ret = mona_msg_init_unexpected(mona, msg_buf, msg_len);
munit_assert_int(ret, ==, NA_SUCCESS);
// send unexpected message
ret = mona_msg_send_unexpected(
mona, msg_buf, msg_len, plugin_data, context->other_addr, 0, 1234);
munit_assert_int(ret, ==, NA_SUCCESS);
// free remote handle
ret = mona_mem_handle_free(mona, remote_mem_handle);
munit_assert_int(ret, ==, NA_SUCCESS);
}
ret = mona_msg_buf_free(mona, msg_buf, plugin_data);
munit_assert_int(ret, ==, NA_SUCCESS);
ret = mona_mem_deregister(mona, mem_handle);
munit_assert_int(ret, ==, NA_SUCCESS);
ret = mona_mem_handle_free(mona, mem_handle);
munit_assert_int(ret, ==, NA_SUCCESS);
return MUNIT_OK;
}
static MunitTest test_suite_tests[] = {
{ (char*) "/put-get", test_put_get, 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/rma", 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);
}
......@@ -83,7 +83,7 @@ static MunitResult test_send_recv_expected(const MunitParameter params[], void*
MPI_Barrier(MPI_COMM_WORLD);
ret = mona_msg_send_expected(
mona, buf, msg_len, plugin_data, context->other_addr, 0, 34);
mona, buf, msg_len, plugin_data, context->other_addr, 0, 0);
munit_assert_int(ret, ==, NA_SUCCESS);
} else { // receiver
......@@ -93,7 +93,7 @@ static MunitResult test_send_recv_expected(const MunitParameter params[], void*
ret = mona_msg_irecv_expected(
mona, buf, msg_len, plugin_data,
context->other_addr, 0, 34, &op, &req);
context->other_addr, 0, 0, &op, &req);
munit_assert_int(ret, ==, NA_SUCCESS);
MPI_Barrier(MPI_COMM_WORLD);
......
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