From 0901f2761cfabcd536cd81140e9474214f934d30 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 10 Jun 2021 22:57:49 +0200 Subject: [PATCH] Tests: PityTest - add env (process_init) --- test/pitytest11/src/PitySwarm.cc | 33 ++++++++++++++++++++------------ test/pitytest11/src/PitySwarm.hh | 5 +++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/test/pitytest11/src/PitySwarm.cc b/test/pitytest11/src/PitySwarm.cc index b8a9c1e..2752d85 100644 --- a/test/pitytest11/src/PitySwarm.cc +++ b/test/pitytest11/src/PitySwarm.cc @@ -3,16 +3,18 @@ #include "PityPerspective.hh" #include "PityUnit.hh" +#include #include #include #include +#include namespace pEp { namespace PityTest11 { bool PitySwarm::debug_log_enabled = false; // The perspective currently is complete defined by specifying a node, since there is a 1-1 node/ident relationship currently - void createPerspective(const PityModel& model, PityPerspective* psp, int node_nr) + void PitySwarm::_createPerspective(const PityModel& model, PityPerspective* psp, int node_nr) { psp->name = model.nodeNr(node_nr)->getName(); @@ -29,13 +31,20 @@ namespace pEp { } } + void PitySwarm::_init_process(PityUnit& unit, PityPerspective* ctx) + { + std::cout << "PROC INIT" << std::endl; + std::string home = unit.processDir(); + setenv("HOME", home.c_str(), true); + } + PitySwarm::PitySwarm(PityModel& model) : _model{ model } { pEpLogClass("called"); // Create perspective for (auto n : _model.nodes()) { auto tmp = std::make_shared(model); - createPerspective(_model, tmp.get(), n->getNr()); + _createPerspective(_model, tmp.get(), n->getNr()); _perspectives.push_back(tmp); } @@ -47,18 +56,15 @@ namespace pEp { nullptr); for (auto n : _model.nodes()) { - _nodeUnits.push_back(std::make_shared>( + + auto tmp = std::make_shared>( _rootUnit.get(), n->getName(), - nullptr, - // std::bind( - // &PityNode::_init, - // this, - // std::placeholders::_1, - // std::placeholders::_2, - // std::placeholders::_3), + std::bind(&PitySwarm::_init_process,this, std::placeholders::_1, std::placeholders::_2), _perspectives.at(n->getNr()).get(), - PityUnit::ExecutionMode::PROCESS_PARALLEL)); + PityUnit::ExecutionMode::PROCESS_PARALLEL); + + _nodeUnits.push_back(tmp); } } @@ -67,7 +73,10 @@ namespace pEp { const std::string& name, PityUnit::TestFunction test_func) { - auto tmp = std::make_shared>(_nodeUnits.at(nodeNr).get(), name, test_func); + auto tmp = std::make_shared>( + _nodeUnits.at(nodeNr).get(), + name, + test_func); _testUnits.push_back(tmp); } diff --git a/test/pitytest11/src/PitySwarm.hh b/test/pitytest11/src/PitySwarm.hh index 05e54ec..8714d65 100644 --- a/test/pitytest11/src/PitySwarm.hh +++ b/test/pitytest11/src/PitySwarm.hh @@ -32,6 +32,11 @@ namespace pEp { Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; private: + // methods + void _createPerspective(const PityModel& model, PityPerspective* psp, int node_nr); + void _init_process(PityUnit& unit, PityPerspective* ctx); + + // fields PityModel& _model; std::shared_ptr> _rootUnit; std::vector>> _nodeUnits;