Browse Source

Test: pEpTestTree - Rebranding! its now PityTest11 \o/

LIB-11
heck 4 years ago
parent
commit
d04f53b4a7
  1. 3
      .gitignore
  2. 0
      test/PityTest11/Makefile
  3. 16
      test/PityTest11/src/PityModel.cc
  4. 8
      test/PityTest11/src/PityModel.hh
  5. 32
      test/PityTest11/src/PityUnit.hh
  6. 171
      test/PityTest11/src/PityUnit.hxx
  7. 65
      test/PityTest11/test/test_execmodes.cc
  8. 50
      test/PityTest11/test/test_processdirs.cc
  9. 16
      test/pEpTest/src/pEpTestModel.cc
  10. 72
      test/pEpTest/test/test_pEpTest_basic.cc
  11. 53
      test/pEpTest/test/test_transport.cc

3
.gitignore

@ -33,3 +33,6 @@ test_pEpLog_basic
*.db *.db
/test/PityTest11/test/test_pEpTest_basic
/test/PityTest11/test/test_transport
/test/PityTest11/test/test_processdirs

0
test/pEpTest/Makefile → test/PityTest11/Makefile

16
test/PityTest11/src/PityModel.cc

@ -0,0 +1,16 @@
#include "PityModel.hh"
#include "iostream"
using namespace std;
namespace pEp {
namespace PityTest11 {
bool PityModel::log_enabled = true;
PityModel::PityModel(const string& name) : name(name) {}
const std::string& PityModel::getName() const
{
return name;
}
} // namespace Test
} // namespace pEp

8
test/pEpTest/src/pEpTestModel.hh → test/PityTest11/src/PityModel.hh

