-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicVerifier.py
60 lines (53 loc) · 1.89 KB
/
DynamicVerifier.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
from Common import *
import time
import lib.xmltodict as xml
def verifyRuntimeConstraints(log, assertion):
calls = xml.parse(log)[u"history"][u"call"]
if not isinstance(calls, list):
# hack to deal with xml quirk
calls = [calls]
processed = []
for call in calls:
invocation = (call[u"methodName"],
time.strptime(call[u"startTime"], "%Y/%m/%d %H:%M:%S"))
processed.append(invocation)
# sort it to enhance efficiency
processed.sort(key = lambda x: x[1])
offended = []
# this is a sufficient bases
for statement in assertion.statements:
# print statement
if statement.action == "return":
continue
failed = True
for i in xrange(len(processed)):
if str(statement.object) == processed[i][0]:
satisfiedAll = True
for modifier in statement.modifiers:
# proceed only if it's a valid modifier
if modifier:
satisfied = False
if modifier[0] == 'after':
for j in xrange(0, i):
if str(modifier[1]) == processed[j][0]:
satisfied = True
break
elif modifier[0] == 'before':
for j in xrange(i, len(processed)):
if str(modifier[1]) == processed[j][0]:
satisfied = True
break
elif modifier[0] == 'less' or modifier[0] == 'more':
num = sum([1 for call in processed if str(statement.object) == call[0]])
# print modifier, num
if modifier[0] == 'less':
satisfied = True if num < modifier[1] else satisfied
else:
satisfied = True if num > modifier[1] else satisfied
if not satisfied:
satisfiedAll = False
if satisfiedAll:
failed = False
if failed ^ statement.negated:
offended.append(statement)
return offended