refactor tests

* move to gtest
* add shmem tests
* cleanup cmake file (organize tests in suites)
This commit is contained in:
Dennis Klein
2017-03-28 14:19:08 +02:00
committed by Mohammad Al-Turany
parent 55a9d69908
commit 7e34f7042f
38 changed files with 1185 additions and 1298 deletions

View File

@@ -0,0 +1,69 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* @file fairmq/test/protocols/_pub_sub.cxx
*/
#include "runner.h"
#include <gtest/gtest.h>
#include <sstream> // std::stringstream
#include <thread>
namespace
{
using namespace std;
using namespace fair::mq::test;
auto RunPubSub(string transport) -> void
{
auto pub = execute_result{"", 0};
thread pub_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id pub_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
pub = execute(cmd.str(), "[PUB]");
});
auto sub1 = execute_result{"", 0};
thread sub1_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id sub_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
sub1 = execute(cmd.str(), "[SUB1]");
});
auto sub2 = execute_result{"", 0};
thread sub2_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id sub_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
sub2 = execute(cmd.str(), "[SUB2]");
});
pub_thread.join();
sub1_thread.join();
sub2_thread.join();
cerr << pub.error_out << sub1.error_out << sub2.error_out;
exit(pub.exit_code + sub1.exit_code + sub2.exit_code);
}
TEST(PubSub, ZeroMQ)
{
EXPECT_EXIT(RunPubSub("zeromq"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull");
}
#ifdef NANOMSG_FOUND
TEST(PubSub, Nanomsg)
{
EXPECT_EXIT(RunPubSub("nanomsg"), ::testing::ExitedWithCode(0), "PUB-SUB test successfull");
}
#endif /* NANOMSG_FOUND */
} // namespace

View File

@@ -0,0 +1,65 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* @file fairmq/test/protocols/_push_pull.cxx
*/
#include "runner.h"
#include <gtest/gtest.h>
#include <sstream> // std::stringstream
#include <thread>
namespace
{
using namespace std;
using namespace fair::mq::test;
auto RunPushPull(string transport) -> void
{
auto push = execute_result{"", 100};
thread push_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id push_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
push = execute(cmd.str(), "[PUSH]");
});
auto pull = execute_result{"", 100};
thread pull_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id pull_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
pull = execute(cmd.str(), "[PULL]");
});
push_thread.join();
pull_thread.join();
cerr << push.error_out << pull.error_out;
exit(push.exit_code + pull.exit_code);
}
TEST(PushPull, ZeroMQ)
{
EXPECT_EXIT(RunPushPull("zeromq"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
}
TEST(PushPull, ShMem)
{
EXPECT_EXIT(RunPushPull("shmem"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
}
#ifdef NANOMSG_FOUND
TEST(PushPull, Nanomsg)
{
EXPECT_EXIT(RunPushPull("nanomsg"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
}
#endif /* NANOMSG_FOUND */
} // namespace

View File

@@ -0,0 +1,74 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* @file fairmq/test/protocols/_req_rep.cxx
*/
#include "runner.h"
#include <gtest/gtest.h>
#include <sstream> // std::stringstream
#include <thread>
namespace
{
using namespace std;
using namespace fair::mq::test;
auto RunReqRep(string transport) -> void
{
auto rep = execute_result{ "", 0 };
thread rep_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id rep_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
rep = execute(cmd.str(), "[REP]");
});
auto req1 = execute_result{ "", 0 };
thread req1_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id req_1" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
req1 = execute(cmd.str(), "[REQ1]");
});
auto req2 = execute_result{ "", 0 };
thread req2_thread([&]() {
stringstream cmd;
cmd << runTestDevice << " --id req_2" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
req2 = execute(cmd.str(), "[REQ2]");
});
rep_thread.join();
req1_thread.join();
req2_thread.join();
cerr << req1.error_out << req2.error_out << rep.error_out;
exit(req1.exit_code + req2.exit_code + rep.exit_code);
}
TEST(ReqRep, ZeroMQ)
{
EXPECT_EXIT(RunReqRep("zeromq"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
}
TEST(ReqRep, ShMem)
{
EXPECT_EXIT(RunReqRep("shmem"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
}
#ifdef NANOMSG_FOUND
TEST(ReqRep, Nanomsg)
{
EXPECT_EXIT(RunReqRep("nanomsg"), ::testing::ExitedWithCode(0), "REQ-REP test successfull");
}
#endif /* NANOMSG_FOUND */
} // namespace

View File

@@ -0,0 +1,51 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* @file fairmq/test/protocols/_transfer_timeout.cxx
*/
#include "runner.h"
#include <gtest/gtest.h>
#include <sstream> // std::stringstream
namespace
{
using namespace std;
using namespace fair::mq::test;
auto RunTransferTimeout(string transport) -> void
{
stringstream cmd;
cmd << runTestDevice << " --id transfer_timeout_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\"";
auto res = execute(cmd.str());
cerr << res.error_out;
exit(res.exit_code);
}
TEST(TransferTimeout, ZeroMQ)
{
EXPECT_EXIT(RunTransferTimeout("zeromq"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
}
TEST(TransferTimeout, ShMem)
{
EXPECT_EXIT(RunTransferTimeout("shmem"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
}
#ifdef NANOMSG_FOUND
TEST(TransferTimeout, Nanomsg)
{
EXPECT_EXIT(RunTransferTimeout("nanomsg"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
}
#endif /* NANOMSG_FOUND */
} // namespace

View File

@@ -0,0 +1,348 @@
{
"fairMQOptions": {
"devices": [
{
"id": "push_zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5557",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "push"
}
]
},
{
"id": "pull_zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5557",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "pull"
}
]
},
{
"id": "push_nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5757",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "push"
}
]
},
{
"id": "pull_nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5757",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "pull"
}
]
},
{
"id": "push_shmem",
"channels": [
{
"address": "tcp://127.0.0.1:5857",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "shmem",
"type": "push"
}
]
},
{
"id": "pull_shmem",
"channels": [
{
"address": "tcp://127.0.0.1:5857",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "shmem",
"type": "pull"
}
]
},
{
"id": "pub_zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5556",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "pub"
},
{
"address": "tcp://127.0.0.1:5555",
"method": "bind",
"name": "control",
"rateLogging": 0,
"transport": "zeromq",
"type": "pull"
}
]
},
{
"id": "pub_nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5756",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "pub"
},
{
"address": "tcp://127.0.0.1:5755",
"method": "bind",
"name": "control",
"rateLogging": 0,
"transport": "nanomsg",
"type": "pull"
}
]
},
{
"id": "sub_zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5556",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "sub"
},
{
"address": "tcp://127.0.0.1:5555",
"method": "connect",
"name": "control",
"rateLogging": 0,
"transport": "zeromq",
"type": "push"
}
]
},
{
"id": "sub_nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5756",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "sub"
},
{
"address": "tcp://127.0.0.1:5755",
"method": "connect",
"name": "control",
"rateLogging": 0,
"transport": "nanomsg",
"type": "push"
}
]
},
{
"id": "req_1zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5558",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "req"
}
]
},
{
"id": "req_1nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5758",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "req"
}
]
},
{
"id": "req_2zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5558",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "req"
}
]
},
{
"id": "req_2nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5758",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "req"
}
]
},
{
"id": "req_1shmem",
"channels": [
{
"address": "tcp://127.0.0.1:5758",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "shmem",
"type": "req"
}
]
},
{
"id": "req_2shmem",
"channels": [
{
"address": "tcp://127.0.0.1:5758",
"method": "connect",
"name": "data",
"rateLogging": 0,
"transport": "shmem",
"type": "req"
}
]
},
{
"id": "rep_zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5558",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "zeromq",
"type": "rep"
}
]
},
{
"id": "rep_nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5758",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "nanomsg",
"type": "rep"
}
]
},
{
"id": "rep_shmem",
"channels": [
{
"address": "tcp://127.0.0.1:5758",
"method": "bind",
"name": "data",
"rateLogging": 0,
"transport": "shmem",
"type": "rep"
}
]
},
{
"id": "transfer_timeout_zeromq",
"channels": [
{
"address": "tcp://127.0.0.1:5559",
"method": "bind",
"name": "data-in",
"rateLogging": 0,
"transport": "zeromq",
"type": "pull"
},
{
"address": "tcp://127.0.0.1:5560",
"method": "bind",
"name": "data-out",
"rateLogging": 0,
"transport": "zeromq",
"type": "push"
}
]
},
{
"id": "transfer_timeout_shmem",
"channels": [
{
"address": "tcp://127.0.0.1:5959",
"method": "bind",
"name": "data-in",
"rateLogging": 0,
"transport": "shmem",
"type": "pull"
},
{
"address": "tcp://127.0.0.1:5960",
"method": "bind",
"name": "data-out",
"rateLogging": 0,
"transport": "shmem",
"type": "push"
}
]
},
{
"id": "transfer_timeout_nanomsg",
"channels": [
{
"address": "tcp://127.0.0.1:5759",
"method": "bind",
"name": "data-in",
"rateLogging": 0,
"transport": "nanomsg",
"type": "pull"
},
{
"address": "tcp://127.0.0.1:5560",
"method": "bind",
"name": "data-out",
"rateLogging": 0,
"transport": "nanomsg",
"type": "push"
}
]
}
]
}
}

