[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] applications/HLA_TestsSuite CMakeLists.txt test...
From: |
certi-cvs |
Subject: |
[certi-cvs] applications/HLA_TestsSuite CMakeLists.txt test... |
Date: |
Thu, 15 Oct 2009 20:56:52 +0000 |
CVSROOT: /sources/certi
Module name: applications
Changes by: Eric NOULARD <erk> 09/10/15 20:56:51
Modified files:
HLA_TestsSuite : CMakeLists.txt test_TRTCCallbacks.cc
Added files:
HLA_TestsSuite : dtest_test_TRTCCallbacks-withLateFederate.py
Log message:
Update with a new TRTCCallback test.
Not finished [yet]
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/CMakeLists.txt?cvsroot=certi&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_TRTCCallbacks.cc?cvsroot=certi&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/dtest_test_TRTCCallbacks-withLateFederate.py?cvsroot=certi&rev=1.1
Patches:
Index: CMakeLists.txt
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/CMakeLists.txt,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- CMakeLists.txt 15 Oct 2009 16:11:28 -0000 1.33
+++ CMakeLists.txt 15 Oct 2009 20:56:51 -0000 1.34
@@ -160,7 +160,7 @@
FED_FILE test_TRTCCallbacks.fed
SOURCE_FILES test_TRTCCallbacks.cc
MORELIBS ${LIBHLA}
- DTEST_SCRIPT dtest_test_TRTCCallbacks.py
+ DTEST_SCRIPT dtest_test_TRTCCallbacks.py
dtest_test_TRTCCallbacks-withLateFederate.py
COMMENTS "Test HLA TimeRegulating and TimeConstrained
Callbacks")
#########################################################################
Index: test_TRTCCallbacks.cc
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_TRTCCallbacks.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- test_TRTCCallbacks.cc 15 Oct 2009 16:12:39 -0000 1.5
+++ test_TRTCCallbacks.cc 15 Oct 2009 20:56:51 -0000 1.6
@@ -23,9 +23,11 @@
private:
string federationName;
string fedFile;
+ string federateName;
bool creator;
bool TIME_REGULATION_ENABLED, TIME_CONSTRAINED_ENABLED;
bool TIME_ADVANCE_GRANT;
+ int nbTARstepsToDo;
typedef struct UpdateMeH {
RTI::ObjectClassHandle och_updateMe;
RTI::AttributeHandle ah_pingMe;
@@ -34,27 +36,29 @@
UpdateMeH_t umoh;
typedef struct UpdateMeObject {
+ std::string name;
RTI::ObjectHandle oh_updateMe;
libhla::HLAdata<libhla::HLAinteger64LE> pingMe;
libhla::HLAdata<libhla::HLAinteger64LE> counter;
} UpdateMeObject_t;
- std::vector<UpdateMeObject_t> umo;
+ UpdateMeObject_t myUmo;
+ std::map<RTI::ObjectHandle,UpdateMeObject_t*> otherUmo;
RTIfedTime mytime;
RTIfedTime myLookahead;
public:
TRTCCallbacksFed(void) {
- UpdateMeObject_t initVal;
federationName = "TestTRTCCallbacks";
fedFile = "test_TRTCCallbacks.fed";
creator = false;
TIME_REGULATION_ENABLED = false;
TIME_CONSTRAINED_ENABLED = false;
- umo.reserve(MAX_FEDERATES);
- *(initVal.pingMe) = 0;
- *(initVal.counter) = 0;
- umo[0] = initVal;
+ TIME_ADVANCE_GRANT = false;
+ nbTARstepsToDo = 0;
+ myUmo.name ="unknown";
+ *(myUmo.pingMe) = 0;
+ *(myUmo.counter) = 0;
// initial simulation time is 0
mytime.setZero();
myLookahead.setZero();
@@ -63,8 +67,16 @@
};
virtual ~TRTCCallbacksFed() throw (RTI::FederateInternalError) {
+ for (std::map<RTI::ObjectHandle,UpdateMeObject_t*>::iterator it
= otherUmo.begin(); it != otherUmo.end(); it++) {
+ delete (it->second);
+ }
+ otherUmo.clear();
};
+ void setNbTARStepToDo(int nbsteps) {
+ this->nbTARstepsToDo = nbsteps;
+ }
+
int
main(void) {
this->create_and_join();
@@ -72,6 +84,8 @@
if (creator) {
cout << "Press ENTER to start execution ..." << endl;
getchar();
+ }
+ this->publishAndRegister();
this->enableTimeReg();
while (!TIME_REGULATION_ENABLED) this->tickRTI();
@@ -79,18 +93,88 @@
this->enableTimeCon();
while (!TIME_CONSTRAINED_ENABLED) this->tickRTI();
TIME_CONSTRAINED_ENABLED=false;
- } else {
- this->enableTimeReg();
- while (!TIME_REGULATION_ENABLED) this->tickRTI();
- TIME_REGULATION_ENABLED=false;
- this->enableTimeCon();
- while (!TIME_CONSTRAINED_ENABLED) this->tickRTI();
- TIME_CONSTRAINED_ENABLED=false;
+
+ // advance time loop
+ while (nbTARstepsToDo>0) {
+ this->advanceTime(mytime+myLookahead);
+ nbTARstepsToDo--;
}
+
this->resign_and_destroy();
return 0;
};
+ void
+ discoverObjectInstance (RTI::ObjectHandle theObject,
+ RTI::ObjectClassHandle theObjectClass,
+ const char *theObjectName)
+ throw ( RTI::CouldNotDiscover,
+ RTI::ObjectClassNotKnown,
+ RTI::FederateInternalError) {
+
+ UpdateMeObject_t* newObject = new UpdateMeObject_t();
+
+ newObject->name = std::string(theObjectName);
+ newObject->oh_updateMe = theObject;
+ otherUmo[newObject->oh_updateMe] = newObject;
+ cout << "Discovered " << newObject->name
+ << " [handle =" << newObject->oh_updateMe
<<"]"<< endl;
+ }
+
+ void
+ reflectAttributeValues (RTI::ObjectHandle theObject,
+ const RTI::AttributeHandleValuePairSet&
+ theAttributes,
+ const char *theTag)
+ throw ( RTI::ObjectNotKnown,
+ RTI::AttributeNotKnown,
+ RTI::FederateOwnsAttributes,
+ RTI::FederateInternalError) {
+
+ RTI::ULong rul;
+ char* value;
+
+ if (theAttributes.getHandle(0)==umoh.ah_counter) {
+ value = theAttributes.getValuePointer(0,rul);
+ //libhla::HLAdata<libhla::HLAinteger64LE>
newval(value,rul);
+ (*(otherUmo[theObject]->counter)).copy(value);
+ }
+
+ if (theAttributes.getHandle(0)==umoh.ah_pingMe) {
+ value = theAttributes.getValuePointer(0,rul);
+ //libhla::HLAdata<libhla::HLAinteger64LE>
newval(value,rul);
+ (*(otherUmo[theObject]->pingMe)).copy(value);
+ }
+
+ cout << "rav wo ts" << endl;
+ }
+
+ void
+ reflectAttributeValues (RTI::ObjectHandle theObject,
+ const RTI::AttributeHandleValuePairSet&
+ theAttributes,
+ const RTI::FedTime& theTime,
+ const char *theTag,
+ RTI::EventRetractionHandle erhdl)
+ throw ( RTI::ObjectNotKnown,
+ RTI::AttributeNotKnown,
+ RTI::FederateOwnsAttributes,
+ RTI::InvalidFederationTime,
+ RTI::FederateInternalError) {
+
+ cout << "rav w ts " <<
(static_cast<RTIfedTime>(theTime)).getTime() << endl;
+ }
+
+ void
+ timeAdvanceGrant(const RTI::FedTime &newTime)
+ throw (RTI::InvalidFederationTime,
+ RTI::TimeAdvanceWasNotInProgress,
+ RTI::FederateInternalError) {
+ TIME_ADVANCE_GRANT = true;
+ mytime = newTime;
+ cout << "TIME_ADVANCE_GRANT" << endl;
+ }
+
private:
void
@@ -109,7 +193,7 @@
cerr << "Error: Unknown non-RTI exception." << endl;
}
- string federateName = "TRTCCallbacks0";
+ federateName = "TRTCCallbacks0";
for (int i=1;i<=MAX_FEDERATES;i++) {
cout << "Try to join joining federation: " << i << endl;
try {
@@ -199,6 +283,7 @@
try {
rtiamb.publishObjectClass(umoh.och_updateMe,
*attributes);
+
} catch ( RTI::Exception &e ) {
cerr << "RTI exception: " << e._name << " ["
<< (e._reason ? e._reason :
"undefined") << "]." << endl;
@@ -209,7 +294,8 @@
// Register My Object instance
try {
- umo[0].oh_updateMe =
rtiamb.registerObjectInstance(umoh.och_updateMe);
+ myUmo.name = "UMO-"+federateName;
+ myUmo.oh_updateMe =
rtiamb.registerObjectInstance(umoh.och_updateMe);
} catch ( RTI::Exception &e ) {
cerr << "RTI exception: " << e._name << " ["
<< (e._reason ? e._reason :
"undefined") << "]." << endl;
@@ -223,20 +309,18 @@
* @param ts true if the UAV is timestamped false otherwise
*/
void UAV(bool ts) {
-
-
auto_ptr<RTI::AttributeHandleValuePairSet>
ahvps(RTI::AttributeSetFactory::create(2));
- ahvps->add(umoh.ah_counter, umo[0].counter.data(),
umo[0].counter.size());
- ahvps->add(umoh.ah_pingMe, umo[0].pingMe.data(),
umo[0].pingMe.size());
+ ahvps->add(umoh.ah_counter, myUmo.counter.data(),
myUmo.counter.size());
+ ahvps->add(umoh.ah_pingMe, myUmo.pingMe.data(),
myUmo.pingMe.size());
try {
if (ts) {
-
rtiamb.updateAttributeValues(umo[0].oh_updateMe, *ahvps,mytime+myLookahead,
"upd");
+ rtiamb.updateAttributeValues(myUmo.oh_updateMe,
*ahvps,mytime+myLookahead, "upd");
}
else {
-
rtiamb.updateAttributeValues(umo[0].oh_updateMe, *ahvps,"upd");
+ rtiamb.updateAttributeValues(myUmo.oh_updateMe,
*ahvps,"upd");
}
} catch ( RTI::Exception &e ) {
cerr << "RTI exception: " << e._name << " ["
@@ -297,9 +381,9 @@
}
void
- advanceTime(double time) {
+ advanceTime(const RTIfedTime& time) {
try {
- rtiamb.timeAdvanceRequest(RTIfedTime(time));
+ rtiamb.timeAdvanceRequest(time);
} catch ( RTI::Exception &e ) {
cerr << "RTI exception: " << e._name << " ["
<< (e._reason ? e._reason :
"undefined") << "]." << endl;
@@ -308,6 +392,7 @@
}
while (!TIME_ADVANCE_GRANT) this->tickRTI();
TIME_ADVANCE_GRANT = false;
+ getchar();
}
/* Federate Ambassador services */
@@ -339,5 +424,9 @@
int main(int argc, char **argv) {
TRTCCallbacksFed testFed;
+ if (argc>1) {
+ testFed.setNbTARStepToDo(atoi(argv[1]));
+ }
+
return testFed.main();
}
Index: dtest_test_TRTCCallbacks-withLateFederate.py
===================================================================
RCS file: dtest_test_TRTCCallbacks-withLateFederate.py
diff -N dtest_test_TRTCCallbacks-withLateFederate.py
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dtest_test_TRTCCallbacks-withLateFederate.py 15 Oct 2009 20:56:51
-0000 1.1
@@ -0,0 +1,139 @@
+#!/usr/bin/env python
+
+##-----------------------------------------------------------------------
+##
+## HLA Tests Suite
+##
+## Copyright (c) 2006-2008 Eric NOULARD, Jean-Yves ROUSSELOT
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+##-----------------------------------------------------------------------
+
+import logging
+import os
+import time
+import threading
+import getopt, sys
+import dtest
+
+def usage():
+ print "Usage:\n %s [--help] [--certi_home=<path>]
--rtig=[[<user>@]<host>]:<rtig_path>
--federate=[[<user>@]<host>]:<federate_path>" % sys.argv[0]
+
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "hr:f:c:", ["help","rtig=",
"federate=","certi_home="])
+except getopt.GetoptError, err:
+ print >> sys.stderr, "opt = %s, msg = %s" % (err.opt,err.msg)
+ usage()
+ sys.exit(2)
+
+## default values
+certi_home_defined=False
+rtig_param = dtest.Utils.getUserHostPath("rtig")
+federate_param = dtest.Utils.getUserHostPath("test_TRTCCallbacks")
+federate_param['fom']="test_TRTCCallbacks.fed"
+
+for o, a in opts:
+ if o in ("--help"):
+ usage()
+ sys.exit(2)
+ if o in ("-r", "--rtig"):
+ rtig_param = dtest.Utils.getUserHostPath(a)
+ if o in ("-f", "--federate"):
+ federate_param = dtest.Utils.getUserHostPath(a)
+ if o in ("-c", "--certi_home"):
+ certi_home = a
+ certi_home_defined=True
+
+if not certi_home_defined:
+ if os.environ.has_key("CERTI_HOME"):
+ certi_home=os.environ["CERTI_HOME"]
+ else:
+ print "You must define CERTI_HOME environment variable"
+ sys.exit(2)
+
+rtig = dtest.DTester("RTIG",
+
session=dtest.SSHSessionHandler(rtig_param['user'],host=rtig_param['host']))
+
+firstFederate = dtest.DTester("test_TRTCCallbacks_First",
+
session=dtest.SSHSessionHandler(federate_param['user'],host=federate_param['host']))
+
+# you may change the default time out value
+rtig.timeout = 40
+# you add want to save the output of your dtester to a file.
+rtig.stdout = file(rtig.name + ".out",'w+')
+rtig.stdin = file(rtig.name + ".in",'w+')
+rtig.stderr = file(rtig.name + ".err",'w+')
+
+# describe RTIG run steps
+rtig.addRunStep("ok",True,"HLA test test_TRTCCallbacks Starts.")
+dtest.ReusableSequences.addConditionalRunShellScript(rtig,c_shell_cmd="source
"+certi_home+"/share/scripts/myCERTI_env.csh "+rtig_param['host'],
+ bourne_shell_cmd="source
"+certi_home+"/share/scripts/myCERTI_env.sh "+rtig_param['host'])
+rtig.addRunStep("runCommand",command=rtig_param['path'])
+rtig.addRunStep("expectFromCommand",pattern="CERTI RTIG up and
running",timeout=5)
+rtig.addRunStep("barrier","RTIG started")
+rtig.addRunStep("barrier","All Federate(s) ended")
+rtig.addRunStep("terminateCommand")
+rtig.addRunStep("waitCommandTermination")
+rtig.addRunStep("ok",True,"HLA test test_TRTCCallbacks Ends.")
+
+#dtest.DTester.logger.setLevel(level=logging.DEBUG)
+
+# describe first federate run steps
+firstFederate.timeout = 20
+firstFederate.nbTAR = 5
+firstFederate.stdout = file(firstFederate.name + ".out",'w+')
+firstFederate.stdin = file(firstFederate.name + ".in",'w+')
+firstFederate.stderr = file(firstFederate.name + ".err",'w+')
+firstFederate.addRunStep("barrier","RTIG started")
+dtest.ReusableSequences.addConditionalRunShellScript(firstFederate,c_shell_cmd="source
"+certi_home+"/share/scripts/myCERTI_env.csh "+rtig_param['host'],
+ bourne_shell_cmd="source
"+certi_home+"/share/scripts/myCERTI_env.sh "+rtig_param['host'])
+firstFederate.addRunStep("runCommand",command=federate_param['path'] + "
"+str(firstFederate.nbTAR))
+firstFederate.addRunStep("expectFromCommand",pattern="Joined federation.*")
+firstFederate.addRunStep("ok",firstFederate.getFutureLastStepStatus,"First
Federate started and has joined federation")
+firstFederate.addRunStep("expectFromCommand",pattern="Press ENTER to start
execution")
+#firstFederate.addRunStep("barrier","First Federate waiting other(s) before
going on")
+#firstFederate.addRunStep("barrier","Other Federate started")
+firstFederate.addRunStep("sendToCommand",string="\n")
+
+firstFederate.addRunStep("barrier","TRTC Sequence starts...")
+
+firstFederate.addRunStep("expectFromCommand",pattern="Time Regulation Enabled,
press ENTER to continue")
+firstFederate.addRunStep("ok",firstFederate.getFutureLastStepStatus,"TimeRegulationEnabled
received - "+firstFederate.name)
+firstFederate.addRunStep("sendToCommand",string="\n")
+
+firstFederate.addRunStep("expectFromCommand",pattern="Time Constrained
Enabled, press ENTER to continue")
+firstFederate.addRunStep("ok",firstFederate.getFutureLastStepStatus,"TimeConstrainedEnabled
received - "+firstFederate.name)
+firstFederate.addRunStep("sendToCommand",string="\n")
+
+for i in range(1,firstFederate.nbTAR):
+ firstFederate.addRunStep("expectFromCommand",pattern="TIME_ADVANCE_GRANT")
+ firstFederate.addRunStep("ok",firstFederate.getFutureLastStepStatus,"TAG
received - "+firstFederate.name)
+ firstFederate.addRunStep("sendToCommand",string="\n")
+ time.sleep(1)
+firstFederate.addRunStep("barrier","TRTC Sequence end.")
+firstFederate.addRunStep("terminateCommand")
+firstFederate.addRunStep("barrier","All Federate(s) ended")
+
+def goTest():
+ myDTestMaster = dtest.DTestMaster("HLA test test_TRTCCallbacks
Starts","Launch RTIG + 1 federate for testing TimeRegulated and TimeConstrained
callbacks,...")
+ myDTestMaster.timeout = 40
+ myDTestMaster.register(rtig)
+ myDTestMaster.register(firstFederate)
+ myDTestMaster.startTestSequence()
+ myDTestMaster.waitTestSequenceEnd()
+
+goTest()
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] applications/HLA_TestsSuite CMakeLists.txt test...,
certi-cvs <=