scyther/test/results/process.py

109 lines
2.2 KiB
Python
Raw Normal View History

2005-03-11 14:59:35 +00:00
#!/usr/bin/python
#
# Process the main results
#
import sys
class buffer:
def __init__(self, name="unnamed", prefix=">>>"):
2005-03-11 15:44:50 +00:00
self.claims = {}
2005-03-11 14:59:35 +00:00
self.count = 0
self.name = name
self.prefix = prefix
def reset(self):
self.count = 0
2005-03-11 15:44:50 +00:00
self.claims = {}
2005-03-11 14:59:35 +00:00
def size(self):
return self.count
2005-03-11 15:44:50 +00:00
def add(self,(cl, hl), match=-1):
2005-03-11 14:59:35 +00:00
# cleanup cl
usloc = cl.rfind("_")
if usloc != -1:
# cut off any underscore stuff (ignore for now)
cl = cl[:usloc]
# possibly add
2005-03-11 15:44:50 +00:00
if not (cl,hl) in self.claims.keys():
if match >= 0:
self.claims[(cl,hl)] = [match]
else:
self.claims[(cl,hl)] = []
2005-03-11 14:59:35 +00:00
self.count = self.count + 1
2005-03-11 15:44:50 +00:00
elif match >= 0 and match not in self.claims[(cl,hl)]:
self.claims[(cl,hl)].append(match)
2005-03-11 14:59:35 +00:00
def dump(self):
if self.size() == 0:
return
print "Dumping buffer " + self.name
print
counted = 0
2005-03-11 15:44:50 +00:00
for (cl,hl) in self.claims.keys():
2005-03-11 14:59:35 +00:00
# Determine whether to print
#
toprint = True
if cl.rfind("Nisynch") != -1:
# Nisynch claim
# Construct comparable Niagree claim
newcl = cl.replace("Nisynch","Niagree")
# Now check whether this one occurs
2005-03-11 15:44:50 +00:00
if (newcl,hl) in self.claims.keys():
2005-03-11 14:59:35 +00:00
toprint = False
if toprint:
2005-03-11 15:44:50 +00:00
res = self.prefix
res = res + "\t" + cl
res = res + "\t" + str(self.claims[(cl,hl)])
res = res + "\t" + str(hl)
2005-03-11 14:59:35 +00:00
print res
counted = counted + 1
print
print "Count: " + str(counted) + " in " + self.name
print
self.reset()
def main():
buf_big = buffer("[Global]",">>>G")
buf_small = buffer("[Local]", ">>>L")
2005-03-11 15:44:50 +00:00
match = -1
2005-03-11 14:59:35 +00:00
line = sys.stdin.readline()
while line != "":
# Clean input
line = line.strip()
data = line.split("\t")
# Is it an attack thing?
if data[0] != "***":
# Nope
buf_small.dump()
print line
2005-03-11 15:44:50 +00:00
# Maybe it reports the match type?
matchprefix = "Testing match "
loc = line.rfind(matchprefix)
if loc != -1:
match = int(line[loc + len(matchprefix)])
print "Detected match type", match
2005-03-11 14:59:35 +00:00
else:
# Yes!
claim = data[3]
helpers = "\t".join(data[4:])
2005-03-11 15:44:50 +00:00
buf_big.add((claim,helpers), match)
buf_small.add((claim,helpers), match)
2005-03-11 14:59:35 +00:00
# Proceed to next line
line = sys.stdin.readline()
buf_small.dump()
buf_big.dump()
main()