Forráskód Böngészése

adding private port tests and discovered a mistake in the creation of private outports, now fixed

sampieters 1 éve
szülő
commit
600b9b5dd8

+ 1 - 0
README.md

@@ -202,5 +202,6 @@ A window can also be deleted by clicking on the close window button on the top r
 ## TODO
 - [] Create elevator balls example
 - [] Fix bug in narrow cast for testing framework
+- maybe add private ports tests
 - [] Check paper
 - [] Send in paper, FINALLY!

+ 17 - 4
sccd/compiler/DEVS_generator.py

@@ -266,9 +266,13 @@ class DEVSGenerator(Visitor):
                                       GLC.FunctionCall(GLC.SelfProperty("addInPort"), [GLC.String(p)]))
 
         for p in class_node.outports:
-            self.writer.addAssignment(
-                GLC.MapIndexedExpression(GLC.SelfProperty("outports"), GLC.String(p)),
-                GLC.FunctionCall(GLC.Property("controller", "addOutputPort"), [GLC.String(p), GLC.SelfExpression()]))
+            self.writer.addAssignment(GLC.SelfProperty(p),
+                                      GLC.FunctionCall(GLC.SelfProperty("addOutPort"), [GLC.String(p)]))
+
+        #for p in class_node.outports:
+        #    self.writer.addAssignment(
+        #        GLC.MapIndexedExpression(GLC.SelfProperty("outports"), GLC.String(p)),
+        #        GLC.FunctionCall(GLC.Property("controller", "addOutputPort"), [GLC.String(p), GLC.SelfExpression()]))
 
         if class_node.name == class_node.class_diagram.default_class.name:
             self.writer.addAssignment("new_instance", GLC.SelfProperty("constructObject(0, 0, [])"))
@@ -373,11 +377,20 @@ class DEVSGenerator(Visitor):
         self.writer.addAssignment("port_name", GLC.FunctionCall("addInputPort", [GLC.String("<narrow_cast>"), "start_port_id"]))
         self.writer.addAssignment("atomdevs.state.port_mappings[port_name]", "id")
 
+        total_ports = 0
         for index, inp in enumerate(constructor.parent_class.inports):
-            self.writer.addAssignment("port_name", GLC.FunctionCall("addInputPort", [GLC.String(inp), f"start_port_id + {index + 1}"]))
+            total_ports += 1
+            self.writer.addAssignment("port_name", GLC.FunctionCall("addInputPort", [GLC.String(inp), f"start_port_id + {total_ports}"]))
             self.writer.addAssignment("atomdevs.state.port_mappings[port_name]", "id")
             self.writer.addAssignment(GLC.SelfProperty(f"inports[\"{inp}\"]"), "port_name")
 
+        for index, inp in enumerate(constructor.parent_class.outports):
+            total_ports += 1
+            self.writer.addAssignment("port_name", GLC.FunctionCall("addOutputPort", [GLC.String(inp), f"start_port_id + {total_ports}"]))
+            self.writer.addAssignment("atomdevs.state.port_mappings[port_name]", "id")
+            self.writer.addAssignment(GLC.SelfProperty(f"outports[\"{inp}\"]"), "port_name")
+
+
         self.writer.endMethodBody()
         self.writer.endConstructor()
 

+ 1 - 1
sccd/runtime/DEVS_statecharts_core.py

@@ -625,7 +625,7 @@ class ClassBase(AtomicDEVS):
                 to_dict[self.obj_manager_out] = sending
             else:
                 # Get the port to sent to the outside of the simulation
-                the_port = next((port for port in self.OPorts if port.name == sending.port), None)
+                the_port = next((port for port in self.OPorts if port.name == DEVSutils.get_general_port(sending.port)), None)
                 to_dict[the_port] = sending
         return to_dict
     

tests/6.0) MultipleFiles/config.json → tests/0.0) PrivatePortInputTest/config.json


+ 3 - 0
tests/0.0) PrivatePortInputTest/expected_trace.txt

@@ -0,0 +1,3 @@
+0.50 MainApp: exit /state1
+0.50 MainApp: transition (/state1 -> /state2)
+0.50 MainApp: enter /state2

+ 1 - 0
tests/0.0) PrivatePortInputTest/input.txt

@@ -0,0 +1 @@
+0.5 (event name: priv_event; port: private_1_priv_port; parameters: [])

+ 15 - 0
tests/0.0) PrivatePortInputTest/sccd.xml

@@ -0,0 +1,15 @@
+<?xml version="1.1" ?>
+<diagram author="Sam Pieters" name="InputPrivatePortTest">
+    <description>
+        Classes could have a private port, check if this port can receive events.
+    </description>
+    <class name="MainApp" default="true">
+        <inport name="priv_port"/>
+        <scxml initial="state1">
+            <state id="state1">
+                <transition port="priv_port" event="priv_event" target="../state2" />
+            </state>
+            <state id="state2" />
+        </scxml>
+    </class>
+</diagram>

+ 3 - 0
tests/0.1) PrivatePortOutputTest/config.json

@@ -0,0 +1,3 @@
+{
+    "trace": ["statechart", "external"]
+}

+ 1 - 0
tests/0.1) PrivatePortOutputTest/expected_trace.txt

@@ -0,0 +1 @@
+0.00 (event name: priv_event; port: private_2_priv_port)

+ 18 - 0
tests/0.1) PrivatePortOutputTest/sccd.xml

@@ -0,0 +1,18 @@
+<?xml version="1.1" ?>
+<diagram author="Sam Pieters" name="InputPrivatePortTest">
+    <description>
+        Classes could have a private port, check if this port can receive events.
+    </description>
+    <class name="MainApp" default="true">
+        <inport name="check" />
+        <outport name="priv_port"/>
+        <scxml initial="state1">
+            <state id="state1">
+                <onentry>
+                    <raise port="priv_port" event="priv_event" />
+                </onentry>
+            </state>
+            <state id="state2" />
+        </scxml>
+    </class>
+</diagram>

tests/5.0) Inheritance/expected_trace.txt → tests/6.0) Inheritance/expected_trace.txt


tests/5.0) Inheritance/sccd.xml → tests/6.0) Inheritance/sccd.xml


tests/6.0) MultipleFiles/classes/A.xml → tests/7.0) MultipleFiles/classes/A.xml


tests/6.0) MultipleFiles/classes/B.xml → tests/7.0) MultipleFiles/classes/B.xml


+ 3 - 0
tests/7.0) MultipleFiles/config.json

@@ -0,0 +1,3 @@
+{
+    "trace": "statechart"
+}

tests/6.0) MultipleFiles/expected_trace.txt → tests/7.0) MultipleFiles/expected_trace.txt


tests/6.0) MultipleFiles/sccd.xml → tests/7.0) MultipleFiles/sccd.xml