-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComputabilityTest.py
executable file
·148 lines (128 loc) · 3.16 KB
/
ComputabilityTest.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
import subprocess, time, os, shutil, sys
""" Script for generating random queries
Input: List of model files
Output: Files where each line contains a random query
"""
# Memory bound in KiB
MemoryBound = 1024*1024*1024*2
# Time to wait between process polls
PollTime = 2
# Start with interval at InitialPollTime and increase to PollTime is reached (Set 0 to disable)
InitialPollTime = 0.1
# Seconds before timeout
TimeOut = 60*2
Strategies = [
"BestFS Ultimate Edition DFS",
"BestFS Ultimate Edition BFS",
]
# NULL-Device
FNULL = open('/dev/null', 'w')
Kanban = [
#"Kanban5.pet",
#"Kanban10.pet",
#"Kanban20.pet",
#"Kanban50.pet",
"Kanban100.pet",
"Kanban200.pet",
"Kanban500.pet",
"Kanban1000.pet"
]
FMS = [
#"FMS2.pet",
#"FMS10.pet",
#"FMS20.pet",
"FMS50.pet",
"FMS100.pet",
"FMS200.pet",
"FMS500.pet"
]
MAPK = [
#"MAPK8.pet",
#"MAPK40.pet",
#"MAPK80.pet",
#"MAPK160.pet",
"MAPK320.pet",
"MAPK640.pet",
"MAPK1280.pet",
"MAPK2560.pet"
]
Models = Kanban + FMS + MAPK
ModelDir = "Samples/"
PeTer = "../PeTe-build-desktop/PeTer/PeTer"
OutputDir = "TestData/Computability/"
peterbin = os.path.abspath(PeTer)
modeldir = os.path.abspath(ModelDir) + "/"
outputdir = os.path.abspath(OutputDir) + "/"
# Copy PeTe to /tmp during tests
shutil.copyfile(peterbin, "/tmp/PeTer-Test-Bin")
shutil.copystat(peterbin, "/tmp/PeTer-Test-Bin")
peterbin = "/tmp/PeTer-Test-Bin"
def getMemory(pid):
argvs = ["ps", "-p", str(pid), "-o", "vsz="]
p2 = subprocess.Popen(argvs, stdout=subprocess.PIPE)
memory = 0;
for l in p2.stdout.readlines():
try:
memory = int(l)
except: pass
p2.wait()
return memory
def genQuery(model):
global peterbin, modeldir
argvs = [peterbin, "--test", modeldir + model, "--gen-query"]
p = subprocess.Popen(argvs, stdout=subprocess.PIPE, stderr=FNULL)
p.wait()
for line in p.stdout.readlines():
if line.strip() != "":
return line.strip()
return None
def runQuery(model, strategy, query):
global TimeOut, MemoryBound, QuickStepPoll, PollTime, peterbin, modeldir
argvs = [peterbin, "--test", modeldir + model, "--strategy", strategy , "--literal-query", query]
p = subprocess.Popen(argvs, stdout=subprocess.PIPE, stderr=FNULL)
t = 0.0
peekMem = 0
if InitialPollTime == 0:
pt = PollTime
else:
pt = InitialPollTime
while t < TimeOut and p.poll() == None:
mem = getMemory(p.pid)
if mem > peekMem: peekMem = mem
if peekMem > MemoryBound:
break
if InitialPollTime > 0 and pt < PollTime:
pt += InitialPollTime
if pt > PollTime: pt = PollTime
t += pt
time.sleep(pt)
if p.poll() == None:
p.kill()
p.wait()
return False
return p.poll() == 0
Files = {}
#Setup headers and create files
for model in Models:
fp = outputdir + model + ".result"
if os.path.isfile(fp):
Files[model] = open(fp, "a")
else:
Files[model] = open(fp, "w")
result = "Query,\t"
for strategy in Strategies:
result += strategy.replace(",","-") + ","
Files[model].write(result + "\n")
while True:
for model in Models:
f = Files[model]
query = genQuery(model)
result = query + ",\t"
for strategy in Strategies:
if runQuery(model, strategy, query):
result += "1,\t"
else:
result += "0,\t"
f.write(result + "\n")
f.flush()