Tests for MQ examples

This commit is contained in:
Alexey Rybalchenko
2017-08-23 11:12:29 +02:00
committed by Mohammad Al-Turany
parent 984eed1a89
commit 319bdc91a1
57 changed files with 658 additions and 118 deletions

View File

@@ -6,12 +6,11 @@
# copied verbatim in the file "LICENSE" #
################################################################################
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/5-req-rep/ex5-req-rep.json
${CMAKE_BINARY_DIR}/bin/config/ex5-req-rep.json)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/5-req-rep/startMQEx5.sh.in
${CMAKE_BINARY_DIR}/bin/examples/MQ/5-req-rep/startMQEx5.sh)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/5-req-rep/ex5-req-rep.json ${CMAKE_BINARY_DIR}/bin/config/ex5-req-rep.json)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/5-req-rep/startMQEx5.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/5-req-rep/startMQEx5.sh)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/5-req-rep/testMQEx5.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/5-req-rep/testMQEx5.sh)
Set(INCLUDE_DIRECTORIES
set(INCLUDE_DIRECTORIES
${CMAKE_SOURCE_DIR}/fairmq
${CMAKE_SOURCE_DIR}/fairmq/devices
${CMAKE_SOURCE_DIR}/fairmq/tools
@@ -20,19 +19,19 @@ Set(INCLUDE_DIRECTORIES
${CMAKE_CURRENT_BINARY_DIR}
)
Set(SYSTEM_INCLUDE_DIRECTORIES
set(SYSTEM_INCLUDE_DIRECTORIES
${Boost_INCLUDE_DIR}
${ZeroMQ_INCLUDE_DIR}
)
Include_Directories(${INCLUDE_DIRECTORIES})
Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
include_directories(${INCLUDE_DIRECTORIES})
include_directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
Set(LINK_DIRECTORIES
set(LINK_DIRECTORIES
${Boost_LIBRARY_DIRS}
)
Link_Directories(${LINK_DIRECTORIES})
link_directories(${LINK_DIRECTORIES})
set(SRCS
"FairMQExample5Client.cxx"
@@ -64,16 +63,21 @@ math(EXPR _length ${_length}-1)
set(BIN_DESTINATION share/fairbase/examples/MQ/5-req-rep/bin)
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/examples/MQ/5-req-rep")
ForEach(_file RANGE 0 ${_length})
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 FairMQExample5)
GENERATE_EXECUTABLE()
EndForEach(_file RANGE 0 ${_length})
endforeach(_file RANGE 0 ${_length})
Install(
add_test(NAME MQ.ex5-req-rep COMMAND ${CMAKE_BINARY_DIR}/bin/examples/MQ/5-req-rep/testMQEx5.sh)
set_tests_properties(MQ.ex5-req-rep PROPERTIES TIMEOUT "30")
set_tests_properties(MQ.ex5-req-rep PROPERTIES RUN_SERIAL true)
set_tests_properties(MQ.ex5-req-rep PROPERTIES PASS_REGULAR_EXPRESSION "Received reply from server: ")
install(
FILES ex5-req-rep.json
DESTINATION share/fairbase/examples/MQ/5-req-rep/config/
)

View File

@@ -24,17 +24,19 @@ using namespace std;
FairMQExample5Client::FairMQExample5Client()
: fText()
, fMaxIterations(0)
, fNumIterations(0)
{
}
void FairMQExample5Client::InitTask()
{
fText = fConfig->GetValue<string>("text");
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
}
bool FairMQExample5Client::ConditionalRun()
{
this_thread::sleep_for(chrono::seconds(1));
string* text = new string(fText);
@@ -55,6 +57,15 @@ bool FairMQExample5Client::ConditionalRun()
if (Receive(reply, "data") >= 0)
{
LOG(INFO) << "Received reply from server: \"" << string(static_cast<char*>(reply->GetData()), reply->GetSize()) << "\"";
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
{
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
return false;
}
this_thread::sleep_for(chrono::seconds(1));
return true;
}
}

View File

@@ -27,6 +27,8 @@ class FairMQExample5Client : public FairMQDevice
protected:
std::string fText;
uint64_t fMaxIterations;
uint64_t fNumIterations;
virtual bool ConditionalRun();
virtual void InitTask();

View File

@@ -14,14 +14,23 @@
#include "FairMQExample5Server.h"
#include "FairMQLogger.h"
#include "FairMQProgOptions.h" // device->fConfig
using namespace std;
FairMQExample5Server::FairMQExample5Server()
: fMaxIterations(0)
, fNumIterations(0)
{
OnData("data", &FairMQExample5Server::HandleData);
}
void FairMQExample5Server::InitTask()
{
// Get the fMaxIterations value from the command line options (via fConfig)
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
}
bool FairMQExample5Server::HandleData(FairMQMessagePtr& request, int /*index*/)
{
LOG(INFO) << "Received request from client: \"" << string(static_cast<char*>(request->GetData()), request->GetSize()) << "\"";
@@ -37,6 +46,12 @@ bool FairMQExample5Server::HandleData(FairMQMessagePtr& request, int /*index*/)
if (Send(reply, "data") > 0)
{
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
{
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
return false;
}
return true;
}

View File

@@ -24,7 +24,12 @@ class FairMQExample5Server : public FairMQDevice
virtual ~FairMQExample5Server();
protected:
virtual void InitTask();
bool HandleData(FairMQMessagePtr&, int);
private:
uint64_t fMaxIterations;
uint64_t fNumIterations;
};
#endif /* FAIRMQEXAMPLE5SERVER_H_ */

View File

@@ -14,7 +14,8 @@ namespace bpo = boost::program_options;
void addCustomOptions(bpo::options_description& options)
{
options.add_options()
("text", bpo::value<std::string>()->default_value("Hello"), "Text to send out");
("text", bpo::value<std::string>()->default_value("Hello"), "Text to send out")
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
}
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -11,8 +11,10 @@
namespace bpo = boost::program_options;
void addCustomOptions(bpo::options_description& /*options*/)
void addCustomOptions(bpo::options_description& options)
{
options.add_options()
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
}
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -0,0 +1,26 @@
#!/bin/bash
ex5config="@CMAKE_BINARY_DIR@/bin/config/ex5-req-rep.json"
# setup a trap to kill everything if the test fails/timeouts
trap 'kill -TERM $CLIENT_PID; kill -TERM $SERVER_PID; wait $CLIENT_PID; wait $SERVER_PID;' TERM
CLIENT="ex5-client"
CLIENT+=" --id client"
CLIENT+=" --control static --log-color false"
CLIENT+=" --max-iterations 1"
CLIENT+=" --mq-config $ex5config"
@CMAKE_BINARY_DIR@/bin/examples/MQ/5-req-rep/$CLIENT &
CLIENT_PID=$!
SERVER="ex5-server"
SERVER+=" --id server"
SERVER+=" --control static --log-color false"
SERVER+=" --max-iterations 1"
SERVER+=" --mq-config $ex5config"
@CMAKE_BINARY_DIR@/bin/examples/MQ/5-req-rep/$SERVER &
SERVER_PID=$!
# wait for everything to finish
wait $CLIENT_PID
wait $SERVER_PID