Browse Source

Fixed PW tests (updated utils file)

Yentl Van Tendeloo 3 years ago
parent
commit
0de2af5580

+ 9 - 13
integration/utils.py

@@ -5,16 +5,11 @@ import os
 import sys
 import time
 import json
-
-
-if sys.version_info[0] < 3:
-    from urllib2 import urlopen as urlopen
-    from urllib2 import Request as Request
-    from urllib import urlencode as urlencode
-else:
-    from urllib.request import urlopen as urlopen
-    from urllib.request import Request as Request
-    from urllib.parse import urlencode as urlencode
+import urllib
+try:
+    import urllib2
+except ImportError:
+    import urllib as urllib2
 
 import subprocess
 import signal
@@ -22,7 +17,7 @@ import random
 
 sys.path.append("interface/HUTN")
 sys.path.append("scripts")
-from hutn_compiler.compiler import main as do_compile
+#from interface.HUTN.hutn_compiler.compiler import main as do_compile
 
 taskname = "test_task"
 INIT_TIMEOUT = 30
@@ -64,7 +59,7 @@ def child_kill(pid):
     subprocess.call(["pkill", "-P", "%i" % pid])
     start = time.time()
     with open(os.devnull, 'w') as null:
-        while subprocess.call(["pgrep", "-P", "%i" % pid], stdout=null) != 1:
+        while subprocess.call(["pgrep", "-P", "%i" % pid], stdout=null) > 1:
             time.sleep(0.1)
             if time.time() > start + 4:
                 subprocess.call(["pkill", "-9", "-P", "%i" % pid])
@@ -81,11 +76,12 @@ def kill(process):
 
 def flush_data(address, data):
     if data:
-        urlopen(Request(address, urlencode({"op": "set_input", "data": json.dumps(data), "taskname": taskname})), timeout=INIT_TIMEOUT).read()
+        urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "taskname": taskname})), timeout=INIT_TIMEOUT).read()
     return []
 
 def start_mvc():
     port = getFreePort()
     address = "127.0.0.1:%s" % port
+    print("Execute run local MV")
     proc = execute("run_local_modelverse", [str(port)], wait=False)
     return proc, address

+ 6 - 11
kernel/modelverse_kernel/main.py

@@ -282,22 +282,17 @@ class ModelverseKernel(object):
             value = "func_result_" + str(ModelverseKernel.counter)
             ModelverseKernel.counter += 1
 
-            if func_name in intrinsics:
-                #TODO test and fix
-                #actual_computation = value + " = " + intrinsics[func_name](*param_list)
-                pass
-            else:
-                param_list = "{" + ", ".join(["'%s': %s" % (k, v) for k, v in param_list.items()]) + "}"
-                actual_computation = "%s, = yield [('CALL_ARGS', [_mvk.execute_jit, (_root, %s['id'], _taskname, %s)])]\n" % (value, func_name, param_list)
+            param_list = "{" + ", ".join(["'%s': %s" % (k, v) for k, v in param_list.items()]) + "}"
+            actual_computation = "$$INDENT$$%s, = yield [('CALL_ARGS', [_mvk.execute_jit, (_root, %s['id'], _taskname, %s)])]\n" % (value, func_name, param_list)
 
             if indent == 0:
                 # No indent, meaning that we use it inline
                 # Therefore, we output the prev and value individually
-                prev, instruction = prev_func_name + computation + "  " * nested_indent + actual_computation, value
+                prev, instruction = prev_func_name + computation + actual_computation.replace("$$INDENT$$", "  " * nested_indent), value
             else:
                 # Some indentation, meaning that we don't even use the return value
                 # Therefore, we only do the yield
-                prev, instruction = prev_func_name + computation, "  " * indent + actual_computation
+                prev, instruction = prev_func_name + computation, actual_computation.replace("$$INDENT$$", "  " * indent)
 
         elif inst_type["value"] == "access":
             value, = yield [("RD", [inst, "var"])]
@@ -348,8 +343,8 @@ class ModelverseKernel(object):
         #print(func)
 
         # To write out all generated functions
-        with open('/tmp/junk/%s' % suggested_name, 'w') as f:
-            f.write(func)
+        #with open('/tmp/junk/%s' % suggested_name, 'w') as f:
+        #    f.write(func)
 
         yield [("RETURN", [func])]
 

+ 2 - 2
kernel/modelverse_kernel/request_handler.py

@@ -45,11 +45,11 @@ class RequestHandler(object):
         self.reply = None
 
     def execute_call_args(self, request_args):
-        print("CALL " + str(request_args[0]))
+        #print("CALL " + str(request_args[0]))
         self.generator_stack.append(request_args[0](*(request_args[1])))
         self.reply = None
 
     def execute_call_kwargs(self, request_args):
-        print("KWCALL " + str(request_args[0]))
+        #print("KWCALL " + str(request_args[0]))
         self.generator_stack.append(request_args[0](**(request_args[1])))
         self.reply = None

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Wed May  2 14:22:40 2018
+Date:   Thu May  3 09:33:36 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server