I am currently developing an IPC library for the needs of my project. The library should establish a point-to point communication channel between two independent applications. It should be able to use different mechanisms for data transmission. I've written a set of unit tests using Boost.Test library to test different parts of the functionality. Currently, I am facing a slight inconvenience in a testing framework behaviour when it comes to running transport layer tests. Since, one of the transports is using MPI as a communication channel I need to run at least two processes (server and client), but I want to have only one instance of test (let's say server-side). Instead, when I run the test - I get two instances at once, which I wouldn't call a real problem but it is somewhat inconvenient. My code for testing is here:
void prepare_test() {
MPI_Init(NULL, NULL);
int size;
int rank;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
BOOST_TEST(size == 2);
int color = rank;
MPI_Comm_split(MPI_COMM_WORLD, color, rank, &small_comm);
server = rank == 0;
if (server) {
mkdir(CLIENT_PATH.c_str(), 0777);
}
}
void destroy_test() {
if (server) {
rmdir(CLIENT_PATH.c_str());
}
MPI_Finalize();
}
BOOST_DATA_TEST_CASE(connect_test,
bdata::make(generate_transports()),
each_transport) {
prepare_test();
Transport* current_transport = dynamic_cast<Transport*>(each_transport);
int result;
if (server) {
current_transport->init_server(CLIENT_PATH, 1);
result = current_transport->accept_connection(1);
current_transport->destroy(CLIENT_PATH);
BOOST_TEST(result == 0);
} else {
current_transport->init_client(CLIENT_PATH);
result = current_transport->connect_address(0);
}
destroy_test();
}
One of the possible solutions that I can see is to create a separate binary with client code and run it along with the test binary (which should be launched with only one process now), but this solution feels a little clumsy, so maybe someone can suggest a better way of doing that?
Aucun commentaire:
Enregistrer un commentaire