Ver código fonte

Merge branch 'testing' into powerwindow

Yentl Van Tendeloo 8 anos atrás
pai
commit
5e5d3dec5e

+ 14 - 7
bootstrap/conformance_scd.alc

@@ -263,13 +263,20 @@ String function conformance_scd(model : Element):
 			if (result != "OK"):
 				return ((("Complex attribute doesn't match for: " + complex_instance) + "\n Message: ") + result)!
 
-	// Structure seems fine, now do static semantics
-	if (dict_in(metamodel, "constraints")):
-		Element constraint_function
-		constraint_function = metamodel["constraints"]
-		return constraint_function(model)!
-	else:
-		return "OK"!
+	// Structure seems fine, now do global constraints
+	Element global_constraints
+	String constraint
+	Element func
+
+	global_constraints = allInstances(model, "GlobalConstraints")
+	while (read_nr_out(global_constraints) > 0):
+		constraint = set_pop(global_constraints)
+		func = get_func_AL_model(import_node(read_attribute(model, constraint, "global_constraint")))
+		result = func(model)
+		if (result != "OK"):
+			return result!
+
+	return "OK"!
 
 String function check_location_conformance(instance_location : String, type_location : String):
 	// Check whether the instance is typed by the type

+ 3 - 0
bootstrap/metamodels.alc

@@ -136,6 +136,9 @@ Element function initialize_SCD(location : String):
 	instantiate_attribute_code(scd, "Location", "constraint", constraint_Location)
 	instantiate_attribute_code(scd, "ActionLanguage", "constraint", constraint_ActionLanguage)
 
+	instantiate_node(scd, "Class", "GlobalConstraint")
+	model_define_attribute(scd, "GlobalConstraint", "global_constraint", False, "ActionLanguage")
+
 	return scd!
 
 Element function initialize_PN(location_SCD : String, location_PN : String):

+ 13 - 9
bootstrap/object_operations.alc

@@ -11,17 +11,21 @@ Element function allInstances(model : Element, type_name : String):
 	Element keys
 
 	keys = dict_keys(model["model"])
-	type = model["metamodel"]["model"][type_name]
-	result = create_node()
+	if (dict_in(model["metamodel"]["model"], type_name)):
+		type = model["metamodel"]["model"][type_name]
+		result = create_node()
 
-	// TODO more efficient to work backwards: find all instances of an element through the type mapping directly
-	//      must then take into account all inheritance links ourselves...
-	while (0 < list_len(keys)):
-		key = set_pop(keys)
-		if (is_nominal_instance(model, key, type_name)):
-			set_add(result, key)
+		// TODO more efficient to work backwards: find all instances of an element through the type mapping directly
+		//      must then take into account all inheritance links ourselves...
+		while (0 < list_len(keys)):
+			key = set_pop(keys)
+			if (is_nominal_instance(model, key, type_name)):
+				set_add(result, key)
 
-	return result!
+		return result!
+	else:
+		log("No such type in the metamodel!")
+		return create_node()!
 
 Element function selectPossibleIncoming(model : Element, target : String, limit_set : Element):
 	// Find all possible incoming link types for the target model

+ 27 - 20
hybrid_server/classes/mvkcontroller.xml

@@ -213,23 +213,22 @@
                 </state>
             </state>
 
-            <state id="execution">
+            <state id="execution" initial="execution">
                 <state id="execution">
                     <onentry>
                         <script>
+                            self.outputs = []
                             self.timeout = False
-                            self.destination = None
                             if self.tasks:
                                 task = self.tasks.pop()
                                 if not task in self.debugged_tasks or self.debug_info[task]['state'] == 'running':
                                     # Check if there are values to input
-                                    if self.input_queue[task]:
+                                    while self.input_queue[task]:
                                         source, args = self.input_queue[task].pop(0)
                                         for args_entry in args:
                                             self.execute_modelverse(task, "set_input", [args_entry])
 
-                                        self.destination = source
-                                        self.value = "OK"
+                                        self.outputs.append((source, "OK"))
                                         self.all_failed = False
 
                                     nr_of_steps = 1 if task in self.debugged_tasks else 100
