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,10 +6,9 @@
# copied verbatim in the file "LICENSE" #
################################################################################
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/4-copypush/ex4-copypush.json
${CMAKE_BINARY_DIR}/bin/config/ex4-copypush.json)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/4-copypush/startMQEx4.sh.in
${CMAKE_BINARY_DIR}/bin/examples/MQ/4-copypush/startMQEx4.sh)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/4-copypush/ex4-copypush.json ${CMAKE_BINARY_DIR}/bin/config/ex4-copypush.json)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/4-copypush/startMQEx4.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/4-copypush/startMQEx4.sh)
configure_file(${CMAKE_SOURCE_DIR}/examples/MQ/4-copypush/testMQEx4.sh.in ${CMAKE_BINARY_DIR}/bin/examples/MQ/4-copypush/testMQEx4.sh)
Set(INCLUDE_DIRECTORIES
${CMAKE_SOURCE_DIR}/fairmq
@@ -73,6 +72,11 @@ ForEach(_file RANGE 0 ${_length})
GENERATE_EXECUTABLE()
EndForEach(_file RANGE 0 ${_length})
add_test(NAME MQ.ex4-copypush COMMAND ${CMAKE_BINARY_DIR}/bin/examples/MQ/4-copypush/testMQEx4.sh)
set_tests_properties(MQ.ex4-copypush PROPERTIES TIMEOUT "30")
set_tests_properties(MQ.ex4-copypush PROPERTIES RUN_SERIAL true)
set_tests_properties(MQ.ex4-copypush PROPERTIES PASS_REGULAR_EXPRESSION "Received message: ")
Install(
FILES ex4-copypush.json
DESTINATION share/fairbase/examples/MQ/4-copypush/config/

View File

@@ -17,21 +17,26 @@
#include "FairMQExample4Sampler.h"
#include "FairMQLogger.h"
#include "FairMQProgOptions.h" // device->fConfig
using namespace std;
FairMQExample4Sampler::FairMQExample4Sampler()
: fNumDataChannels(0)
, fCounter(0)
, fMaxIterations(0)
, fNumIterations(0)
{
}
void FairMQExample4Sampler::InitTask()
{
fNumDataChannels = fChannels.at("data").size();
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
}
bool FairMQExample4Sampler::ConditionalRun()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
// NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
// Should only be used for small data because of the cost of an additional copy
@@ -44,6 +49,15 @@ bool FairMQExample4Sampler::ConditionalRun()
Send(msgCopy, "data", i);
}
Send(msg, "data", fNumDataChannels - 1);
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

@@ -31,6 +31,8 @@ class FairMQExample4Sampler : public FairMQDevice
int fNumDataChannels;
uint64_t fCounter;
uint64_t fMaxIterations;
uint64_t fNumIterations;
};
#endif /* FAIRMQEXAMPLE4SAMPLER_H_ */

View File

@@ -14,18 +14,33 @@
#include "FairMQExample4Sink.h"
#include "FairMQLogger.h"
#include "FairMQProgOptions.h" // device->fConfig
#include <stdint.h> // uint64_t
FairMQExample4Sink::FairMQExample4Sink()
: fMaxIterations(0)
, fNumIterations(0)
{
OnData("data", &FairMQExample4Sink::HandleData);
}
void FairMQExample4Sink::InitTask()
{
// Get the fMaxIterations value from the command line options (via fConfig)
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
}
bool FairMQExample4Sink::HandleData(FairMQMessagePtr& msg, int /*index*/)
{
LOG(INFO) << "Received message: \"" << *(static_cast<uint64_t*>(msg->GetData())) << "\"";
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
{
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
return false;
}
// return true if want to be called again (otherwise go to IDLE state)
return true;
}

View File

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

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

@@ -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,35 @@
#!/bin/bash
ex4config="@CMAKE_BINARY_DIR@/bin/config/ex4-copypush.json"
# setup a trap to kill everything if the test fails/timeouts
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK1_PID; kill -TERM $SINK2_PID; wait $SAMPLER_PID; wait $SINK1_PID; wait $SINK2_PID;' TERM
SAMPLER="ex4-sampler"
SAMPLER+=" --id sampler1"
SAMPLER+=" --control static --log-color false"
SAMPLER+=" --max-iterations 1"
SAMPLER+=" --mq-config $ex4config"
@CMAKE_BINARY_DIR@/bin/examples/MQ/4-copypush/$SAMPLER &
SAMPLER_PID=$!
SINK1="ex4-sink"
SINK1+=" --id sink1"
SINK1+=" --control static --log-color false"
SINK1+=" --max-iterations 1"
SINK1+=" --mq-config $ex4config"
@CMAKE_BINARY_DIR@/bin/examples/MQ/4-copypush/$SINK1 &
SINK1_PID=$!
SINK2="ex4-sink"
SINK2+=" --id sink2"
SINK2+=" --control static --log-color false"
SINK2+=" --max-iterations 1"
SINK2+=" --mq-config $ex4config"
@CMAKE_BINARY_DIR@/bin/examples/MQ/4-copypush/$SINK2 &
SINK2_PID=$!
# wait for everything to finish
wait $SAMPLER_PID
wait $SINK1_PID
wait $SINK2_PID