Browse Source

Tests: PityTest - add env (process_init)

master
heck 4 years ago
parent
commit
802b9ebcc8
  1. 33
      src/PitySwarm.cc
  2. 5
      src/PitySwarm.hh

33
src/PitySwarm.cc

@ -3,16 +3,18 @@
#include "PityPerspective.hh" #include "PityPerspective.hh"
#include "PityUnit.hh" #include "PityUnit.hh"
#include <iostream>
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <stdlib.h>
namespace pEp { namespace pEp {
namespace PityTest11 { namespace PityTest11 {
bool PitySwarm::debug_log_enabled = false; 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 // 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(); psp->name = model.nodeNr(node_nr)->getName();
@ -29,13 +31,20 @@ namespace pEp {
} }
} }
void PitySwarm::_init_process(PityUnit<PityPerspective>& 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 } PitySwarm::PitySwarm(PityModel& model) : _model{ model }
{ {
pEpLogClass("called"); pEpLogClass("called");
// Create perspective // Create perspective
for (auto n : _model.nodes()) { for (auto n : _model.nodes()) {
auto tmp = std::make_shared<PityPerspective>(model); auto tmp = std::make_shared<PityPerspective>(model);
createPerspective(_model, tmp.get(), n->getNr()); _createPerspective(_model, tmp.get(), n->getNr());
_perspectives.push_back(tmp); _perspectives.push_back(tmp);
} }
@ -47,18 +56,15 @@ namespace pEp {
nullptr); nullptr);
for (auto n : _model.nodes()) { for (auto n : _model.nodes()) {
_nodeUnits.push_back(std::make_shared<PityUnit<PityPerspective>>(
auto tmp = std::make_shared<PityUnit<PityPerspective>>(
_rootUnit.get(), _rootUnit.get(),
n->getName(), n->getName(),
nullptr, std::bind(&PitySwarm::_init_process,this, std::placeholders::_1, std::placeholders::_2),
// std::bind(
// &PityNode::_init,
// this,
// std::placeholders::_1,
// std::placeholders::_2,
// std::placeholders::_3),
_perspectives.at(n->getNr()).get(), _perspectives.at(n->getNr()).get(),
PityUnit<PityPerspective>::ExecutionMode::PROCESS_PARALLEL)); PityUnit<PityPerspective>::ExecutionMode::PROCESS_PARALLEL);
_nodeUnits.push_back(tmp);
} }
} }
@ -67,7 +73,10 @@ namespace pEp {
const std::string& name, const std::string& name,
PityUnit<PityPerspective>::TestFunction test_func) PityUnit<PityPerspective>::TestFunction test_func)
{ {
auto tmp = std::make_shared<PityUnit<PityPerspective>>(_nodeUnits.at(nodeNr).get(), name, test_func); auto tmp = std::make_shared<PityUnit<PityPerspective>>(
_nodeUnits.at(nodeNr).get(),
name,
test_func);
_testUnits.push_back(tmp); _testUnits.push_back(tmp);
} }

5
src/PitySwarm.hh

@ -32,6 +32,11 @@ namespace pEp {
Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled };
private: private:
// methods
void _createPerspective(const PityModel& model, PityPerspective* psp, int node_nr);
void _init_process(PityUnit<PityPerspective>& unit, PityPerspective* ctx);
// fields
PityModel& _model; PityModel& _model;
std::shared_ptr<PityUnit<PityPerspective>> _rootUnit; std::shared_ptr<PityUnit<PityPerspective>> _rootUnit;
std::vector<std::shared_ptr<PityUnit<PityPerspective>>> _nodeUnits; std::vector<std::shared_ptr<PityUnit<PityPerspective>>> _nodeUnits;

Loading…
Cancel
Save