diff --git a/ameasure2/src/ameasure.cpp b/ameasure2/src/ameasure.cpp index 50ce571c64764e48f288d493f0b040d2eff6c616..fc0dff650b42631e0a0cd6b2b57cd86959b870a4 100644 --- a/ameasure2/src/ameasure.cpp +++ b/ameasure2/src/ameasure.cpp @@ -25,34 +25,7 @@ int main ( int argc, char * * argv ) { else sax::SaxParseInterface::parseFile ( input.getValue ( ), tokens ); - provisioner::MeasurementProvisionerConfiguration configuration; - - provisioner::MPCInputBatch b1; - b1.batch.push_back ( { provisioner::MPCInputDatum::Type::FILE, 1, 1, "~/repositories/automata-library/local/examples/data[1-9].xml" } ); - b1.batch.push_back ( { provisioner::MPCInputDatum::Type::FILE, 2, 1, "~/repositories/automata-library/local/examples/data[1-9].pattern.xml" } ); - configuration.inputBatches.push_back ( b1 ); - - provisioner::MPCInputBatch b2; - b2.batch.push_back ( { provisioner::MPCInputDatum::Type::GENERATOR, 1, 1, "./arand2 -t ST --length 1024 --terminals 26" } ); - b2.batch.push_back ( { provisioner::MPCInputDatum::Type::GENERATOR, 2, 1, "./arand2 -t ST --length 1024 --terminals 26" } ); - configuration.inputBatches.push_back ( b2 ); - - provisioner::MPCInputBatch b3; - b3.forcedDependencyBatch = true; - b3.batch.push_back ( { provisioner::MPCInputDatum::Type::GENERATOR, 1, 2, "./arand2 -t ST --length 1024 --terminals 26" } ); - b3.batch.push_back ( { provisioner::MPCInputDatum::Type::FILE, 2, 1, "~/repositories/automata-library/local/examples/data[1-9].pattern.xml" } ); - configuration.inputBatches.push_back ( b3 ); - - provisioner::MPCInputBatch b4; - b4.forcedDependencyBatch = true; - b4.batch.push_back ( { provisioner::MPCInputDatum::Type::GENERATOR, 1, 2, "./arand2 -t ST --length 1024 --terminals 26" } ); - b4.batch.push_back ( { provisioner::MPCInputDatum::Type::GENERATOR, 2, 2, "./arand2 -t ST --length 512 --terminals 26" } ); - b4.batch.push_back ( { provisioner::MPCInputDatum::Type::GENERATOR, 2, 2, "./arand2 -t ST --length 1024 --terminals 26" } ); - configuration.inputBatches.push_back ( b4 ); - - - configuration.pipelines = { { "./astringology2 -a boyerMooreHorspool -s $1 -p $2 " }, { "./astringology2 -a reversedBoyerMooreHorspool -s $1 -p $2 " } }; - + auto configuration = provisioner::MeasurementProvisionerXmlFactory::parseMeasurementProvisionerConfiguration ( tokens ); provisioner::MeasurementProvisioner::runConfiguration ( configuration ); /*auto configuration = provisioner::MeasurementProvisionerXmlFactory::parseMeasurementProvisionerConfiguration ( tokens ); diff --git a/ameasure2/src/provisioner/MeasurementProvisionerUtils.cpp b/ameasure2/src/provisioner/MeasurementProvisionerUtils.cpp index 07d7e99df1934c10a4082e35f6e1bec69fb19502..c8037d55bb804e3ff5e7f91823ced767d16da854 100644 --- a/ameasure2/src/provisioner/MeasurementProvisionerUtils.cpp +++ b/ameasure2/src/provisioner/MeasurementProvisionerUtils.cpp @@ -6,6 +6,7 @@ #include "exception/CommonException.h" #include <wordexp.h> #include <unistd.h> +#include <iostream> namespace provisioner { @@ -36,6 +37,8 @@ std::string MPUtils::generateTmpfileFromCommand ( const std::string & command ) int stdoutfd = dup ( 1 ); close ( 1 ); dup ( tempfd ); + + int status = system ( command.c_str ( ) ); close ( 1 ); diff --git a/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.cpp b/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.cpp index 00eda897b1323cfda853b7cb0b44d4b0e606c506..ccb1c2f65e6d05d56bc18f5f98c1f088671eb7d3 100644 --- a/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.cpp +++ b/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.cpp @@ -1,7 +1,7 @@ /* * Author: Radovan Cerveny */ -/* + #include "sax/FromXMLParserHelper.h" #include "MeasurementProvisionerXmlFactory.hpp" #include "exception/CommonException.h" @@ -37,8 +37,8 @@ void MeasurementProvisionerXmlFactory::parseMeasurementProvisioner ( Measurement FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, BINARIES_DIRECTORY_TAG ); mpc.binariesDirectory = FromXMLParserHelper::popTokenData ( iter, Token::TokenType::CHARACTER ); FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, BINARIES_DIRECTORY_TAG ); - } else if ( data == MEASUREMENT_PROVISIONS_TAG ) { - parseMeasurementProvisions ( mpc, iter ); + } else if ( data == MEASUREMENT_PROVISION_TAG ) { + parseMeasurementProvision ( mpc, iter ); } else { break; } @@ -47,76 +47,90 @@ void MeasurementProvisionerXmlFactory::parseMeasurementProvisioner ( Measurement FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, MEASUREMENT_PROVISIONER_TAG ); } -void MeasurementProvisionerXmlFactory::parseMeasurementProvisions ( MeasurementProvisionerConfiguration & mpc, std::deque < sax::Token >::iterator & iter ) { - FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, MEASUREMENT_PROVISIONS_TAG ); +void MeasurementProvisionerXmlFactory::parseMeasurementProvision ( MeasurementProvisionerConfiguration & mpc, std::deque < sax::Token >::iterator & iter ) { + FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, MEASUREMENT_PROVISION_TAG ); for ( ; ; ) { if ( !FromXMLParserHelper::isTokenType ( iter, Token::TokenType::START_ELEMENT ) ) break; string data = FromXMLParserHelper::getTokenData ( iter, Token::TokenType::START_ELEMENT ); - if ( data == MEASUREMENT_PROVISION_TAG ) - parseMeasurementProvision ( mpc, iter ); + if ( data == INPUT_DATA_TAG ) + parseInputData ( mpc, iter ); + else if ( data == PIPELINES_TAG ) + parsePipelines ( mpc, iter ); + else if ( data == MEASUREMENT_CONFIGURATION_TAG ) + parseMeasurementConfiguration ( mpc, iter ); else break; } - FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, MEASUREMENT_PROVISIONS_TAG ); + FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, MEASUREMENT_PROVISION_TAG ); } -void MeasurementProvisionerXmlFactory::parseMeasurementProvision ( MeasurementProvisionerConfiguration & mpc, std::deque < sax::Token >::iterator & iter ) { - FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, MEASUREMENT_PROVISION_TAG ); - - MeasurementProvision mp; +void MeasurementProvisionerXmlFactory::parseInputData ( MeasurementProvisionerConfiguration & mpc, std::deque < sax::Token >::iterator & iter ) { + FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, INPUT_DATA_TAG ); for ( ; ; ) { if ( !FromXMLParserHelper::isTokenType ( iter, Token::TokenType::START_ELEMENT ) ) break; string data = FromXMLParserHelper::getTokenData ( iter, Token::TokenType::START_ELEMENT ); - if ( data == INPUT_DATA_TAG ) - parseInputData ( mp, iter ); - else if ( data == PIPELINES_TAG ) - parsePipelines ( mp, iter ); - else if ( data == MEASUREMENT_CONFIGURATION_TAG ) - parseMeasurementConfiguration ( mp, iter ); + if ( data == INPUT_DATA_BATCH_TAG ) + parseInputBatch ( mpc, iter ); else break; } - mpc.measurementProvisions.emplace_back ( std::move ( mp ) ); - - FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, MEASUREMENT_PROVISION_TAG ); + FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, INPUT_DATA_TAG ); } -void MeasurementProvisionerXmlFactory::parseInputData ( MeasurementProvision & mp, std::deque < sax::Token >::iterator & iter ) { - FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, INPUT_DATA_TAG ); +void MeasurementProvisionerXmlFactory::parseInputBatch ( MeasurementProvisionerConfiguration & mpc, std::deque < sax::Token >::iterator & iter ) { + FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, INPUT_DATA_BATCH_TAG ); + + MPCInputBatch mpcib; + + mpcib.forcedDependencyBatch = false; + + if ( FromXMLParserHelper::isTokenType ( iter, Token::TokenType::START_ATTRIBUTE ) ) { + string attrName = FromXMLParserHelper::getTokenData ( iter, Token::TokenType::START_ATTRIBUTE ); + + if ( attrName == INPUT_DATA_BATCH_ATTR_DEPENDENCY_NAME ) { + FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ATTRIBUTE, attrName ); + string attrVal = FromXMLParserHelper::popTokenData ( iter, Token::TokenType::CHARACTER ); + + if ( attrVal == "true" ) + mpcib.forcedDependencyBatch = true; + + FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ATTRIBUTE, attrName ); + } + } for ( ; ; ) { if ( !FromXMLParserHelper::isTokenType ( iter, Token::TokenType::START_ELEMENT ) ) break; string data = FromXMLParserHelper::getTokenData ( iter, Token::TokenType::START_ELEMENT ); - if ( data == INPUT_DATA_FILE_TAG ) - mp.inputData.emplace_back ( parseInputDatum ( INPUT_DATA_FILE_TAG, iter ) ); - else if ( data == INPUT_DATA_GENERATOR_TAG ) - mp.inputData.emplace_back ( parseInputDatum ( INPUT_DATA_GENERATOR_TAG, iter ) ); - else - break; + mpcib.batch.push_back ( parseInputDatum ( data, iter ) ); } - FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, INPUT_DATA_TAG ); + mpc.inputBatches.push_back ( std::move ( mpcib ) ); + + FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, INPUT_DATA_BATCH_TAG ); } -MeasurementInputDatum MeasurementProvisionerXmlFactory::parseInputDatum ( const std::string & tag, std::deque < sax::Token >::iterator & iter ) { - MeasurementInputDatum mid; +MPCInputDatum MeasurementProvisionerXmlFactory::parseInputDatum ( const std::string & tag, std::deque < sax::Token >::iterator & iter ) { + MPCInputDatum mpcid; + + mpcid.id = -1; + mpcid.count = 1; if ( tag == INPUT_DATA_FILE_TAG ) - mid.type = MeasurementInputDatum::Type::FILE; + mpcid.type = MPCInputDatum::Type::FILE; else if ( tag == INPUT_DATA_GENERATOR_TAG ) - mid.type = MeasurementInputDatum::Type::GENERATOR; + mpcid.type = MPCInputDatum::Type::GENERATOR; else - throw::exception::CommonException ( "Unknown InputData type" ); + throw::exception::CommonException ( "XML: Unknown MPCInputDatum type" ); FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, tag ); @@ -131,24 +145,25 @@ MeasurementInputDatum MeasurementProvisionerXmlFactory::parseInputDatum ( const FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ATTRIBUTE, attrName ); if ( attrName == INPUT_DATA_ATTR_ID_NAME ) { - mid.id = std::stoi ( attrVal ); - foundId = true; + mpcid.id = std::stoi ( attrVal ); + foundId = true; + } else if ( attrName == INPUT_DATA_ATTR_COUNT_NAME ) { + mpcid.count = std::stoi ( attrVal ); + } else { + throw::exception::CommonException ( "XML: MPCInputDatum unknown attr: " + attrName ); } - else - mid.attrs[attrName] = attrVal; } - if(!foundId) - throw::exception::CommonException ( "InputData id was not specified" ); - + if ( !foundId ) + throw::exception::CommonException ( "XML: MPCInputDatum id attr was not specified" ); - mid.value = FromXMLParserHelper::popTokenData ( iter, Token::TokenType::CHARACTER ); + mpcid.value = FromXMLParserHelper::popTokenData ( iter, Token::TokenType::CHARACTER ); FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, tag ); - return mid; + return mpcid; } -void MeasurementProvisionerXmlFactory::parsePipelines ( MeasurementProvision & mp, std::deque < sax::Token >::iterator & iter ) { +void MeasurementProvisionerXmlFactory::parsePipelines ( MeasurementProvisionerConfiguration & mpc, std::deque < sax::Token >::iterator & iter ) { FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, PIPELINES_TAG ); for ( ; ; ) { @@ -157,8 +172,8 @@ void MeasurementProvisionerXmlFactory::parsePipelines ( MeasurementProvision & m string data = FromXMLParserHelper::getTokenData ( iter, Token::TokenType::START_ELEMENT ); if ( data == PIPELINE_TAG ) { - mp.pipelines.push_back ( { } ); - parsePipeline ( mp.pipelines.back ( ), iter ); + mpc.pipelines.push_back ( { } ); + parsePipeline ( mpc.pipelines.back ( ), iter ); } else { break; } @@ -187,7 +202,7 @@ void MeasurementProvisionerXmlFactory::parsePipeline ( std::vector < std::string FromXMLParserHelper::popToken ( iter, Token::TokenType::END_ELEMENT, PIPELINE_TAG ); } -void MeasurementProvisionerXmlFactory::parseMeasurementConfiguration ( MeasurementProvision &, std::deque < sax::Token >::iterator & iter ) { +void MeasurementProvisionerXmlFactory::parseMeasurementConfiguration ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & iter ) { FromXMLParserHelper::popToken ( iter, Token::TokenType::START_ELEMENT, MEASUREMENT_CONFIGURATION_TAG ); // skip everything for now @@ -200,13 +215,17 @@ string MeasurementProvisionerXmlFactory::MEASUREMENT_PROVISIONER_TAG = "Measurem string MeasurementProvisionerXmlFactory::BINARIES_DIRECTORY_TAG = "BinariesDirectory"; -string MeasurementProvisionerXmlFactory::MEASUREMENT_PROVISIONS_TAG = "MeasurementProvisions"; -string MeasurementProvisionerXmlFactory::MEASUREMENT_PROVISION_TAG = "MeasurementProvision"; +string MeasurementProvisionerXmlFactory::MEASUREMENT_PROVISION_TAG = "MeasurementProvision"; string MeasurementProvisionerXmlFactory::INPUT_DATA_TAG = "InputData"; +string MeasurementProvisionerXmlFactory::INPUT_DATA_BATCH_TAG = "InputBatch"; +string MeasurementProvisionerXmlFactory::INPUT_DATA_BATCH_ATTR_DEPENDENCY_NAME = "dependency"; + string MeasurementProvisionerXmlFactory::INPUT_DATA_FILE_TAG = "File"; string MeasurementProvisionerXmlFactory::INPUT_DATA_GENERATOR_TAG = "Generator"; + string MeasurementProvisionerXmlFactory::INPUT_DATA_ATTR_ID_NAME = "id"; +string MeasurementProvisionerXmlFactory::INPUT_DATA_ATTR_COUNT_NAME = "count"; string MeasurementProvisionerXmlFactory::PIPELINES_TAG = "Pipelines"; string MeasurementProvisionerXmlFactory::PIPELINE_TAG = "Pipeline"; @@ -214,4 +233,3 @@ string MeasurementProvisionerXmlFactory::COMMAND_TAG = "Command"; string MeasurementProvisionerXmlFactory::MEASUREMENT_CONFIGURATION_TAG = "MeasurementConfiguration"; } -*/ diff --git a/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.hpp b/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.hpp index 743ef02f4023f489fdbf4fb9dc6dd664b472d3b3..4db31f10d97395f8a0bb24bb3daa1ab10edbf949 100644 --- a/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.hpp +++ b/ameasure2/src/provisioner/MeasurementProvisionerXmlFactory.hpp @@ -4,7 +4,7 @@ #ifndef MEASUREMENT_PROVISIONER_XML_FACTORY_HPP_ #define MEASUREMENT_PROVISIONER_XML_FACTORY_HPP_ -/* + #include <deque> #include "sax/Token.h" #include "MeasurementProvisionerConfiguration.hpp" @@ -16,13 +16,17 @@ class MeasurementProvisionerXmlFactory { static std::string BINARIES_DIRECTORY_TAG; - static std::string MEASUREMENT_PROVISIONS_TAG; static std::string MEASUREMENT_PROVISION_TAG; static std::string INPUT_DATA_TAG; + static std::string INPUT_DATA_BATCH_TAG; + static std::string INPUT_DATA_BATCH_ATTR_DEPENDENCY_NAME; + static std::string INPUT_DATA_FILE_TAG; static std::string INPUT_DATA_GENERATOR_TAG; + static std::string INPUT_DATA_ATTR_ID_NAME; + static std::string INPUT_DATA_ATTR_COUNT_NAME; static std::string PIPELINES_TAG; static std::string PIPELINE_TAG; @@ -31,20 +35,21 @@ class MeasurementProvisionerXmlFactory { static std::string MEASUREMENT_CONFIGURATION_TAG; static void parseMeasurementProvisioner ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); - static void parseMeasurementProvisions ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); static void parseMeasurementProvision ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); - static void parseInputData ( MeasurementProvision &, std::deque < sax::Token >::iterator & ); - static MeasurementInputDatum parseInputDatum ( const std::string &, std::deque < sax::Token >::iterator & ); - static void parsePipelines ( MeasurementProvision &, std::deque < sax::Token >::iterator & ); + static void parseInputData ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); + static void parseInputBatch ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); + static MPCInputDatum parseInputDatum ( const std::string &, std::deque < sax::Token >::iterator & ); + + static void parsePipelines ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); static void parsePipeline ( std::vector < std::string > &, std::deque < sax::Token >::iterator & ); - static void parseMeasurementConfiguration ( MeasurementProvision &, std::deque < sax::Token >::iterator & ); + static void parseMeasurementConfiguration ( MeasurementProvisionerConfiguration &, std::deque < sax::Token >::iterator & ); public: static MeasurementProvisionerConfiguration parseMeasurementProvisionerConfiguration ( std::deque < sax::Token > & ); }; } -*/ + #endif /* MEASUREMENT_PROVISIONER_XML_FACTORY_HPP_ */ diff --git a/examples2/measurements/ameasure.xml b/examples2/measurements/ameasure.xml index a66fb31a56312aaea5d2760af3b07c501ac88487..371119122b9033182c19200322961290e777cb55 100644 --- a/examples2/measurements/ameasure.xml +++ b/examples2/measurements/ameasure.xml @@ -1,61 +1,40 @@ <?xml version="1.0"?> <MeasurementProvisioner> <BinariesDirectory>~/repositories/automata-library/bin-debug</BinariesDirectory> - <MeasurementProvisions> - <MeasurementProvision> - <InputData> - <InputBatch> - <File id="1">my_data[1-9].xml</File> - <File id="2">my_data[1-9].pattern.xml</File> + <MeasurementProvision> + <InputData> + <InputBatch> + <File id="1">~/repositories/automata-library/local/examples/data[1-9].xml</File> + <File id="2">~/repositories/automata-library/local/examples/data[1-9].pattern.xml</File> + </InputBatch> + <InputBatch> + <Generator id="1">./arand2 -t ST --length 1024 --terminals 26</Generator> + <Generator id="2">./arand2 -t ST --length 1024 --terminals 26</Generator> + </InputBatch> + <InputBatch dependency="true"> + <Generator id="1" count="2">./arand2 -t ST --length 1024 --terminals 26</Generator> + <File id="2">~/repositories/automata-library/local/examples/data[1-9].pattern.xml</File> </InputBatch> - <InputBatch> - <File id="1">my_data[1-9].xml</File> - <Generator id="2">./arand2pattern -i $1</Generator> - </InputBatch> - <InputBatch> - <Generator id="1" count="2">./arand2 -t ST --length 1024 --terminals 26</Generator> - <Generator id="2">./arand2pattern --length 128 -i $1</Generator> - <Generator id="2">./arand2pattern --length 256 -i $1</Generator> - <Generator id="2">./arand2pattern --length 512 -i $1</Generator> - </InputBatch> - <InputBatch> - <File id="1">my_data[1-9].xml</File> - <Generator id="2">./arand2pattern -i $1</Generator> - <File id="3">fooback</File> - </InputBatch> - </InputData> - <Pipelines> - <Pipeline> - <Command>./astringology2 -a boyerMooreHorspool -s $1 -p $2</Command> - </Pipeline> - <Pipeline> - <Command>./astringology2 -a reversedBoyerMooreHorspool -s $1 -p $2</Command> - </Pipeline> - </Pipelines> - <MeasurementConfiguration> - <Engines> - <Engine>TIME</Engine> - <Engine>MEMORY</Engine> - <Engine>COUNTER</Engine> - </Engines> - </MeasurementConfiguration> - </MeasurementProvision> - <MeasurementProvision> - <InputData> - <File id="1">~/repositories/automata-library/examples2/automaton/NFSM[12].xml</File> - </InputData> - <Pipelines> - <Pipeline> - <Command>./adeterminize2</Command> - <Command>./aminimize2</Command> - </Pipeline> - </Pipelines> - <MeasurementConfiguration> - <Engines> - <Engine>MEMORY</Engine> - <Engine>COUNTER</Engine> - </Engines> - </MeasurementConfiguration> - </MeasurementProvision> - </MeasurementProvisions> + <InputBatch> + <Generator id="1" count="2">./arand2 -t ST --length 1024 --terminals 26</Generator> + <Generator id="2" count="2">./arand2 -t ST --length 256 --terminals 26 # -i $1</Generator> + <Generator id="2" count="2">./arand2 -t ST --length 512 --terminals 26 # -i $1"</Generator> + </InputBatch> + </InputData> + <Pipelines> + <Pipeline> + <Command>./astringology2 -a boyerMooreHorspool -s $1 -p $2</Command> + </Pipeline> + <Pipeline> + <Command>./astringology2 -a reversedBoyerMooreHorspool -s $1 -p $2</Command> + </Pipeline> + </Pipelines> + <MeasurementConfiguration> + <Engines> + <Engine>TIME</Engine> + <Engine>MEMORY</Engine> + <Engine>COUNTER</Engine> + </Engines> + </MeasurementConfiguration> + </MeasurementProvision> </MeasurementProvisioner> \ No newline at end of file