Browse Source

Patched up the remainder of the Power Window for Windows

Yentl Van Tendeloo 3 years ago
parent
commit
2ec870d4fd
1 changed files with 77 additions and 62 deletions
  1. 77 62
      integration/test_powerwindow.py

+ 77 - 62
integration/test_powerwindow.py

@@ -8,6 +8,8 @@ import shutil
 sys.path.append("wrappers")
 from modelverse import *
 import threading
+import uuid
+import glob
 
 def traceability_CTRL2EPN(model):
     instantiate(model, "Association", ("PW_Control/State", "Encapsulated_PetriNet/Place"), ID="CTRL2EPN_link")
@@ -24,6 +26,69 @@ def traceability_EPN2PN(model):
     instantiate(model, "Association", ("Encapsulated_PetriNet/Place", "PetriNet/Place"), ID="EPN2PN_transition_link")
     instantiate(model, "Association", ("Encapsulated_PetriNet/Transition", "PetriNet/Transition"), ID="EPN2PN_place_link")
 
+def upload_req_debug(model):
+    model_overwrite(model, open("models/PowerWindow/models/requirements.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/req_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 11
+
+def upload_plant_debug(model):
+    model_overwrite(model, open("models/PowerWindow/models/plant.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/plant_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 11
+
+def upload_env_debug(model):
+    model_overwrite(model, open("models/PowerWindow/models/environment.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/env_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 11
+
+def upload_ctrl_debug(model):
+    if (len(glob.glob(".TEST_POWER_WINDOW/ctrl_*")) == 0):
+        model_overwrite(model, open("models/PowerWindow/models/control_wrong.mvc", "r").read())
+    else:
+        model_overwrite(model, open("models/PowerWindow/models/control.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/ctrl_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 11
+
+def upload_query_debug(model):
+    model_overwrite(model, open("models/SafetyQuery/models/powerwindow_safe.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/query_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 11
+
+def upload_arch_debug(model):
+    model_overwrite(model, open("models/PowerWindow/models/architecture.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/arch_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 11
+
+def upload_req_fast(model):
+    model_overwrite(model, open("models/PowerWindow/models/requirements.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/req_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 6
+
+def upload_plant_fast(model):
+    model_overwrite(model, open("models/PowerWindow/models/plant.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/plant_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 6
+
+def upload_env_fast(model):
+    model_overwrite(model, open("models/PowerWindow/models/environment.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/env_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 6
+
+def upload_ctrl_fast(model):
+    model_overwrite(model, open("models/PowerWindow/models/control.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/ctrl_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 6
+
+def upload_query_fast(model):
+    model_overwrite(model, open("models/SafetyQuery/models/powerwindow_safe.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/query_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 6
+
+def upload_arch_fast(model):
+    model_overwrite(model, open("models/PowerWindow/models/architecture.mvc", "r").read())
+    open(".TEST_POWER_WINDOW/arch_%s" % uuid.uuid4(), 'w').close()
+    assert len(glob.glob(".TEST_POWER_WINDOW/*")) <= 6
+
 class TestPowerWindow(unittest.TestCase):
     def setUp(self):
         self.proc, self.address = start_mvc()
@@ -64,42 +129,19 @@ class TestPowerWindow(unittest.TestCase):
         transformation_add_AL({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/bfs", open("models/ReachabilityGraph/transformations/bfs.alc", 'r').read())
         transformation_add_AL({"EPN_Plant": "formalisms/Encapsulated_PetriNet", "EPN_Control": "formalisms/Encapsulated_PetriNet", "EPN_Environment": "formalisms/Encapsulated_PetriNet"}, {"Encapsulated_PetriNet": "formalisms/Encapsulated_PetriNet"}, "models/merge_EPN", open("models/EncapsulatedPetriNets/transformations/merge.alc", 'r').read())
 
-        nr_of_operations = 6
-
         try:
             shutil.rmtree(".TEST_POWER_WINDOW")
         except:
             pass
         os.makedirs(".TEST_POWER_WINDOW")
 
-        def get_function(filename):
-            def func(model):
-                import uuid
-                import os
-                called = len(os.listdir(".TEST_POWER_WINDOW/"))
-                if called > nr_of_operations:
-                    raise Exception("Seemingly called some operation twice!")
-                else:
-                    f = open(".TEST_POWER_WINDOW/%s" % str(uuid.uuid4()), 'w')
-                    f.write(filename)
-                    f.close()
-                model_overwrite(model, open(filename, "r").read())
-            return func
-
-        cb_req = get_function(  "models/PowerWindow/models/requirements.mvc")
-        cb_plant = get_function("models/PowerWindow/models/plant.mvc")
-        cb_env = get_function(  "models/PowerWindow/models/environment.mvc")
-        cb_ctrl = get_function( "models/PowerWindow/models/control.mvc")
-        cb_query = get_function("models/SafetyQuery/models/powerwindow_safe.mvc")
-        cb_arch = get_function( "models/PowerWindow/models/architecture.mvc")
-
         callbacks = {
-            "models/revise_req": cb_req,
-            "models/revise_plant": cb_plant,
-            "models/revise_environment": cb_env,
-            "models/revise_control": cb_ctrl,
-            "models/revise_query": cb_query,
-            "models/revise_architecture": cb_arch,
+            "models/revise_req": upload_req_fast,
+            "models/revise_plant": upload_plant_fast,
+            "models/revise_environment": upload_env_fast,
+            "models/revise_control": upload_ctrl_fast,
+            "models/revise_query": upload_query_fast,
+            "models/revise_architecture": upload_arch_fast,
             }
 
         try:
@@ -108,7 +150,6 @@ class TestPowerWindow(unittest.TestCase):
             import traceback
             print(traceback.format_exc())
 
-
         called = len(os.listdir(".TEST_POWER_WINDOW/"))
         shutil.rmtree(".TEST_POWER_WINDOW")
         if called != 6:
@@ -153,32 +194,6 @@ class TestPowerWindow(unittest.TestCase):
             pass
         os.makedirs(".TEST_POWER_WINDOW")
 
-        executed = set([])
-
-        def get_function(filename, fixed=None):
-            def func(model):
-                import uuid
-                import os
-                import glob
-                nr_operations = 11
-                called = len(os.listdir(".TEST_POWER_WINDOW/"))
-                if (len(os.listdir(".TEST_POWER_WINDOW")) > nr_operations):
-                    raise Exception("Seemingly called some operation twice!")
-                elif (len(glob.glob(".TEST_POWER_WINDOW/%s_*" % str(filename.rsplit("/", 1)[-1]))) == 0) or fixed is None:
-                    model_overwrite(model, open(filename, "r").read())
-                else:
-                    model_overwrite(model, open(fixed, "r").read())
-
-                open(".TEST_POWER_WINDOW/%s_%s" % (filename.rsplit("/", 1)[-1], uuid.uuid4()), 'w').close()
-            return func
-
-        cb_req = get_function(  "models/PowerWindow/models/requirements.mvc")
-        cb_plant = get_function("models/PowerWindow/models/plant.mvc")
-        cb_env = get_function(  "models/PowerWindow/models/environment.mvc")
-        cb_ctrl = get_function( "models/PowerWindow/models/control_wrong.mvc", fixed="models/PowerWindow/models/control.mvc")
-        cb_query = get_function("models/SafetyQuery/models/powerwindow_safe.mvc")
-        cb_arch = get_function( "models/PowerWindow/models/architecture.mvc")
-
         import log_output
         error_path = []
         ctrl = log_output.Controller(error_path, keep_running=False)
@@ -187,12 +202,12 @@ class TestPowerWindow(unittest.TestCase):
         thrd.start()
 
         callbacks = {
-                "models/revise_req": cb_req,
-                "models/revise_plant": cb_plant,
-                "models/revise_environment": cb_env,
-                "models/revise_control": cb_ctrl,
-                "models/revise_query": cb_query,
-                "models/revise_architecture": cb_arch,
+                "models/revise_req": upload_req_debug,
+                "models/revise_plant": upload_plant_debug,
+                "models/revise_environment": upload_env_debug,
+                "models/revise_control": upload_ctrl_debug,
+                "models/revise_query": upload_query_debug,
+                "models/revise_architecture": upload_arch_debug,
                 "models/bfs": (ctrl, "inp", "outp"),
             }