Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
* move to gtest
* add shmem tests
* cleanup cmake file (organize tests in suites)
  • Loading branch information
dennisklein authored and MohammadAlTurany committed Apr 5, 2017
1 parent 644a4a0 commit 46ce442
Show file tree
Hide file tree
Showing 38 changed files with 1,184 additions and 1,297 deletions.
176 changes: 50 additions & 126 deletions fairmq/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,137 +1,61 @@
################################################################################
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence version 3 (LGPL) version 3, #
# copied verbatim in the file "LICENSE" #
################################################################################

configure_file(${CMAKE_SOURCE_DIR}/fairmq/test/test-fairmq-push-pull.sh.in ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-push-pull.sh)
configure_file(${CMAKE_SOURCE_DIR}/fairmq/test/test-fairmq-pub-sub.sh.in ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-pub-sub.sh)
configure_file(${CMAKE_SOURCE_DIR}/fairmq/test/test-fairmq-req-rep.sh.in ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-req-rep.sh)

Set(INCLUDE_DIRECTORIES
${CMAKE_SOURCE_DIR}/fairmq
${CMAKE_SOURCE_DIR}/fairmq/zeromq
${CMAKE_SOURCE_DIR}/fairmq/nanomsg
${CMAKE_SOURCE_DIR}/fairmq/devices
${CMAKE_SOURCE_DIR}/fairmq/tools
${CMAKE_SOURCE_DIR}/fairmq/options
${CMAKE_SOURCE_DIR}/fairmq/test/
${CMAKE_SOURCE_DIR}/fairmq/test/push-pull
${CMAKE_SOURCE_DIR}/fairmq/test/pub-sub
${CMAKE_SOURCE_DIR}/fairmq/test/req-rep
${CMAKE_CURRENT_BINARY_DIR}
################################################################################
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence version 3 (LGPL) version 3, #
# copied verbatim in the file "LICENSE" #
################################################################################

find_package(GTest REQUIRED)
set(PSTREAMS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/pstreams)
find_package(PStreams REQUIRED)
include(GTestHelper)

#############################
# FairMQ Testsuites/helpers #
#############################

add_testhelper(runTestDevice
SOURCES
helper/runTestDevice.cxx
helper/devices/TestPub.cxx
helper/devices/TestPull.cxx
helper/devices/TestPush.cxx
helper/devices/TestRep.cxx
helper/devices/TestReq.cxx
helper/devices/TestSub.cxx
helper/devices/TestTransferTimeout.cxx

LINKS FairMQ
)

Set(SYSTEM_INCLUDE_DIRECTORIES
${Boost_INCLUDE_DIR}
${ZeroMQ_INCLUDE_DIR}
)

If(NANOMSG_FOUND)
Set(SYSTEM_INCLUDE_DIRECTORIES
${SYSTEM_INCLUDE_DIRECTORIES}
${NANOMSG_INCLUDE_DIR}
)
EndIf(NANOMSG_FOUND)

Include_Directories(${INCLUDE_DIRECTORIES})
Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})

Set(LINK_DIRECTORIES
${Boost_LIBRARY_DIRS}
)

Link_Directories(${LINK_DIRECTORIES})
set(MQ_CONFIG "${CMAKE_BINARY_DIR}/bin/testsuite_FairMQ.IOPatterns_config.json")
set(RUN_TEST_DEVICE "${CMAKE_BINARY_DIR}/bin/testhelper_runTestDevice")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protocols/config.json.in ${MQ_CONFIG})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/protocols/runner.cxx.in ${CMAKE_CURRENT_BINARY_DIR}/protocols/runner.cxx)

