Commit c9cda525 authored by niklas.baumgarten's avatar niklas.baumgarten

added new test

parent 11d7065d
......@@ -30,3 +30,5 @@ target_link_libraries(TestMain MONTECARLO LIB_TEST)
add_executable(TestParallelization TestParallelization.cpp)
target_link_libraries(TestParallelization LIB_TEST)
add_executable(TestExchangeBuffer TestExchangeBuffer.cpp)
target_link_libraries(TestExchangeBuffer LIB_TEST)
#include "parallel/Parallel.hpp"
#include "TestEnvironment.hpp"
class TestExchangeBuffer : public Test {
public:
ExchangeBuffer exBuffer;
void SetUp() {}
void TearDown() {
exBuffer.Destruct();
}
};
TEST_F(TestExchangeBuffer, TestIsInitialized) {
EXPECT_FALSE(exBuffer.Initialized());
}
TEST_F(TestExchangeBuffer, ReceiveSize) {
for (int p = 0; p < PPM->Size(); p++)
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
TEST_F(TestExchangeBuffer, TestSendCstr) {
std::string message = "Test";
const char *cline = message.c_str();
for (int i = 0; i < message.length(); ++i)
exBuffer.Send(0) << cline[i];
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 4);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
TEST_F(TestExchangeBuffer, TestSendStr) {
std::string message = "Test";
for (int i = 0; i < message.length(); ++i)
exBuffer.Send(0) << message[i];
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 4);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
// std::string messageR = "";
//
// for (int p = 0; p < PPM->Size(); p++) {
// if (PPM->Proc() == 0) {
// for (int i = 0; i < message.length(); ++i)
// exBuffer.Receive(p) >> messageR[i];
// std::cout << messageR;
//// EXPECT_EQ(messageR, message);
// }
// else {
// exBuffer.Receive(p) >> messageR;
// std::cout << messageR;
//// EXPECT_EQ(messageR, "____");
// }
// }
}
TEST_F(TestExchangeBuffer, TestInt) {
ExchangeBuffer exBuffer;
int message = 0;
exBuffer.Send(0) << message;
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 4);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
TEST_F(TestExchangeBuffer, TestDouble) {
double message = 0.0;
exBuffer.Send(0) << message;
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 8);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
TEST_F(TestExchangeBuffer, TestShort) {
short message = 0.0;
exBuffer.Send(0) << message;
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 2);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
/*
* Todo
* finish at least some tests on exchange buffer
* extend with new PPM
* write some tests with split
* move tests to kernel
*
*/
//TEST(TestExchangeBuffer, Duff) {
// ExchangeBuffer exBuffer;
// const char *mSendA = "A";
// const char *mSendB = "B";
// const char *mSendC = "C";
// const char *mSendD = "D";
//
//
// /*
// * p = 0: ABC
// * p = 1: AB
// * p = 2: A
// * p = 3: D
// */
//
// int q = 0;
//// if (PPM->Proc() == q) {
//// exBuffer.Send(0) << mSendA << mSendB;
// exBuffer.Send(1) << "proc 1 send: " << mSendA;
//// exBuffer.Send(2) << mSendA;
//// exBuffer.Send(1) << mSendB;
//// exBuffer.Send(0) << mSendC;
//// exBuffer.Send(3) << mSendD;
//// }
//
// exBuffer.Communicate();
//
// char *mRecv;
// char *procID;
// std::string mRecvStr = "";
//
// int p = 0;
// for (p = 0; p < PPM->Size(); p++) {
// if (PPM->Proc() == p) {
// while (exBuffer.Receive(p).size() < exBuffer.ReceiveSize((p))) {
// exBuffer.Receive(p) >> procID;
//// exBuffer.Receive(p) >> mRecv;
//
// mRecvStr += procID;
// mRecvStr += mRecv;
// std::cout << mRecvStr << endl;
// }
// }
// }
//}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithPPM().
WithScreenLogging().
WithParallelListeners()
).RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
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