@@ -244,15 +243,14 @@
                                         # Could at least execute one instruction, so mark it as "not failed"
                                         self.all_failed = False
 
-                                    # Check that we don't have anything to output yet, otherwise we wait
-                                    if self.destination is None:
-                                        # Perform output if there is anything
-                                        if self.output_queue[task]:
-                                            self.execute_modelverse(task, "get_output", [])
-                                            if self.mvk.success:
-                                                self.destination = self.output_queue[task].pop(0)
-                                                self.value = self.mvk.returnvalue
-                                                self.all_failed = False
+                                    # Perform output if there is anything
+                                    while self.output_queue[task]:
+                                        self.execute_modelverse(task, "get_output", [])
+                                        if self.mvk.success:
+                                            self.outputs.append((self.output_queue[task].pop(0), self.mvk.returnvalue))
+                                            self.all_failed = False
+                                        else:
+                                            break
 
                             else:
                                 if self.count >= 2000:
@@ -276,15 +274,24 @@
                         </script>
                     </onentry>
 
-                    <transition cond="self.destination is not None" after="self.sccd_yield()" target=".">
-                        <raise event="HTTP_input" scope="narrow" target="'to_mvi/%s' % self.destination">
-                            <parameter expr="json.dumps(self.value)"/>
+                    <transition cond="self.outputs" after="self.sccd_yield()" target="../process_data"/>
+
+                    <transition cond="self.timeout and not self.outputs" after="self.sccd_yield() + 0.10" target="."/>
+
+                    <transition cond="not self.timeout and not self.outputs" after="self.sccd_yield()" target="."/>
+                </state>
+
+                <state id="process_data">
+                    <transition cond="self.outputs" target=".">
+                        <script>
+                            destination, value = self.outputs.pop()
+                        </script>
+                        <raise event="HTTP_input" scope="narrow" target="'to_mvi/%s' % destination">
+                            <parameter expr="json.dumps(value)"/>
                         </raise>
                     </transition>
 
-                    <transition cond="self.timeout and self.destination is None" after="self.sccd_yield() + 0.10" target="."/>
-
-                    <transition cond="not self.timeout and self.destination is None" after="self.sccd_yield()" target="."/>
+                    <transition cond="not self.outputs" target="../execution"/>
                 </state>
             </state>
 

+ 2 - 10
integration/test_binary2decimal.py

@@ -2,16 +2,8 @@ import unittest
 
 from utils import run_file
 
-
 class TestBinary2Decimal(unittest.TestCase):
-    def test_po_binary2decimal(self):
-        self.binary2decimal("PO")
-
-    def test_co_binary2decimal(self):
-        self.binary2decimal("CO")
-
-    def binary2decimal(self, mode):
+    def test_binary2decimal(self):
         self.assertTrue(run_file(["binary_to_decimal.alc", "primitives.alc"],
             ["1", "10", "11", "100", "001", "1100111101"],
-            [1, 2, 3, 4, 1, 829],
-            mode))
+            [1, 2, 3, 4, 1, 829]))

+ 2 - 10
integration/test_factorial.py

@@ -2,16 +2,8 @@ import unittest
 
 from utils import run_file
 
-
 class TestFactorial(unittest.TestCase):
-    def test_po_factorial(self):
-        self.factorial("PO")
-
-    def test_co_factorial(self):
-        self.factorial("CO")
-
-    def factorial(self, mode):
+    def test_factorial(self):
         self.assertTrue(run_file(["factorial.alc", "primitives.alc"],
             [1, 2, 3, 4, 20],
-            [1, 2, 6, 24, 2432902008176640000],
-            mode))
+            [1, 2, 6, 24, 2432902008176640000]))

+ 2 - 9
integration/test_fibonacci.py

@@ -4,14 +4,7 @@ from utils import run_file
 
 
 class TestFibonacci(unittest.TestCase):
-    def test_po_fibonacci(self):
-        self.fibonacci("PO")
-
-    def test_co_fibonacci(self):
-        self.fibonacci("CO")
-
-    def fibonacci(self, mode):
+    def test_fibonacci(self):
         self.assertTrue(run_file(["fibonacci.alc", "primitives.alc"],
             [1, 2, 3, 4],
-            [1, 1, 2, 3],
-            mode))
+            [1, 1, 2, 3]))

