-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathwadi_harness.py
executable file
·70 lines (54 loc) · 1.48 KB
/
wadi_harness.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import PyV8
import sys
from cStringIO import StringIO
from multiprocessing import Process,Manager
import time
from twisted.web.resource import Resource
from twisted.web import server
from twisted.internet import reactor
from twisted.python.util import println
PORT=8000
class MyHandler(Resource):
isLeaf = True
def __init__(self,q):
self.queue = q
def render_GET(self,request):
#print request.path
if request.path == "/wait":
return "<html><head><meta http-equiv='refresh' content='5;url=/' /></head><body><h1>Waiting ...</h1></body></html>"
#return server.NOT_DONE_YET
else:
testCase = ctx.eval("generateTestCase()")
self.queue.append(testCase)
#return server.NOT_DONE_YET
return testCase
class Global(PyV8.JSClass):
def string(self,num):
return '%n'*num
ctx = PyV8.JSContext(Global())
class Harness():
def __init__(self,f,p,t):
self.f = f
self.PORT=p
self.tcases = t
def run_server(self):
self.Handler = server.Site(MyHandler(self.tcases))
#try:
reactor.listenTCP(int(self.PORT),self.Handler)
print "Serving at port", self.PORT
reactor.run()
#except:
#sys.exit()
def get_testCase(self):
return self.ctx.eval("generateTestCase()")
def test(self):
time.sleep(2)
print 'Test'
def run(self):
ctx.enter()
ctx.eval(open('randoms.js').read())
ctx.eval(open(self.f).read())
self.run_server()
if __name__ == '__main__':
h = Harness(sys.argv[1],sys.argv[2],Manager().list())
h.run()