From 8545264a928c252e406a2fa27dd4dde00fc48f1d Mon Sep 17 00:00:00 2001 From: Phanes Date: Fri, 1 Dec 2017 01:13:30 -0500 Subject: [PATCH] removed output checks from data model and from implementation. prepared to implement STD{IN,OUT,ERR} piping for subprocess execution. Hoping to maintain compatibility with curses dialogs. --- conf/units/all_test.units | 24 ++++++++++-------------- src/loaders/Task.cpp | 21 ++++++++++++++------- src/loaders/Unit.cpp | 3 --- src/sproc/Sproc.cpp | 7 +++++-- src/sproc/Sproc.h | 23 +++-------------------- 5 files changed, 32 insertions(+), 46 deletions(-) diff --git a/conf/units/all_test.units b/conf/units/all_test.units index 6f76a54..efe4a0e 100644 --- a/conf/units/all_test.units +++ b/conf/units/all_test.units @@ -2,36 +2,32 @@ "units": [ { "name": "independent test 1", - "target": "/bin/pwd", - "output": "pass", - "rectifier": "/bin/pwd", + "target": "/usr/bin/true", + "rectifier": "/usr/bin/true", "active": true, "required": true, "rectify": true }, { "name": "independent test 2", - "target": "/bin/pwd", - "output": "pass", - "rectifier": "/bin/pwd", + "target": "/usr/bin/false", + "rectifier": "/usr/bin/true", "active": true, "required": true, - "rectify": true + "rectify": false }, { "name": "A DEFINITION THAT IS NOT USED", - "target": "/bin/pwd", - "output": "pass", - "rectifier": "/bin/pwd", + "target": "/usr/bin/false", + "rectifier": "/usr/bin/true", "active": true, "required": true, - "rectify": true + "rectify": false }, { "name": "dependent test", - "target": "/home/phanes/tests/test-script-pass.sh", - "output": "pass", - "rectifier": "/home/phanes/tests/test-script-rectifier.sh", + "target": "/usr/bin/false", + "rectifier": "/usr/bin/true", "active": true, "required": true, "rectify": false diff --git a/src/loaders/Task.cpp b/src/loaders/Task.cpp index 058c74a..889f37d 100644 --- a/src/loaders/Task.cpp +++ b/src/loaders/Task.cpp @@ -97,15 +97,22 @@ void Task::execute( bool verbose ) std::cout << "\t Executing target \"" << this->definition.get_target() << "\"." << std::endl; } - ExecutionInput execIn; - Execution Result; + std::string executionString = this->definition.get_target(); + std::string rectifierString = this->definition.get_rectifier(); - execIn.executionString = this->definition.get_target(); + int return_code = Sproc::execute( executionString ); - int execution_status = Sproc::execute( execIn, Result ); - - if ( execution_status ) + if ( return_code ) { - std::cout << std::endl << "STDOUT:" << std::endl<< Result.STDOUT << std::endl; + std::cout << "Process failed with exit code " << return_code << "." << std::endl; + + std::cout << "Performing rectification: " << rectifierString << "." << std::endl; + int rectifier_error = Sproc::execute( rectifierString ); + + if ( rectifier_error ) + { + std::cout << "Designated rectification script failed with error " << rectifier_error << "." << std::endl; + } + } } \ No newline at end of file diff --git a/src/loaders/Unit.cpp b/src/loaders/Unit.cpp index 3bb6424..23f71e6 100644 --- a/src/loaders/Unit.cpp +++ b/src/loaders/Unit.cpp @@ -48,9 +48,6 @@ int Unit::load_root(Json::Value loader_root) if ( loader_root.isMember("target") ) { this->target = loader_root.get("target", errmsg).asString(); } else throw Unit_DataStructureException(); - if ( loader_root.isMember("output") ) - { this->output = loader_root.get("output", errmsg).asString(); } else throw Unit_DataStructureException(); - if ( loader_root.isMember("rectifier") ) { this->rectifier = loader_root.get("rectifier", errmsg).asString(); } else throw Unit_DataStructureException(); diff --git a/src/sproc/Sproc.cpp b/src/sproc/Sproc.cpp index f429c45..580760a 100644 --- a/src/sproc/Sproc.cpp +++ b/src/sproc/Sproc.cpp @@ -1,7 +1,10 @@ #include "Sproc.h" -int Sproc::execute(ExecutionInput input, Execution &output) + + +int Sproc::execute( std::string input ) { - output.STDOUT = "it worked"; + std::cout << std::endl << "made it to subprocess execution but not implemented yet" << std::endl << std::endl; + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/src/sproc/Sproc.h b/src/sproc/Sproc.h index 0e28205..ea151ca 100644 --- a/src/sproc/Sproc.h +++ b/src/sproc/Sproc.h @@ -1,32 +1,15 @@ #ifndef FTESTS_SPROC_H #define FTESTS_SPROC_H -#include "string" - - -struct ExecutionInput { - std::string executionString; -// std::string STDIN; -// std::vector EnvironmentVariables; -}; - -struct Execution { - //input - ExecutionInput input; - - // output - int return_code; - - std::string STDOUT; - std::string STDERR; -}; +#include +#include // executes a subprocess and captures STDOUT, STDERR, and return code. // should be able to recieve path of binary to be executed as well as any parameters class Sproc { public: // call the object. returnvalue is enum representing external execution attempt not binary exit code - static int execute( ExecutionInput input, Execution & output ); + static int execute( std::string input ); }; #endif //FTESTS_SPROC_H