set(SRCS
"push-pull/FairMQTestPush.cxx"
"push-pull/FairMQTestPull.cxx"
"pub-sub/FairMQTestPub.cxx"
"pub-sub/FairMQTestSub.cxx"
"req-rep/FairMQTestReq.cxx"
"req-rep/FairMQTestRep.cxx"
)
add_testsuite(FairMQ.Protocols
SOURCES
${CMAKE_CURRENT_BINARY_DIR}/protocols/runner.cxx
protocols/_pub_sub.cxx
protocols/_push_pull.cxx
protocols/_req_rep.cxx
protocols/_transfer_timeout.cxx

set(DEPENDENCIES
${DEPENDENCIES}
FairMQ
LINKS PStreams
DEPENDS testhelper_runTestDevice
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/protocols
TIMEOUT 30
)

set(LIBRARY_NAME FairMQTest)

GENERATE_LIBRARY()

set(Exe_Names
test-fairmq-push
test-fairmq-pull
test-fairmq-pub
test-fairmq-sub
test-fairmq-req
test-fairmq-rep
test-fairmq-transfer-timeout
##############################
# Aggregate all test targets #
##############################
add_custom_target(FairMQTests
DEPENDS
${ALL_TEST_TARGETS}
)

set(Exe_Source
push-pull/runTestPush.cxx
push-pull/runTestPull.cxx
pub-sub/runTestPub.cxx
pub-sub/runTestSub.cxx
req-rep/runTestReq.cxx
req-rep/runTestRep.cxx
runTransferTimeoutTest.cxx
)

list(LENGTH Exe_Names _length)
math(EXPR _length ${_length}-1)

ForEach(_file RANGE 0 ${_length})
list(GET Exe_Names ${_file} _name)
list(GET Exe_Source ${_file} _src)
set(EXE_NAME ${_name})
set(SRCS ${_src})
set(DEPENDENCIES FairMQTest)
GENERATE_EXECUTABLE()
EndForEach(_file RANGE 0 ${_length})

add_test(NAME run_fairmq_push_pull_zmq COMMAND ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-push-pull.sh zeromq)
set_tests_properties(run_fairmq_push_pull_zmq PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_push_pull_zmq PROPERTIES PASS_REGULAR_EXPRESSION "PUSH-PULL test successfull")

add_test(NAME run_fairmq_pub_sub_zmq COMMAND ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-pub-sub.sh zeromq)
set_tests_properties(run_fairmq_pub_sub_zmq PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_pub_sub_zmq PROPERTIES PASS_REGULAR_EXPRESSION "PUB-SUB test successfull")
Set_Tests_Properties(run_fairmq_pub_sub_zmq PROPERTIES DEPENDS run_fairmq_push_pull_zmq)

add_test(NAME run_fairmq_req_rep_zmq COMMAND ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-req-rep.sh zeromq)
set_tests_properties(run_fairmq_req_rep_zmq PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_req_rep_zmq PROPERTIES PASS_REGULAR_EXPRESSION "REQ-REP test successfull")
Set_Tests_Properties(run_fairmq_req_rep_zmq PROPERTIES DEPENDS run_fairmq_pub_sub_zmq)

add_test(NAME run_fairmq_transfer_timeout_zmq COMMAND ${CMAKE_BINARY_DIR}/bin/test-fairmq-transfer-timeout zeromq)
set_tests_properties(run_fairmq_transfer_timeout_zmq PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_transfer_timeout_zmq PROPERTIES PASS_REGULAR_EXPRESSION "Transfer timeout test successfull")
Set_Tests_Properties(run_fairmq_transfer_timeout_zmq PROPERTIES DEPENDS run_fairmq_pub_sub_zmq)

If(NANOMSG_FOUND)
add_test(NAME run_fairmq_push_pull_nn COMMAND ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-push-pull.sh nanomsg)
set_tests_properties(run_fairmq_push_pull_nn PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_push_pull_nn PROPERTIES PASS_REGULAR_EXPRESSION "PUSH-PULL test successfull")
Set_Tests_Properties(run_fairmq_push_pull_nn PROPERTIES DEPENDS run_fairmq_transfer_timeout_zmq)

add_test(NAME run_fairmq_pub_sub_nn COMMAND ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-pub-sub.sh nanomsg)
set_tests_properties(run_fairmq_pub_sub_nn PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_pub_sub_nn PROPERTIES PASS_REGULAR_EXPRESSION "PUB-SUB test successfull")
Set_Tests_Properties(run_fairmq_pub_sub_nn PROPERTIES DEPENDS run_fairmq_push_pull_nn)

add_test(NAME run_fairmq_req_rep_nn COMMAND ${CMAKE_BINARY_DIR}/fairmq/test/test-fairmq-req-rep.sh nanomsg)
set_tests_properties(run_fairmq_req_rep_nn PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_req_rep_nn PROPERTIES PASS_REGULAR_EXPRESSION "REQ-REP test successfull")
Set_Tests_Properties(run_fairmq_req_rep_nn PROPERTIES DEPENDS run_fairmq_pub_sub_nn)

add_test(NAME run_fairmq_transfer_timeout_nn COMMAND ${CMAKE_BINARY_DIR}/bin/test-fairmq-transfer-timeout nanomsg)
set_tests_properties(run_fairmq_transfer_timeout_nn PROPERTIES TIMEOUT "30")
set_tests_properties(run_fairmq_transfer_timeout_nn PROPERTIES PASS_REGULAR_EXPRESSION "Transfer timeout test successfull")
Set_Tests_Properties(run_fairmq_transfer_timeout_nn PROPERTIES DEPENDS run_fairmq_req_rep_nn)
EndIf(NANOMSG_FOUND)
64 changes: 64 additions & 0 deletions fairmq/test/helper/devices/TestPub.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/********************************************************************************
* Copyright (C) 2015-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/helper/devices/TestPub.cxx
*/

#include <FairMQDevice.h>
#include <FairMQLogger.h>

namespace fair
{
namespace mq
{
namespace test
{

class Pub : public FairMQDevice
{
protected:
auto Run() -> void override
{
auto ready1 = FairMQMessagePtr{NewMessage()};
auto ready2 = FairMQMessagePtr{NewMessage()};
auto r1 = Receive(ready1, "control");
auto r2 = Receive(ready2, "control");
if (r1 >= 0 && r2 >= 0)
{
LOG(INFO) << "Received both ready signals, proceeding to publish data";

auto msg = FairMQMessagePtr{NewMessage()};
auto d1 = Send(msg, "data");
if (d1 < 0)
{
LOG(ERROR) << "Failed sending data: d1 = " << d1;
}

auto ack1 = FairMQMessagePtr{NewMessage()};
auto ack2 = FairMQMessagePtr{NewMessage()};
auto a1 = Receive(ack1, "control");
auto a2 = Receive(ack2, "control");
if (a1 >= 0 && a2 >= 0)
{
LOG(INFO) << "PUB-SUB test successfull";
}
else
{
LOG(ERROR) << "Failed receiving ack signal: a1 = " << a1 << ", a2 = " << a2;
}
}
else
{
LOG(ERROR) << "Failed receiving ready signal: r1 = " << r1 << ", r2 = " << r2;
}
};
};

} // namespace test
} // namespace mq
} // namespace fair
40 changes: 40 additions & 0 deletions fairmq/test/helper/devices/TestPull.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/********************************************************************************
* Copyright (C) 2015-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/helper/devices/TestPull.cxx
*/

#include <FairMQDevice.h>
#include <FairMQLogger.h>

namespace fair
{
namespace mq
{
namespace test
{

using namespace std;

class Pull : public FairMQDevice
{
protected:
auto Run() -> void override
{
auto msg = FairMQMessagePtr{NewMessage()};

if (Receive(msg, "data") >= 0)
{
LOG(INFO) << "PUSH-PULL test successfull";
}
};
};

} // namespace test
} // namespace mq
} // namespace fair
33 changes: 33 additions & 0 deletions fairmq/test/helper/devices/TestPush.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************************************************************************
* Copyright (C) 2015-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/helper/devices/TestPush.cxx
*/

#include <FairMQDevice.h>

namespace fair
{
namespace mq
{
namespace test
{

class Push : public FairMQDevice
{
protected:
auto Run() -> void override
{
auto msg = FairMQMessagePtr{NewMessage()};
Send(msg, "data");
};
};

} // namespace test
} // namespace mq
} // namespace fair
48 changes: 48 additions & 0 deletions fairmq/test/helper/devices/TestRep.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************************
* Copyright (C) 2015-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/helper/devices/TestRep.cxx
*/

#include <FairMQDevice.h>
#include <FairMQLogger.h>

namespace fair
{
namespace mq
{
namespace test
{

class Rep : public FairMQDevice
{
protected:
auto Run() -> void override
{
auto request1 = FairMQMessagePtr{NewMessage()};
if (Receive(request1, "data") >= 0)
{
LOG(INFO) << "Received request 1";
auto reply = FairMQMessagePtr{NewMessage()};
Send(reply, "data");
}
auto request2 = FairMQMessagePtr{NewMessage()};
if (Receive(request2, "data") >= 0)
{
LOG(INFO) << "Received request 2";
auto reply = FairMQMessagePtr{NewMessage()};
Send(reply, "data");
}

LOG(INFO) << "REQ-REP test successfull";
};
};

} // namespace test
} // namespace mq
} // namespace fair

0 comments on commit 46ce442

Please sign in to comment.