+ 2 - 10
integration/test_fibonacci_smart.py

@@ -2,16 +2,8 @@ import unittest
 
 from utils import run_file
 
-
 class TestFibonacciSmart(unittest.TestCase):
-    def test_po_fibonacci_smart(self):
-        self.fibonacci_smart("PO")
-
-    def test_co_fibonacci_smart(self):
-        self.fibonacci_smart("CO")
-
-    def fibonacci_smart(self, mode):
+    def test_fibonacci_smart(self):
         self.assertTrue(run_file(["fibonacci_smart.alc", "primitives.alc"],
             [1, 2, 3, 4, 5, 6, 7, 8],
-            [1, 1, 2, 3, 5, 8, 13, 21],
-            mode))
+            [1, 1, 2, 3, 5, 8, 13, 21]))

+ 4 - 18
integration/test_if_elif.py

@@ -4,26 +4,12 @@ from utils import run_file
 
 
 class TestIfElif(unittest.TestCase):
-    def test_po_if_elif_else(self):
-        self.if_elif_else("PO")
-
-    def test_co_if_elif_else(self):
-        self.if_elif_else("CO")
-
-    def if_elif_else(self, mode):
+    def test_if_elif_else(self):
         self.assertTrue(run_file(["if_elif_else.alc", "primitives.alc"],
             [-1, 10, 11, 0, 1, 0, -100],
-            [-1, 1, 1, 0, 1, 0, -1],
-            mode))
-
-    def test_po_if_elif(self):
-        self.if_elif("PO")
-
-    def test_co_if_elif(self):
-        self.if_elif("CO")
+            [-1, 1, 1, 0, 1, 0, -1]))
 
-    def if_elif(self, mode):
+    def test_if_elif(self):
         self.assertTrue(run_file(["if_elif.alc", "primitives.alc"],
                                  [-1, 10, 11, 0, 1, 0, -100],
-                                 [-1, 1, 1, 0, 1, 0, -1],
-                                 mode))
+                                 [-1, 1, 1, 0, 1, 0, -1]))

+ 2 - 9
integration/test_leap_year.py

@@ -4,14 +4,7 @@ from utils import run_file
 
 
 class TestLeapYear(unittest.TestCase):
-    def test_po_leap_year(self):
-        self.leap_year("PO")
-
-    def test_co_leap_year(self):
-        self.leap_year("CO")
-
-    def leap_year(self, mode):
+    def test_leap_year(self):
         self.assertTrue(run_file(["leap_year.alc", "primitives.alc"],
             [2016, 2015, 2014, 2013, 2012, 2001, 2000, 1999],
-            [True, False, False, False, True, False, False, False],
-            mode))
+            [True, False, False, False, True, False, False, False]))

+ 2 - 9
integration/test_main.py

@@ -4,14 +4,7 @@ from utils import run_file
 
 
 class TestMain(unittest.TestCase):
-    def test_po_main(self):
-        self.main("PO")
-
-    def test_co_main(self):
-        self.main("CO")
-
-    def main(self, mode):
+    def test_main(self):
         self.assertTrue(run_file(["main.alc", "primitives.alc"],
             [],
-            ["Hello, world!", "Hello, world!", "Hello, world!"],
-            mode))
+            ["Hello, world!", "Hello, world!", "Hello, world!"]))

+ 24 - 75
integration/test_mvc.py

@@ -20,13 +20,7 @@ all_files = [   "core/mini_modify.alc",
             ]
 
 class TestModelverseCore(unittest.TestCase):
-    def test_po_list(self):
-        self.list("PO")
-
-    def test_co_list(self):
-        self.list("CO")
-
-    def list(self, mode):
+    def test_list(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_list",
@@ -42,13 +36,9 @@ class TestModelverseCore(unittest.TestCase):
                      "  CoreFormalism : SimpleClassDiagrams",
                      "  ActionLanguage : SimpleClassDiagrams",
                      "  core : CoreFormalism"]),
-            ],
-            mode))
+            ]))
 
