|
@@ -42,6 +42,40 @@ def flush_data(data):
|
|
|
urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": username})), timeout=10).read()
|
|
|
return []
|
|
|
|
|
|
+def compile_file(mod_filename, filename, mode, proc):
|
|
|
+ # Load in the file required
|
|
|
+ try:
|
|
|
+ timeout_val = 120
|
|
|
+ while 1:
|
|
|
+ proc2 = execute("compile", [mod_filename, username, filename, mode], wait=False)
|
|
|
+
|
|
|
+ if proc.returncode is not None:
|
|
|
+ # Modelverse has already terminated, which isn't a good sign!
|
|
|
+ raise Exception("Modelverse died!")
|
|
|
+
|
|
|
+ while proc2.returncode is None:
|
|
|
+ time.sleep(0.01)
|
|
|
+ proc2.poll()
|
|
|
+ timeout_val -= 0.01
|
|
|
+ if timeout_val < 0:
|
|
|
+ kill(proc2)
|
|
|
+ print("Compilation timeout expired!")
|
|
|
+ return False
|
|
|
+ if proc2.returncode not in [7, 56]:
|
|
|
+ break
|
|
|
+
|
|
|
+ # Make sure everything stopped correctly
|
|
|
+ assert proc2.returncode == 0
|
|
|
+ if proc2.returncode != 0:
|
|
|
+ return False
|
|
|
+ except:
|
|
|
+ raise
|
|
|
+ finally:
|
|
|
+ try:
|
|
|
+ kill(proc2)
|
|
|
+ except UnboundLocalError:
|
|
|
+ pass
|
|
|
+
|
|
|
def run_file(files, parameters, expected, mode):
|
|
|
# Resolve file
|
|
|
import os.path
|
|
@@ -51,88 +85,57 @@ def run_file(files, parameters, expected, mode):
|
|
|
# Run Modelverse server
|
|
|
proc = execute("run_local_modelverse", ["bootstrap/bootstrap.m"], wait=False)
|
|
|
|
|
|
- try:
|
|
|
- for filename in files:
|
|
|
- if filename == "--fast":
|
|
|
- continue
|
|
|
- if os.path.isfile("integration/code/%s" % filename):
|
|
|
- mod_filename = "integration/code/%s" % filename
|
|
|
- elif os.path.isfile("bootstrap/%s" % filename):
|
|
|
- mod_filename = "bootstrap/%s" % filename
|
|
|
- else:
|
|
|
- raise Exception("File not found: %s" % filename)
|
|
|
- print("Found file " + str(mod_filename))
|
|
|
+ for filename in files:
|
|
|
+ if filename == "--fast":
|
|
|
+ continue
|
|
|
+ if os.path.isfile("integration/code/%s" % filename):
|
|
|
+ mod_filename = "integration/code/%s" % filename
|
|
|
+ elif os.path.isfile("bootstrap/%s" % filename):
|
|
|
+ mod_filename = "bootstrap/%s" % filename
|
|
|
+ else:
|
|
|
+ raise Exception("File not found: %s" % filename)
|
|
|
+ print("Found file " + str(mod_filename))
|
|
|
|
|
|
- # Load in the file required
|
|
|
- timeout_val = 120
|
|
|
- while 1:
|
|
|
- proc2 = execute("compile", [mod_filename, username, filename, mode], wait=False)
|
|
|
+ compile_file(mod_filename, filename, mode, proc)
|
|
|
|
|
|
- if proc.returncode is not None:
|
|
|
- # Modelverse has already terminated, which isn't a good sign!
|
|
|
- raise Exception("Modelverse died!")
|
|
|
-
|
|
|
- while proc2.returncode is None:
|
|
|
- time.sleep(0.01)
|
|
|
- proc2.poll()
|
|
|
- timeout_val -= 0.01
|
|
|
- if timeout_val < 0:
|
|
|
- kill(proc2)
|
|
|
- print("Compilation timeout expired!")
|
|
|
- return False
|
|
|
- if proc2.returncode not in [7, 56]:
|
|
|
- break
|
|
|
-
|
|
|
- # Make sure everything stopped correctly
|
|
|
- assert proc2.returncode == 0
|
|
|
- if proc2.returncode != 0:
|
|
|
- return False
|
|
|
+ if mode[-1] == "O":
|
|
|
+ # Fire up the linker
|
|
|
+ val = execute("link_and_load", [username] + files, wait=True)
|
|
|
+ if val != 0:
|
|
|
+ raise Exception("Linking error")
|
|
|
|
|
|
- if mode[-1] == "O":
|
|
|
- # Fire up the linker
|
|
|
- val = execute("link_and_load", [username] + files, wait=True)
|
|
|
- if val != 0:
|
|
|
- raise Exception("Linking error")
|
|
|
-
|
|
|
- # Send in the actual request and wait for replies
|
|
|
- data = []
|
|
|
- for p in parameters:
|
|
|
- if isinstance(p, tuple):
|
|
|
- for v in p:
|
|
|
- data.append(["V", serialize(v)])
|
|
|
+ # Send in the actual request and wait for replies
|
|
|
+ data = []
|
|
|
+ for p in parameters:
|
|
|
+ if isinstance(p, tuple):
|
|
|
+ for v in p:
|
|
|
+ data.append(["V", serialize(v)])
|
|
|
+ else:
|
|
|
+ data.append(["V", serialize(p)])
|
|
|
+ flush_data(data)
|
|
|
+
|
|
|
+ for e in expected:
|
|
|
+ c = len(e) if isinstance(e, set) else 1
|
|
|
+ for _ in range(c):
|
|
|
+ val = urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "get_output", "username": username})), timeout=10).read()
|
|
|
+
|
|
|
+ if proc.returncode is not None:
|
|
|
+ # Modelverse has already terminated, which isn't a good sign!
|
|
|
+ raise Exception("Modelverse died!")
|
|
|
+
|
|
|
+ val = val.split("=", 2)[2]
|
|
|
+ print("Got %s, expect %s" % (val, e))
|
|
|
+ if isinstance(e, set):
|
|
|
+ assert str(val) in e
|
|
|
+ if str(val) not in e:
|
|
|
+ return False
|
|
|
else:
|
|
|
- data.append(["V", serialize(p)])
|
|
|
- flush_data(data)
|
|
|
-
|
|
|
- for e in expected:
|
|
|
- c = len(e) if isinstance(e, set) else 1
|
|
|
- for _ in range(c):
|
|
|
- val = urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "get_output", "username": username})), timeout=10).read()
|
|
|
+ assert str(val) == e
|
|
|
+ if str(val) != e:
|
|
|
+ return False
|
|
|
|
|
|
- if proc.returncode is not None:
|
|
|
- # Modelverse has already terminated, which isn't a good sign!
|
|
|
- raise Exception("Modelverse died!")
|
|
|
-
|
|
|
- val = val.split("=", 2)[2]
|
|
|
- print("Got %s, expect %s" % (val, e))
|
|
|
- if isinstance(e, set):
|
|
|
- assert str(val) in e
|
|
|
- if str(val) not in e:
|
|
|
- return False
|
|
|
- else:
|
|
|
- assert str(val) == e
|
|
|
- if str(val) != e:
|
|
|
- return False
|
|
|
-
|
|
|
- # All passed!
|
|
|
- return True
|
|
|
- except:
|
|
|
- raise
|
|
|
- finally:
|
|
|
- try:
|
|
|
- kill(proc2)
|
|
|
- except UnboundLocalError:
|
|
|
- pass
|
|
|
+ # All passed!
|
|
|
+ return True
|
|
|
except:
|
|
|
raise
|
|
|
finally:
|