|
@@ -9,9 +9,10 @@ import urllib
|
|
|
import urllib2
|
|
|
import subprocess
|
|
|
import signal
|
|
|
+import random
|
|
|
|
|
|
username = "test_user"
|
|
|
-parallel_push = True
|
|
|
+parallel_push = False
|
|
|
|
|
|
def serialize(value):
|
|
|
if isinstance(value, str):
|
|
@@ -38,19 +39,19 @@ def kill(process):
|
|
|
elif os.name == "posix":
|
|
|
subprocess.call(["pkill", "-P", "%i" % process.pid])
|
|
|
|
|
|
-def flush_data(data):
|
|
|
+def flush_data(address, data):
|
|
|
if data:
|
|
|
- urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": username})), timeout=10).read()
|
|
|
+ urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": username})), timeout=10).read()
|
|
|
return []
|
|
|
|
|
|
-def compile_file(mod_filename, filename, mode, proc):
|
|
|
+def compile_file(address, mod_filename, filename, mode, proc):
|
|
|
# Load in the file required
|
|
|
try:
|
|
|
timeout_val = 120
|
|
|
import random
|
|
|
username = str(random.random())
|
|
|
while 1:
|
|
|
- proc2 = execute("compile", [mod_filename, username, filename, mode], wait=False)
|
|
|
+ proc2 = execute("compile", [address, mod_filename, username, filename, mode], wait=False)
|
|
|
|
|
|
if proc.returncode is not None:
|
|
|
# Modelverse has already terminated, which isn't a good sign!
|
|
@@ -84,9 +85,11 @@ def run_file(files, parameters, expected, mode):
|
|
|
import os.path
|
|
|
|
|
|
time.sleep(0.01)
|
|
|
+ port = random.randint(10000, 10100)
|
|
|
+ address = "http://localhost:%i" % port
|
|
|
try:
|
|
|
# Run Modelverse server
|
|
|
- proc = execute("run_local_modelverse", ["bootstrap/bootstrap.m"], wait=False)
|
|
|
+ proc = execute("run_local_modelverse", [str(port)], wait=False)
|
|
|
|
|
|
threads = []
|
|
|
for filename in files:
|
|
@@ -102,10 +105,10 @@ def run_file(files, parameters, expected, mode):
|
|
|
|
|
|
if parallel_push:
|
|
|
import threading
|
|
|
- threads.append(threading.Thread(target=compile_file, args=[mod_filename, filename, mode, proc]))
|
|
|
+ threads.append(threading.Thread(target=compile_file, args=[address, mod_filename, filename, mode, proc]))
|
|
|
threads[-1].start()
|
|
|
else:
|
|
|
- compile_file(mod_filename, filename, mode, proc)
|
|
|
+ compile_file(address, mod_filename, filename, mode, proc)
|
|
|
|
|
|
if parallel_push:
|
|
|
for t in threads:
|
|
@@ -113,7 +116,7 @@ def run_file(files, parameters, expected, mode):
|
|
|
|
|
|
if mode[-1] == "O":
|
|
|
# Fire up the linker
|
|
|
- val = execute("link_and_load", [username] + files, wait=True)
|
|
|
+ val = execute("link_and_load", [address, username] + files, wait=True)
|
|
|
if val != 0:
|
|
|
raise Exception("Linking error")
|
|
|
|
|
@@ -125,12 +128,12 @@ def run_file(files, parameters, expected, mode):
|
|
|
data.append(["V", serialize(v)])
|
|
|
else:
|
|
|
data.append(["V", serialize(p)])
|
|
|
- flush_data(data)
|
|
|
+ flush_data(address, 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()
|
|
|
+ val = urllib2.urlopen(urllib2.Request(address, 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!
|
|
@@ -158,18 +161,20 @@ def run_file(files, parameters, expected, mode):
|
|
|
pass
|
|
|
|
|
|
def run_barebone(parameters, expected, interface="0", timeout=False, wait=False, link=None):
|
|
|
+ port = random.randint(10000, 10100)
|
|
|
+ address = "http://localhost:%i" % port
|
|
|
try:
|
|
|
# Run Modelverse server
|
|
|
- proc = execute("run_local_modelverse", ["bootstrap/bootstrap.m"], wait=False)
|
|
|
+ proc = execute("run_local_modelverse", [str(port)], wait=False)
|
|
|
|
|
|
# Create user and set interface
|
|
|
timeout_val = 15
|
|
|
start = time.time()
|
|
|
while 1:
|
|
|
try:
|
|
|
- urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"%s"' % username, "username": "user_manager"})), timeout=1).read()
|
|
|
+ urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"%s"' % username, "username": "user_manager"})), timeout=1).read()
|
|
|
if interface is not None:
|
|
|
- urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "set_input", "element_type": "V", "value": interface, "username": username})), timeout=1).read()
|
|
|
+ urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": interface, "username": username})), timeout=1).read()
|
|
|
break
|
|
|
except:
|
|
|
time.sleep(0.01)
|
|
@@ -187,8 +192,8 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
|
|
|
for p in parameters:
|
|
|
if isinstance(p, int):
|
|
|
if p not in var_list:
|
|
|
- data = flush_data(data)
|
|
|
- val = urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "get_output", "username": username})), timeout=10).read()
|
|
|
+ data = flush_data(address, data)
|
|
|
+ val = urllib2.urlopen(urllib2.Request(address, 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!
|
|
@@ -204,13 +209,13 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
|
|
|
val = p
|
|
|
t = "V"
|
|
|
data.append([t, val])
|
|
|
- data = flush_data(data)
|
|
|
+ data = flush_data(address, data)
|
|
|
|
|
|
# Now do linking and loading
|
|
|
if link is not None:
|
|
|
# Execute linker
|
|
|
timeout_val = 10
|
|
|
- proc2 = execute("link_and_load", [username] + link, wait=False)
|
|
|
+ proc2 = execute("link_and_load", [address, username] + link, wait=False)
|
|
|
|
|
|
while proc2.returncode is None:
|
|
|
time.sleep(0.01)
|
|
@@ -227,7 +232,7 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
|
|
|
c = len(e) if isinstance(e, set) else 1
|
|
|
for _ in range(c):
|
|
|
try:
|
|
|
- val = urllib2.urlopen(urllib2.Request("http://localhost:8001/", urllib.urlencode({"op": "get_output", "username": username})), timeout=15).read()
|
|
|
+ val = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username})), timeout=15).read()
|
|
|
except:
|
|
|
if timeout:
|
|
|
return True
|