@ -7,11 +7,11 @@
#include "../../../src/pEpLog.hh" #include "../../../src/pEpLog.hh"
namespace pEp { namespace pEp {
namespace Test { namespace PityTest11 {
class pEpTestModel { class PityModel {
public: public:
pEpTestModel() = delete; PityModel() = delete;
pEpTestModel(const std::string& name); PityModel(const std::string& name);
virtual const std::string& getName() const; virtual const std::string& getName() const;
private: private:

32
test/pEpTest/src/pEpTestTree.hh → test/PityTest11/src/PityUnit.hh

@ -1,8 +1,8 @@
// This file is under GNU General Public License 3.0 // This file is under GNU General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#ifndef LIBPEPADAPTER_PEPTEST_PEPTESTTREE_HH #ifndef PITYTEST_PITYUNIT_HH
#define LIBPEPADAPTER_PEPTEST_PEPTESTTREE_HH #define PITYTEST_PITYUNIT_HH
#include <string> #include <string>
#include <functional> #include <functional>
@ -12,11 +12,11 @@
// Yes, the mem mgmt is purely static on purpose (so far) // Yes, the mem mgmt is purely static on purpose (so far)
namespace pEp { namespace pEp {
namespace Test { namespace PityTest11 {
template<class T = void> template<class T = void>
class pEpTestTree { class PityUnit {
public: public:
using NodeFunc = std::function<void(const pEpTestTree&)>; using NodeFunc = std::function<void(const PityUnit&)>;
enum class ExecutionMode enum class ExecutionMode
{ {
@ -29,9 +29,9 @@ namespace pEp {
}; };
// Constructors are private // Constructors are private
pEpTestTree() = delete; PityUnit() = delete;
explicit pEpTestTree( explicit PityUnit(
pEpTestTree* parent, PityUnit* parent,
const std::string& name, const std::string& name,
const NodeFunc test_func = nullptr, const NodeFunc test_func = nullptr,
T* model = nullptr, T* model = nullptr,
@ -76,13 +76,13 @@ namespace pEp {
void _waitChildProcesses() const; void _waitChildProcesses() const;
// Modify // Modify
void _addChildNode(pEpTestTree& node); void _addChildNode(PityUnit& node);
// Query // Query
bool _isProcessNode() const; bool _isProcessNode() const;
bool _isRootNode() const; bool _isRootNode() const;
const pEpTestTree& _rootNode() const; const PityUnit& _rootNode() const;
const pEpTestTree& _parentingProcessNode() const; const PityUnit& _parentingProcessNode() const;
// Util // Util
std::string _normalizeName(std::string name) const; std::string _normalizeName(std::string name) const;
@ -94,13 +94,13 @@ namespace pEp {
// Fields // Fields
const std::string _name; const std::string _name;
const pEpTestTree* _parent; //nullptr if RootUnit const PityUnit* _parent; //nullptr if RootUnit
T* _model; //nullptr if inherited T* _model; //nullptr if inherited
const NodeFunc _test_func; const NodeFunc _test_func;
ExecutionMode _exec_mode; ExecutionMode _exec_mode;
static std::string _global_root_dir; static std::string _global_root_dir;
std::map<const std::string, pEpTestTree&> _children; // map to guarantee uniqueness of sibling-names std::map<const std::string, PityUnit&> _children; // map to guarantee uniqueness of sibling-names
// internal logging // internal logging
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug;
@ -108,6 +108,6 @@ namespace pEp {
}; // namespace Test }; // namespace Test
}; // namespace pEp }; // namespace pEp
#include "pEpTestTree.hxx" #include "PityUnit.hxx"
#endif // LIBPEPADAPTER_PEPTEST_PEPTESTTREE_HH #endif // PITYTEST_PITYUNIT_HH

171
test/pEpTest/src/pEpTestTree.hxx → test/PityTest11/src/PityUnit.hxx

@ -1,8 +1,8 @@
// This file is under GNU General Public License 3.0 // This file is under GNU General Public License 3.0
// see LICENSE.txt // see LICENSE.txt
#ifndef LIBPEPADAPTER_PEPTEST_PEPTESTTREE_HXX #ifndef LIBPEPADAPTER_PEPTEST_PityUnit_HXX
#define LIBPEPADAPTER_PEPTEST_PEPTESTTREE_HXX #define LIBPEPADAPTER_PEPTEST_PityUnit_HXX
#include "../../../src/std_utils.hh" #include "../../../src/std_utils.hh"
#include "../../framework/utils.hh" #include "../../framework/utils.hh"
@ -15,22 +15,20 @@
#include <sstream> #include <sstream>
using namespace std; using namespace pEp::Adapter::pEpLog;
using namespace pEp::Adapter;
using namespace pEp::Utils;
namespace pEp { namespace pEp {
namespace Test { namespace PityTest11 {
template<class T> template<class T>
string pEpTestTree<T>::_global_root_dir = "./peptest"; std::string PityUnit<T>::_global_root_dir = "./peptest";
template<class T> template<class T>
bool pEpTestTree<T>::debug_log_enabled = false; bool PityUnit<T>::debug_log_enabled = false;
// PUBLIC CONCSTRUCTORS / FACTORY ----------------------------------------------------------- // PUBLIC CONCSTRUCTORS / FACTORY -----------------------------------------------------------
template<class T> template<class T>
pEpTestTree<T>::pEpTestTree( PityUnit<T>::PityUnit(
pEpTestTree* const parent, PityUnit* const parent,
const string& name, const std::string& name,
const NodeFunc test_func, const NodeFunc test_func,
T* model, T* model,
ExecutionMode exec_mode) : ExecutionMode exec_mode) :
@ -44,16 +42,15 @@ namespace pEp {
} }
template<class T> template<class T>
string pEpTestTree<T>::getNodeName() const std::string PityUnit<T>::getNodeName() const
{ {
return _name; return _name;
} }
template<class T> template<class T>
string pEpTestTree<T>::getNodePath() const std::string PityUnit<T>::getNodePath() const
{ {
pEpLogClass("called"); std::string ret;
string ret;
if (!_isRootNode()) { if (!_isRootNode()) {
ret = _parent->getNodePath() + "/" + getNodeName(); ret = _parent->getNodePath() + "/" + getNodeName();
@ -69,9 +66,9 @@ namespace pEp {
// When Process as dir. parent - ".../<proc>/name" // When Process as dir. parent - ".../<proc>/name"
// When no process as dir. parent - ".../<proc>/.../name" // When no process as dir. parent - ".../<proc>/.../name"
template<class T> template<class T>
std::string pEpTestTree<T>::getNodePathShort() const std::string PityUnit<T>::getNodePathShort() const
{ {
string ret; std::string ret;
if (_isRootNode()) { if (_isRootNode()) {
ret = getNodeName(); ret = getNodeName();
} else { } else {
@ -90,7 +87,7 @@ namespace pEp {
// Inherited (if null see parent recursively) // Inherited (if null see parent recursively)
template<class T> template<class T>
T* pEpTestTree<T>::getModel() const T* PityUnit<T>::getModel() const
{ {
pEpLogClass("called"); pEpLogClass("called");
T* ret = nullptr; T* ret = nullptr;
@ -105,114 +102,100 @@ namespace pEp {
return ret; return ret;
} }
// RootNodes have their own data_dir
// ProcessNodes have their own data_dir inside their RootNote dir (nameclash prossible)
// All other nodes inherit data_dir from their Root/ProcessNode
// string pEpTestTree::dataDir() const
// {
// pEpLogClass("called");
// string ret;
// if(!_isRootNode()) {
// ret = getRootNodesDir() + _getRootNode().getNodeName() + "/" + _getParentingProcessNode().getNodeName() + "/";
// } else {
// ret = getRootNodesDir() + _getRootNode().getNodeName() + "/";
// }
// return ret;
// }
//
// Every RootNode has its own dir // Every RootNode has its own dir
template<class T> template<class T>
string pEpTestTree<T>::rootNodeDir() const std::string PityUnit<T>::rootNodeDir() const
{ {
return getGlobalRootDir() + _rootNode().getNodeName() + "/"; return getGlobalRootDir() + _rootNode().getNodeName() + "/";
} }
// Every process has its own dir inside its rootNodeDir // Every process has its own dir inside its rootNodeDir
// The Root node has its own processDir for future use // All other nodes inherit processDir from their Root/ProcessNode
template<class T> template<class T>
string pEpTestTree<T>::processDir() const std::string PityUnit<T>::processDir() const
{ {
if (_isRootNode()) { if (_isRootNode()) {
return rootNodeDir() + "rootnode_data"; return rootNodeDir();
} else { } else {
if (&_parentingProcessNode() == &_rootNode()) { if (_isProcessNode()) {
return rootNodeDir() + getNodeName() + "/"; return rootNodeDir() + getNodeName() + "/";
} else { } else{
return rootNodeDir() + _parentingProcessNode().getNodeName() + "/"; return _parent->processDir();
}; }
} }
} }
template<class T> template<class T>
void pEpTestTree<T>::setExecutionMode(ExecutionMode mode) void PityUnit<T>::setExecutionMode(ExecutionMode mode)
{ {
_exec_mode = mode; _exec_mode = mode;
} }
// static // static
template<> template<>
void pEpTestTree<void>::setGlobalRootDir(const string& dir) void PityUnit<void>::setGlobalRootDir(const std::string& dir)
{ {
pEpTestTree::_global_root_dir = dir; PityUnit::_global_root_dir = dir;
} }
// static // static
template<class T> template<class T>
string pEpTestTree<T>::getGlobalRootDir() std::string PityUnit<T>::getGlobalRootDir()
{ {
return pEpTestTree::_global_root_dir + "/"; return PityUnit::_global_root_dir;
} }
template<class T> template<class T>
void pEpTestTree<T>::run() const void PityUnit<T>::run() const
{ {
pEpLogClass("called"); pEpLogClass("called");
// caller is never nullptr if called by another pEpTestTree // caller is never nullptr if called by another PityUnit
if (_isRootNode()) { if (_isRootNode()) {
pEpLog::logH1("Starting pEpTestTree from node: " + getNodePathShort()); logH1("Starting PityUnit from node: " + getNodePathShort());
pEpLog::log(to_string()); log(to_string());
} }
// Execute in fork and wait here until process ends // Execute in fork and wait here until process ends
if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL) { // fork if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL) { // fork
pEpLog::logH2("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + "]"); logH2("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + " ]");
_executeInFork(bind(&pEpTestTree::_run, this), true); _executeInFork(std::bind(&PityUnit::_run, this), true);
// Execute in fork and go on, wait for process execution in the end // Execute in fork and go on, wait for process execution in the end
} else if (_exec_mode == ExecutionMode::PROCESS_PARALLEL) { } else if (_exec_mode == ExecutionMode::PROCESS_PARALLEL) {
pEpLog::logH2("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + "]"); logH2("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + " ]");
_executeInFork(bind(&pEpTestTree::_run, this), false); _executeInFork(std::bind(&PityUnit::_run, this), false);
// Execute as normal funciton // Execute as normal funciton
} else if (_exec_mode == ExecutionMode::FUNCTION) { } else if (_exec_mode == ExecutionMode::FUNCTION) {
pEpLog::logH3("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + "]"); logH3("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + " ]");
_run(); _run();
} else if (_exec_mode == ExecutionMode::THREAD_PARALLEL) { } else if (_exec_mode == ExecutionMode::THREAD_PARALLEL) {
throw invalid_argument(to_string(_exec_mode) + " - not implemented"); throw std::invalid_argument(to_string(_exec_mode) + " - not implemented");
} else if (_exec_mode == ExecutionMode::THREAD_SEQUENTIAL) { } else if (_exec_mode == ExecutionMode::THREAD_SEQUENTIAL) {
throw invalid_argument(to_string(_exec_mode) + " - not implemented"); throw std::invalid_argument(to_string(_exec_mode) + " - not implemented");
} }
_waitChildProcesses(); if(_isRootNode()) {
_waitChildProcesses();
}
} }
template<class T> template<class T>
string pEpTestTree<T>::to_string(bool recursive, int indent) const std::string PityUnit<T>::to_string(bool recursive, int indent) const
{ {
string ret; std::string ret;
stringstream builder; std::stringstream builder;
builder << string(indent * 4, ' '); builder << std::string(indent * 4, ' ');
builder << getNodeName(); builder << getNodeName();
builder << " [ "; builder << " [ ";
builder << to_string(_exec_mode) << " - "; builder << to_string(_exec_mode) << " - ";
builder << "\"" << processDir() << "\""; builder << "\"" << processDir() << "\"";
builder << " ]"; builder << " ]";
builder << endl; builder << std::endl;
ret = builder.str(); ret = builder.str();
if (recursive) { if (recursive) {
indent++; indent++;
for (const pair<string, const pEpTestTree&> child : _children) { for (const std::pair<std::string, const PityUnit&> child : _children) {
ret += child.second.to_string(true, indent); ret += child.second.to_string(true, indent);
} }
indent--; indent--;
@ -221,7 +204,7 @@ namespace pEp {
} }
template<class T> template<class T>
string pEpTestTree<T>::to_string(const ExecutionMode& emode) std::string PityUnit<T>::to_string(const ExecutionMode& emode)
{ {
switch (emode) { switch (emode) {
case ExecutionMode::FUNCTION: case ExecutionMode::FUNCTION:
@ -243,50 +226,50 @@ namespace pEp {
//Well, ok, lets just add some little convenience logging service in here, too //Well, ok, lets just add some little convenience logging service in here, too
template<class T> template<class T>
void pEpTestTree<T>::log(const string& msg) const void PityUnit<T>::log(const std::string& msg) const
{ {
stringstream builder; std::stringstream builder;
builder << "["; builder << "[";
builder << std::to_string(getpid()); builder << std::to_string(getpid());
builder << " - "; builder << " - ";
builder << getNodePathShort(); builder << getNodePathShort();
builder << "] - "; builder << "] - ";
builder << msg; builder << msg;
builder << endl; builder << std::endl;
cout << builder.str(); std::cout << builder.str();
} }
// PRIVATE --------------------------------------------------------------------------------- // PRIVATE ---------------------------------------------------------------------------------
template<class T> template<class T>
void pEpTestTree<T>::_run() const void PityUnit<T>::_run() const
{ {
_runSelf(); _runSelf();
_runChildren(); _runChildren();
} }
template<class T> template<class T>
void pEpTestTree<T>::_runSelf() const void PityUnit<T>::_runSelf() const
{ {
if (_test_func != nullptr) { if (_test_func != nullptr) {
_test_func(*this); _test_func(*this);
} else { } else {
pEpLog::log("No function to execute"); log("No function to execute");
} }
} }
template<class T> template<class T>
void pEpTestTree<T>::_runChildren() const void PityUnit<T>::_runChildren() const
{ {
if (!_children.empty()) { if (!_children.empty()) {
for (const pair<string, pEpTestTree&> child : _children) { for (const std::pair<std::string, PityUnit&> child : _children) {
child.second.run(); child.second.run();
} }
} }
} }
template<class T> template<class T>
void pEpTestTree<T>::_executeInFork(function<void(void)> func, bool wait_child) const void PityUnit<T>::_executeInFork(std::function<void(void)> func, bool wait_child) const
{ {
pid_t pid; pid_t pid;
pid = fork(); pid = fork();
@ -294,7 +277,7 @@ namespace pEp {
func(); func();
exit(0); exit(0);
} else if (pid < pid_t(0)) { } else if (pid < pid_t(0)) {
throw runtime_error("Error forking"); throw std::runtime_error("Error forking");
} }
if (wait_child) { if (wait_child) {
_waitChildProcesses(); _waitChildProcesses();
@ -302,25 +285,25 @@ namespace pEp {
} }
template<class T> template<class T>
void pEpTestTree<T>::_waitChildProcesses() const void PityUnit<T>::_waitChildProcesses() const
{ {
int status; int status;
pid_t pid; pid_t pid;
while ((pid = wait(&status)) > 0) { while ((pid = wait(&status)) > 0) {
pEpLog::log( log(
"process[" + std::to_string((int)pid) + "process[" + std::to_string((int)pid) +
"] terminated with status: " + std::to_string(status)); "] terminated with status: " + std::to_string(status));
} }
} }
template<class T> template<class T>
void pEpTestTree<T>::_addChildNode(pEpTestTree& node) void PityUnit<T>::_addChildNode(PityUnit& node)
{ {
_children.insert(pair<string, pEpTestTree&>(node.getNodeName(), node)); _children.insert(std::pair<std::string, PityUnit&>(node.getNodeName(), node));
} }
template<class T> template<class T>
bool pEpTestTree<T>::_isProcessNode() const bool PityUnit<T>::_isProcessNode() const
{ {
bool ret = false; bool ret = false;
if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL || if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL ||
@ -331,7 +314,7 @@ namespace pEp {
} }
template<class T> template<class T>
bool pEpTestTree<T>::_isRootNode() const bool PityUnit<T>::_isRootNode() const
{ {
if (_parent == nullptr) { if (_parent == nullptr) {
return true; return true;
@ -341,9 +324,9 @@ namespace pEp {
} }
template<class T> template<class T>
const pEpTestTree<T>& pEpTestTree<T>::_rootNode() const const PityUnit<T>& PityUnit<T>::_rootNode() const
{ {
const pEpTestTree* ret = nullptr; const PityUnit* ret = nullptr;
if (!_isRootNode()) { if (!_isRootNode()) {
ret = &(_parent->_rootNode()); ret = &(_parent->_rootNode());
} else { } else {
@ -356,7 +339,7 @@ namespace pEp {
} }
template<class T> template<class T>
const pEpTestTree<T>& pEpTestTree<T>::_parentingProcessNode() const const PityUnit<T>& PityUnit<T>::_parentingProcessNode() const
{ {
if (_isRootNode() || _isProcessNode()) { if (_isRootNode() || _isProcessNode()) {
return *this; return *this;
@ -367,7 +350,7 @@ namespace pEp {
// name is alphanumeric only (everything else will be replaced by an underscore) // name is alphanumeric only (everything else will be replaced by an underscore)
template<class T> template<class T>
string pEpTestTree<T>::_normalizeName(string name) const std::string PityUnit<T>::_normalizeName(std::string name) const
{ {
replace_if( replace_if(
name.begin(), name.begin(),
@ -379,24 +362,24 @@ namespace pEp {
} }
template<class T> template<class T>
void pEpTestTree<T>::_data_dir_create() void PityUnit<T>::_data_dir_create()
{ {
// Utils::dir_create(dataDir()); // Utils::dir_create(dataDir());
pEpLog::log("creating dir:" + getGlobalRootDir()); log("creating dir:" + getGlobalRootDir());
} }
template<class T> template<class T>
void pEpTestTree<T>::_data_dir_delete() void PityUnit<T>::_data_dir_delete()
{ {
try { try {
Utils::path_delete_all(getGlobalRootDir()); Utils::path_delete_all(getGlobalRootDir());
} catch (const exception& e) { } catch (const std::exception& e) {
pEpLog::log("DistTest: - could not delete data dir: " + getGlobalRootDir()); log("DistTest: - could not delete data dir: " + getGlobalRootDir());
} }
} }
template<class T> template<class T>
void pEpTestTree<T>::_data_dir_recreate() void PityUnit<T>::_data_dir_recreate()
{ {
_data_dir_delete(); _data_dir_delete();
_data_dir_create(); _data_dir_create();
@ -404,4 +387,4 @@ namespace pEp {
} // namespace Test } // namespace Test
} // namespace pEp } // namespace pEp
#endif // LIBPEPADAPTER_PEPTEST_PEPTESTTREE_HXX #endif // LIBPEPADAPTER_PEPTEST_PityUnit_HXX

65
test/PityTest11/test/test_execmodes.cc

@ -0,0 +1,65 @@
#include "../src/PityUnit.hh"
#include <iostream>
using namespace std;
using namespace pEp::PityTest11;
void printHomeDir(const PityUnit<>& myself, int sleepmilis, int rep_count)
{
int i = 0;
while (i < rep_count) {
myself.log(myself.getNodeName() + " - " + to_string(i));
sleep_millis(sleepmilis);
i++;
}
}
int main(int argc, char* argv[])
{
{
// DEBUG Logging of pEpTestTree itself
PityUnit<>::debug_log_enabled = false;
// Configure DataRoot for all TestNodes
PityUnit<>::setGlobalRootDir("./basic_data_root");
// The RootNode is the
PityUnit<> root = PityUnit<>{ nullptr, "Test Execution Model" };
// Subprocess 1
PityUnit<> test1 = PityUnit<>{ &root,
"node1",
[](const PityUnit<>& mynode) {
printHomeDir(mynode, 200, 10);
},
nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test1_1 = PityUnit<>{ &test1, "test1.1", [](const PityUnit<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
PityUnit<> test1_2 = PityUnit<>{ &test1, "test1.2", [](const PityUnit<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
// Subprocess 2
PityUnit<> test2 = PityUnit<>{ &root,
"node2",
[](const PityUnit<>& mynode) {
printHomeDir(mynode, 200, 10);
},
nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test2_1 = PityUnit<>{ &test2, "test2.1", [](const PityUnit<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
PityUnit<> test2_2 = PityUnit<>{ &test2, "test2.2", [](const PityUnit<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
test1.run();
}
}

50
test/PityTest11/test/test_processdirs.cc

@ -0,0 +1,50 @@
#include "../src/PityUnit.hh"
#include "../../framework/utils.hh"
#include <iostream>
#include <algorithm>
using namespace std;
using namespace pEp::PityTest11;
void printHomeDir(const PityUnit<>& myself)
{
// TESTLOG(string(myself.getFQName() + " - PID: " + to_string(getpid())));
// cout << "[" << to_string(getpid()) << "/" << myself.getFQName() << "] - " << endl;
setenv("HOME", myself.processDir().c_str(), 1);
myself.log("HOME=" + string(getenv("HOME")));
}
int main(int argc, char* argv[])
{
PityUnit<>::debug_log_enabled = false;
PityUnit<>::setGlobalRootDir("./");
PityUnit<> root = PityUnit<>{ nullptr, "rootnode" };
PityUnit<> test1 = PityUnit<>{ &root, "node 1", [](const PityUnit<>& mynode) {
assert(mynode.processDir() == "./rootnode/");
} };
PityUnit<> test1_1 = PityUnit<>{ &test1, "node 1.1", [](const PityUnit<>& mynode) {
assert(mynode.processDir() == "./rootnode/");
} };
PityUnit<> test2 = PityUnit<>{ &root, "node 2", [](const PityUnit<>& mynode) {
assert(mynode.processDir() == "./rootnode/");
} };
PityUnit<> test2_1 = PityUnit<>{ &test2,
"node 2.1",
[](const PityUnit<>& mynode) {
assert(mynode.processDir() == "./rootnode/");
},
nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test2_1_1 = PityUnit<>{ &test2_1, "node 2.1.1", [](PityUnit<> mynode) {
assert(mynode.processDir() == "./rootnode/");
} };
root.run();
}

16
test/pEpTest/src/pEpTestModel.cc

@ -1,16 +0,0 @@
#include "pEpTestModel.hh"
#include "iostream"
using namespace std;
namespace pEp {
namespace Test {
bool pEpTestModel::log_enabled = true;
pEpTestModel::pEpTestModel(const string& name) : name(name) {}
const std::string& pEpTestModel::getName() const
{
return name;
}
} // namespace Test
} // namespace pEp

72
test/pEpTest/test/test_pEpTest_basic.cc

@ -1,72 +0,0 @@
#include "../src/pEpTestTree.hh"
#include "../../framework/utils.hh"
#include <iostream>
#include <unistd.h>
using namespace std;
using namespace pEp;
using namespace pEp::Test;
void printHomeDir(const pEpTestTree<>& myself, int sleepmilis, int rep_count)
{
// TESTLOGH1("HYA FROM:" + myself.getFQName());
int i = 0;
while (i < rep_count) {
myself.log(myself.getNodeName() + " - " + to_string(i));
// TESTLOG(string(myself.getFQName() + " - PID: " + to_string(getpid()) + " - " + to_string(i)));
sleep_millis(sleepmilis);
i++;
}
}
int main(int argc, char* argv[])
{
string dummy;
{
// DEBUG Logging of pEpTestTree itself
pEpTestTree<>::debug_log_enabled = false;
// Configure DataRoot for all TestNodes
pEpTestTree<>::setGlobalRootDir("./basic_data_root");
// The RootNode is the
pEpTestTree<> root = pEpTestTree<>{ nullptr, "Test Execution Model"};
// Subprocess 1
pEpTestTree<> test1 = pEpTestTree<>{
&root,
"node1",
[](const pEpTestTree<>& mynode) { printHomeDir(mynode, 200, 10); },
nullptr,
pEp::Test::pEpTestTree<>::ExecutionMode::PROCESS_PARALLEL
};
pEpTestTree<> test1_1 = pEpTestTree<>{ &test1, "test1.1", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
pEpTestTree<> test1_2 = pEpTestTree<>{ &test1, "test1.2", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
// Subprocess 2
pEpTestTree<> test2 = pEpTestTree<>{
&root,
"node2",
[](const pEpTestTree<>& mynode) { printHomeDir(mynode, 200, 10); },
nullptr,
pEp::Test::pEpTestTree<>::ExecutionMode::PROCESS_PARALLEL
};
pEpTestTree<> test2_1 = pEpTestTree<>{ &test2, "test2.1", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
pEpTestTree<> test2_2 = pEpTestTree<>{ &test2, "test2.2", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode, 200, 10);
} };
root.run();
}
}

53
test/pEpTest/test/test_transport.cc

@ -1,53 +0,0 @@
#include "../src/pEpTestTree.hh"
#include "../../framework/utils.hh"
#include <iostream>
#include <unistd.h>
#include <cstdlib>
#include <algorithm>
//#include <regex>
using namespace std;
using namespace pEp;
using namespace pEp::Test;
void printHomeDir(const pEpTestTree<>& myself)
{
// TESTLOG(string(myself.getFQName() + " - PID: " + to_string(getpid())));
// cout << "[" << to_string(getpid()) << "/" << myself.getFQName() << "] - " << endl;
setenv("HOME", myself.processDir().c_str(), 1);
myself.log("HOME=" + string(getenv("HOME")));
}
int main(int argc, char* argv[])
{
pEpTestTree<>::debug_log_enabled = true;
pEpTestTree<>::setGlobalRootDir("./testdata");
pEpTestTree<> root = pEpTestTree<>{ nullptr, "rootnode"};
pEpTestTree<> test1 = pEpTestTree<>{ &root, "node 1", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode);
} };
pEpTestTree<> test1_1 = pEpTestTree<>{ &test1, "node 1.1", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode);
} };
pEpTestTree<> test2 = pEpTestTree<>{ &root, "node 2", [](const pEpTestTree<>& mynode) {
printHomeDir(mynode);
} };
pEpTestTree<> test2_1 = pEpTestTree<>{ &test2,
"node 2.1",
[](const pEpTestTree<>& mynode) { printHomeDir(mynode); },
nullptr,
pEp::Test::pEpTestTree<>::ExecutionMode::PROCESS_PARALLEL };
pEpTestTree<> test2_1_1 = pEpTestTree<>{ &test2_1, "node 2.1.1", [](pEpTestTree<> mynode) {
printHomeDir(mynode);
} };
root.run();
}
Loading…
Cancel
Save