diff --git a/simulators/c++2/Makefile b/simulators/c++2/Makefile index 3683c91f05f5f0abc4e995157b36e60b1d99c2bf..7d3fd362b686e6cc46b9f0f53f69c5e496416cb1 100755 --- a/simulators/c++2/Makefile +++ b/simulators/c++2/Makefile @@ -19,8 +19,8 @@ OBJDIR = lib MODULE = run include Makefile.src -SRCS_base = app/TMLTask.cpp app/TMLCommand.cpp TMLTransaction.cpp app/TMLChannel.cpp arch/SingleCoreCPU.cpp app/TMLWriteCommand.cpp app/TMLWriteMultCommand.cpp app/TMLStateChannel.cpp app/TMLbrbwChannel.cpp app/TMLnbrnbwChannel.cpp app/TMLbrnbwChannel.cpp app/TMLEventChannel.cpp app/TMLEventBChannel.cpp app/TMLEventFChannel.cpp app/TMLEventFBChannel.cpp app/TMLReadCommand.cpp app/TMLExeciCommand.cpp app/TMLActionCommand.cpp app/TMLChoiceCommand.cpp app/TMLWaitCommand.cpp app/TMLSendCommand.cpp app/TMLSelectCommand.cpp app/TMLRequestCommand.cpp app/TMLNotifiedCommand.cpp app/TMLStopCommand.cpp arch/Bus.cpp definitions.cpp arch/Bridge.cpp arch/Memory.cpp MemPool.cpp Comment.cpp sim/Server.cpp sim/ServerLocal.cpp sim/Simulator.cpp sim/SimComponents.cpp sim/ServerIF.cpp evt/ListenersSimCmd.cpp arch/PrioScheduler.cpp arch/RRScheduler.cpp arch/WorkloadSource.cpp ebrdd/EBRDDCommand.cpp ebrdd/EBRDDActionCommand.cpp ebrdd/EBRDDChoiceCommand.cpp ebrdd/EBRDDStopCommand.cpp ebrdd/EBRDD.cpp ebrdd/ERC.cpp ebrdd/EventIF.cpp ebrdd/ERB.cpp ebrdd/ESO.cpp ebrdd/NotifyIF.cpp -#app/RdvChannel.cpp +SRCS_base = app/TMLTask.cpp app/TMLCommand.cpp TMLTransaction.cpp app/TMLChannel.cpp arch/SingleCoreCPU.cpp app/TMLWriteCommand.cpp app/TMLWriteMultCommand.cpp app/TMLStateChannel.cpp app/TMLbrbwChannel.cpp app/TMLnbrnbwChannel.cpp app/TMLbrnbwChannel.cpp app/TMLEventChannel.cpp app/TMLEventBChannel.cpp app/TMLEventFChannel.cpp app/TMLEventFBChannel.cpp app/TMLReadCommand.cpp app/TMLExeciCommand.cpp app/TMLExeciRangeCommand.cpp app/TMLActionCommand.cpp app/TMLChoiceCommand.cpp app/TMLRandomChoiceCommand.cpp app/TMLWaitCommand.cpp app/TMLSendCommand.cpp app/TMLSelectCommand.cpp app/TMLRequestCommand.cpp app/TMLNotifiedCommand.cpp app/TMLRandomCommand.cpp app/TMLStopCommand.cpp arch/Bus.cpp definitions.cpp arch/Bridge.cpp arch/Memory.cpp MemPool.cpp Comment.cpp sim/Server.cpp sim/ServerLocal.cpp sim/Simulator.cpp sim/SimComponents.cpp sim/ServerIF.cpp evt/ListenersSimCmd.cpp arch/PrioScheduler.cpp arch/RRScheduler.cpp arch/WorkloadSource.cpp + SRCS_base_DIR = src_simulator SRCS_generated = . diff --git a/simulators/c++2/src_simulator/HashAlgo.h b/simulators/c++2/src_simulator/HashAlgo.h index 5b9f23e9cdad9d289e96d598f4d0e6a3e5ba80bc..b7d0fd2e7283e8749c69f814bab9d70d59e9f55c 100644 --- a/simulators/c++2/src_simulator/HashAlgo.h +++ b/simulators/c++2/src_simulator/HashAlgo.h @@ -103,7 +103,7 @@ public: } void addValue(HashValueType iVal){ - std::cout << "++++++++++++++++++++ Added value: " << iVal << std::endl; + //std::cout << "++++++++++++++++++++ Added value: " << iVal << std::endl; _finalized = false; switch(_state){ case 0: _a+= iVal; break; diff --git a/simulators/c++2/src_simulator/app/IndeterminismSource.h b/simulators/c++2/src_simulator/app/IndeterminismSource.h new file mode 100644 index 0000000000000000000000000000000000000000..58b604e9c124a283356c0bb7cc95e7626c7c09bd --- /dev/null +++ b/simulators/c++2/src_simulator/app/IndeterminismSource.h @@ -0,0 +1,54 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +#ifndef IndeterminismSourceH +#define IndeterminismSourceH + +class IndeterminismSource{ + public: + IndeterminismSource(): _randomValue(-1) {} + virtual unsigned int getRandomRange()=0; + virtual void setRandomValue(unsigned int iValue){ + _randomValue=iValue; + } + protected: + mutable unsigned int _randomValue; +}; +#endif diff --git a/simulators/c++2/src_simulator/app/Parameter.h b/simulators/c++2/src_simulator/app/Parameter.h index 11668825e23aea0c69b68c6a477d8d73b008f8b0..dc6d028c125441eaa7f4f8e4278bbf0f94975ca0 100644 --- a/simulators/c++2/src_simulator/app/Parameter.h +++ b/simulators/c++2/src_simulator/app/Parameter.h @@ -99,14 +99,14 @@ public: } inline std::ostream& writeObject(std::ostream& s){ - std::cout << "writeObject:\n"; + //std::cout << "writeObject:\n"; for (unsigned int i=0;i<_paramNo;i++){ WRITE_STREAM(s, _p[i]); } #ifdef DEBUG_SERIALIZE print(); #endif - std::cout << "end writeObject:\n"; + //std::cout << "end writeObject:\n"; return s; } ///Stream operator >> @@ -121,13 +121,13 @@ public: \param s Stream */ void streamStateXML(std::ostream& s) const{ - std::cout << "streamStateXML:\n"; + //std::cout << "streamStateXML:\n"; s << TAG_PARAMo; for (unsigned int i=0;i<_paramNo;i++){ s << TAG_Pxo << i << ">" << _p[i] << TAG_Pxc << i << ">"; } s << TAG_PARAMc; - std::cout << "end streamStateXML:\n"; + //std::cout << "end streamStateXML:\n"; } /*inline void setP(T ip1 ...){ @@ -141,7 +141,7 @@ public: }*/ inline void getP(T* op1 ...) const { - std::cout << "getP:\n"; + //std::cout << "getP:\n"; T* arg=op1; va_list args; // argument list va_start(args, op1); // initialize args @@ -149,7 +149,7 @@ public: *arg=_p[i]; arg=va_arg(args, T*); } - std::cout << "end getP:\n"; + //std::cout << "end getP:\n"; } //inline T getPByIndex(unsigned int iIndex){ @@ -157,11 +157,11 @@ public: //} inline void getStateHash(HashAlgo* iHash) const{ - std::cout << "add param vals:\n"; + //std::cout << "add param vals:\n"; for (unsigned int i=0;i<_paramNo;i++){ iHash->addValue((HashValueType)_p[i]); } - std::cout << "end add param vals:\n"; + //std::cout << "end add param vals:\n"; } protected: diff --git a/simulators/c++2/src_simulator/app/TMLActionCommand.cpp b/simulators/c++2/src_simulator/app/TMLActionCommand.cpp index 6adb9db929939a1c3379db9ced30754fb480e30b..4dce43a94da3a13f0b708bec80d857d0dec86afb 100755 --- a/simulators/c++2/src_simulator/app/TMLActionCommand.cpp +++ b/simulators/c++2/src_simulator/app/TMLActionCommand.cpp @@ -52,7 +52,7 @@ void TMLActionCommand::execute(){ TMLCommand* TMLActionCommand::prepareNextTransaction(){ if (_simComp->getStopFlag()){ _simComp->setStoppedOnAction(); - std::cout << "sim stopped in action command " << std::endl; + //std::cout << "sim stopped in action command " << std::endl; _task->setCurrCommand(this); return this; //for command which generates transactions this is returned anyway by prepareTransaction } diff --git a/simulators/c++2/src_simulator/app/TMLChannel.cpp b/simulators/c++2/src_simulator/app/TMLChannel.cpp index b134ac9078bfb5031e3b92a55c6e69a95f3d5880..20748bbb689d6eba6a8ff1b24cb34e4b1da6df86 100755 --- a/simulators/c++2/src_simulator/app/TMLChannel.cpp +++ b/simulators/c++2/src_simulator/app/TMLChannel.cpp @@ -113,6 +113,7 @@ std::string TMLChannel::toShortString() const{ std::ostream& TMLChannel::writeObject(std::ostream& s){ //WRITE_STREAM(s,_writeTransCurrHop); //WRITE_STREAM(s,_readTransCurrHop); + //if (_ID==53 && _significance==0) std::cout << "failure before write\n"; WRITE_STREAM(s, _significance); return s; } @@ -120,6 +121,8 @@ std::istream& TMLChannel::readObject(std::istream& s){ //READ_STREAM(s,_writeTransCurrHop); //READ_STREAM(s,_readTransCurrHop); READ_STREAM(s, _significance); + //if (_ID==53 && _significance==0) std::cout << "failure after read\n"; + //std::cout << "read\n"; return s; } @@ -132,6 +135,7 @@ void TMLChannel::reset(){ _writeTransCurrHop=0; _readTransCurrHop=_numberOfHops-1; _significance=0; + //std::cout << "reset\n"; //std::cout << "Channel reset end" << std::endl; } @@ -168,13 +172,16 @@ unsigned int TMLChannel::getWidth(){ } void TMLChannel::setSignificance(TMLTask* iTask, bool iSignificance){ - int aInput = (iTask==_writeTask)?1:2; + //unsigned int aInput = (iTask==_writeTask)?1:2; + unsigned char aInput = (iTask==_writeTask)?1:2; if (iSignificance) _significance |= aInput; else - _significance &= (~aInput); + _significance &= (~aInput); } -//bool TMLChannel::getSignificance(){ -// return (_significance != 0); -//} +bool TMLChannel::getSignificance(){ + //std::cout << "get\n"; + //if (_ID==53 && _significance==0) std::cout << "failure\n"; + return (_significance != 0); +} diff --git a/simulators/c++2/src_simulator/app/TMLChannel.h b/simulators/c++2/src_simulator/app/TMLChannel.h index a5990a03b3293128a5b685bbc372f6bd78534240..8214a9c4cd5858b2b1dddc54c188bcda5a8263ed 100755 --- a/simulators/c++2/src_simulator/app/TMLChannel.h +++ b/simulators/c++2/src_simulator/app/TMLChannel.h @@ -191,6 +191,7 @@ public: \param iSignificance Flag indicating if operations performed by this task are still reachable */ void setSignificance(TMLTask* iTask, bool iSignificance); + bool getSignificance(); protected: ///ID of channel ID _ID; @@ -219,6 +220,7 @@ protected: ///channel priority Priority _priority; ///Flag indicating if read or write commands for that channel are still reachable + //unsigned int _significance; unsigned char _significance; }; diff --git a/simulators/c++2/src_simulator/app/TMLChoiceCommand.cpp b/simulators/c++2/src_simulator/app/TMLChoiceCommand.cpp index 1286e359a3c45194a227118abc89bbf47d44084d..31fcf1382258d51e8a6a6117eff5bd67e388dd1d 100755 --- a/simulators/c++2/src_simulator/app/TMLChoiceCommand.cpp +++ b/simulators/c++2/src_simulator/app/TMLChoiceCommand.cpp @@ -44,54 +44,35 @@ Ludovic Apvrille, Renaud Pacalet #include <SimComponents.h> #include <CommandListener.h> -TMLChoiceCommand::TMLChoiceCommand(ID iID, TMLTask* iTask, CondFuncPointer iCondFunc, unsigned int iNbOfBranches, bool iNonDeterm):TMLCommand(iID, iTask, 1, iNbOfBranches, 0, false), _condFunc(iCondFunc), _indexNextCommand(0), /*_nbOfBranches(iNbOfBranches),*/ _preferredBranch(-1), _nonDeterm(iNonDeterm){ +TMLChoiceCommand::TMLChoiceCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, unsigned int iNbOfBranches /*, bool iNonDeterm*/):TMLCommand(iID, iTask, 1, iNbOfBranches, 0, false), _rangeFunc(iRangeFunc) { } void TMLChoiceCommand::execute(){ } TMLCommand* TMLChoiceCommand::getNextCommand() const{ - if (_preferredBranch==((unsigned int)-1)){ - return _nextCommand[_indexNextCommand]; - }else{ - std::cout << "Command was enforced: " << _preferredBranch << std::endl; - unsigned int aPreferredBranch=_preferredBranch; - _preferredBranch=-1; - return _nextCommand[aPreferredBranch]; - } + ParamType aMin, aMax; + return _nextCommand[(_task->*_rangeFunc)(aMin, aMax)]; } TMLCommand* TMLChoiceCommand::prepareNextTransaction(){ - //std::cout << "In TMLChoice::prepare next transaction\n"; if (_simComp->getStopFlag()){ - std::cout << "aSimStopped=true " << std::endl; _simComp->setStoppedOnAction(); _task->setCurrCommand(this); return this; //for command which generates transactions this is returned anyway by prepareTransaction } - //TMLCommand* aNextCommand; - //std::cout << "Choice func " << std::endl; - _indexNextCommand=(_task->*_condFunc)(); - //std::cout << "after Choice func " << std::endl; TMLCommand* aNextCommand=getNextCommand(); - //std::cout << "get next cmd" << std::endl; _task->setCurrCommand(aNextCommand); - //std::cout << " after get next cmd" << std::endl; #ifdef LISTENERS_ENABLED NOTIFY_CMD_FINISHED(this); #endif - //std::cout << "after notify listeners" << std::endl; if (aNextCommand!=0) return aNextCommand->prepare(false); return 0; } -/*TMLTask* TMLChoiceCommand::getDependentTask() const{ - return 0; -}*/ - std::string TMLChoiceCommand::toString() const{ std::ostringstream outp; - outp << "Choice in " << TMLCommand::toString() << " nextCommand:" << _indexNextCommand; + outp << "Choice in " << TMLCommand::toString(); return outp.str(); } @@ -102,15 +83,3 @@ std::string TMLChoiceCommand::toShortString() const{ std::string TMLChoiceCommand::getCommandStr() const{ return "cho"; } - -void TMLChoiceCommand::setPreferredBranch(unsigned int iBranch){ - _preferredBranch=iBranch; -} - -//unsigned int TMLChoiceCommand::getNumberOfBranches(){ -// return _nbOfBranches; -//} - -bool TMLChoiceCommand::isNonDeterministic(){ - return _nonDeterm; -} diff --git a/simulators/c++2/src_simulator/app/TMLChoiceCommand.h b/simulators/c++2/src_simulator/app/TMLChoiceCommand.h index 8c63a39d1f66ba2ab791d58dcf957434d8f6fa65..4a5731a9f325e27cae9024aab3b8ee345621c5a2 100755 --- a/simulators/c++2/src_simulator/app/TMLChoiceCommand.h +++ b/simulators/c++2/src_simulator/app/TMLChoiceCommand.h @@ -55,39 +55,17 @@ public: \param iTask Pointer to the task the command belongs to \param iCondFunc Member function pointer to the condition function returning the index of the next command \param iNbOfBranches Number of branches of the choice - \param iNonDeterm Flag is true for non deterministic commands */ - TMLChoiceCommand(ID iID, TMLTask* iTask, CondFuncPointer iCondFunc, unsigned int iNbOfBranches, bool iNonDeterm); + TMLChoiceCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, unsigned int iNbOfBranches); void execute(); - //TMLTask* getDependentTask() const; std::string toString() const; std::string toShortString() const; std::string getCommandStr() const; - ///Set preferred branch manually - void setPreferredBranch(unsigned int iBranch); - /////Returns the number of branches - ////** - //\return Number of branches - //*/ - //unsigned int getNumberOfBranches(); - ///Returns the state of non non deterministic flag - /** - \return Non deterministic flag - */ - bool isNonDeterministic(); protected: ///Member function pointer to the condition function returning the index of the next command - CondFuncPointer _condFunc; - ///Index of the next command within the _nextCommand array - unsigned int _indexNextCommand; - /////Number of branches - //unsigned int _nbOfBranches; - ///Index of the manually set branch - mutable unsigned int _preferredBranch; - ///Flag to label non determinsitic choice commands - bool _nonDeterm; - TMLCommand* getNextCommand() const; - TMLCommand* prepareNextTransaction(); + RangeFuncPointer _rangeFunc; + virtual TMLCommand* getNextCommand() const; + virtual TMLCommand* prepareNextTransaction(); }; #endif diff --git a/simulators/c++2/src_simulator/app/TMLCommand.cpp b/simulators/c++2/src_simulator/app/TMLCommand.cpp index dc2c49c8909ba70e5aa54a4d0e27dac5eb0016ec..ee8462d2db618e8a1a2be2d0c0b1f23a48741d34 100755 --- a/simulators/c++2/src_simulator/app/TMLCommand.cpp +++ b/simulators/c++2/src_simulator/app/TMLCommand.cpp @@ -45,6 +45,7 @@ Ludovic Apvrille, Renaud Pacalet #include <CommandListener.h> #include <Parameter.h> #include <TMLChoiceCommand.h> +#include <TMLRandomChoiceCommand.h> #include <TMLActionCommand.h> #include <TMLNotifiedCommand.h> #include <TMLWaitCommand.h> @@ -75,11 +76,13 @@ TMLCommand* TMLCommand::prepare(bool iInit){ if(_length==_progress){ TMLCommand* aNextCommand; #ifdef STATE_HASH_ENABLED - _task->refreshStateHash(_liveVarList); - if(_checkpoint){ - ID aStateID=0; - aStateID = _simComp->checkForRecurringSystemState(); - if (_currTransaction!=0) _currTransaction->setStateID(aStateID); + if(!_simComp->getOnKnownPath()){ + _task->refreshStateHash(_liveVarList); + if(_checkpoint){ + ID aStateID=0; + aStateID = _simComp->checkForRecurringSystemState(); + if (_currTransaction!=0) _currTransaction->setStateID(aStateID); + } } #endif //std::cout << "COMMAND FINISHED!!n"; @@ -101,7 +104,7 @@ TMLCommand* TMLCommand::prepare(bool iInit){ return aNextCommand->prepare(false); } }else{ - if (_commandStartTime==-1) _commandStartTime = SchedulableDevice::getSimulatedTime(); + if (_commandStartTime==((TMLTime)-1)) _commandStartTime = SchedulableDevice::getSimulatedTime(); //std::cout << "Prepare next transaction TMLCmd " << _listeners.size() << std::endl; TMLCommand* result; if (iInit){ @@ -224,6 +227,9 @@ std::istream& TMLCommand::readObject(std::istream& s){ READ_STREAM(s,_progress); #ifdef DEBUG_SERIALIZE std::cout << "Read: TMLCommand " << _ID << " progress: " << _progress << std::endl; +#endif +#ifdef STATE_HASH_ENABLED + if (_liveVarList!=0) _task->refreshStateHash(_liveVarList); #endif //std::cout << "End Read Object TMLCommand " << _ID << std::endl; return s; @@ -278,13 +284,14 @@ unsigned long TMLCommand::getStateHash() const{ } TMLTime TMLCommand::getCommandStartTime() const{ - return (_commandStartTime==-1)? 0: _commandStartTime; + return (_commandStartTime==((TMLTime)-1))? 0: _commandStartTime; } TMLLength TMLCommand::getLength() const{ return _length; } +template void TMLCommand::registerGlobalListenerForType<IndeterminismSource>(CommandListener* iListener, TMLTask* aTask); template void TMLCommand::registerGlobalListenerForType<TMLChoiceCommand>(CommandListener* iListener, TMLTask* aTask); template void TMLCommand::registerGlobalListenerForType<TMLActionCommand>(CommandListener* iListener, TMLTask* aTask); template void TMLCommand::registerGlobalListenerForType<TMLNotifiedCommand>(CommandListener* iListener, TMLTask* aTask); diff --git a/simulators/c++2/src_simulator/app/TMLEventBChannel.cpp b/simulators/c++2/src_simulator/app/TMLEventBChannel.cpp index a88a530cfc3093def46749ac6f431ef955c3a9c5..5dc33ad40da4c151e4c4e6a8db980107a4249c7e 100644 --- a/simulators/c++2/src_simulator/app/TMLEventBChannel.cpp +++ b/simulators/c++2/src_simulator/app/TMLEventBChannel.cpp @@ -101,7 +101,7 @@ void TMLEventBChannel::write(){ void TMLEventBChannel::write(TMLTransaction* iTrans){ _content++; - _paramQueue.push_back(_tmpParam); //NEW + if (_paramNo!=0) _paramQueue.push_back(_tmpParam); //NEW #ifdef STATE_HASH_ENABLED //_stateHash+=_tmpParam.getStateHash(); _tmpParam->getStateHash(&_stateHash); @@ -126,13 +126,16 @@ bool TMLEventBChannel::read(){ //std::cout << "read next" << std::endl; //if (_readTrans->getCommand()->getParamFuncPointer()!=0) (_readTask->*(_readTrans->getCommand()->getParamFuncPointer()))(_paramQueue.front()); //NEW //std::cout << "read!!!!!!!!!!!!!\n"; - _readTrans->getCommand()->setParams(_paramQueue.front()); + if (_paramNo!=0){ + _readTrans->getCommand()->setParams(_paramQueue.front()); + _paramQueue.pop_front(); //NEW + } #ifdef STATE_HASH_ENABLED //_stateHash-=_paramQueue.front().getStateHash(); //_paramQueue.front().removeStateHash(&_stateHash); _hashValid = false; #endif - _paramQueue.pop_front(); //NEW + #ifdef LISTENERS_ENABLED NOTIFY_READ_TRANS_EXECUTED(_readTrans); #endif diff --git a/simulators/c++2/src_simulator/app/TMLEventChannel.cpp b/simulators/c++2/src_simulator/app/TMLEventChannel.cpp index ac8dd918da66b8ad05bcdc80df2272da5113689d..a87d24f726f347aaa1b25eba3d6b1ec653b2a2e0 100644 --- a/simulators/c++2/src_simulator/app/TMLEventChannel.cpp +++ b/simulators/c++2/src_simulator/app/TMLEventChannel.cpp @@ -60,8 +60,10 @@ std::ostream& TMLEventChannel::writeObject(std::ostream& s){ ParamQueue::iterator i; //std::cout << "write size of channel " << _name << " :" << _content << std::endl; TMLStateChannel::writeObject(s); - for(i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ - (*i)->writeObject(s); + if (_paramNo!=0){ + for(i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ + (*i)->writeObject(s); + } } //for_each( _paramQueue.begin(), _paramQueue.end(), std::bind2nd(std::bind1st(std::mem_fun(&(Parameter<ParamType>::writeObject)),s),(unsigned int)_writeTask)); return s; @@ -74,10 +76,12 @@ std::istream& TMLEventChannel::readObject(std::istream& s){ TMLStateChannel::readObject(s); //std::cout << "Read Object TMLEventChannel " << _name << std::endl; //_paramQueue.clear(); - for(aParamNo=0; aParamNo < _content; aParamNo++){ - //aNewParam = new Parameter<ParamType>(s, (unsigned int) _writeTask); - //_paramQueue.push_back(Parameter<ParamType>(s)); - _paramQueue.push_back(new Parameter<ParamType>(_paramNo, s)); + if (_paramNo!=0){ + for(aParamNo=0; aParamNo < _content; aParamNo++){ + //aNewParam = new Parameter<ParamType>(s, (unsigned int) _writeTask); + //_paramQueue.push_back(Parameter<ParamType>(s)); + _paramQueue.push_back(new Parameter<ParamType>(_paramNo, s)); + } } _hashValid = false; return s; @@ -112,14 +116,16 @@ void TMLEventChannel::getStateHash(HashAlgo* iHash) const{ //TMLStateChannel::getStateHash(iHash); //iHash->addValue(_stateHash.getHash()); if (_significance!=0){ - if (!_hashValid){ - _stateHash.init((HashValueType)this, 30); - for(ParamQueue::const_iterator i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ - (*i)->getStateHash(&_stateHash); + if (_paramNo!=0){ + if (!_hashValid){ + _stateHash.init((HashValueType)this, 30); + for(ParamQueue::const_iterator i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ + (*i)->getStateHash(&_stateHash); + } + _hashValid = true; } - _hashValid = true; + iHash->addValue(_stateHash.getHash()); } - iHash->addValue(_stateHash.getHash()); iHash->addValue(_content); } } diff --git a/simulators/c++2/src_simulator/app/TMLEventFBChannel.cpp b/simulators/c++2/src_simulator/app/TMLEventFBChannel.cpp index efde2647105273f9cad182f593803cd265cc260c..73043c3dea12c9f73ae65f7e92c7a0af29b7a2ee 100644 --- a/simulators/c++2/src_simulator/app/TMLEventFBChannel.cpp +++ b/simulators/c++2/src_simulator/app/TMLEventFBChannel.cpp @@ -63,7 +63,7 @@ void TMLEventFBChannel::testRead(TMLTransaction* iTrans){ void TMLEventFBChannel::write(){ _content++; //_paramQueue.push_back(_writeTrans->getCommand()->getParam()); - _paramQueue.push_back(_tmpParam); //NEW + if (_paramNo!=0) _paramQueue.push_back(_tmpParam); //NEW #ifdef STATE_HASH_ENABLED //_stateHash+=_tmpParam.getStateHash(); _tmpParam->getStateHash(&_stateHash); @@ -86,13 +86,16 @@ bool TMLEventFBChannel::read(){ }else{ _content--; //if (_readTrans->getCommand()->getParamFuncPointer()!=0) (_readTask->*(_readTrans->getCommand()->getParamFuncPointer()))(_paramQueue.front()); //NEW - _readTrans->getCommand()->setParams(_paramQueue.front()); + if (_paramNo!=0){ + _readTrans->getCommand()->setParams(_paramQueue.front()); + _paramQueue.pop_front(); //NEW + } #ifdef STATE_HASH_ENABLED //_stateHash-=_paramQueue.front().getStateHash(); //_paramQueue.front().removeStateHash(&_stateHash); _hashValid = false; #endif - _paramQueue.pop_front(); //NEW + if (_writeTrans!=0 && _writeTrans->getVirtualLength()==0){ _writeTrans->setRunnableTime(_readTrans->getEndTime()); _writeTrans->setChannel(this); diff --git a/simulators/c++2/src_simulator/app/TMLEventFChannel.cpp b/simulators/c++2/src_simulator/app/TMLEventFChannel.cpp index 2973ea2c0467bab0cebf17d68b83517c1539b10d..e13014feadfbd2d57020cb7f3791f0f70e3d243e 100644 --- a/simulators/c++2/src_simulator/app/TMLEventFChannel.cpp +++ b/simulators/c++2/src_simulator/app/TMLEventFChannel.cpp @@ -64,7 +64,7 @@ void TMLEventFChannel::write(){ if (_content<_length){ _content++; //_paramQueue.push_back(_writeTrans->getCommand()->getParam()); - _paramQueue.push_back(_tmpParam); //NEW + if (_paramNo!=0) _paramQueue.push_back(_tmpParam); //NEW #ifdef STATE_HASH_ENABLED //_stateHash+=_tmpParam.getStateHash(); _tmpParam->getStateHash(&_stateHash); @@ -88,13 +88,15 @@ bool TMLEventFChannel::read(){ }else{ _content--; //if (_readTrans->getCommand()->getParamFuncPointer()!=0) (_readTask->*(_readTrans->getCommand()->getParamFuncPointer()))(_paramQueue.front()); //NEW - _readTrans->getCommand()->setParams(_paramQueue.front()); + if (_paramNo!=0){ + _readTrans->getCommand()->setParams(_paramQueue.front()); + _paramQueue.pop_front(); //NEW + } #ifdef STATE_HASH_ENABLED //_stateHash-=_paramQueue.front().getStateHash(); //_paramQueue.front().removeStateHash(&_stateHash); _hashValid = false; #endif - _paramQueue.pop_front(); //NEW #ifdef LISTENERS_ENABLED NOTIFY_READ_TRANS_EXECUTED(_readTrans); #endif diff --git a/simulators/c++2/src_simulator/app/TMLExeciCommand.cpp b/simulators/c++2/src_simulator/app/TMLExeciCommand.cpp index 0602a6679f9e84d23979bbd66ff41a8861d09aed..00aa585b6335d96e39687e75d75ec38a3f6b77fc 100755 --- a/simulators/c++2/src_simulator/app/TMLExeciCommand.cpp +++ b/simulators/c++2/src_simulator/app/TMLExeciCommand.cpp @@ -48,21 +48,15 @@ TMLExeciCommand::TMLExeciCommand(ID iID, TMLTask* iTask, LengthFuncPointer iLeng } void TMLExeciCommand::execute(){ - //std::cout << _currTransaction->toShortString() << std::endl; + std::cout << "execi: " << _currTransaction->toShortString() << std::endl; _progress+=_currTransaction->getVirtualLength(); - //std::cout << "Execi execute set end" << std::endl; - //_task->setEndLastTransaction(_currTransaction->getEndTime()); _task->addTransaction(_currTransaction); //std::cout << "Execi execute prepare" << std::endl; prepare(false); - //if (aNextCommand==0) _currTransaction->setTerminatedFlag(); - //if (_progress==0 && aNextCommand!=this) _currTransaction=0; } TMLCommand* TMLExeciCommand::prepareNextTransaction(){ - //std::cout << "ExeciCommand prepare " << toString() << std::endl; - //if (_progress==0) _length = (_task->*_lengthFunc)(); - //new test code + //std::cout << _ID << " prepare execi: " << _length << std::endl; if (_progress==0){ if (_lengthFunc!=0) _length = (_task->*_lengthFunc)(); if (_length==0){ @@ -78,10 +72,6 @@ TMLCommand* TMLExeciCommand::prepareNextTransaction(){ return this; } -/*TMLTask* TMLExeciCommand::getDependentTask() const{ - return 0; -}*/ - std::string TMLExeciCommand::toString() const{ std::ostringstream outp; outp << "Execi in " << TMLCommand::toString(); diff --git a/simulators/c++2/src_simulator/app/TMLExeciRangeCommand.cpp b/simulators/c++2/src_simulator/app/TMLExeciRangeCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d7b3cb132bde170868d3a4aaeb1c2c4da09a36e4 --- /dev/null +++ b/simulators/c++2/src_simulator/app/TMLExeciRangeCommand.cpp @@ -0,0 +1,101 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +#include <TMLExeciRangeCommand.h> +#include <TMLTask.h> +#include <TMLTransaction.h> + + +TMLExeciRangeCommand::TMLExeciRangeCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, unsigned int iType, const char* iLiveVarList, bool iCheckpoint): TMLCommand(iID, iTask, 1, 1, iLiveVarList, iCheckpoint), _rangeFunc(iRangeFunc), _minRange(0), _type(iType){ +} + +void TMLExeciRangeCommand::execute(){ + _progress+=_currTransaction->getVirtualLength(); + _task->addTransaction(_currTransaction); + prepare(false); +} + +TMLCommand* TMLExeciRangeCommand::prepareNextTransaction(){ + //std::cout << "Prepare\n"; + if (_progress==0){ + ParamType aMax; + _length = (_task->*_rangeFunc)(_minRange, aMax); + //_length = myrand(aMin, aMax); + if (_length==0){ + TMLCommand* aNextCommand=getNextCommand(); + _task->setCurrCommand(aNextCommand); + if (aNextCommand!=0) return aNextCommand->prepare(false); + } + } + _currTransaction=new TMLTransaction(this, _length-_progress,_task->getEndLastTransaction()); + //std::cout << "new fails? " << _currTransaction->toString() << std::endl; + return this; +} + +std::string TMLExeciRangeCommand::toString() const{ + std::ostringstream outp; + outp << "Execi in " << TMLCommand::toString(); + return outp.str(); +} + +std::string TMLExeciRangeCommand::toShortString() const{ + std::ostringstream outp; + outp << _task->toString() << ": Execi " << _length; + return outp.str(); +} + +std::string TMLExeciRangeCommand::getCommandStr() const{ + return "exe"; +} + +unsigned int TMLExeciRangeCommand::getRandomRange(){ + ParamType aMax, aMin; + (_task->*_rangeFunc)(aMin, aMax); + //std::cout << "Got amin: " << aMin << " got amax: " << aMax << "\n"; + return aMax-aMin+1; +} + +void TMLExeciRangeCommand::setRandomValue(unsigned int iValue){ + //std::cout << "Set random value\n"; + //ParamType aMax, aMin; + //(_task->*_rangeFunc)(aMin, aMax); + _length= _minRange + iValue; + _currTransaction=new TMLTransaction(this, _length,_task->getEndLastTransaction()); +} diff --git a/simulators/c++2/src_simulator/app/TMLExeciRangeCommand.h b/simulators/c++2/src_simulator/app/TMLExeciRangeCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..9c8578a798a900d318122f88452edd231fc9e7bc --- /dev/null +++ b/simulators/c++2/src_simulator/app/TMLExeciRangeCommand.h @@ -0,0 +1,77 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +#ifndef TMLExeciRangeCommandH +#define TMLExeciRangeCommandH + +#include <definitions.h> +#include <TMLCommand.h> +#include <IndeterminismSource.h> + +///This class models the computational complexity of an algorithm +class TMLExeciRangeCommand:public TMLCommand, public IndeterminismSource{ +public: + ///Constructor + /** + \param iID ID of the command + \param iTask Pointer to the task the command belongs to + \param iRangeFunc Pointer to the function returning the length range of the command + \param iType Exec Type (ExecI, ExecC,...) + \param iLiveVarList Bitmap of live variables + \param iCheckpoint Checkpoint Flag + */ + TMLExeciRangeCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, unsigned int iType, const char* iLiveVarList, bool iCheckpoint); + void execute(); + //TMLTask* getDependentTask() const; + std::string toString() const; + std::string toShortString() const; + std::string getCommandStr() const; + unsigned int getRandomRange(); + void setRandomValue(unsigned int iValue); +protected: + TMLCommand* prepareNextTransaction(); + ///Pointer to the function returning the length of the command + RangeFuncPointer _rangeFunc; + ParamType _minRange; + ///Type of command: EXECI, EXECC + unsigned int _type; +}; + +#endif diff --git a/simulators/c++2/src_simulator/app/TMLRandomChoiceCommand.cpp b/simulators/c++2/src_simulator/app/TMLRandomChoiceCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e064da16b6119a1be16200c49c6c9a7bf8cc5745 --- /dev/null +++ b/simulators/c++2/src_simulator/app/TMLRandomChoiceCommand.cpp @@ -0,0 +1,84 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +#include <TMLRandomChoiceCommand.h> +#include <SimComponents.h> +#include <CommandListener.h> +#include <TMLTask.h> + +TMLRandomChoiceCommand::TMLRandomChoiceCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, unsigned int iNbOfBranches):TMLChoiceCommand(iID, iTask, iRangeFunc, iNbOfBranches), _dynamicRange(0){ +} + +TMLCommand* TMLRandomChoiceCommand::prepareNextTransaction(){ + ParamType aMin, aMax; + _randomValue = (_task->*_rangeFunc)(aMin, aMax); + //std::cout << "Random value set:" << _randomValue << "\n"; + + if (aMin==-1) + _dynamicRange = aMax | INT_MSB; + else + _dynamicRange = aMax+1; + if (_simComp->getStopFlag()){ + _simComp->setStoppedOnAction(); + _task->setCurrCommand(this); + return this; //for command which generates transactions this is returned anyway by prepareTransaction + } + + TMLCommand* aNextCommand=getNextCommand(); + //std::cout << "set next:" << aNextCommand << "\n"; + _task->setCurrCommand(aNextCommand); +#ifdef LISTENERS_ENABLED + NOTIFY_CMD_FINISHED(this); +#endif + //std::cout << "TMLRandomChoiceCommand prepare Next Cmd:\n"; + if (aNextCommand!=0) return aNextCommand->prepare(false); + //else + //std::cout << "no next\n"; + return 0; +} + +unsigned int TMLRandomChoiceCommand::getRandomRange(){ + return _dynamicRange; +} + +TMLCommand* TMLRandomChoiceCommand::getNextCommand() const{ + //std::cout << "Here we go " << _randomValue << " .................\n"; + return _nextCommand[_randomValue]; +} diff --git a/simulators/c++2/src_simulator/app/TMLRandomChoiceCommand.h b/simulators/c++2/src_simulator/app/TMLRandomChoiceCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..a5d8863d326d4029dbd0dd1b905d42eeef8dbe8b --- /dev/null +++ b/simulators/c++2/src_simulator/app/TMLRandomChoiceCommand.h @@ -0,0 +1,57 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +#ifndef TMLRandomChoiceCommandH +#define TMLRandomChoiceCommandH + +#include <TMLChoiceCommand.h> +#include <IndeterminismSource.h> + +class TMLRandomChoiceCommand: public TMLChoiceCommand, public IndeterminismSource{ +public: + TMLRandomChoiceCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, unsigned int iNbOfBranches); + TMLCommand* prepareNextTransaction(); + unsigned int getRandomRange(); +protected: + unsigned int _dynamicRange; + TMLCommand* getNextCommand() const; +}; + +#endif \ No newline at end of file diff --git a/simulators/c++2/src_simulator/app/TMLRandomCommand.cpp b/simulators/c++2/src_simulator/app/TMLRandomCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01e10153a3c54f07a22b1c285b7c2ee58fca8c7e --- /dev/null +++ b/simulators/c++2/src_simulator/app/TMLRandomCommand.cpp @@ -0,0 +1,96 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ +#include <TMLRandomCommand.h> +#include <SimComponents.h> +#include <CommandListener.h> +#include <TMLTask.h> + +TMLRandomCommand::TMLRandomCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, ParamType* iResultVar): TMLCommand(iID, iTask, 1, 1, 0, false), _rangeFunc(iRangeFunc), _resultVar(iResultVar), _aMin(0){ +} + +void TMLRandomCommand::execute(){ +} + +unsigned int TMLRandomCommand::getRandomRange(){ + ParamType aMax; + (_task->*_rangeFunc)(_aMin, aMax); + std::cout << "Got amin: " << _aMin << " got amax: " << aMax << "\n"; + return aMax-_aMin+1; +} + +TMLCommand* TMLRandomCommand::prepareNextTransaction(){ + //std::cout << "In TMLChoice::prepare next transaction\n"; + if (_simComp->getStopFlag()){ + //std::cout << "aSimStopped=true " << std::endl; + _simComp->setStoppedOnAction(); + _task->setCurrCommand(this); + return this; //for command which generates transactions this is returned anyway by prepareTransaction + } + TMLCommand* aNextCommand=getNextCommand(); + if (_randomValue==(unsigned int)-1){ + ParamType aMin, aMax; + (_task->*_rangeFunc)(aMin, aMax); + *_resultVar = myrand(aMin, aMax); + }else{ + *_resultVar = _aMin + _randomValue; + _randomValue=(unsigned int)-1; + } + _task->setCurrCommand(aNextCommand); +#ifdef LISTENERS_ENABLED + NOTIFY_CMD_FINISHED(this); +#endif + //std::cout << "after notify listeners" << std::endl; + if (aNextCommand!=0) return aNextCommand->prepare(false); + return 0; +} + +std::string TMLRandomCommand::TMLRandomCommand::toString() const{ + std::ostringstream outp; + outp << "Random in " << TMLCommand::toString(); + return outp.str(); +} + +std::string TMLRandomCommand::toShortString() const{ + return "Random"; +} + +std::string TMLRandomCommand::getCommandStr() const{ + return "rnd"; +} diff --git a/simulators/c++2/src_simulator/app/TMLRandomCommand.h b/simulators/c++2/src_simulator/app/TMLRandomCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..322cbaafad6cb2878c9cabcf2d288f736445080d --- /dev/null +++ b/simulators/c++2/src_simulator/app/TMLRandomCommand.h @@ -0,0 +1,63 @@ +/*Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Daniel Knorreck, +Ludovic Apvrille, Renaud Pacalet + * + * ludovic.apvrille AT telecom-paristech.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + */ + +#ifndef TMLRandomCommandH +#define TMLRandomCommandH + +#include <IndeterminismSource.h> +#include <TMLCommand.h> + +class TMLRandomCommand: public TMLCommand, public IndeterminismSource{ +public: + TMLRandomCommand(ID iID, TMLTask* iTask, RangeFuncPointer iRangeFunc, ParamType* iResultVar); + + void execute(); + unsigned int getRandomRange(); + TMLCommand* prepareNextTransaction(); + std::string toString() const; + std::string toShortString() const; + std::string getCommandStr() const; +protected: + RangeFuncPointer _rangeFunc; + ParamType* _resultVar; + ParamType _aMin; +}; + +#endif diff --git a/simulators/c++2/src_simulator/app/TMLSelectCommand.cpp b/simulators/c++2/src_simulator/app/TMLSelectCommand.cpp index ab8741fd7c1cb9a5432e38b39e8b08ba5bcde29d..d56a5a94212e5d1f3597d2005bbb8adc7402dcef 100644 --- a/simulators/c++2/src_simulator/app/TMLSelectCommand.cpp +++ b/simulators/c++2/src_simulator/app/TMLSelectCommand.cpp @@ -44,7 +44,7 @@ Ludovic Apvrille, Renaud Pacalet #include <TMLTransaction.h> #include <Bus.h> -TMLSelectCommand::TMLSelectCommand(ID iID, TMLTask* iTask, TMLEventChannel** iChannel, unsigned int iNumbChannels, const char* iLiveVarList, bool iCheckpoint, ParamFuncPointer* iParamFuncs):TMLCommand(iID, iTask, WAIT_SEND_VLEN, iNumbChannels, iLiveVarList, iCheckpoint), _channel(iChannel), _paramFuncs(iParamFuncs), /*_numbChannels(iNumbChannels),*/ _indexNextCommand(0), _maxChannelIndex(0) { +TMLSelectCommand::TMLSelectCommand(ID iID, TMLTask* iTask, TMLEventChannel** iChannel, unsigned int iNumbChannels, const char* iLiveVarList, bool iCheckpoint, ParamFuncPointer* iParamFuncs):TMLCommand(iID, iTask, WAIT_SEND_VLEN, iNumbChannels, iLiveVarList, iCheckpoint), _channel(iChannel), _paramFuncs(iParamFuncs), /*_numbChannels(iNumbChannels),*/ _indexNextCommand(0) { } TMLSelectCommand::~TMLSelectCommand(){ @@ -195,3 +195,7 @@ Parameter<ParamType>* TMLSelectCommand::setParams(Parameter<ParamType>* ioParam) delete ioParam; return aResult; } + +//unsigned int TMLSelectCommand::getRandomRange(){ +// return _nbOfPossSync ; +//} diff --git a/simulators/c++2/src_simulator/app/TMLStateChannel.cpp b/simulators/c++2/src_simulator/app/TMLStateChannel.cpp index e45395c91483e4d578ac7f9265e5e8225772fd74..d44b47d9ba8a318919ab0a981948d0735f7d39b4 100644 --- a/simulators/c++2/src_simulator/app/TMLStateChannel.cpp +++ b/simulators/c++2/src_simulator/app/TMLStateChannel.cpp @@ -93,7 +93,7 @@ bool TMLStateChannel::getUnderflow() const{ void TMLStateChannel::getStateHash(HashAlgo* iHash) const{ if (_significance!=0){ - std::cout << "add channel content:\n"; + //std::cout << "add channel content:\n"; iHash->addValue(_content); } } diff --git a/simulators/c++2/src_simulator/app/TMLTask.cpp b/simulators/c++2/src_simulator/app/TMLTask.cpp index 9ecc24687883a39716b952bf9471516baebe4667..e16d71d7ce011e8047a4bbbba893764196b1bf27 100755 --- a/simulators/c++2/src_simulator/app/TMLTask.cpp +++ b/simulators/c++2/src_simulator/app/TMLTask.cpp @@ -416,7 +416,7 @@ void TMLTask::resetScheduledFlag(){ //_isScheduled=false; //std::cout << _name << " CAN be scheduled by CPUs\n"; //if (_noOfCPUs>1) _currentCPU=0; - std::cout << " ---------- RESET scheduled flag end in task " << _name << "\n"; + //std::cout << " ---------- RESET scheduled flag end in task " << _name << "\n"; RESET_SCHEDULING; } @@ -426,7 +426,7 @@ void TMLTask::setRescheduleFlagForCores(){ //_currentCPU=0; RESET_SCHEDULING; for (unsigned int i=0; i< _noOfCPUs; i++){ - std::cout << "in Task " << _name << " next CPU\n"; + //std::cout << "in Task " << _name << " next CPU\n"; _cpus[i]->setRescheduleFlag(); } } diff --git a/simulators/c++2/src_simulator/arch/CPU.h b/simulators/c++2/src_simulator/arch/CPU.h index 2167df41b0ed3a49506e12962f6d957246ebb887..7ab03627d0bad3cb0c522172867317c78456c02e 100755 --- a/simulators/c++2/src_simulator/arch/CPU.h +++ b/simulators/c++2/src_simulator/arch/CPU.h @@ -88,7 +88,7 @@ public: \param iTime Indicates at what time the transaction should be truncated \return Returns true if scheduling of device has been performed */ - virtual bool truncateAndAddNextTransAt(TMLTime iTime)=0; + virtual void truncateAndAddNextTransAt(TMLTime iTime)=0; //virtual TMLTime truncateNextTransAt(TMLTime iTime)=0; ///Adds a new bus master to the internal list /** @@ -114,7 +114,7 @@ public: ///Invalidate schedule of CPU void setRescheduleFlag(){ _schedulingNeeded=true; - std::cout <<" CPU " << _name << " forwards to scheduler\n"; + //std::cout <<" CPU " << _name << " forwards to scheduler\n"; _scheduler->resetScheduledFlag(); } diff --git a/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp b/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp index 3079f9eb6951a0ad8e9cde50a3da890298ff35a6..bc341a830c5ab7841473fdb261a30c93881eccf9 100644 --- a/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp +++ b/simulators/c++2/src_simulator/arch/SingleCoreCPU.cpp @@ -156,7 +156,7 @@ void SingleCoreCPU::calcStartTimeLength(TMLTime iTimeSlice){ #endif } -bool SingleCoreCPU::truncateAndAddNextTransAt(TMLTime iTime){ +void SingleCoreCPU::truncateAndAddNextTransAt(TMLTime iTime){ //std::cout << "CPU:schedule BEGIN " << _name << "+++++++++++++++++++++++++++++++++\n"; //return truncateNextTransAt(iTime); //not a problem if scheduling does not take place at time when transaction is actually truncated, tested diff --git a/simulators/c++2/src_simulator/arch/SingleCoreCPU.h b/simulators/c++2/src_simulator/arch/SingleCoreCPU.h index eb93d24c8d36f961c980f29a329a214c7fef2eef..eb979026da608eded5f00cb0f2fd228242919f2d 100644 --- a/simulators/c++2/src_simulator/arch/SingleCoreCPU.h +++ b/simulators/c++2/src_simulator/arch/SingleCoreCPU.h @@ -94,7 +94,7 @@ public: \return Pointer to transaction */ TMLTransaction* getNextTransaction(); - bool truncateAndAddNextTransAt(TMLTime iTime); + void truncateAndAddNextTransAt(TMLTime iTime); ///Returns a string representation of the CPU /** \return Detailed string representation diff --git a/simulators/c++2/src_simulator/definitions.cpp b/simulators/c++2/src_simulator/definitions.cpp index 37da48e896b5fa60170cfa3d029b9e1b148309e8..a13c00fca68d3a94104dee62d7a20ec5e40154d1 100644 --- a/simulators/c++2/src_simulator/definitions.cpp +++ b/simulators/c++2/src_simulator/definitions.cpp @@ -111,3 +111,12 @@ int getexename(char* buf, size_t size){ buf[ret] = 0; return ret; } + +unsigned int getEnabledBranchNo(int iNo, int iMask){ + unsigned int retIndex=0; + while (iMask!=0 && iNo!=0){ + if ((iMask & 1)!=0) iNo--; + iMask >>= 1; retIndex++; + } + return retIndex-1; +} diff --git a/simulators/c++2/src_simulator/definitions.h b/simulators/c++2/src_simulator/definitions.h index 948c56fa0b1b7e6ef32d5bd7fcfb038618494a3e..285f79955e418ae9f1b597e6375714eb7ffff293 100644 --- a/simulators/c++2/src_simulator/definitions.h +++ b/simulators/c++2/src_simulator/definitions.h @@ -83,6 +83,7 @@ using std::max; #undef PENALTIES_ENABLED #define STATE_HASH_ENABLED #define LISTENERS_ENABLED +#undef EBRDD_ENABLED #define CLOCK_INC 20 #define BLOCK_SIZE 500000 @@ -101,6 +102,8 @@ using std::max; #define RUNNABLE 1 #define SUSPENDED 0 +#define INT_MSB (1 << (sizeof(unsigned int)*8-1)) + //XML Tags #define TAG_HEADER "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" #define TAG_STARTo "<siminfo>" @@ -162,12 +165,6 @@ using std::max; #define TAG_CONTENTc "</content>" #define TAG_PARAMo "<param>" #define TAG_PARAMc "</param>" -//#define TAG_E1o "<e1>" -//#define TAG_E1c "</e1>" -//#define TAG_E2o "<e2>" -//#define TAG_E2c "</e2>" -//#define TAG_E3o "<e3>" -//#define TAG_E3c "</e3>" #define TAG_Pxo "<e" #define TAG_Pxc "</e" @@ -225,14 +222,12 @@ typedef std::list<Serializable*> SerializableList; typedef std::list<Slave*> SlaveList; ///Datatype used in SimComponents to store channel objects typedef std::list<TMLChannel*> ChannelList; -///Datatype used in SimComponents to store EBRDD objects -typedef std::list<EBRDD*> EBRDDList; + ///Datatype used in Tasks to store comments concerning the task execution typedef std::vector<Comment*> CommentList; ///Datatype used in Tasks in order to associate a command with an ID typedef std::map<ID, TMLCommand*> CommandHashTab; -///Datatype used in EBRDD Tasks in order to associate a command with an ID -typedef std::map<ID, EBRDDCommand*> CommandHashTabEBRDD; + ///Datatype for event parameters typedef int ParamType; ///Datatype used in EventChannels to store parameters of events @@ -240,11 +235,12 @@ typedef std::deque<Parameter<ParamType>* > ParamQueue; ///Type of member function pointer used to indicate a function encapsulating a condition (for TMLChoiceCommand) typedef unsigned int (TMLTask::*CondFuncPointer) (); ///Type of member function pointer used to indicate a function encapsulating an action (for TMLActionCommand) -typedef unsigned int (TMLTask::*ActionFuncPointer) (); +typedef void (TMLTask::*ActionFuncPointer) (); ///Type of member function pointer used to indicate a function encapsulating a condition (for TMLChoiceCommand) typedef TMLTime (TMLTask::*LengthFuncPointer) (); -///Type of member function pointer used to indicate a function encapsulating a condition (for TMLChoiceCommand) -typedef int (EBRDD::*EBRDDFuncPointer) (); + +typedef unsigned int (TMLTask::*RangeFuncPointer) (ParamType& oMin, ParamType& oMax); + ///Type of member function pointer used to indicate a function encapsulating parameter manipulation (for TMLWaitCommand, TMLSendCommand) typedef Parameter<ParamType>* (TMLTask::*ParamFuncPointer) (Parameter<ParamType>* ioParam); ///Breakpoint condition function pointer (points to condition function in shared library) @@ -262,9 +258,17 @@ typedef std::list<BusMaster*> BusMasterList; ///Type used for hash values of system states typedef uint32_t HashValueType; ///Set used by Commands to store encountered state hash values -//typedef std::set<HashValueType> StateHashSet; typedef std::map<HashValueType,ID> StateHashSet; +#ifdef EBRDD_ENABLED +///Datatype used in SimComponents to store EBRDD objects +typedef std::list<EBRDD*> EBRDDList; +///Type of member function pointer used to indicate a function encapsulating a condition (for TMLChoiceCommand) +typedef int (EBRDD::*EBRDDFuncPointer) (); +///Datatype used in EBRDD Tasks in order to associate a command with an ID +typedef std::map<ID, EBRDDCommand*> CommandHashTabEBRDD; +#endif + struct ltstr{ bool operator()(const char* s1, const char* s2) const{ return strcmp(s1, s2) < 0; @@ -413,4 +417,5 @@ long getTimeDiff(struct timeval& begin, struct timeval& end); void replaceAll(std::string& ioHTML, std::string iSearch, std::string iReplace); std::string vcdValConvert(unsigned int iVal); int getexename(char* buf, size_t size); +unsigned int getEnabledBranchNo(int iNo, int iMask); #endif diff --git a/simulators/c++2/src_simulator/evt/ListenersSimCmd.cpp b/simulators/c++2/src_simulator/evt/ListenersSimCmd.cpp index 280f32fe2e171540e6b5c9c1992346e978318bda..e810b9aa5734a720ec788dec9085fab146e6e553 100644 --- a/simulators/c++2/src_simulator/evt/ListenersSimCmd.cpp +++ b/simulators/c++2/src_simulator/evt/ListenersSimCmd.cpp @@ -42,7 +42,7 @@ Ludovic Apvrille, Renaud Pacalet #include <SimComponents.h> #include <SchedulableDevice.h> #include <TMLCommand.h> -#include <TMLChoiceCommand.h> +#include <TMLRandomChoiceCommand.h> #include <TMLActionCommand.h> #include <TMLNotifiedCommand.h> #include <TMLWaitCommand.h> @@ -199,12 +199,14 @@ CondBreakpoint::~CondBreakpoint(){ //************************************************************************ RunTillNextRandomChoice::RunTillNextRandomChoice(SimComponents* iSimComp):_simComp(iSimComp), _enabled(false){ - TMLCommand::registerGlobalListenerForType<TMLChoiceCommand>(this,0); + //TMLCommand::registerGlobalListenerForType<TMLRandomChoiceCommand>(this,0); + TMLCommand::registerGlobalListenerForType<IndeterminismSource>(this,0); } void RunTillNextRandomChoice::commandEntered(TMLCommand* iComm, ID iID){ - TMLChoiceCommand* aChoice=dynamic_cast<TMLChoiceCommand*>(iComm); - if (_enabled && aChoice!=0 && aChoice->isNonDeterministic()){ + //TMLRandomChoiceCommand* aChoice=dynamic_cast<TMLRandomChoiceCommand*>(iComm); + IndeterminismSource* aChoice=dynamic_cast<IndeterminismSource*>(iComm); + if (_enabled && aChoice!=0 ){ _simComp->setStopFlag(true, MSG_RANDOMCHOICE); //return true; } diff --git a/simulators/c++2/src_simulator/main.h b/simulators/c++2/src_simulator/main.h index 669c8c8ad9f271c9f27a2d28d5b86e41fb6a320f..8327f64ef5c3be8b35d13ab5f8e6efc41d8db869 100644 --- a/simulators/c++2/src_simulator/main.h +++ b/simulators/c++2/src_simulator/main.h @@ -63,8 +63,10 @@ int main(int len, char ** args) { Simulator mySim(&mySync); mySync._simComponents->setSimulator(&mySim); TMLCommand::setSimComponents(mySync._simComponents); +#ifdef EBRDD_ENABLED ERB::setSimComponents(mySync._simComponents); ERC::setSimComponents(mySync._simComponents); +#endif //ESO::setSimComponents(mySync._simComponents); gettimeofday(&end,NULL); std::cout << "The preparation took " << getTimeDiff(begin,end) << "usec.\n"; diff --git a/simulators/c++2/src_simulator/sim/Server.cpp b/simulators/c++2/src_simulator/sim/Server.cpp index 1828dfab6fc5c2f960947b7ff0894965d0859480..611db2f41ae3486175fbffaaa1f939772d181d6a 100644 --- a/simulators/c++2/src_simulator/sim/Server.cpp +++ b/simulators/c++2/src_simulator/sim/Server.cpp @@ -45,7 +45,7 @@ Server::Server():_socketClient(-1){ } int Server::run(){ - int aSocketServer; // listen on aSocketServer, client connection on _socketClient + int aSocketServer=0; // listen on aSocketServer, client connection on _socketClient struct addrinfo aHints; //aHints for getaddrinfo struct addrinfo *aServerInfo; //information about the server, created by getaddrinfo struct sockaddr_storage aClientAddrInfo;// connector's address information diff --git a/simulators/c++2/src_simulator/sim/SimComponents.cpp b/simulators/c++2/src_simulator/sim/SimComponents.cpp index 329001f27219484a920cc4296a92977eca00a726..bdd8f553f3eb13f5d2c3f9496a5507b1e0969657 100644 --- a/simulators/c++2/src_simulator/sim/SimComponents.cpp +++ b/simulators/c++2/src_simulator/sim/SimComponents.cpp @@ -49,11 +49,13 @@ Ludovic Apvrille, Renaud Pacalet #include <Slave.h> #include <Memory.h> #include <Bridge.h> -#include <TMLChoiceCommand.h> +#include <IndeterminismSource.h> #include <ListenersSimCmd.h> +#ifdef EBRDD_ENABLED #include <EBRDD.h> +#endif -SimComponents::SimComponents(int iHashValue): _simulator(0), _stopFlag(false), _hashValue(iHashValue), _stoppedOnAction(false), _systemHash(), _knownStateReached(0) { +SimComponents::SimComponents(int iHashValue): _simulator(0), _stopFlag(false), _hashValue(iHashValue), _stoppedOnAction(false), _systemHash(), _knownStateReached(0), _onKnownPath(false) { } SimComponents::~SimComponents(){ @@ -63,9 +65,12 @@ SimComponents::~SimComponents(){ for(SlaveList::iterator i=_slList.begin(); i != _slList.end(); ++i){ delete (*i); } +#ifdef EBRDD_ENABLED for(EBRDDList::iterator i=_ebrddList.begin(); i != _ebrddList.end(); ++i){ delete (*i); } +#endif + //_myfile.close(); } void SimComponents::addTask(TMLTask* iTask){ @@ -114,9 +119,11 @@ void SimComponents::addMem(Memory* iMem){ _slList.push_back(dynamic_cast<Slave*>(iMem)); } +#ifdef EBRDD_ENABLED void SimComponents::addEBRDD(EBRDD* iEBRDD){ _ebrddList.push_back(iEBRDD); } +#endif void SimComponents::streamBenchmarks(std::ostream& s) const{ for (TraceableDeviceList::const_iterator i=_vcdList.begin(); i!= _vcdList.end(); ++i){ @@ -131,11 +138,14 @@ std::ostream& SimComponents::writeObject(std::ostream& s){ for(SerializableList::const_iterator i=_serList.begin(); i != _serList.end(); ++i){ (*i)->writeObject(s); } +#ifdef EBRDD_ENABLED for(EBRDDList::const_iterator i=_ebrddList.begin(); i != _ebrddList.end(); ++i){ (*i)->writeObject(s); } +#endif TMLTime aSimulatedTime = SchedulableDevice::getSimulatedTime(); WRITE_STREAM(s, aSimulatedTime); + WRITE_STREAM(s, _onKnownPath); #ifdef DEBUG_SERIALIZE std::cout << "Write: SimComponents simulatedTime: " << aSimulatedTime << std::endl; std::cout << "----------------------------------------------------\n"; @@ -151,12 +161,15 @@ std::istream& SimComponents::readObject(std::istream& s){ //std::cout << "SimComponents --> next Device" << std::endl; (*i)->readObject(s); } +#ifdef EBRDD_ENABLED for(EBRDDList::const_iterator i=_ebrddList.begin(); i != _ebrddList.end(); ++i){ (*i)->readObject(s); } +#endif TMLTime aSimulatedTime; READ_STREAM(s, aSimulatedTime); SchedulableDevice::setSimulatedTime(aSimulatedTime); + READ_STREAM(s, _onKnownPath); #ifdef DEBUG_SERIALIZE std::cout << "Read: SimComponents simulatedTime: " << aSimulatedTime << std::endl; std::cout << "----------------------------------------------------\n"; @@ -175,9 +188,11 @@ void SimComponents::reset(){ #ifdef ADD_COMMENTS Comment::reset(); #endif +#ifdef EBRDD_ENABLED for(EBRDDList::const_iterator i=_ebrddList.begin(); i != _ebrddList.end(); ++i){ (*i)->reset(); } +#endif //std::cout << "----------------------------------------------- RESET\n"; _knownStateReached = false; } @@ -185,6 +200,7 @@ void SimComponents::reset(){ void SimComponents::resetStateHash(){ _systemHashTable.clear(); TMLTransaction::resetID(); + _onKnownPath=false; } SchedulableDevice* SimComponents::getCPUByName(const std::string& iCPU) const{ @@ -262,15 +278,25 @@ TMLChannel* SimComponents::getChannelByID(ID iID) const{ return NULL; } -TMLChoiceCommand* SimComponents::getCurrentChoiceCmd(){ +/*TMLChoiceCommand* SimComponents::getCurrentChoiceCmd(){ TMLChoiceCommand* aResult; for(TaskList::const_iterator i=_taskList.begin(); i != _taskList.end(); ++i){ aResult = dynamic_cast<TMLChoiceCommand*>((*i)->getCurrCommand()); if (aResult!=0) return aResult; } return 0; +}*/ + +IndeterminismSource* SimComponents::getCurrentRandomCmd(){ + IndeterminismSource* aResult; + for(TaskList::const_iterator i=_taskList.begin(); i != _taskList.end(); ++i){ + aResult = dynamic_cast<IndeterminismSource*>((*i)->getCurrCommand()); + if (aResult!=0) return aResult; + } + return 0; } + std::string SimComponents::getCmpNameByID(ID iID){ SchedulableDevice* aSched = getCPUByID(iID); if (aSched!=0) return aSched->toString(); @@ -301,9 +327,11 @@ TraceableDeviceList::const_iterator SimComponents::getVCDIterator(bool iEnd) con return (iEnd)? _vcdList.end():_vcdList.begin(); } +#ifdef EBRDD_ENABLED EBRDDList::const_iterator SimComponents::getEBRDDIterator(bool iEnd) const{ return (iEnd)? _ebrddList.end():_ebrddList.begin(); } +#endif CPUList::const_iterator SimComponents::getCPUIterator(bool iEnd) const{ return (iEnd)? _cpuList.end():_cpuList.begin(); @@ -342,37 +370,42 @@ ID SimComponents::checkForRecurringSystemState(){ _systemHash.addValue((HashValueType)(aCurrCmd->getProgress())); } } + //std::cout << " *** New channel list: ***\n"; for(ChannelList::const_iterator i=_channelList.begin(); i != _channelList.end(); ++i){ //std::cout << "add channel " << (*i)->toString() << "\n"; (*i)->getStateHash(&_systemHash); + /*if ((*i)->getSignificance()) std::cout << (*i)->toShortString() << " has sig. content: " << (*i)->getContent() << "\n"; + else + std::cout << (*i)->toShortString() << " is not significant in 2nd step!!!!!!!!!!!!!!\n";*/ } - //std::cout << "HASH VALUE: " << _systemHash.getHash() << "\n"; - //std::pair<StateHashSet::iterator,bool> aRet = _systemHashTable.insert(_systemHash); - //TMLTransaction* iInfoTrans = new TMLTransaction(0,_systemHash.getHash(),0); - /*for(CPUList::const_iterator i=_cpuList.begin(); i != _cpuList.end(); ++i){ - (*i)->addRawTransaction(iInfoTrans); - }*/ - /*for(TaskList::const_iterator i=_taskList.begin(); i != _taskList.end(); ++i){ - (*i)->addRawTransaction(iInfoTrans); - }*/ - //if (_systemHashTable.insert(_systemHash.getHash()).second){ + //std::cout << "-> Hash Value: " << _systemHash.getHash() << "\n"; + ID aRetVal; std::pair<StateHashSet::const_iterator,bool> aRes = _systemHashTable.insert(std::pair<HashValueType,ID>(_systemHash.getHash(),TMLTransaction::getID())); if (aRes.second){ + aRetVal=TMLTransaction::getID(); TMLTransaction::incID(); - //_knownStateReached = false; + //std::cout << "*** Added as " << aRetVal << "***\n"; + //std::cout << "STATE CREATED "<< TMLTransaction::getID() << " +++++++++++++++++++++++++++++\n"; _knownStateReached = 0; + if (_onKnownPath) std::cout << "YOU SHOULD NOT SEE THIS\n"; }else{ - setStopFlag(true, "Recurring system state"); - //_knownStateReached= true; + _onKnownPath=true; + setStopFlag(true, "Recurring system state"); //to be restablished!!!!!!!!!!!! + //std::cout << "KNOWN STATE REACHED "<< aRes.first->second << " ***************************\n"; _knownStateReached= aRes.first->second; + aRetVal = aRes.first->second; + //std::cout << "*** Merged with " << aRetVal << "***\n"; } - return _knownStateReached; + //return _knownStateReached; + return aRetVal; } -//ID SimComponents::wasKnownStateReached(HashValueType* oSystemHash) const{ ID SimComponents::wasKnownStateReached() const{ - //*oSystemHash = _systemHash.getHash(); - //return _knownStateReached; return _knownStateReached; } +bool SimComponents::getOnKnownPath(){ + _knownStateReached=0; + return _onKnownPath; +} + diff --git a/simulators/c++2/src_simulator/sim/SimComponents.h b/simulators/c++2/src_simulator/sim/SimComponents.h index 932f50bf080e70a3de7ce8f83ef69d1e6c5d84d3..e4e3bc27634939766078fd31ac3f31ec12c14502 100644 --- a/simulators/c++2/src_simulator/sim/SimComponents.h +++ b/simulators/c++2/src_simulator/sim/SimComponents.h @@ -50,8 +50,10 @@ class TMLEventBChannel; class Bridge; class Memory; class Simulator; -class TMLChoiceCommand; +class IndeterminismSource; +#ifdef EBRDD_ENABLED class EBRDD; +#endif ///Class encapsulating architecture and application objects class SimComponents: public Serializable{ @@ -103,11 +105,13 @@ public: \param iMem Pointer to memory */ void addMem(Memory* iMem); +#ifdef EBRDD_ENABLED ///Add an EBRDD /** \param iEBRDD Pointer to EBRDD */ void addEBRDD(EBRDD* iEBRDD); +#endif ///Calls streamBenchmarks of all traceable devices contained in vcdList /** param s Reference to output stream object @@ -217,7 +221,8 @@ public: /** \return Pointer if choice command was found, null otherwise */ - TMLChoiceCommand* getCurrentChoiceCmd(); + //TMLChoiceCommand* getCurrentChoiceCmd(); + IndeterminismSource* getCurrentRandomCmd(); ///Returns a hash value for the current application and architecture /** \return Hash value @@ -229,12 +234,14 @@ public: \return Const iterator for task list */ TaskList::const_iterator getTaskIterator(bool iEnd) const; +#ifdef EBRDD_ENABLED ///Returns an iterator for the internal EBRDD list /** \param iEnd true for iterator pointing to the end of the list, false for iterator pointing to the first element \return Const iterator for EBRDD list */ EBRDDList::const_iterator getEBRDDIterator(bool iEnd) const; +#endif ///Returns the reason why the simulation stopped /** \return Reason why the simulation stopped @@ -266,6 +273,7 @@ public: ID wasKnownStateReached() const; ///Resets the global system hash void resetStateHash(); + bool getOnKnownPath(); protected: ///Pointer to simulator Simulator* _simulator; @@ -283,8 +291,10 @@ protected: TaskList _taskList; ///List holding channels ChannelList _channelList; +#ifdef EBRDD_ENABLED ///List holding EBRDDs EBRDDList _ebrddList; +#endif ///Flag indicating whether the simulation must be stopped bool _stopFlag; ///Hash Value for application and architecture @@ -299,6 +309,9 @@ protected: HashAlgo _systemHash; ///Flag indicating whether a known state has been encountered ID _knownStateReached; + bool _onKnownPath; + + //std::ofstream _myfile; }; #endif diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index d47bde70a916558c04b5cf3ac43e88b65aa4816e..7850cb79719d3b8c60c84d633ef42b57608e8b5a 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -42,9 +42,13 @@ Ludovic Apvrille, Renaud Pacalet #include <Server.h> #include <ServerLocal.h> #include <TMLSelectCommand.h> +#include <IndeterminismSource.h> +#ifdef EBRDD_ENABLED #include <EBRDD.h> #include <EBRDDCommand.h> #include <ERC.h> +#endif + Simulator::Simulator(SimServSyncInfo* iSyncInfo):_syncInfo(iSyncInfo), _simComp(_syncInfo->_simComponents), _busy(false), _simTerm(false), _leafsID(0), _randChoiceBreak(_syncInfo->_simComponents) { } @@ -144,22 +148,22 @@ ID Simulator::schedule2GraphDOT(std::ostream& iFile, ID iStartState) const{ CPU* aCPU; aTopElement = aQueue.top(); aCPU = aTopElement->getCommand()->getTask()->getCPU(); - for (TMLLength a=0; a < aTopElement->getVirtualLength(); a++){ - aEndState = aTopElement->getStateID(); - if (aEndState==0){ - aEndState=TMLTransaction::getID(); - TMLTransaction::incID(); - } - //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; - iFile << aStartState << " -> " << aEndState << " [label = \"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); - if (aTopElement->getChannel()!=0){ - iFile << "__" << aTopElement->getChannel()->toShortString(); - //if (dynamic_cast<TMLEventChannel*>(aTopElement->getChannel())==0) aOutp << "<" << aTopElement->getVirtualLength() << ", " << ">"; - } - iFile << ")\"]\n"; - aStartState = aEndState; - //aOutp << aTempStr.str() << ++aTransitionNo << ")\n"; + //for (TMLLength a=0; a < aTopElement->getVirtualLength(); a++){ + aEndState = aTopElement->getStateID(); + if (aEndState==0){ + aEndState=TMLTransaction::getID(); + TMLTransaction::incID(); } + //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; + iFile << aStartState << " -> " << aEndState << " [label = \"i(" << aCPU->toString() << "__" << aTopElement->getCommand()->getTask()->toString() << "__" << aTopElement->getCommand()->getCommandStr(); + if (aTopElement->getChannel()!=0){ + iFile << "__" << aTopElement->getChannel()->toShortString(); + //if (dynamic_cast<TMLEventChannel*>(aTopElement->getChannel())==0) aOutp << "<" << aTopElement->getVirtualLength() << ", " << ">"; + } + iFile << "<" << aTopElement->getVirtualLength() << ">)\"]\n"; + aStartState = aEndState; + //aOutp << aTempStr.str() << ++aTransitionNo << ")\n"; + //} //myfile << aTempStr.str(); aQueue.pop(); aTrans = aCPU->getTransactions1By1(false); @@ -350,9 +354,11 @@ bool Simulator::simulate(TMLTransaction*& oLastTrans){ //std::cout << "loop it end" << (*i)->toString() << std::endl; } //std::cout << "after loop1" << std::endl; +#ifdef EBRDD_ENABLED for(EBRDDList::const_iterator i=_simComp->getEBRDDIterator(false); i!=_simComp->getEBRDDIterator(true);i++){ if ((*i)->getCurrCommand()!=0) (*i)->getCurrCommand()->prepare(); } +#endif //std::cout << "after loop2" << std::endl; for_each(_simComp->getCPUIterator(false), _simComp->getCPUIterator(true),std::mem_fun(&CPU::setRescheduleFlag)); for_each(_simComp->getCPUIterator(false), _simComp->getCPUIterator(true),std::mem_fun(&CPU::schedule)); @@ -631,11 +637,13 @@ void Simulator::decodeCommand(std::string iCmd){ std::cout << "Explore tree." << std::endl; _leafsID=0; std::ofstream myfile ("tree.dot"); - if (myfile.is_open()){ + //std::ofstream myfile2 ("tree.txt"); + if (myfile.is_open() /*&& myfile2.is_open()*/){ myfile << "digraph BCG {\nsize = \"7, 10.5\";\ncenter = TRUE;\nnode [shape = circle];\n0 [peripheries = 2];\n"; - exploreTree(0, 0, myfile); + exploreTree(0, 0, myfile /*, myfile2*/); myfile << "}\n"; myfile.close(); + //myfile2.close(); } aGlobMsg << TAG_MSGo << "Tree was explored" << TAG_MSGc << std::endl; _simTerm=true; @@ -726,8 +734,8 @@ void Simulator::decodeCommand(std::string iCmd){ break; } case 13:{//Run to next random choice command - std::cout << "Run to next random choice command." << std::endl; - _simTerm=runToNextChoiceCommand(oLastTrans); + std::cout << "Run to next random command." << std::endl; + _simTerm=runToNextRandomCommand(oLastTrans); std::cout << "End Run to next random choice command." << std::endl; break; } @@ -1023,10 +1031,12 @@ void Simulator::decodeCommand(std::string iCmd){ anErrorCode=2; }else{ aInpStream >> aParam1; - TMLChoiceCommand* aChoiceCmd=dynamic_cast<TMLChoiceCommand*>(aTask->getCommandByID(aParam1)); - if (aChoiceCmd!=0){ + //TMLChoiceCommand* aChoiceCmd=dynamic_cast<TMLChoiceCommand*>(aTask->getCommandByID(aParam1)); + IndeterminismSource* aRandomCmd=dynamic_cast<IndeterminismSource*>(aTask->getCommandByID(aParam1)); + if (aRandomCmd!=0){ aInpStream >> aParam2; - aChoiceCmd->setPreferredBranch(aParam2); + //aChoiceCmd->setPreferredBranch(aParam2); + aRandomCmd->setRandomValue(aParam2); aGlobMsg << TAG_MSGo << "Preferred branch was set" << TAG_MSGc << std::endl; }else{ aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; @@ -1061,15 +1071,15 @@ void Simulator::decodeCommand(std::string iCmd){ } case 17:{//Get number of branches of current cmd std::cout << "Get number of branches of current cmd." << std::endl; - TMLChoiceCommand* aCurrChCmd =_simComp->getCurrentChoiceCmd(); - if (aCurrChCmd==0){ + IndeterminismSource* aRandomCmd =_simComp->getCurrentRandomCmd(); + if (aRandomCmd==0){ aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; anErrorCode=2; }else{ unsigned int aNbNextCmds; - aCurrChCmd->getNextCommands(aNbNextCmds); - TMLTask* aTask=aCurrChCmd->getTask(); - anEntityMsg << TAG_TASKo << " id=\"" << aTask-> getID() << "\" name=\"" << aTask->toString() << "\">" << TAG_CURRCMDo << " id=\"" << aCurrChCmd->getID() << "\">" << TAG_BRANCHo << aNbNextCmds << TAG_BRANCHc << "\">" << TAG_CURRCMDc << TAG_TASKc << std::endl; + aNbNextCmds = aRandomCmd->getRandomRange(); + TMLCommand* aCmd = dynamic_cast<TMLCommand*>(aRandomCmd); + anEntityMsg << TAG_TASKo << " id=\"" << aCmd->getTask()-> getID() << "\" name=\"" << aCmd->getTask()->toString() << "\">" << TAG_CURRCMDo << " id=\"" << aCmd->getID() << "\">" << TAG_BRANCHo << aNbNextCmds << TAG_BRANCHc << "\">" << TAG_CURRCMDc << TAG_TASKc << std::endl; aGlobMsg << TAG_MSGo << "Current choice command" << TAG_MSGc << std::endl; } std::cout << "End Get number of branches of current cmd." << std::endl; @@ -1190,7 +1200,7 @@ bool Simulator::runToChannelTrans(TMLChannel* iChannel, TMLTransaction*& oLastTr return simulate(oLastTrans); } -bool Simulator::runToNextChoiceCommand(TMLTransaction*& oLastTrans){ +bool Simulator::runToNextRandomCommand(TMLTransaction*& oLastTrans){ _randChoiceBreak.setEnabled(true); bool aSimTerminated=simulate(oLastTrans); _randChoiceBreak.setEnabled(false); @@ -1205,68 +1215,80 @@ bool Simulator::runUntilCondition(std::string& iCond, TMLTask* iTask, TMLTransac if (oSuccess) return simulate(oLastTrans); else return false; } -void Simulator::exploreTree(unsigned int iDepth, ID iPrevID, std::ofstream& iFile){ -/*std::ofstream myfile (iTraceFileName.c_str()); - if (myfile.is_open()){ - for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - (*i)->schedule2TXT(myfile); - } - myfile.close();*/ +void Simulator::exploreTree(unsigned int iDepth, ID iPrevID, std::ofstream& iFile/*, std::ofstream& iFile2*/){ TMLTransaction* aLastTrans; if (iDepth<RECUR_DEPTH){ //ID aMyID= ++_leafsID; - ID aLastID, knownID; + ID aLastID; bool aSimTerminated=false; - TMLChoiceCommand* aChoiceCmd; + IndeterminismSource* aRandomCmd; do{ - aSimTerminated=runToNextBreakpoint(aLastTrans); - aChoiceCmd=_simComp->getCurrentChoiceCmd(); + //aSimTerminated=runToNextBreakpoint(aLastTrans); + aSimTerminated=runToNextRandomCommand(aLastTrans); + //aChoiceCmd=_simComp->getCurrentChoiceCmd(); + aRandomCmd = _simComp->getCurrentRandomCmd(); //}while (!aSimTerminated && aChoiceCmd==0 && !_simComp->getStopFlag()); - }while (!aSimTerminated && aChoiceCmd==0); - //aStreamBuffer << "sched" << iDepth << "." << leafsForLevel[iDepth]++; - //aStreamBuffer << "edge_" << iPrevID << "_" << aMyID; - //std::string aStringBuffer(aStreamBuffer.str()); - //schedule2TXT(aStringBuffer); - //iFile << "***** edge_" << iPrevID << "_" << aMyID << " *****\n"; - /*for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ - (*i)->schedule2TXT(iFile); + }while (!aSimTerminated && aRandomCmd==0 && _simComp->wasKnownStateReached()==0); + /*iFile2 << "\n\nnext section: \n"; + for(CPUList::const_iterator i=_simComp->getCPUIterator(false); i != _simComp->getCPUIterator(true); ++i){ + (*i)->schedule2TXT(iFile2); }*/ - //for(TaskList::const_iterator i=_simComp->getTaskIterator(false); i !=_simComp->getTaskIterator(true); ++i){ aLastID = schedule2GraphDOT(iFile,iPrevID); - //} - //iFile << "\n"; - //HashValueType aCurrState; - //if (_simComp->wasKnownStateReached(&aCurrState)){ - if ((knownID=_simComp->wasKnownStateReached())!=0){ - //iFile << "Simulation " << iPrevID << "_" << aMyID << " encountered known state " << aCurrState << std::endl; - //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; - iFile << aLastID << " -> " << knownID << " [label = \"i\"]\n"; - }else{ - if(aChoiceCmd==0){ + if (_simComp->wasKnownStateReached()==0){ + //aLastID = schedule2GraphDOT(iFile,iPrevID); + if(aRandomCmd==0){ //iFile << "Simulation " << iPrevID << "_" << aMyID << " terminated" << std::endl; - knownID = TMLTransaction::getID(); + //knownID = TMLTransaction::getID(); + //iFile << aLastID << " -> " << knownID << " [label = \"i(exit)\"]\n"; + iFile << aLastID << " -> " << TMLTransaction::getID() << " [label = \"i(exit)\"]\n"; TMLTransaction::incID(); - iFile << aLastID << " -> " << knownID << " [label = \"i(exit)\"]\n"; }else{ unsigned int aNbNextCmds; std::stringstream aStreamBuffer; std::string aStringBuffer; - aChoiceCmd->getNextCommands(aNbNextCmds); + //aChoiceCmd->getNextCommands(aNbNextCmds); + aNbNextCmds = aRandomCmd->getRandomRange(); //std::cout << "Simulation " << iPrevID << "_" << aMyID << "continued " << aNbNextCmds << std::endl; _simComp->writeObject(aStreamBuffer); aStringBuffer=aStreamBuffer.str(); - //for (unsigned int aBranch=0; aBranch<aNbNextCmds && !_simComp->getStopFlag(); aBranch++){ - for (unsigned int aBranch=0; aBranch<aNbNextCmds; aBranch++){ - _simComp->reset(); - aStreamBuffer.str(aStringBuffer); - _simComp->readObject(aStreamBuffer); - aChoiceCmd->setPreferredBranch(aBranch); - //exploreTree(iDepth+1, aMyID, iFile); - exploreTree(iDepth+1, aLastID, iFile); - //_simComp->reset(); - //_simComp->readObject(aBuffer); + if ((aNbNextCmds & INT_MSB)==0){ + for (unsigned int aBranch=0; aBranch<aNbNextCmds; aBranch++){ + _simComp->reset(); + aStreamBuffer.str(aStringBuffer); + _simComp->readObject(aStreamBuffer); + aRandomCmd->setRandomValue(aBranch); + exploreTree(iDepth+1, aLastID, iFile/*, iFile2*/); + } + }else{ + unsigned int aBranch=0; + aNbNextCmds ^= INT_MSB; + while (aNbNextCmds!=0){ + if ((aNbNextCmds & 1)!=0){ + _simComp->reset(); + aStreamBuffer.str(aStringBuffer); + _simComp->readObject(aStreamBuffer); + aRandomCmd->setRandomValue(aBranch); + exploreTree(iDepth+1, aLastID, iFile/*, iFile2*/); + } + aBranch++; aNbNextCmds >>=1; + } } } + }else{ + //iFile << "Simulation " << iPrevID << "_" << aMyID << " encountered known state " << aCurrState << std::endl; + //13 -> 17 [label = "i(CPU0__test1__TMLTask_1__wro__test1__ch<4 ,4>)"]; + //iFile << aLastID << " -> " << knownID << " [label = \"i\"]\n"; + ID aNewID = TMLTransaction::getID(); + TMLTransaction::incID(); + iFile << aLastID << " -> " << aNewID << " [label = \"option\"]\n"; + std::stringstream aStreamBuffer; + std::string aStringBuffer; + _simComp->writeObject(aStreamBuffer); + aStringBuffer=aStreamBuffer.str(); + _simComp->reset(); + aStreamBuffer.str(aStringBuffer); + _simComp->readObject(aStreamBuffer); + exploreTree(iDepth, aNewID, iFile/*, iFile2*/); } } } diff --git a/simulators/c++2/src_simulator/sim/Simulator.h b/simulators/c++2/src_simulator/sim/Simulator.h index f96a36497c45d2c27c0c0594bc51829edb1999aa..724c514f0b1397e061d13d9484ba2f9354cc8cfa 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.h +++ b/simulators/c++2/src_simulator/sim/Simulator.h @@ -56,7 +56,6 @@ Ludovic Apvrille, Renaud Pacalet #include <TMLEventBChannel.h> #include <TMLEventFChannel.h> #include <TMLEventFBChannel.h> -//#include <RdvChannel.h> #include <TMLTransaction.h> #include <TMLCommand.h> #include <TMLTask.h> @@ -66,8 +65,10 @@ Ludovic Apvrille, Renaud Pacalet #include <ListenersSimCmd.h> #include <KernelListener.h> #include <KernelListener.h> +#ifdef EBRDD_ENABLED #include <ERC.h> #include <ERB.h> +#endif #define RECUR_DEPTH 20 @@ -188,7 +189,7 @@ public: \param oLastTrans Returns the last transaction executed during a simulation \return Return value of simulate() function */ - bool runToNextChoiceCommand(TMLTransaction*& oLastTrans); + bool runToNextRandomCommand(TMLTransaction*& oLastTrans); ///Runs the simulation until a given condition is satisfied /** \param iCond Condition expressed in terms of task variables of a given task @@ -204,7 +205,7 @@ public: \param iPrevID ID of the parent leaf \param iFile Reference to the output file */ - void exploreTree(unsigned int iDepth, ID iPrevID, std::ofstream& iFile); + void exploreTree(unsigned int iDepth, ID iPrevID, std::ofstream& iFile/*, std::ofstream& iFile2*/); ///Writes a HTML representation of the schedule of CPUs and buses to an output file void schedule2HTML(std::string& iTraceFileName) const; ///Writes simulation traces in VCD format to an output file