Browse Source

Tests: PityTest11 - Test status output

master
heck 4 years ago
parent
commit
6ac82c72b0
  1. 38
      src/PityUnit.hxx

38
src/PityUnit.hxx

@ -5,7 +5,7 @@
#define PITYTEST_PITYUNIT_HXX #define PITYTEST_PITYUNIT_HXX
#include "../../../src/std_utils.hh" #include "../../../src/std_utils.hh"
#include "../../framework/utils.hh" //#include "../../framework/utils.hh"
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <cstdlib> #include <cstdlib>
@ -13,7 +13,7 @@
#include <functional> #include <functional>
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <exception>
using namespace pEp::Adapter::pEpLog; using namespace pEp::Adapter::pEpLog;
@ -119,7 +119,7 @@ namespace pEp {
} else { } else {
if (_isProcessNode()) { if (_isProcessNode()) {
return rootNodeDir() + getNodeName() + "/"; return rootNodeDir() + getNodeName() + "/";
} else{ } else {
return _parent->processDir(); return _parent->processDir();
} }
} }
@ -152,20 +152,20 @@ namespace pEp {
// caller is never nullptr if called by another PityUnit // caller is never nullptr if called by another PityUnit
if (_isRootNode()) { if (_isRootNode()) {
logH1("Starting PityUnit from node: " + getNodePathShort()); logH1("Starting PityUnit from node: " + getNodePathShort());
log(to_string()); std::cout << to_string() << std::endl;
} }
// 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
logH2("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + " ]"); logH2(_status_string("RUNNING"));
_executeInFork(std::bind(&PityUnit::_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) {
logH2("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + " ]"); logH2(_status_string("RUNNING"));
_executeInFork(std::bind(&PityUnit::_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) {
logH3("[ " + to_string(_exec_mode) + " / " + getNodePathShort() + " ]"); logH3(_status_string("RUNNING"));
_run(); _run();
} else if (_exec_mode == ExecutionMode::THREAD_PARALLEL) { } else if (_exec_mode == ExecutionMode::THREAD_PARALLEL) {
throw std::invalid_argument(to_string(_exec_mode) + " - not implemented"); throw std::invalid_argument(to_string(_exec_mode) + " - not implemented");
@ -173,7 +173,7 @@ namespace pEp {
throw std::invalid_argument(to_string(_exec_mode) + " - not implemented"); throw std::invalid_argument(to_string(_exec_mode) + " - not implemented");
} }
if(_isRootNode()) { if (_isRootNode()) {
_waitChildProcesses(); _waitChildProcesses();
} }
} }
@ -252,7 +252,13 @@ namespace pEp {
void PityUnit<T>::_runSelf() const void PityUnit<T>::_runSelf() const
{ {
if (_test_func != nullptr) { if (_test_func != nullptr) {
_test_func(*this); try {
_test_func(*this);
logH3(_status_string("SUCCESS"));
} catch (const std::exception& e) {
log("reason: " + std::string(e.what()));
logH3(_status_string("FAILED"));
}
} else { } else {
log("No function to execute"); log("No function to execute");
} }
@ -290,8 +296,7 @@ namespace pEp {
int status; int status;
pid_t pid; pid_t pid;
while ((pid = wait(&status)) > 0) { while ((pid = wait(&status)) > 0) {
log( pEpLogClass("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));
} }
} }
@ -361,6 +366,15 @@ namespace pEp {
return name; return name;
} }
template<class T>
std::string PityUnit<T>::_status_string(const std::string& msg) const
{
std::string ret;
ret = "[ " + to_string(_exec_mode) + ":" + std::to_string(getpid()) + " ] [ " +
getNodePathShort() + " ] [ " + msg + " ]";
return ret;
}
template<class T> template<class T>
void PityUnit<T>::_data_dir_create() void PityUnit<T>::_data_dir_create()
{ {
@ -384,7 +398,7 @@ namespace pEp {
_data_dir_delete(); _data_dir_delete();
_data_dir_create(); _data_dir_create();
}; };
} // namespace Test } // namespace PityTest11
} // namespace pEp } // namespace pEp
#endif // PITYTEST_PITYUNIT_HXX #endif // PITYTEST_PITYUNIT_HXX
Loading…
Cancel
Save