summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-01-31 07:42:51 (EST)
committerJuergen Haug2013-01-31 07:42:51 (EST)
commitb4f8ff64438d6ac7caa28b42d7af2fe55fd83e9d (patch)
tree105c22413bb87a45c6ea9e9dc98f0aac9ee7399b
parentc6f4dda244f74e45aa6f8fb507098a6c97e2566b (diff)
downloadorg.eclipse.etrice-b4f8ff64438d6ac7caa28b42d7af2fe55fd83e9d.zip
org.eclipse.etrice-b4f8ff64438d6ac7caa28b42d7af2fe55fd83e9d.tar.gz
org.eclipse.etrice-b4f8ff64438d6ac7caa28b42d7af2fe55fd83e9d.tar.bz2
[abstractExec] check on missing warnings, dependency addedrefs/changes/43/9843/6
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java27
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java11
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java64
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java3
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/META-INF/MANIFEST.MF1
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/models/cashTerminal.room216
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics.room2
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics_basic.room329
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestReachability.java31
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemanticValidation.java7
-rw-r--r--tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemantics.java143
12 files changed, 761 insertions, 74 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF
index dc5107b..de2f484 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF
@@ -14,3 +14,4 @@ Require-Bundle: org.eclipse.etrice.core.room;bundle-version="0.3.0",
org.eclipse.xtext.ui;bundle-version="2.1.1"
Bundle-Activator: org.eclipse.etrice.abstractexec.behavior.Activator
Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.etrice.abstractexec.behavior;x-friends:="org.eclipse.etrice.abstractexec.behavior.tests"
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
index 5288a4d..c87cd53 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
@@ -10,7 +10,6 @@
*
*******************************************************************************/
-
package org.eclipse.etrice.abstractexec.behavior;
import java.util.List;
@@ -43,6 +42,12 @@ import org.eclipse.xtext.validation.ValidationMessageAcceptor;
*/
public class AbstractExecutionValidator implements IRoomValidator {
+ // c&p in tests
+ public static String DIAG_CODE_VIOLATION_TRIGGER = "etrice.violation_trigger";
+ public static String DIAG_CODE_VIOLATION_MESSAGESEND = "etrice.violation_messagesend";
+ public static String DIAG_CODE_MISSING_TRIGGER = "etrice.receive_message";
+ public static String DIAG_CODE_MISSING_MESSAGESEND = "etrice.send_message";
+
private static boolean traceExec = false;
private static String traceName = "";
static {
@@ -72,11 +77,12 @@ public class AbstractExecutionValidator implements IRoomValidator {
if (!(object instanceof ActorClass))
return;
ActorClass ac = (ActorClass) object;
- if (traceExec && !ac.getName().equals(traceName))
- return;
- if (traceExec)
+ if (traceExec) {
+ if (!(traceName.isEmpty() || ac.getName().equals(traceName)))
+ return;
System.out.println("AbstractExecutionValidator checking class "
+ ac.getName());
+ }
boolean oneProtocolsWithSemantics = false;
List<InterfaceItem> ifItems = RoomHelpers.getAllInterfaceItems(ac);
for (InterfaceItem item : ifItems) {
@@ -137,6 +143,9 @@ public class AbstractExecutionValidator implements IRoomValidator {
.println("AbstractExecutionValidator done checking class "
+ ac.getName());
}
+ else
+ if(traceExec)
+ System.out.println("No checking because internal generation failed");
}
}
@@ -164,16 +173,16 @@ public class AbstractExecutionValidator implements IRoomValidator {
messageAcceptor.acceptWarning("State should handle the message "
+ msg.getMessage().getName() + " from port "
+ msg.getFrom().getName() + " ", container,
- orig.eContainingFeature(), idx, "Receive message",
+ orig.eContainingFeature(), idx, DIAG_CODE_MISSING_TRIGGER,
st.getName());
}
List<MessageFromIf> outgoing = propGen.getOutgoingProposals();
for (MessageFromIf msg : outgoing) {
- messageAcceptor.acceptInfo("State could send the message "
+ messageAcceptor.acceptInfo("State should send the message "
+ msg.getMessage().getName() + " to port "
+ msg.getFrom().getName() + " ", container,
- orig.eContainingFeature(), idx, "Send message",
+ orig.eContainingFeature(), idx, DIAG_CODE_MISSING_MESSAGESEND,
st.getName());
}
@@ -212,7 +221,7 @@ public class AbstractExecutionValidator implements IRoomValidator {
mif.eContainingFeature(),
trig.getMsgFromIfPairs()
.indexOf(trig),
- "VIOLATION", trigger
+ DIAG_CODE_VIOLATION_TRIGGER, trigger
.getMsg().getName());
}
}
@@ -225,7 +234,7 @@ public class AbstractExecutionValidator implements IRoomValidator {
"The message violates the semantic rule",
orig.eContainer(), orig.eContainingFeature(),
ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
- "VIOLATION");
+ DIAG_CODE_VIOLATION_MESSAGESEND);
}
}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
index dabe29c..9d2152c 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
@@ -142,12 +142,13 @@ public class ActiveRules {
.getActorClass());
for (InterfaceItem ifitem : portList) {
GeneralProtocolClass gpc = ifitem.getGeneralProtocol();
- if (gpc instanceof ProtocolClass
- && ((ProtocolClass) gpc).getSemantics() != null)
- rules.put(ifitem, ((ProtocolClass) gpc).getSemantics()
- .getRules());
+ if (gpc instanceof ProtocolClass) {
+ ProtocolClass pc = (ProtocolClass) gpc;
+ if (pc.getSemantics() != null)
+ rules.put(ifitem, new ArrayList<SemanticsRule>(pc
+ .getSemantics().getRules()));
+ }
}
-
}
public void print() {
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
index 61eede3..d41ccb0 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
@@ -21,8 +21,8 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.etrice.core.genmodel.etricegen.ActiveTrigger;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.MessageFromIf;
-import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.SemanticsRule;
import org.eclipse.etrice.core.room.State;
@@ -57,7 +57,6 @@ public class ProposalGenerator {
return outgoingProposal;
}
-
public void createProposals(State st) {
ActiveRules rules = checker.getActiveRules(st);
@@ -65,49 +64,36 @@ public class ProposalGenerator {
if (rules == null)
return;
+ // ignore substates
+ if (RoomHelpers.hasDirectSubStructure(st))
+ return;
+
outgoingProposal.clear();
incomingProposal.clear();
- Set<SemanticsRule> rulesToIgnore = new HashSet<SemanticsRule>();
-
- for (ActiveTrigger trigger : xpac.getActiveTriggers(st)) {
- SemanticsRule match = null;
- Port port = (Port) trigger.getIfitem();
- if (rules.getPortList().contains(port)) {
- List<SemanticsRule> ruleList = rules.getRulesForPort(port);
- for (SemanticsRule curRule : ruleList) {
- if (curRule.getMsg() == trigger.getMsg()) {
- match = curRule;
- break;
+ for (InterfaceItem port : rules.getPortList()) {
+ // collect all messages from active triggers
+ Set<Message> messages = new HashSet<Message>();
+ for (ActiveTrigger t : xpac.getActiveTriggers(st))
+ if (t.getIfitem().equals(port))
+ messages.add(t.getMsg());
+ // check if every rule has its messages
+ if (rules.getPortList().contains(port)) {
+ for (SemanticsRule curRule : rules.getRulesForPort(port)) {
+ if (!messages.contains(curRule.getMsg())) {
+ MessageFromIf mif = RoomFactory.eINSTANCE
+ .createMessageFromIf();
+ mif.setFrom(port);
+ mif.setMessage(curRule.getMsg());
+ boolean isOutgoing = RoomHelpers.getMessageListDeep(
+ port, true).contains(curRule.getMsg());
+ if (isOutgoing) {
+ outgoingProposal.add(mif);
+ } else {
+ incomingProposal.add(mif);
}
}
}
- if (match != null) {
- // mark this rule for ignoring while generating proposals
- // as they have already been taken care of
- rulesToIgnore.add(match);
- }
- }
-
- // now start generating proposals by listing all the rules and ignoring
- // the ones
- // marked above
- for (InterfaceItem item : rules.getPortList()) {
- for (SemanticsRule ruleToCheck : rules.getRulesForPort(item)) {
- if (!rulesToIgnore.contains(ruleToCheck)) {
- MessageFromIf mif = RoomFactory.eINSTANCE
- .createMessageFromIf();
- mif.setFrom(item);
- mif.setMessage(ruleToCheck.getMsg());
- boolean isOutgoing = RoomHelpers.getMessageListDeep(item, true)
- .contains(ruleToCheck.getMsg());
- if (isOutgoing) {
- outgoingProposal.add(mif);
- } else {
- incomingProposal.add(mif);
- }
-
- }
}
}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
index 85da621..03a06da 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
@@ -25,7 +25,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
import org.eclipse.xtext.validation.Check;
@@ -212,7 +211,7 @@ public class ValidatorExtensionManager extends AbstractDeclarativeValidator {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable exception) {
- System.out.println("Exception in IRoomValidator");
+ System.out.println("Exception in IRoomValidator " + validator.getName());
}
@Override
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.etrice.abstractexec.behavior.tests/META-INF/MANIFEST.MF
index b294487..227d9b1 100644
--- a/tests/org.eclipse.etrice.abstractexec.behavior.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/META-INF/MANIFEST.MF
@@ -13,3 +13,4 @@ Require-Bundle: org.eclipse.core.runtime,
org.junit;bundle-version="4.10.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.etrice.abstractexec.behavior
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/cashTerminal.room b/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/cashTerminal.room
new file mode 100644
index 0000000..753b3bc
--- /dev/null
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/cashTerminal.room
@@ -0,0 +1,216 @@
+RoomModel CashTerminal {
+
+ ActorClass Controller {
+ Interface {
+ conjugated Port terminal:TerminalProtocol
+ conjugated Port auth:AuthProtocol
+ }
+ Structure {
+ external Port terminal
+ external Port auth
+ }
+ Behavior {
+ StateMachine{
+ Transition init: initial -> state0_sm {
+ action {
+ "auth.hello();"
+ }
+ }
+ Transition tr0: state0_sm -> offline {
+ triggers {
+ <serviceNA: auth>
+ }
+ action {
+ "terminal.showOffline();"
+ }
+ }
+ Transition tr1: state0_sm -> idle_sm {
+ triggers {
+ <hello: auth>
+ }
+ }
+ Transition tr2: idle_sm -> handleCard {
+ triggers {
+ <cardEntered: terminal>
+ }
+ }
+ Transition tr3: tp0 of handleCard -> tp0 of handlePIN
+ Transition tr4: tp1 of handlePIN -> idle_sm
+ Transition tr5: handlePIN -> idle_sm {
+ triggers {
+ <correctPIN: auth>
+ }
+ action {
+ "terminal.dispenseMoney();"
+ }
+ }
+ Transition tr6: tp1 of handleCard -> idle_sm
+ State state0_sm
+ State idle_sm {
+ entry {
+ "terminal.showWelcome();"
+ }
+ }
+ State offline
+ State handleCard {
+ subgraph {
+ Transition init: initial -> state0_sm {
+ action {
+ "auth.checkCard();"
+ }
+ }
+ Transition tr0: state0_sm -> wait_sm {
+ triggers {
+ <validCard: auth>
+ }
+ action {
+ "terminal.showPIN();"
+ }
+ }
+ Transition tr1: wait_sm -> my tp0 {
+ triggers {
+ <pinEntered: terminal>
+ }
+ }
+ Transition tr2: state0_sm -> my tp1 {
+ triggers {
+ <invalidCard: auth>
+ }
+ }
+ ExitPoint tp0
+ ExitPoint tp1
+ State state0_sm
+ State wait_sm
+ }
+ }
+ State handlePIN {
+ subgraph {
+ Transition tr0: my tp0 -> wait_sm
+ Transition tr1: wait_sm -> cp cp0 {
+ triggers {
+ <wrongPIN: auth>
+ }
+ }
+ Transition tr2: cp cp0 -> my tp1 {
+ action {
+ "terminal.confiscateCard();"
+ }
+ }
+ Transition tr3: cp cp0 -> wait_sm {
+ cond {
+ "if(count_tries < 2)"
+ }
+ }
+ ChoicePoint cp0
+ EntryPoint tp0
+ ExitPoint tp1
+ State wait_sm {
+ entry {
+ "auth.checkPIN();"
+ }
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ ActorClass AuthServer {
+ Interface {
+ Port client:AuthProtocol
+ }
+ Structure {
+ external Port client
+ }
+ Behavior {
+ StateMachine {
+ Transition tr0: cp cp0 -> error {
+ action {
+ "client.serviceNA();"
+ }
+ }
+ Transition tr2: cp cp0 -> standby {
+ cond {
+ "if(okay)"
+ }
+ action {
+ "client.hello();"
+ }
+ }
+ Transition tr4: standby -> standby {
+ triggers {
+ <checkCard: client>
+ }
+ action {
+ "if(valid)"
+ "\tclient.validCard();"
+ "else"
+ "\tinvalidCard();"
+ }
+ }
+ Transition tr5_vm: standby -> standby {
+ triggers {
+ <checkPIN: client>
+ }
+ action {
+ "if(correct)"
+ "\tclient.correctPIN();"
+ "else"
+ "\tclient.wrongPIN();"
+ }
+ }
+ Transition init: initial -> state0 { }
+ Transition tr6: state0 -> cp cp0 {
+ triggers {
+ <hello: client>
+ }
+ }
+ ChoicePoint cp0
+ State standby
+ State error
+ State state0
+ }
+ }
+ }
+
+ ProtocolClass TerminalProtocol {
+ incoming {
+ Message showWelcome()
+ Message showPIN()
+ Message confiscateCard()
+ Message dispenseMoney()
+ Message showOffline()
+
+ }
+ outgoing {
+ Message pinEntered()
+ Message cardEntered()
+ }
+ semantics {
+ in:showOffline
+ in:showWelcome->out:cardEntered->(in:showPIN->out:pinEntered->(in:dispenseMoney->in:showWelcome,in:confiscateCard->in:showWelcome),in:showWelcome)
+ }
+ }
+
+ ProtocolClass AuthProtocol {
+ incoming {
+ Message hello()
+ Message checkCard()
+ Message checkPIN()
+ }
+
+ outgoing {
+ Message validCard()
+ Message invalidCard()
+ Message correctPIN()
+ Message wrongPIN()
+ Message serviceNA()
+ Message hello()
+ }
+ semantics {
+ in:hello->(out:hello->in:checkCard->(out:validCard->in:checkPIN->(out:correctPIN, out:wrongPIN->in:checkPIN->(out:correctPIN, out:wrongPIN)), out:invalidCard), out:serviceNA)
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics.room b/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics.room
index a9b53b8..f05f407 100644
--- a/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics.room
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics.room
@@ -1,4 +1,4 @@
-RoomModel semantics {
+RoomModel Semantics {
// simple cascade
ActorClass AETest1 {
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics_basic.room b/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics_basic.room
new file mode 100644
index 0000000..b9c2981
--- /dev/null
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/models/semantics_basic.room
@@ -0,0 +1,329 @@
+RoomModel Semantics_basic {
+
+ ActorClass GroupTransition_ac {
+ Structure {
+ Port p0 : Sem_Protocol2
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 {
+ action {
+ "p0.out3();"
+ }
+ }
+ Transition tr0: state0 -> state1 {
+ triggers {
+ <in1: p0>
+ }
+ }
+ Transition tr1: state1 -> state0 {
+ triggers {
+ <in2: p0>
+ }
+ }
+ Transition tr2: state0 -> tp0 of state2 {
+ triggers {
+ <in1: p0 guard {
+ "if(true)"
+ }>
+ }
+ }
+ Transition tr3: tp1 of state2 -> state0
+ Transition tr4: state2 -> state0 {
+ triggers {
+ <in2: p0>
+ }
+ }
+ Transition tr5_vt: state2 -> state1 {
+ triggers {
+ <wrong1: p0>
+ }
+ }
+ State state0
+ State state1 {
+ subgraph {
+ Transition init: initial -> state1_0 { }
+ State state1_0 {
+ subgraph {
+ Transition init: initial -> state1_0_0_vm { }
+ State state1_0_0_vm {
+ entry {
+ "p0.out2();"
+ }
+ }
+ }
+ }
+ }
+ }
+ State state2 {
+ subgraph {
+ Transition tr0: my tp0 -> state0
+ Transition tr1: state0 -> my tp1 {
+ triggers {
+ <in2: p0 guard {
+ "if(true)"
+ }>
+ }
+ }
+ EntryPoint tp0
+ ExitPoint tp1
+ State state0
+ }
+ }
+ }
+ }
+ }
+
+ ActorClass SimpleAlternative_ac {
+ Structure {
+ Port p0 : Sem_Protocol2
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 { }
+ Transition tr0: state0 -> state1 {
+ triggers {
+ <in1: p0>
+ }
+ }
+ Transition tr1: state0 -> state2 {
+ triggers {
+ <in2: p0>
+ }
+ }
+ Transition tr2: state2 -> state3 {
+ triggers {
+ <in3: p0 guard {
+ "if(true)"
+ }>
+ }
+ }
+ Transition tr3: state1 -> state3 {
+ triggers {
+ <in3: p0>
+ }
+ }
+ Transition tr4: state3 -> state5 {
+ triggers {
+ <in1: p0>
+ }
+ }
+ Transition tr5: state3 -> state4 {
+ triggers {
+ <in2: p0>
+ }
+ }
+ Transition tr6_vt: state3 -> state6_rm {
+ triggers {
+ <in3: p0>
+ }
+ }
+ State state0 {
+ entry {
+ "p0.out1();"
+ }
+ }
+ State state1
+ State state2
+ State state3
+ State state4
+ State state5
+ State state6_rm
+ }
+ }
+ }
+
+ ActorClass TransitionsPoint_ac{
+ Structure {
+ Port p0 : Sem_Protocol2
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 {
+ action {
+ "p0.out2();"
+ }
+ }
+ Transition tr0: state0 -> state1 {
+ triggers {
+ <in1: p0>
+ }
+ }
+ Transition tr1: my tp0 -> state2 {
+ triggers {
+ <in3: p0>
+ }
+ }
+ Transition tr2: state2 -> state1 {
+ triggers {
+ <in1: p0>
+ }
+ }
+ Transition tr3_vtvm: my tp0 -> state1 {
+ triggers {
+ <in1: p0>
+ }
+ action {
+ "p0.out1();"
+ }
+ }
+ TransitionPoint tp0
+ State state0
+ State state1
+ State state2
+ }
+ }
+ }
+
+ ActorClass NoSemantics_ac{
+ Structure {
+ Port p0 : Sem_ProtocolA
+ Port p1: Dummy
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0_rm { }
+ Transition tr0: state0_rm -> state1_rm {
+ triggers {
+ <someEvent1: p1>
+ }
+ }
+ Transition tr1: state1_rm -> state0_rm {
+ triggers {
+ <someEvent2: p1>
+ }
+ }
+ State state0_rm
+ State state1_rm
+ }
+ }
+ }
+
+ ActorClass DualSemantics_ac{
+ Structure {
+ Port a: Sem_ProtocolA
+ Port b: Sem_ProtocolB
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 {
+ action {
+ "b.outB1();"
+ }
+ }
+ Transition tr0: state0 -> state1 {
+ triggers {
+ <inA1: a>
+ }
+ }
+ Transition tr1: state0 -> state2_sm {
+ triggers {
+ <inA1: a guard {
+ "if(true)"
+ }>
+ }
+ }
+ Transition tr3: state1 -> state3 {
+ triggers {
+ <inB1: b>
+ }
+ }
+ Transition tr4: state2_sm -> state3 {
+ triggers {
+ <inB1: b>
+ }
+ }
+ Transition tr2: state0 -> state0 {
+ triggers {
+ <inB1: b>
+ }
+ }
+ Transition tr5_vm: state2_sm -> state4 {
+ triggers {
+ <inB1: b guard {
+ "if(true)"
+ }>
+ }
+ action {
+ "a.outA1();"
+ }
+ }
+ State state0
+ State state1 {
+ entry {
+ "a.outA1();"
+ }
+ }
+ State state2_sm {
+ exit {
+ "a.outA1();"
+ }
+ }
+ State state3
+ State state4
+ }
+ }
+ }
+
+ ProtocolClass Sem_Protocol2 {
+ incoming {
+ Message in1()
+ Message in2()
+ Message in3()
+ Message wrong1()
+ }
+ outgoing {
+ Message out1()
+ Message out2()
+ Message out3()
+ Message wrong1()
+ }
+ semantics {
+ // TransitionPoint
+ out:out1->(in:in2->in:in3->in:in2, in:in1->in:in3->in:in1)
+ // SimpleAlternative
+ out:out2->(in:in1->in:in3->in:in1, in:in3->(in:in1, in:in3))
+ // GroupTransition
+ out:out3->in:in1->in:in2
+
+ }
+ }
+
+ ProtocolClass Sem_ProtocolA {
+ incoming {
+ Message inA1()
+ }
+ outgoing {
+ Message outA1()
+ }
+ semantics {
+ in: inA1 -> out: outA1
+ }
+ }
+
+ ProtocolClass Sem_ProtocolB {
+ incoming {
+ Message inB1()
+ }
+ outgoing {
+ Message outB1()
+ }
+ semantics {
+ out: outB1 -> in: inB1
+ }
+ }
+
+ ProtocolClass Dummy {
+ incoming {
+ Message someEvent1()
+ Message someEvent2()
+ Message someEvent3()
+ }
+ outgoing {
+ Message someEvent1()
+ Message someEvent2()
+ Message someEvent3()
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestReachability.java b/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestReachability.java
index 9490ec0..7342845 100644
--- a/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestReachability.java
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestReachability.java
@@ -18,6 +18,7 @@ import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.abstractexec.behavior.ReachabilityValidator;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.RoomModel;
@@ -32,8 +33,6 @@ import org.junit.Test;
public class TestReachability extends TestBase {
- public static String DIAG_CODE_UNREACHABLE = "etrice.unreachable";
-
private RoomModel model = null;
@Before
@@ -49,18 +48,18 @@ public class TestReachability extends TestBase {
Set<StateGraphItem> items = new HashSet<StateGraphItem>();
for (ActorClass ac : model.getActorClasses()) {
- if(ac.getStateMachine() == null)
+ if (ac.getStateMachine() == null)
continue;
TreeIterator<EObject> iter = ac.getStateMachine().eAllContents();
- while(iter.hasNext()){
+ while (iter.hasNext()) {
EObject obj = iter.next();
- if(obj instanceof StateGraphItem)
- items.add((StateGraphItem)obj);
+ if (obj instanceof StateGraphItem)
+ items.add((StateGraphItem) obj);
}
}
for (AbstractValidationDiagnostic d : getIssueCode2diagnostic().get(
- DIAG_CODE_UNREACHABLE)) {
+ ReachabilityValidator.DIAG_CODE_UNREACHABLE)) {
if (d instanceof FeatureBasedDiagnostic) {
FeatureBasedDiagnostic dx = (FeatureBasedDiagnostic) d;
StateGraph graph = (StateGraph) dx.getSourceEObject();
@@ -79,24 +78,28 @@ public class TestReachability extends TestBase {
for (StateGraphItem item : items) {
if (item instanceof InitialTransition) {
- if(item.eContainer().eContainer() instanceof ActorClass)
+ if (item.eContainer().eContainer() instanceof ActorClass)
continue;
State container = (State) item.eContainer().eContainer();
- Assert.assertTrue(item + " is NOT marked Unreachable (or name doesn't end with '_1' ?)",
+ Assert.assertTrue(
+ item + " is NOT marked Unreachable (or name doesn't end with '_1' ?)",
container.getName().endsWith("_1"));
} else
- Assert.assertTrue(item + " is NOT marked Unreachable (or name doesn't end with '_1' ?)", item
- .getName().endsWith("_1"));
+ Assert.assertTrue(
+ item + " is NOT marked Unreachable (or name doesn't end with '_1' ?)",
+ item.getName().endsWith("_1"));
}
}
private void checkUnreachable(StateGraphItem item) {
if (item instanceof InitialTransition) {
State container = (State) item.eContainer().eContainer();
- Assert.assertTrue(item + " is incorrectly marked UNreachable (or name doesn't end with '_0' ?)",
+ Assert.assertTrue(
+ item + " is incorrectly marked UNreachable (or name doesn't end with '_0' ?)",
container.getName().endsWith("_0"));
} else
- Assert.assertTrue(item + " is incorrectly marked UNreachable (or name doesn't end with '_0' ?)", item
- .getName().endsWith("_0"));
+ Assert.assertTrue(
+ item + " is incorrectly marked UNreachable (or name doesn't end with '_0' ?)",
+ item.getName().endsWith("_0"));
}
}
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemanticValidation.java b/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemanticValidation.java
index d02843a..4019deb 100644
--- a/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemanticValidation.java
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemanticValidation.java
@@ -13,8 +13,6 @@
package org.eclipse.etrice.abstractexec.behavior.tests;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
import org.junit.Before;
import org.junit.Test;
@@ -24,6 +22,7 @@ import org.junit.Test;
*/
public class TestSemanticValidation extends TestBase {
+ @SuppressWarnings("unused")
private static final String MSG1 = "replace this with the expected error/Warning message";
@Before
@@ -33,8 +32,8 @@ public class TestSemanticValidation extends TestBase {
@Test
public void testSomething() {
- assertEquals("number of infos", 0, getInfoMsgToDiagnostic().size());
- assertEquals("number of warnings", 0, getWarningMsgToDiagnostic().size());
+ assertEquals("number of infos", 2, getInfoMsgToDiagnostic().size());
+ assertEquals("number of warnings", 3, getWarningMsgToDiagnostic().size());
// assertEquals("number of errors", 1, getErrorMsgToDiagnostic().size());
// assertNotNull(MSG1, getErrorMsgToDiagnostic().get(MSG1));
// further checks for all other messages...
diff --git a/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemantics.java b/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemantics.java
new file mode 100644
index 0000000..b7d6e86
--- /dev/null
+++ b/tests/org.eclipse.etrice.abstractexec.behavior.tests/src/org/eclipse/etrice/abstractexec/behavior/tests/TestSemantics.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.abstractexec.behavior.tests;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.abstractexec.behavior.AbstractExecutionValidator;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.core.room.StateGraphItem;
+import org.eclipse.etrice.core.room.Transition;
+import org.eclipse.etrice.core.room.Trigger;
+import org.eclipse.xtext.validation.AbstractValidationDiagnostic;
+import org.eclipse.xtext.validation.FeatureBasedDiagnostic;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestSemantics {
+
+ public enum DiagCode {
+ DIAG_CODE_VIOLATION_TRIGGER(
+ AbstractExecutionValidator.DIAG_CODE_VIOLATION_TRIGGER, "vt"), DIAG_CODE_VIOLATION_MESSAGESEND(
+ AbstractExecutionValidator.DIAG_CODE_VIOLATION_MESSAGESEND,
+ "vm"), DIAG_CODE_MISSING_TRIGGER(
+ AbstractExecutionValidator.DIAG_CODE_MISSING_TRIGGER, "rm"), DIAG_CODE_MISSING_MESSAGESEND(
+ AbstractExecutionValidator.DIAG_CODE_MISSING_MESSAGESEND, "sm");
+
+ public String diagCode, shortCut;
+
+ DiagCode(String diagCode, String shortcut) {
+ this.diagCode = diagCode;
+ this.shortCut = shortcut;
+ }
+ }
+
+ String PATTERN = ".*_("
+ + DiagCode.DIAG_CODE_VIOLATION_TRIGGER.shortCut + "|"
+ + DiagCode.DIAG_CODE_VIOLATION_MESSAGESEND.shortCut + "|"
+ + DiagCode.DIAG_CODE_MISSING_MESSAGESEND.shortCut + "|"
+ + DiagCode.DIAG_CODE_MISSING_TRIGGER.shortCut + ")+";
+
+ TestBase basic, cashTerminal, current = null;
+
+ @Before
+ public void setUp() {
+ basic = new TestBase();
+ basic.prepare("semantics_basic.room");
+ cashTerminal = new TestBase();
+ cashTerminal.prepare("cashTerminal.room");
+
+ }
+
+ @Test
+ public void test() {
+ for (TestBase test : new TestBase[] { basic, cashTerminal }) {
+ current = test;
+
+ Set<StateGraphItem> items = new HashSet<StateGraphItem>();
+ for (ActorClass ac : current.getRoomModel().getActorClasses()) {
+ if (ac.getStateMachine() == null)
+ continue;
+ TreeIterator<EObject> iter = ac.getStateMachine()
+ .eAllContents();
+ while (iter.hasNext()) {
+ EObject obj = iter.next();
+ if (obj instanceof StateGraphItem)
+ items.add((StateGraphItem) obj);
+ }
+ }
+
+ for (DiagCode marker : DiagCode.values())
+ if (test.getIssueCode2diagnostic().containsKey(marker.diagCode))
+ for (AbstractValidationDiagnostic d : test
+ .getIssueCode2diagnostic().get(marker.diagCode))
+ if (d instanceof FeatureBasedDiagnostic)
+ checkDiagnostic((FeatureBasedDiagnostic) d, marker,
+ items);
+
+ for (StateGraphItem item : items) {
+ Assert.assertTrue(item + " does not have warnings", !item
+ .getName().matches(".*_(vt|vm|rm|sm)+"));
+ }
+ }
+
+ }
+
+ private void checkDiagnostic(FeatureBasedDiagnostic d, DiagCode marker,
+ Set<StateGraphItem> items) {
+ EObject container = d.getSourceEObject();
+ if (container instanceof StateGraph) {
+ Object feature = container.eGet(d.getFeature());
+ if (feature instanceof EList) {
+ EList<?> list = (EList<?>) feature;
+ Object source = list.get(d.getIndex());
+ if (source instanceof StateGraphItem) {
+ checkItem(((StateGraphItem) source).getName(), marker);
+ items.remove(source);
+ }
+ }
+ } else if (container instanceof Trigger) {
+ if (container.eContainer() instanceof Transition) {
+ checkItem(((Transition) container.eContainer()).getName(),
+ marker);
+ items.remove(container.eContainer());
+ } else
+ Assert.fail("unexpected test object: " + container.eContainer());
+ } else if (container instanceof Transition) {
+ checkItem(((Transition) container).getName(), marker);
+ items.remove(container);
+ } else if (container instanceof State) {
+ checkItem(((State) container).getName(), marker);
+ items.remove(container);
+ } else
+ Assert.fail("unexpected test object: " + container);
+ }
+
+ private void checkItem(String name, DiagCode diagCode) {
+ int begin = name.lastIndexOf("_");
+ String errorCodes = "";
+ if (begin != -1)
+ errorCodes = name.substring(begin);
+ Assert.assertTrue("Missing warning (" + diagCode.diagCode
+ + ") for item " + name + " ("
+ + current.getRoomModel().getName() + ")",
+ errorCodes.contains(diagCode.shortCut));
+ }
+}