summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Jung2011-04-04 16:43:14 (EDT)
committerThomas Schuetz2011-04-04 16:43:14 (EDT)
commit6c9498396351f08fda26479dba36f732ff57a294 (patch)
tree62fb4bad2e5eb2ad7ea51878f1d2fc96d4961647
parent9c99893df7e0526ad637d3281c68340c72b144cc (diff)
downloadorg.eclipse.etrice-6c9498396351f08fda26479dba36f732ff57a294.zip
org.eclipse.etrice-6c9498396351f08fda26479dba36f732ff57a294.tar.gz
org.eclipse.etrice-6c9498396351f08fda26479dba36f732ff57a294.tar.bz2
applied patch for system port: https://bugs.eclipse.org/bugs/show_bug.cgi?id=339803
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt12
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt4
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt18
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTSystemServicesProtocol.java279
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java27
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java40
-rw-r--r--tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTest.room158
-rw-r--r--tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTestReplPort.room123
-rw-r--r--tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.tests.room320
-rw-r--r--tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java24
-rw-r--r--tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestPingPongThread.java73
11 files changed, 891 insertions, 187 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
index 6a54aa7..2fa6083 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/ActorClass.xpt
@@ -62,11 +62,11 @@ public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null
«ENDFOREACH»
//--------------------- interface item IDs
- «FOREACH ac.getEndPorts() AS ep»protected static final int IFITEM_«ep.name» = «xpac.getInterfaceItemLocalId(ep)»;
+ «FOREACH ac.getEndPorts() AS ep»protected static final int IFITEM_«ep.name» = «xpac.getInterfaceItemLocalId(ep)+1»;
«ENDFOREACH»
- «FOREACH ac.strSAPs AS sap»protected static final int IFITEM_«sap.name» = «xpac.getInterfaceItemLocalId(sap)»;
+ «FOREACH ac.strSAPs AS sap»protected static final int IFITEM_«sap.name» = «xpac.getInterfaceItemLocalId(sap)+1»;
«ENDFOREACH»
- «FOREACH ac.serviceImplementations AS svc»protected static final int IFITEM_«svc.spp.name» = «xpac.getInterfaceItemLocalId(svc.spp)»;
+ «FOREACH ac.serviceImplementations AS svc»protected static final int IFITEM_«svc.spp.name» = «xpac.getInterfaceItemLocalId(svc.spp)+1»;
«ENDFOREACH»
«EXPAND ProcedureHelpers::Attributes FOR ac.attributes»
@@ -74,11 +74,11 @@ public «IF ac.abstract»abstract «ENDIF»class «ac.name» extends «IF ac.base!=null
«EXPAND ProcedureHelpers::Operations FOR ac.operations»
//--------------------- construction
- public «ac.name»(IRTObject parent, String name, Address ownAddr, Address[][] port_addr, Address[][] peer_addr){
+ public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
«IF ac.base==null»
- super(parent, name, ownAddr);
+ super(parent, name, port_addr[0][0], peer_addr[0][0]);
«ELSE»
- super(parent, name, ownAddr, port_addr, peer_addr);
+ super(parent, name, port_addr, peer_addr);
«ENDIF»
setClassName("«ac.name»");
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
index 6bda5a9..3e186f8 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/ProtocolClass.xpt
@@ -153,6 +153,10 @@ static public class «name»Repl {
return replication;
}
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
public «name» get(int i) {
return ports.get(i);
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
index cb7833f..5cd65d5 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
+++ b/plugins/org.eclipse.etrice.generator.java/src/templates/SubSystemClass.xpt
@@ -74,23 +74,33 @@ public class «comp.name» extends SubSystemClassBase {
// instantiate all actor instances
instances = new ActorClassBase[«comp.allContainedInstances.size»];
- «FOREACH comp.allContainedInstances AS ai»instances[«comp.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
+ «FOREACH comp.allContainedInstances AS ai ITERATOR k»instances[«comp.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
«IF SubSystemInstance.isInstance(ai.eContainer)»this«ELSE»instances[«comp.allContainedInstances.indexOf(ai.eContainer)»]«ENDIF»,
"«ai.name»",
- addr«ai.path.getPathName()»,
// own interface item addresses
- new Address[][] {«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i SEPARATOR ","»addr_item_«pi.path.getPathName()»_«i.counter0»«ENDFOREACH»
+ new Address[][] {{addr_item_«ai.path.getPathName()»},«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i SEPARATOR ","»addr_item_«pi.path.getPathName()»_«i.counter0»«ENDFOREACH»
«ELSE»addr_item_«pi.path.getPathName()»
«ENDIF»}
«ENDFOREACH»},
// peer interface item addresses
- new Address[][] {«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF !ServiceImplInstance.isInstance(pi) && pi.peers.isEmpty»null«ELSE»«FOREACH pi.peers AS pp SEPARATOR ","»«IF ServiceImplInstance.isInstance(pp) || pp.peers.size>1»addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»
+ new Address[][] {{addr_item_SystemPort_«k.counter0»},«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF !ServiceImplInstance.isInstance(pi) && pi.peers.isEmpty»null«ELSE»«FOREACH pi.peers AS pp SEPARATOR ","»«IF ServiceImplInstance.isInstance(pp) || pp.peers.size>1»addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»
«ELSE»addr_item_«pp.path.getPathName()»
«ENDIF»
«ENDFOREACH»«ENDIF»}
«ENDFOREACH»}
);
«ENDFOREACH»
+
+ // create the subsystem system port
+ RTSystemPort = new RTSystemServicesProtocolConjPortRepl(this, "RTSystemPort",
+ 0, //local ID
+ new Address[]{ // own addresses
+ «FOREACH comp.allContainedInstances AS ai ITERATOR i SEPARATOR ","»addr_item_SystemPort_«i.counter0»
+ «ENDFOREACH»},
+ new Address[]{ // peer addresses
+ «FOREACH comp.allContainedInstances AS ai SEPARATOR ","»addr_item_«ai.path.getPathName()»
+ «ENDFOREACH»});
+
}
};
«ENDFILE»
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTSystemServicesProtocol.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTSystemServicesProtocol.java
new file mode 100644
index 0000000..c7cee19
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTSystemServicesProtocol.java
@@ -0,0 +1,279 @@
+package org.eclipse.etrice.runtime.java.messaging;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
+import org.eclipse.etrice.runtime.java.modelbase.*;
+import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
+
+public class RTSystemServicesProtocol {
+ // message IDs
+ // TODO: separate class for message IDs: class MSG{public static volatile int MSG_MIN = 0; ...} -> better structure
+ // error if msgID <= MSG_MIN
+ public static final int MSG_MIN = 0;
+ //IDs for outgoing messages
+ public static final int OUT_dummy = 1;
+
+ //IDs for incoming messages
+ public static final int IN_executeInitialTransition = 2;
+ public static final int IN_startDebugging = 3;
+ public static final int IN_stopDebugging = 4;
+
+ //error if msgID >= MSG_MAX
+ public static final int MSG_MAX = 5;
+
+ private static String messageStrings[] = {"MIN", "dummy",
+ "executeInitialTransition", "startDebugging", "stopDebugging",
+ "MAX"};
+
+ public String getMessageString(int msg_id) {
+ if (msg_id < 0 || msg_id > MSG_MAX + 1) {
+ // id out of range
+ return "Message ID out of range";
+ } else {
+ return messageStrings[msg_id];
+ }
+ }
+
+ // port class
+ static public class RTSystemServicesProtocolPort extends PortBase {
+
+ // constructors
+ public RTSystemServicesProtocolPort(IEventReceiver actor, String name,
+ int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public RTSystemServicesProtocolPort(IEventReceiver actor, String name,
+ int localId, int idx, Address addr, Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+
+ @Override
+ public void receive(Message m) {
+ if (!(m instanceof EventMessage))
+ return;
+ EventMessage msg = (EventMessage) m;
+ if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+ System.out.println("unknown");
+ else {
+ if (messageStrings[msg.getEvtId()] != "timerTick") {
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncIn(
+ getPeerAddress(), getAddress(),
+ messageStrings[msg.getEvtId()]);
+ }
+
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(),
+ ((EventWithDataMessage) msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId());
+
+ }
+ }
+
+ // sent messages
+
+ public void dummy() {
+
+ if (messageStrings[OUT_dummy] != "timerTick") {
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[OUT_dummy]);
+ }
+ if (getPeerAddress() != null)
+ getPeerMsgReceiver().receive(
+ new EventMessage(getPeerAddress(), OUT_dummy));
+
+ }
+
+ }
+
+ // replicated port class
+ static public class RTSystemServicesProtocolPortRepl {
+ private ArrayList<RTSystemServicesProtocolPort> ports;
+ private int replication;
+
+ public RTSystemServicesProtocolPortRepl(IEventReceiver actor,
+ String name, int localId, Address[] addr, Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<RTSystemServicesProtocol.RTSystemServicesProtocolPort>(
+ replication);
+ for (int i = 0; i < replication; ++i) {
+ ports.add(new RTSystemServicesProtocolPort(actor, name + i,
+ localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public RTSystemServicesProtocolPort get(int i) {
+ return ports.get(i);
+ }
+
+ // outgoing messages
+
+ public void dummy() {
+ for (int i = 0; i < replication; ++i) {
+ ports.get(i).dummy();
+ }
+ }
+
+ }
+
+ // interface for port class
+ public interface IRTSystemServicesProtocolPort {
+
+ // incoming messages
+ public void executeInitialTransition();
+ public void startDebugging();
+ public void stopDebugging();
+
+ }
+
+ // port class
+ static public class RTSystemServicesProtocolConjPort extends PortBase {
+
+ // constructors
+ public RTSystemServicesProtocolConjPort(IEventReceiver actor,
+ String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public RTSystemServicesProtocolConjPort(IEventReceiver actor,
+ String name, int localId, int idx, Address addr,
+ Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+
+ @Override
+ public void receive(Message m) {
+ if (!(m instanceof EventMessage))
+ return;
+ EventMessage msg = (EventMessage) m;
+ if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+ System.out.println("unknown");
+ else {
+ if (messageStrings[msg.getEvtId()] != "timerTick") {
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncIn(
+ getPeerAddress(), getAddress(),
+ messageStrings[msg.getEvtId()]);
+ }
+
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(),
+ ((EventWithDataMessage) msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId());
+
+ }
+ }
+
+ // sent messages
+
+ public void executeInitialTransition() {
+
+ if (messageStrings[IN_executeInitialTransition] != "timerTick") {
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(),
+ messageStrings[IN_executeInitialTransition]);
+ }
+ if (getPeerAddress() != null)
+ getPeerMsgReceiver().receive(
+ new EventMessage(getPeerAddress(),
+ IN_executeInitialTransition));
+
+ }
+
+ public void startDebugging() {
+
+ if (messageStrings[IN_startDebugging] != "timerTick") {
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[IN_startDebugging]);
+ }
+ if (getPeerAddress() != null)
+ getPeerMsgReceiver().receive(
+ new EventMessage(getPeerAddress(), IN_startDebugging));
+
+ }
+
+ public void stopDebugging() {
+
+ if (messageStrings[IN_stopDebugging] != "timerTick") {
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[IN_stopDebugging]);
+ }
+ if (getPeerAddress() != null)
+ getPeerMsgReceiver().receive(
+ new EventMessage(getPeerAddress(), IN_stopDebugging));
+
+ }
+
+ }
+
+ // replicated port class
+ static public class RTSystemServicesProtocolConjPortRepl {
+ private ArrayList<RTSystemServicesProtocolConjPort> ports;
+ private int replication;
+
+ public RTSystemServicesProtocolConjPortRepl(IEventReceiver actor,
+ String name, int localId, Address[] addr, Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<RTSystemServicesProtocol.RTSystemServicesProtocolConjPort>(
+ replication);
+ for (int i = 0; i < replication; ++i) {
+ ports.add(new RTSystemServicesProtocolConjPort(actor, name + i,
+ localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public RTSystemServicesProtocolConjPort get(int i) {
+ return ports.get(i);
+ }
+
+ // incoming messages
+
+ public void executeInitialTransition() {
+ for (int i = 0; i < replication; ++i) {
+ ports.get(i).executeInitialTransition();
+ }
+ }
+
+ public void startDebugging() {
+ for (int i = 0; i < replication; ++i) {
+ ports.get(i).startDebugging();
+ }
+ }
+
+ public void stopDebugging() {
+ for (int i = 0; i < replication; ++i) {
+ ports.get(i).stopDebugging();
+ }
+ }
+
+ }
+
+ // interface for port class
+ public interface IRTSystemServicesProtocolConjPort {
+
+ // outgoing messages
+ public void dummy();
+
+ }
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
index f441da6..e01d979 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
@@ -14,6 +14,9 @@ import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.messaging.Message;
import org.eclipse.etrice.runtime.java.messaging.MessageService;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
+import org.eclipse.etrice.runtime.java.messaging.RTSystemServicesProtocol;
+import org.eclipse.etrice.runtime.java.messaging.RTSystemServicesProtocol.*;
+
/**
* The base class for model actor classes.
@@ -39,12 +42,18 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
private MessageService ownMsgsvc = null;
private Address ownAddr = null;
+ // the System Port
+ private RTSystemServicesProtocolPort RTSystemPort = null;
- public ActorClassBase(IRTObject parent, String name, Address ownAddr) {
+ public ActorClassBase(IRTObject parent, String name, Address ownAddr, Address systemPortPeerAddr) {
super(parent, name);
this.ownAddr = ownAddr;
ownMsgsvc = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(this.ownAddr.threadID);
+ // own ports
+ RTSystemPort = new RTSystemServicesProtocolPort(this, "RTSystemPort",
+ 0, 0, ownAddr,
+ systemPortPeerAddr);
}
public String toString(){
@@ -89,4 +98,20 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
public MessageService getMsgsvc() {
return ownMsgsvc;
}
+
+ protected boolean handleSystemEvent(InterfaceItemBase ifitem, int evt, Object... generic_data){
+ if (ifitem.getLocalId()!=0)return false;
+
+ switch (evt){
+ case RTSystemServicesProtocol.IN_executeInitialTransition :
+ executeInitTransition();
+ break;
+ case RTSystemServicesProtocol.IN_startDebugging :
+ break;
+ case RTSystemServicesProtocol.IN_stopDebugging :
+ break;
+ }
+
+ return true;
+ }
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java
index 6da6db7..c9b6456 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/SubSystemClassBase.java
@@ -14,6 +14,8 @@ import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.messaging.MessageService;
import org.eclipse.etrice.runtime.java.messaging.RTObject;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
+import org.eclipse.etrice.runtime.java.messaging.RTSystemServicesProtocol.*;
+import java.util.concurrent.Semaphore;
/**
* The base class for all SubSystems.
@@ -22,13 +24,18 @@ import org.eclipse.etrice.runtime.java.messaging.RTServices;
* @author Henrik Rentz-Reichert
*
*/
-public abstract class SubSystemClassBase extends RTObject {
+public abstract class SubSystemClassBase extends RTObject implements IEventReceiver{
private static SubSystemClassBase instance = null;
-
+ //--------------------- ports
+ protected RTSystemServicesProtocolConjPortRepl RTSystemPort = null;
+ //--------------------- interface item IDs
+ protected static final int IFITEM_RTSystemPort = 0;
private boolean running = false;
protected ActorClassBase[] instances = null;
-
+ private Semaphore testSem=null;
+ private int testErrorCode;
+
public static SubSystemClassBase getInstance() {
return instance;
}
@@ -47,6 +54,7 @@ public abstract class SubSystemClassBase extends RTObject {
DebuggingService.getInstance().getSyncLogger()
.setMSC(name + "_Sync", "");
DebuggingService.getInstance().getSyncLogger().open();
+
}
public void init() {
@@ -75,12 +83,9 @@ public abstract class SubSystemClassBase extends RTObject {
public void start() {
- // start all actor instances
- if (instances!=null)
- for (int i = 0; i < instances.length; i++) {
- instances[i].start();
- }
-
+ // start all actors instances
+ RTSystemPort.executeInitialTransition();
+
// start all message services
RTServices.getInstance().getMsgSvcCtrl().start();
@@ -129,4 +134,21 @@ public abstract class SubSystemClassBase extends RTObject {
return null;
}
+
+ // this is to run integration tests
+ public synchronized void setTestSemaphore(Semaphore sem){
+ testErrorCode = -1;
+ testSem=sem;
+ }
+
+ public synchronized int getTestErrorCode(){
+ return testErrorCode;
+ }
+
+ public synchronized void testFinished(int errorCode){
+ if (testSem != null) {
+ testErrorCode = errorCode;
+ testSem.release(1);
+ }
+ }
}
diff --git a/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTest.room b/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTest.room
new file mode 100644
index 0000000..93f86f5
--- /dev/null
+++ b/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTest.room
@@ -0,0 +1,158 @@
+RoomModel org.eclipse.etrice.integration.PingPongThreadTest {
+
+ import room.basic.service.timing.*
+
+
+ LogicalSystem System_PingPong {
+ SubSystemRef subsystem: SubSystem_PingPong
+ }
+
+ SubSystemClass SubSystem_PingPong {
+ ActorRef application: PingPongTop
+ ActorRef services: ATimingService
+ LayerConnection ref application satisfied_by services.timer
+ LayerConnection ref application satisfied_by services.timeout
+ LogicalThread mrPingThread {application.MrPing}
+ LogicalThread mrPong1Thread {application.MrPong1}
+ LogicalThread mrPong2Thread {application.MrPong2}
+ LogicalThread mrPong3Thread {application.MrPong3}
+ }
+
+ ActorClass PingPongTop {
+ Structure {
+ ActorRef MrPing: MrPingActor
+ ActorRef MrPong1: MrPongActor1
+ ActorRef MrPong2: MrPongActor1
+ ActorRef MrPong3: MrPongActor2
+ Binding MrPing.PingPongPort and MrPong1.PingPongPort
+ Binding MrPing.PingPongPort2 and MrPong2.PingPongPort
+ Binding MrPing.PingPongPort3 and MrPong3.PingPongPort
+ }
+ }
+
+ ActorClass MrPingActor {
+ Interface {
+ conjugated Port PingPongPort : PingPongProtocol
+ conjugated Port PingPongPort2 : PingPongProtocol
+ conjugated Port PingPongPort3 : PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ external Port PingPongPort2
+ external Port PingPongPort3
+ SAP timer: PTimeout
+ Attribute count : int32
+ Attribute pongCount : int32
+ }
+ Behavior {
+ StateMachine {
+ Transition tr0: initial -> waitForTimer {
+ action {
+ "count = 0;"
+ "timer.Start(1000);"
+ }
+ }
+ Transition tr1: waitForTimer -> waitForPong {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "PingPongPort.ping();"
+ "PingPongPort2.ping();"
+ "pongCount = 0;"
+ }
+ }
+ Transition tr3: waitForPong -> cp cp0 {
+ triggers {
+ <pong: PingPongPort2>
+ or
+ <pong: PingPongPort>
+ }
+ action {
+ "pongCount++;"
+ }
+ }
+ Transition tr5: cp cp0 -> waitForTimer {
+ action {
+ "if (count++ > 1000) {"
+ "SubSystemClassBase.getInstance().testFinished(0);"
+ "} else {"
+ "System.out.println(count);"
+ "timer.Start(5);}"
+ }
+ }
+ Transition tr6: cp cp0 -> waitForPong {
+ cond {
+ "pongCount < 2"
+ }
+ }
+ ChoicePoint cp0
+ State waitForTimer { }
+ State waitForPong { }
+ }
+ }
+ }
+
+ ActorClass MrPongActor1 {
+ Interface {
+ Port PingPongPort: PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ }
+ Behavior {
+ StateMachine {
+ Transition tr0: initial -> waitForPing { }
+ Transition myTrigger: waitForPing -> waitForPing {
+ triggers {
+ <ping: PingPongPort>
+ }
+ action {
+ "PingPongPort.pong();"
+ }
+ }
+ State waitForPing { }
+ }
+ }
+ }
+
+ ActorClass MrPongActor2 {
+ Interface {
+ Port PingPongPort: PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ }
+ Behavior {
+ StateMachine {
+ Transition tr0: initial -> waitForPing {
+ action {
+ "// simulate blocking call e.g. Queue"
+ "try{"
+ "Thread.sleep(10000);"
+ "}catch (InterruptedException e){}"
+ }
+ }
+ Transition myTrigger: waitForPing -> waitForPing {
+ triggers {
+ <ping: PingPongPort>
+ }
+ action {
+ "PingPongPort.pong();"
+ }
+ }
+ State waitForPing { }
+ }
+ }
+ }
+
+ ProtocolClass PingPongProtocol {
+ incoming {
+ Message ping()
+ }
+ outgoing {
+ Message pong()
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTestReplPort.room b/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTestReplPort.room
new file mode 100644
index 0000000..d152638
--- /dev/null
+++ b/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.PingPongThreadTestReplPort.room
@@ -0,0 +1,123 @@
+RoomModel org.eclipse.etrice.integration.PingPongThreadTestReplPort {
+
+ import room.basic.service.timing.*
+
+
+ LogicalSystem System_PingPong {
+ SubSystemRef subsystem: SubSystem_PingPong
+ }
+
+ SubSystemClass SubSystem_PingPong {
+ ActorRef application: PingPongTop
+ ActorRef services: ATimingService
+ LayerConnection ref application satisfied_by services.timer
+ LayerConnection ref application satisfied_by services.timeout
+ LogicalThread mrPingThread {application.MrPing}
+ LogicalThread mrPong1Thread {application.MrPong1}
+ LogicalThread mrPong2Thread {application.MrPong2}
+ LogicalThread mrPong3Thread {application.MrPong3}
+ }
+
+ ActorClass PingPongTop {
+ Structure {
+ ActorRef MrPing: MrPingActor
+ ActorRef MrPong1: MrPongActor1
+ ActorRef MrPong2: MrPongActor1
+ ActorRef MrPong3: MrPongActor1
+ Binding MrPing.PingPongPort and MrPong1.PingPongPort
+ Binding MrPing.PingPongPort and MrPong2.PingPongPort
+ Binding MrPing.PingPongPort and MrPong3.PingPongPort
+ }
+ }
+
+ ActorClass MrPingActor {
+ Interface {
+ conjugated Port PingPongPort [3] : PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ SAP timer: PTimeout
+ Attribute count : int32
+ Attribute pongCount : int32
+ }
+ Behavior {
+ StateMachine {
+ Transition tr0: initial -> waitForTimer {
+ action {
+ "count = 0;"
+ "timer.Start(1000);"
+ }
+ }
+ Transition tr1: waitForTimer -> waitForPong {
+ triggers {
+ <timeoutTick: timer>
+ }
+ action {
+ "PingPongPort.get(0).ping();"
+ "PingPongPort.get(1).ping();"
+ "PingPongPort.get(2).ping();"
+ "pongCount = 0;"
+ }
+ }
+ Transition tr3: waitForPong -> cp cp0 {
+ triggers {
+ <pong: PingPongPort>
+ }
+ action {
+ "pongCount++;"
+ }
+ }
+ Transition tr5: cp cp0 -> waitForTimer {
+ action {
+ "if (count++ > 1000) {"
+ "SubSystemClassBase.getInstance().testFinished(0);"
+ "} else {"
+ "System.out.println(count);"
+ "timer.Start(5);}"
+ }
+ }
+ Transition tr6: cp cp0 -> waitForPong {
+ cond {
+ "pongCount < 3"
+ }
+ }
+ ChoicePoint cp0
+ State waitForTimer { }
+ State waitForPong { }
+ }
+ }
+ }
+
+ ActorClass MrPongActor1 {
+ Interface {
+ Port PingPongPort: PingPongProtocol
+ }
+ Structure {
+ external Port PingPongPort
+ }
+ Behavior {
+ StateMachine {
+ Transition tr0: initial -> waitForPing { }
+ Transition myTrigger: waitForPing -> waitForPing {
+ triggers {
+ <ping: PingPongPort>
+ }
+ action {
+ "PingPongPort.pong();"
+ }
+ }
+ State waitForPing { }
+ }
+ }
+ }
+
+ ProtocolClass PingPongProtocol {
+ incoming {
+ Message ping()
+ }
+ outgoing {
+ Message pong()
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.tests.room b/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.tests.room
index bb8aa6f..5cae5e2 100644
--- a/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.tests.room
+++ b/tests/org.eclipse.etrice.integration.tests/model/org.eclipse.etrice.integration.tests.room
@@ -2,73 +2,24 @@ RoomModel org.eclipse.etrice.integration.tests {
import room.basic.service.timing.*
- DataClass d_Packet {
- Attribute data : int32
+ LogicalSystem SystemHFSMTest {
+ SubSystemRef subsystem : SubSystemHFSMTest
}
- ProtocolClass p_SimpleProtocol {
- incoming {
- Message data ()
- }
- outgoing {
- Message ack ()
- Message nak ()
- Message poll ()
- }
- }
+ SubSystemClass SubSystemHFSMTest {
+ ActorRef application : App_SubSystemHFSMTest
+ ActorRef services : ATimingService
- ProtocolClass p_HFSM {
- incoming {
- Message m1 ()
- Message m2 ()
- Message m3 ()
- Message m4 ()
- Message m5 ()
- Message m6 ()
- Message reset ()
- Message m7 ()
- Message m8 ()
- Message m9 ()
- }
- outgoing {
- Message init_action ()
- Message s1_entry ()
- Message s1_exit ()
- Message s2_entry ()
- Message s2_exit ()
- Message s3_entry ()
- Message s3_exit ()
- Message s4_entry ()
- Message s4_exit ()
- Message s2s1_entry ()
- Message s2s1_exit ()
- Message s2s2_entry ()
- Message s2s2_exit ()
- Message s1_m1_s2_action ()
- Message s2_m1_s2s1_action ()
- Message s2s1_m2_s2s2_action ()
- Message s2s2_m3_action ()
- Message s2_m4_s4_action ()
- Message s2_m5_s2_action ()
- Message s2_m6_s2_action ()
- Message s2__s3_action ()
- Message s2_m7_s2_action ()
- Message top_s8_top_action ()
- Message top_s9_top_action ()
- Message top_reset_s2_action ()
- }
+ LayerConnection ref application satisfied_by services.timer
+ LayerConnection ref application satisfied_by services.timeout
}
ActorClass a_HFSM_Tests {
- Interface {
- }
Structure {
ActorRef HFSM : a_HFSM
ActorRef Tester : a_HFSM_Tester
Binding Tester.testee and HFSM.fct
}
- Behavior {
- }
}
ActorClass a_HFSM {
@@ -80,6 +31,67 @@ RoomModel org.eclipse.etrice.integration.tests {
}
Behavior {
StateMachine {
+ Transition tr0: initial -> State1 {
+ action {
+ "fct.init_action();"
+ }
+ }
+ Transition tr1: State1 -> tp0 of State2 {
+ triggers {
+ <m1:fct>
+ }
+ action {
+ "fct.s1_m1_s2_action();"
+ }
+ }
+ Transition tr2: tp1 of State2 -> State3 {
+ action {
+ "fct.s2__s3_action();"
+ }
+ }
+ Transition tr3: State2 -> State4 {
+ triggers {
+ <m4:fct>
+ }
+ action {
+ "fct.s2_m4_s4_action();"
+ }
+ }
+ Transition tr4: my tp0 -> State1 {
+ triggers {
+ <reset:fct>
+ }
+ action {
+ "fct.top_reset_s2_action();"
+ }
+ }
+ Transition tr5: State2 -> State2 {
+ triggers {
+ <m7:fct>
+ }
+ action {
+ "fct.s2_m7_s2_action();"
+ }
+ }
+ Transition tr6: my tp1 -> my tp1 {
+ triggers {
+ <m8:fct>
+ }
+ action {
+ "fct.top_s8_top_action();"
+ }
+ }
+ Transition tr7: my tp2 -> my tp2 {
+ triggers {
+ <m9:fct>
+ }
+ action {
+ "fct.top_s9_top_action();"
+ }
+ }
+ TransitionPoint tp0
+ TransitionPoint tp1
+ handler TransitionPoint tp2
State State1 {
entry {
"fct.s1_entry();"
@@ -96,26 +108,6 @@ RoomModel org.eclipse.etrice.integration.tests {
"fct.s2_exit();"
}
subgraph {
- State State1 {
- entry {
- "fct.s2s1_entry();"
- }
- exit {
- "fct.s2s1_exit();"
- }
- }
- State State2 {
- entry {
- "fct.s2s2_entry();"
- }
- exit {
- "fct.s2s2_exit();"
- }
- }
- EntryPoint tp0
- ExitPoint tp1
- TransitionPoint tp3
- handler TransitionPoint tp4
Transition tr0: my tp0 -> State1 {
action {
"fct.s2_m1_s2s1_action();"
@@ -153,6 +145,26 @@ RoomModel org.eclipse.etrice.integration.tests {
"fct.s2_m6_s2_action();"
}
}
+ EntryPoint tp0
+ ExitPoint tp1
+ TransitionPoint tp3
+ handler TransitionPoint tp4
+ State State1 {
+ entry {
+ "fct.s2s1_entry();"
+ }
+ exit {
+ "fct.s2s1_exit();"
+ }
+ }
+ State State2 {
+ entry {
+ "fct.s2s2_entry();"
+ }
+ exit {
+ "fct.s2s2_exit();"
+ }
+ }
}
}
State State3 {
@@ -171,67 +183,6 @@ RoomModel org.eclipse.etrice.integration.tests {
"fct.s4_exit();"
}
}
- TransitionPoint tp0
- TransitionPoint tp1
- handler TransitionPoint tp2
- Transition tr0: initial -> State1 {
- action {
- "fct.init_action();"
- }
- }
- Transition tr1: State1 -> tp0 of State2 {
- triggers {
- <m1:fct>
- }
- action {
- "fct.s1_m1_s2_action();"
- }
- }
- Transition tr2: tp1 of State2 -> State3 {
- action {
- "fct.s2__s3_action();"
- }
- }
- Transition tr3: State2 -> State4 {
- triggers {
- <m4:fct>
- }
- action {
- "fct.s2_m4_s4_action();"
- }
- }
- Transition tr4: my tp0 -> State1 {
- triggers {
- <reset:fct>
- }
- action {
- "fct.top_reset_s2_action();"
- }
- }
- Transition tr5: State2 -> State2 {
- triggers {
- <m7:fct>
- }
- action {
- "fct.s2_m7_s2_action();"
- }
- }
- Transition tr6: my tp1 -> my tp1 {
- triggers {
- <m8:fct>
- }
- action {
- "fct.top_s8_top_action();"
- }
- }
- Transition tr7: my tp2 -> my tp2 {
- triggers {
- <m9:fct>
- }
- action {
- "fct.top_s9_top_action();"
- }
- }
}
}
}
@@ -245,18 +196,6 @@ RoomModel org.eclipse.etrice.integration.tests {
}
Behavior {
StateMachine {
- State State1 {}
- State State2 {}
- State State3 {}
- State State4 {}
- State State5 {}
- State State6 {}
- State State7 {}
- State TestPass {
- entry {
- "getMsgsvc().terminate();"
- }
- }
Transition tr0: initial -> State1 {}
Transition tr1: State1 -> State2 {
triggers {
@@ -296,27 +235,84 @@ RoomModel org.eclipse.etrice.integration.tests {
<s2s1_entry:testee>
}
}
+ State State1 {}
+ State State2 {}
+ State State3 {}
+ State State4 {}
+ State State5 {}
+ State State6 {}
+ State State7 {}
+ State TestPass {
+ entry {
+ "SubSystemClassBase.getInstance().testFinished(0);"
+ }
+ }
}
}
}
- LogicalSystem SystemHFSMTest {
- SubSystemRef subsystem : SubSystemHFSMTest
+// automatically inserted App_SubSystemHFSMTest
+ ActorClass App_SubSystemHFSMTest {
+ Structure {
+ ActorRef HFSM_Tests : a_HFSM_Tests
+ }
}
- SubSystemClass SubSystemHFSMTest {
- ActorRef application : App_SubSystemHFSMTest
- ActorRef services : ATimingService
-
- LayerConnection ref application satisfied_by services.timer
- LayerConnection ref application satisfied_by services.timeout
+ ProtocolClass p_SimpleProtocol {
+ incoming {
+ Message data ()
+ }
+ outgoing {
+ Message ack ()
+ Message nak ()
+ Message poll ()
+ }
}
- // automatically inserted App_SubSystemHFSMTest
- ActorClass App_SubSystemHFSMTest {
- Structure {
- ActorRef HFSM_Tests : a_HFSM_Tests
+ ProtocolClass p_HFSM {
+ incoming {
+ Message m1 ()
+ Message m2 ()
+ Message m3 ()
+ Message m4 ()
+ Message m5 ()
+ Message m6 ()
+ Message reset ()
+ Message m7 ()
+ Message m8 ()
+ Message m9 ()
}
+ outgoing {
+ Message init_action ()
+ Message s1_entry ()
+ Message s1_exit ()
+ Message s2_entry ()
+ Message s2_exit ()
+ Message s3_entry ()
+ Message s3_exit ()
+ Message s4_entry ()
+ Message s4_exit ()
+ Message s2s1_entry ()
+ Message s2s1_exit ()
+ Message s2s2_entry ()
+ Message s2s2_exit ()
+ Message s1_m1_s2_action ()
+ Message s2_m1_s2s1_action ()
+ Message s2s1_m2_s2s2_action ()
+ Message s2s2_m3_action ()
+ Message s2_m4_s4_action ()
+ Message s2_m5_s2_action ()
+ Message s2_m6_s2_action ()
+ Message s2__s3_action ()
+ Message s2_m7_s2_action ()
+ Message top_s8_top_action ()
+ Message top_s9_top_action ()
+ Message top_reset_s2_action ()
+ }
+ }
+
+ DataClass d_Packet {
+ Attribute data : int32
}
-}
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java b/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java
index 6403e2c..4dd418e 100644
--- a/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java
+++ b/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestFSMGenerator.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher;
import org.eclipse.etrice.integration.tests.SubSystemHFSMTest;
import org.eclipse.etrice.integration.tests.a_HFSM_Tester;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
+import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -26,10 +27,19 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
+import java.util.concurrent.Semaphore;
public class IntegrationTestFSMGenerator {
-
+ private Semaphore testSem = new Semaphore(0);
+
+ private synchronized void waitForTestcase(){
+ try{
+ this.testSem.acquire(1);
+ }catch(InterruptedException e){
+ System.out.println("Semaphore fault !");
+ }
+ }
@Before
public void setUp() throws Exception {
// we have to launch a JUnit Plugin test since for the build we need an Eclipse environment
@@ -42,16 +52,20 @@ public class IntegrationTestFSMGenerator {
*/
}
- @Test(timeout=1000)
+ @Test (timeout=5000)
public void testHFSM(){
SubSystemHFSMTest main_component = new SubSystemHFSMTest(null,"MainComponent");
+
+ // hand over the semaphore to the subsystem
+ SubSystemClassBase.getInstance().setTestSemaphore(this.testSem);
+
main_component.init(); // lifecycle init
main_component.start(); // lifecycle start
- RTServices.getInstance().getMsgSvcCtrl().waitTerminate();
-
- assertEquals(a_HFSM_Tester.STATE_TestPass ,main_component.getInstance("/MainComponent/application/HFSM_Tests/Tester").getState());
+ waitForTestcase();
+ assertEquals(0,main_component.getTestErrorCode());
+
// end the lifecycle
main_component.stop(); // lifecycle stop
main_component.destroy(); // lifecycle destroy
diff --git a/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestPingPongThread.java b/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestPingPongThread.java
new file mode 100644
index 0000000..d809283
--- /dev/null
+++ b/tests/org.eclipse.etrice.integration.tests/src/org/eclipse/etrice/integration/tests/IntegrationTestPingPongThread.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.integration.tests;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.etrice.integration.PingPongThreadTest.SubSystem_PingPong;
+import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.concurrent.Semaphore;
+
+
+public class IntegrationTestPingPongThread {
+ private Semaphore testSem = new Semaphore(0);
+
+ private synchronized void waitForTestcase(){
+ try{
+ this.testSem.acquire(1);
+ }catch(InterruptedException e){
+ System.out.println("Semaphore fault !");
+ }
+ }
+ @Before
+ public void setUp() throws Exception {
+ // we have to launch a JUnit Plugin test since for the build we need an Eclipse environment
+ // in this context the Mwe2Launcher suffers from https://bugs.eclipse.org/bugs/show_bug.cgi?id=318721
+ /*
+ Mwe2Launcher.main(new String[]{"/org.eclipse.etrice.integration.tests/src/de/protos/etrice/integration/test/IntegrationTestFSMGenerator.mwe2"});
+ final IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IProject project = workspace.getRoot().getProject("/org.eclipse.etrice.integration.tests");
+ project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
+ */
+ }
+
+ @Test (timeout=25000)
+ public void testHFSM(){
+ SubSystem_PingPong main_component = new SubSystem_PingPong(null,"MainComponent");
+
+ // hand over the semaphore to the subsystem
+ SubSystemClassBase.getInstance().setTestSemaphore(this.testSem);
+
+ main_component.init(); // lifecycle init
+ main_component.start(); // lifecycle start
+
+ waitForTestcase();
+
+ assertEquals(0,main_component.getTestErrorCode());
+
+ // end the lifecycle
+ main_component.stop(); // lifecycle stop
+ main_component.destroy(); // lifecycle destroy
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+
+}