View File

@@ -0,0 +1,66 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* @file fairmq/test/protocols/runner.cxx.in
*/
#include "runner.h"
#include <gtest/gtest.h>
#include <sstream>
#include <string>
#include <pstream.h> // redi::ipstream
#include <iostream>
namespace fair
{
namespace mq
{
namespace test
{
using namespace std;
string runTestDevice = "@RUN_TEST_DEVICE@";
string mqConfig = "@MQ_CONFIG@";
auto execute(string cmd, string log_prefix) -> execute_result
{
auto res = execute_result{"", 0};
stringstream out;
// Log cmd
out << log_prefix << cmd << endl;
// Execute command and capture stderr, add log_prefix line by line
redi::ipstream in(cmd, redi::pstreams::pstderr);
auto line = string{};
while (getline(in, line))
{
out << log_prefix << line << endl;
}
in.close();
// Capture exit code
res.exit_code = in.rdbuf()->status();
out << log_prefix << " Exit code: " << res.exit_code << endl;
// Return result
res.error_out = out.str();
return res;
}
} /* namespace test */
} /* namespace mq */
} /* namespace fair */
auto main(int argc, char** argv) -> int
{
::testing::InitGoogleTest(&argc, argv);
::testing::FLAGS_gtest_death_test_style = "threadsafe";
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,49 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* @file fairmq/test/protocols/runner.h
*/
#ifndef FAIR_MQ_TEST_RUNNER_H
#define FAIR_MQ_TEST_RUNNER_H
#include <string>
namespace fair
{
namespace mq
{
namespace test
{
extern std::string runTestDevice; /// Path to test device executable.
extern std::string mqConfig; /// Path to FairMQ device config file.
/**
* Result type for execute function. Holds captured stderr output and exit code.
*/
struct execute_result {
std::string error_out;
int exit_code;
};
/**
* Execute given command in forked process and capture stderr output
* and exit code.
*
* @param[in] cmd Command to execute
* @param[in] log_prefix How to prefix each captured output line with
* @return Captured error output and exit code
*/
auto execute(std::string cmd, std::string log_prefix = "") -> execute_result;
} /* namespace test */
} /* namespace mq */
} /* namespace fair */
#endif /* FAIR_MQ_TEST_RUNNER_H */