forked from jonasfj/PeTe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·241 lines (213 loc) · 6.39 KB
/
test.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python
import subprocess, time, os, shutil
# Python script to run batch tests of PeTe
print "PeTe batch test script"
#####################################################################
# Start of Default Configuration #
#####################################################################
# Please use test-config.py for custom config
# Path to PeTe (Relative to execution path)
PeTe = "../PeTe-build-desktop/PeTe"
# Path to samples (Relative to execution path)
ModelDir = "Samples/"
# List of strategies to ignore
IgnoreList = IgnoreList = [
"Naive DFS with Hash",
"Random DFS with Hash",
"Naive BFS with Hash",
"DFS-ArcCount",
"DFS-Delta",
"DFS-TokenCost",
"Linear over-approximation",
#"BestFS-Delta (Sum, Extreme)",
"BestFS-Delta-Deep (Sum, Extreme)",
"BestFS-Delta (Sum, Extreme) Lookahead 1",
"BestFS-Delta (Sum, Extreme) Lookahead 2",
"BestFS-Delta (Sum, Extreme) Lookahead 3",
"BestFS-Delta (Sum, Extreme) Lookahead 4",
"BestFS-Delta (Sum, Extreme) Lookahead 5"]
# List of models to run on
Models = ["MAPK", "DTAPN", "Kanban", "FMS"]
# Memory bound in KiB
MemoryBound = 1048576
# 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.2
# Seconds before timeout
TimeOut = 60
# Number of queries to run from each model (0 for all)
QueriesToRun = 0
# Query prefixes to ignore
QueryPrefixIgnoreList = [
#"fOK",
"fNOK",
]
# Skip the first n from each model list
SkipFirstNModels = 0
#####################################################################
# End of Default Configuration #
#####################################################################
#load config
try:
kill = False
import testconfig
kill = True
PeTe = testconfig.PeTe
ModelDir = testconfig.ModelDir
IgnoreList = testconfig.IgnoreList
MemoryBound = testconfig.MemoryBound
Models = testconfig.Models
PollTime = testconfig.PollTime
InitialPollTime = testconfig.InitialPollTime
TimeOut = testconfig.TimeOut
QueriesToRun = testconfig.QueriesToRun
QueryPrefixIgnoreList = testconfig.QueryPrefixIgnoreList
SkipFirstNModels = testconfig.SkipFirstNModels
except:
print "Failed to load config"
if kill:
print "Attempted to load config, but failed check that you have all settings!"
exit()
# Find some absolute paths
petebin = os.path.abspath(PeTe)
modeldir = os.path.abspath(ModelDir) + "/"
# Copy PeTe to /tmp during tests
shutil.copyfile(petebin, "/tmp/PeTe-Test-Bin")
shutil.copystat(petebin, "/tmp/PeTe-Test-Bin")
petebin = "/tmp/PeTe-Test-Bin"
# NULL-Device
FNULL = open('/dev/null', 'w')
# Get all available strategies from PeTe
p = subprocess.Popen([petebin, "--strategies"], stdout=subprocess.PIPE)
strategies = [i.strip() for i in p.stdout.readlines()]
p.wait()
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"]
DTAPN = ["DTAPNs/PrimeNet-7.pet", "DTAPNs/PrimeNet-11.pet", "DTAPNs/PrimeNet-13.pet", "DTAPNs/PrimeNet-17.pet", "DTAPNs/PrimeNet-19.pet"]
modellists = []
for m in Models:
if m == "MAPK": modellists += (MAPK[SkipFirstNModels:],)
if m == "DTAPN": modellists += (DTAPN[SkipFirstNModels:],)
if m == "Kanban": modellists += (Kanban[SkipFirstNModels:],)
if m == "FMS": modellists += (FMS[SkipFirstNModels:],)
def getMemory(pid):
argvs = ["ps", "-p", str(pid), "-o", "vsz="]
#"ps -p " + str(pid) + " -o vsz=" shell=True
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 run(model, strategy, query):
global TimeOut, MemoryBound, QuickStepPoll, PollTime
argvs = [petebin, model, "--strategy", strategy , "--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)
retval = None
if p.poll() != None:
retval = ""
if p.poll() != 0:
retval = "PeTe error, returned: " + str(p.poll())
for l in p.stdout.readlines():
retval += l.strip()
if p.poll() == None:
p.kill()
if not retval and peekMem > MemoryBound:
p.wait()
return False, os.path.basename(model) + ",\t" + query + ",\t" + strategy + ",\tOutOfMemory,\t-,\t-,\t-,\t-", peekMem
elif not retval and not t < TimeOut:
p.wait()
return False, os.path.basename(model) + ",\t" + query + ",\t" + strategy + ",\tOutOfTime,\t-,\t-,\t-,\t-", peekMem
p.wait()
return True, retval, peekMem
def listqueries(model):
qp = subprocess.Popen(petebin + " " + model + " --list-queries", shell=True, stdout=subprocess.PIPE)
qp.wait()
queries = []
for q in qp.stdout.readlines():
queries += [q.strip(),]
return queries
""" Run models, where scaledModels is a list of scaled models ordered from small to large """
def runScaledModels(scaledModels):
global QueriesToRun
for strategy in strategies:
if strategy in IgnoreList:
continue
for model in scaledModels:
queries = listqueries(modeldir + model)
queriesrun = 0
failed = True
for query in queries:
skipByPrefix = False
for prefix in QueryPrefixIgnoreList:
skipByPrefix |= query.startswith(prefix)
if skipByPrefix: continue
ret, data, mem = run(modeldir + model, strategy, query)
print data.strip() + ",\t" + str(mem)
failed = failed and not ret
queriesrun += 1
if QueriesToRun != 0 and queriesrun >= QueriesToRun:
break
if failed:
break
if __name__ == "__main__":
for ml in modellists:
runScaledModels(ml)
#
#for ml in modellists:
# for i in range(1,10):
# strategy = "Random DFS with Hash"
# for model in ml:
# queries = listqueries(modeldir+model)
# failed = True
# for query in queries:
# ret, data, mem = run(modeldir + model, strategy, query)
# print data.strip() + ",\t" + str(mem)
# failed = failed and not ret
# if failed:
# break