mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Tests for MQ examples
This commit is contained in:
committed by
Mohammad Al-Turany
parent
984eed1a89
commit
319bdc91a1
@@ -6,12 +6,11 @@
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/6-multiple-channels/ex6-multiple-channels.json
|
||||
${CMAKE_BINARY_DIR}/bin/config/ex6-multiple-channels.json)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/6-multiple-channels/startMQEx6.sh.in
|
||||
${CMAKE_BINARY_DIR}/bin/examples/MQ/6-multiple-channels/startMQEx6.sh)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/6-multiple-channels/ex6-multiple-channels.json ${CMAKE_BINARY_DIR}/bin/config/ex6-multiple-channels.json)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/6-multiple-channels/startMQEx6.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/6-multiple-channels/startMQEx6.sh)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/6-multiple-channels/testMQEx6.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/6-multiple-channels/testMQEx6.sh)
|
||||
|
||||
Set(INCLUDE_DIRECTORIES
|
||||
set(INCLUDE_DIRECTORIES
|
||||
${CMAKE_SOURCE_DIR}/fairmq
|
||||
${CMAKE_SOURCE_DIR}/fairmq/devices
|
||||
${CMAKE_SOURCE_DIR}/fairmq/tools
|
||||
@@ -20,42 +19,42 @@ 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
|
||||
set(SRCS
|
||||
"FairMQExample6Sampler.cxx"
|
||||
"FairMQExample6Sink.cxx"
|
||||
"FairMQExample6Broadcaster.cxx"
|
||||
)
|
||||
|
||||
Set(DEPENDENCIES
|
||||
set(DEPENDENCIES
|
||||
${DEPENDENCIES}
|
||||
FairMQ
|
||||
)
|
||||
|
||||
Set(LIBRARY_NAME FairMQExample6)
|
||||
set(LIBRARY_NAME FairMQExample6)
|
||||
|
||||
GENERATE_LIBRARY()
|
||||
|
||||
Set(Exe_Names
|
||||
set(Exe_Names
|
||||
ex6-sampler
|
||||
ex6-sink
|
||||
ex6-broadcaster
|
||||
)
|
||||
|
||||
Set(Exe_Source
|
||||
set(Exe_Source
|
||||
runExample6Sampler.cxx
|
||||
runExample6Sink.cxx
|
||||
runExample6Broadcaster.cxx
|
||||
@@ -67,16 +66,21 @@ math(EXPR _length ${_length}-1)
|
||||
set(BIN_DESTINATION share/fairbase/examples/MQ/6-multiple-channels/bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/examples/MQ/6-multiple-channels")
|
||||
|
||||
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 FairMQExample6)
|
||||
GENERATE_EXECUTABLE()
|
||||
EndForEach(_file RANGE 0 ${_length})
|
||||
endforeach(_file RANGE 0 ${_length})
|
||||
|
||||
Install(
|
||||
add_test(NAME MQ.ex6-multiple-channels COMMAND ${CMAKE_BINARY_DIR}/bin/examples/MQ/6-multiple-channels/testMQEx6.sh)
|
||||
set_tests_properties(MQ.ex6-multiple-channels PROPERTIES TIMEOUT "30")
|
||||
set_tests_properties(MQ.ex6-multiple-channels PROPERTIES RUN_SERIAL true)
|
||||
set_tests_properties(MQ.ex6-multiple-channels PROPERTIES PASS_REGULAR_EXPRESSION "Received messages from both sources.")
|
||||
|
||||
install(
|
||||
FILES ex6-multiple-channels.json
|
||||
DESTINATION share/fairbase/examples/MQ/6-multiple-channels/config/
|
||||
)
|
||||
|
@@ -25,12 +25,15 @@ using namespace std;
|
||||
|
||||
FairMQExample6Sampler::FairMQExample6Sampler()
|
||||
: fText()
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQExample6Sampler::InitTask()
|
||||
{
|
||||
fText = fConfig->GetValue<string>("text");
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
}
|
||||
|
||||
void FairMQExample6Sampler::Run()
|
||||
@@ -62,6 +65,12 @@ void FairMQExample6Sampler::Run()
|
||||
LOG(INFO) << "Sent \"" << fText << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,8 @@ class FairMQExample6Sampler : public FairMQDevice
|
||||
|
||||
protected:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
|
||||
virtual void Run();
|
||||
virtual void InitTask();
|
||||
|
@@ -15,27 +15,52 @@
|
||||
#include <memory> // unique_ptr
|
||||
|
||||
#include "FairMQExample6Sink.h"
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQExample6Sink::FairMQExample6Sink()
|
||||
: fReceivedData(false)
|
||||
, fReceivedBroadcast(false)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
OnData("broadcast", &FairMQExample6Sink::HandleBroadcast);
|
||||
OnData("data", &FairMQExample6Sink::HandleData);
|
||||
}
|
||||
|
||||
void FairMQExample6Sink::InitTask()
|
||||
{
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
}
|
||||
|
||||
bool FairMQExample6Sink::HandleBroadcast(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
LOG(INFO) << "Received broadcast: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
fReceivedBroadcast = true;
|
||||
|
||||
return true;
|
||||
return CheckIterations();
|
||||
}
|
||||
|
||||
bool FairMQExample6Sink::HandleData(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
LOG(INFO) << "Received message: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
fReceivedData = true;
|
||||
|
||||
return CheckIterations();
|
||||
}
|
||||
|
||||
bool FairMQExample6Sink::CheckIterations()
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
if (fReceivedData && fReceivedBroadcast && ++fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(INFO) << "Configured maximum number of iterations reached & Received messages from both sources. Leaving RUNNING state.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -26,6 +26,14 @@ class FairMQExample6Sink : public FairMQDevice
|
||||
protected:
|
||||
bool HandleBroadcast(FairMQMessagePtr&, int);
|
||||
bool HandleData(FairMQMessagePtr&, int);
|
||||
bool CheckIterations();
|
||||
virtual void InitTask();
|
||||
|
||||
private:
|
||||
bool fReceivedData;
|
||||
bool fReceivedBroadcast;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQEXAMPLE6SINK_H_ */
|
||||
|
@@ -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*/)
|
||||
|
@@ -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*/)
|
||||
|
40
examples/MQ/6-multiple-channels/testMQEx6.sh.in
Executable file
40
examples/MQ/6-multiple-channels/testMQEx6.sh.in
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
ex6config="@CMAKE_BINARY_DIR@/bin/config/ex6-multiple-channels.json"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; kill -TERM $BROADCASTER_PID; wait $SAMPLER_PID; wait $SINK_PID; wait $BROADCASTER_PID;' TERM
|
||||
|
||||
|
||||
SINK="ex6-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --max-iterations 1"
|
||||
SINK+=" --control static --log-color false"
|
||||
SINK+=" --mq-config $ex6config"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/6-multiple-channels/$SINK &
|
||||
SINK_PID=$!
|
||||
|
||||
sleep 1
|
||||
|
||||
SAMPLER="ex6-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --max-iterations 1"
|
||||
SAMPLER+=" --control static --log-color false"
|
||||
SAMPLER+=" --mq-config $ex6config"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/6-multiple-channels/$SAMPLER &
|
||||
SAMPLER_PID=$!
|
||||
|
||||
BROADCASTER="ex6-broadcaster"
|
||||
BROADCASTER+=" --id broadcaster1"
|
||||
BROADCASTER+=" --control static --log-color false"
|
||||
BROADCASTER+=" --mq-config $ex6config"
|
||||
@CMAKE_BINARY_DIR@/bin/examples/MQ/6-multiple-channels/$BROADCASTER &
|
||||
BROADCASTER_PID=$!
|
||||
|
||||
wait $SAMPLER_PID
|
||||
wait $SINK_PID
|
||||
|
||||
# stop broadcaster
|
||||
kill -SIGINT $BROADCASTER_PID
|
||||
|
||||
# wait for broadcaster to finish
|
||||
wait $BROADCASTER_PID
|
Reference in New Issue
Block a user