-    def test_po_list_full(self):
-        self.list_full("PO")
-
-    def list_full(self, mode):
+    def test_list_full(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_list_full",
@@ -64,13 +54,9 @@ class TestModelverseCore(unittest.TestCase):
                      "  221  root admin   CoreFormalism : SimpleClassDiagrams",
                      "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
-            ],
-            mode))
-
-    def test_po_model_add_empty(self):
-        self.model_add_empty("PO")
+            ]))
 
-    def model_add_empty(self, mode):
+    def test_model_add_empty(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -104,13 +90,9 @@ class TestModelverseCore(unittest.TestCase):
                      "  200  root nobody   Empty : SimpleClassDiagrams",
                      "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
-            ],
-            mode))
-
-    def test_po_model_empty_modify(self):
-        self.model_empty_modify("PO")
+            ]))
 
-    def model_empty_modify(self, mode):
+    def test_model_empty_modify(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -167,13 +149,9 @@ class TestModelverseCore(unittest.TestCase):
                      "  200  root nobody   Empty : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
-            ],
-            mode))
+            ]))
 
-    def test_po_model_overwrite(self):
-        self.model_overwrite("PO")
-
-    def model_overwrite(self, mode):
+    def test_model_overwrite(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -258,13 +236,9 @@ class TestModelverseCore(unittest.TestCase):
                      "  C : Class"]),
                 "Please give your command.",
                 "Ready for command...",
-            ],
-            mode))
-
-    def test_po_transform_add_MT_language(self):
-        self.transform_add_MT_language("PO")
+            ]))
 
-    def transform_add_MT_language(self, mode):
+    def test_transform_add_MT_language(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -308,13 +282,9 @@ class TestModelverseCore(unittest.TestCase):
                      "  221  root admin   ActionLanguage : SimpleClassDiagrams",
                      "  200  root admin   core : CoreFormalism"]),
                 "Ready for command...",
-            ],
-            mode))
-
-    def test_po_transform_add_MT_instance(self):
-        self.transform_add_MT_instance("PO")
+            ]))
 
-    def transform_add_MT_instance(self, mode):
+    def test_transform_add_MT_instance(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -394,13 +364,9 @@ class TestModelverseCore(unittest.TestCase):
                 set(["  200  root nobody   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
                     ]),
                 "Ready for command...",
-            ],
-            mode))
+            ]))
 
-    def test_po_transform_add_MT_pn_print_upload(self):
-        self.transform_add_MT_pn_print_upload("PO")
-
-    def transform_add_MT_pn_print_upload(self, mode):
+    def test_transform_add_MT_pn_print_upload(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -466,13 +432,9 @@ class TestModelverseCore(unittest.TestCase):
                 set(["  200  root nobody   [ModelTransformation] PetriNets_Print : PetriNets_RAM"
                     ]),
                 "Ready for command...",
-            ],
-            mode))
-
-    def test_po_transform_add_MT_pn_print_exec(self):
-        self.transform_add_MT_pn_print_exec("PO")
+            ]))
 
-    def transform_add_MT_pn_print_exec(self, mode):
+    def test_transform_add_MT_pn_print_exec(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -562,13 +524,9 @@ class TestModelverseCore(unittest.TestCase):
                     ]),
                 "Transformation executed with result: True",
                 "Ready for command...",
-            ],
-            mode))
-
-    def test_po_transform_add_MT_pn_simulate(self):
-        self.transform_add_MT_pn_simulate("PO")
+            ]))
 
-    def transform_add_MT_pn_simulate(self, mode):
+    def test_transform_add_MT_pn_simulate(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -871,14 +829,10 @@ class TestModelverseCore(unittest.TestCase):
                     ]),
                 "Transformation executed with result: True",
                 "Ready for command...",
-            ],
-            mode))
+            ]))
 
     @slow
-    def test_po_transform_add_MT_pn_simulate_larger(self):
-        self.transform_add_MT_pn_simulate_larger("PO")
-
-    def transform_add_MT_pn_simulate_larger(self, mode):
+    def test_transform_add_MT_pn_simulate_larger(self):
         def step_and_print():
             return [ \
                 # transformation_execute (pn_step)
@@ -1187,13 +1141,9 @@ class TestModelverseCore(unittest.TestCase):
                 "Ready for command...",
                 ] + \
                     step_and_print() * 10 +
-                [],
-            mode))
-
-    def test_po_transform_add_AL_pn_simulate(self):
-        self.transform_add_AL_pn_simulate("PO")
+                []))
 
-    def transform_add_AL_pn_simulate(self, mode):
+    def test_transform_add_AL_pn_simulate(self):
         self.assertTrue(run_file(all_files,
             [ "root", "root", "root", 
                 "model_add",
@@ -1488,5 +1438,4 @@ class TestModelverseCore(unittest.TestCase):
                     ]),
                 "Transformation executed with result: True",
                 "Ready for command...",
-            ],
-            mode))
+            ]))

+ 2 - 8
integration/test_power.py

@@ -4,13 +4,7 @@ from utils import run_file
 
 
 class TestPower(unittest.TestCase):
-    def test_po_power(self):
-        self.power("PO")
-
-    def test_cs_power(self):
-        self.power("CO")
-
-    def power(self, mode):
+    def test_power(self):
         self.assertTrue(run_file(["power.alc", "primitives.alc"],
             [1, 0, 2, 1, 5, 0, 2, 2, 3, 2, 10, 2, 10, 10],
-            [1, 2, 1, 4, 9, 100, 10000000000], mode))
+            [1, 2, 1, 4, 9, 100, 10000000000]))

+ 2 - 9
integration/test_remainder.py

@@ -2,15 +2,8 @@ import unittest
 
 from utils import run_file
 
-
 class TestRemainder(unittest.TestCase):
-    def test_po_remainder(self):
-        self.remainder("PO")
-
-    def test_cs_remainder(self):
-        self.remainder("CO")
-
-    def remainder(self, mode):
+    def test_remainder(self):
         self.assertTrue(run_file(["remainder.alc", "primitives.alc"],
             [1, 2, 20, 2, 99, 100, 17, 3],
-            [1, 0, 99, 2], mode))
+            [1, 0, 99, 2]))

+ 2 - 10
integration/test_revert.py

@@ -2,16 +2,8 @@ import unittest
 
 from utils import run_file
 
-
 class TestRevert(unittest.TestCase):
-    def test_po_revert(self):
-        self.revert("PO")
-
-    def test_cs_revert(self):
-        self.revert("CO")
-
-    def revert(self, mode):
+    def test_revert(self):
         self.assertTrue(run_file(["revert.alc", "primitives.alc"],
             ["abc", "defghi", "This is a very simple test case!", "abccba"],
-            ["cba", "ihgfed", "!esac tset elpmis yrev a si sihT", "abccba"],
-            mode))
+            ["cba", "ihgfed", "!esac tset elpmis yrev a si sihT", "abccba"]))

+ 6 - 7
integration/utils.py

@@ -97,7 +97,7 @@ def compile_file(address, mod_filename, filename, mode, proc):
         except UnboundLocalError:
             pass
 
-def run_file(files, parameters, expected, mode, wait=False):
+def run_file(files, parameters, expected, wait=False):
     # Resolve file
     import os.path
 
@@ -131,7 +131,7 @@ def run_file(files, parameters, expected, mode, wait=False):
                 model_mode = "MO"
                 mod_files.remove(mod_filename)
             else:
-                model_mode = mode
+                model_mode = "PO"
             if parallel_push:
                 import threading
                 threads.append(threading.Thread(target=compile_file, args=[address, mod_filename, mod_filename, model_mode, proc]))
@@ -143,11 +143,10 @@ def run_file(files, parameters, expected, mode, wait=False):
             for t in threads:
                 t.join()
 
-        if mode[-1] == "O":
-            # Fire up the linker
-            val = execute("link_and_load", [address, taskname] + mod_files, wait=True)
-            if val != 0:
-                raise Exception("Linking error")
+        # Fire up the linker
+        val = execute("link_and_load", [address, taskname] + mod_files, wait=True)
+        if val != 0:
+            raise Exception("Linking error")
 
         # Send the request ...
         flush_data(address, parameters)