- Modified some scripts, in particular to get compareheuristics to work
with the new versions of Scyther.
This commit is contained in:
parent
41e797413c
commit
494d02a524
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Compare heuristics
|
# Compare heuristics
|
||||||
#
|
#
|
||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
@ -9,169 +9,173 @@ import scythertest
|
|||||||
|
|
||||||
# Parse
|
# Parse
|
||||||
def parse(scout):
|
def parse(scout):
|
||||||
"""Parse Scyther output for heuristics tests
|
"""Parse Scyther output for heuristics tests
|
||||||
|
|
||||||
in:
|
in:
|
||||||
A single Scyther output string (including newlines)
|
A single Scyther output string (including newlines)
|
||||||
out:
|
out:
|
||||||
ra: number of failed claims
|
ra: number of failed claims
|
||||||
rb: number of bounded proofs of claims
|
rb: number of bounded proofs of claims
|
||||||
rc: number of complete proofs of claims
|
rc: number of complete proofs of claims
|
||||||
nc: number of processed claims (should be the sum of the previous)
|
nc: number of processed claims (should be the sum of the previous)
|
||||||
st: number of states traversed
|
st: number of states traversed
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ra = 0
|
ra = 0
|
||||||
rb = 0
|
rb = 0
|
||||||
rp = 0
|
rp = 0
|
||||||
nc = 0
|
nc = 0
|
||||||
st = 0
|
st = 0
|
||||||
for l in scout.splitlines():
|
for l in scout.splitlines():
|
||||||
data = l.split()
|
data = l.split()
|
||||||
if len(data) > 6 and data[0] == 'claim':
|
if len(data) > 4 and data[0] == 'claim':
|
||||||
tag = data[6]
|
# determine claim status
|
||||||
if tag == 'failed:':
|
tag = data[4]
|
||||||
ra = ra + 1
|
if tag == 'Fail':
|
||||||
nc = nc + 1
|
ra = ra + 1
|
||||||
elif tag == 'correct:':
|
nc = nc + 1
|
||||||
nc = nc + 1
|
elif tag == 'Ok':
|
||||||
if l.rfind("complete_proof") != -1:
|
nc = nc + 1
|
||||||
rp = rp + 1
|
if l.rfind("proof of correctness") != -1:
|
||||||
else:
|
rp = rp + 1
|
||||||
rb = rb + 1
|
else:
|
||||||
elif data[0] == 'states':
|
rb = rb + 1
|
||||||
st = int(data[1])
|
# now count the states
|
||||||
return (ra,rb,rp,nc,st)
|
for d in data:
|
||||||
|
if d.startswith("states="):
|
||||||
|
st = st + int(d[7:])
|
||||||
|
|
||||||
|
return (ra,rb,rp,nc,st)
|
||||||
|
|
||||||
|
|
||||||
def test_goal_selector(goalselector, options):
|
def test_goal_selector(goalselector, options):
|
||||||
"""Test with a given goal selector
|
"""Test with a given goal selector
|
||||||
|
|
||||||
in:
|
in:
|
||||||
goalselector: as in Scyther docs.
|
goalselector: as in Scyther docs.
|
||||||
options: options record (formatted as in optparse module)
|
options: options record (formatted as in optparse module)
|
||||||
out:
|
out:
|
||||||
(attacks,bounds,proofs,claims,np,states)
|
(attacks,bounds,proofs,claims,np,states)
|
||||||
attacks: number of failed claims
|
attacks: number of failed claims
|
||||||
bounds: number of bounded proofs
|
bounds: number of bounded proofs
|
||||||
proofs: number of complete proofs
|
proofs: number of complete proofs
|
||||||
np: number of protocols tested
|
np: number of protocols tested
|
||||||
states: total number of states explored.
|
states: total number of states explored.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import protocollist
|
import protocollist
|
||||||
|
|
||||||
scythertest.set_extra_parameters("--goal-select=" + str(goalselector))
|
scythertest.set_extra_parameters("--count-states --heuristic=" + str(goalselector))
|
||||||
result = str(goalselector)
|
result = str(goalselector)
|
||||||
plist = protocollist.from_literature()
|
plist = protocollist.from_literature()
|
||||||
np = len(plist)
|
np = len(plist)
|
||||||
|
|
||||||
attacks = 0
|
attacks = 0
|
||||||
bounds = 0
|
bounds = 0
|
||||||
proofs = 0
|
proofs = 0
|
||||||
claims = 0
|
claims = 0
|
||||||
states = 0
|
states = 0
|
||||||
for p in plist:
|
for p in plist:
|
||||||
(status,scout) = scythertest.default_test([p], \
|
(status,scout) = scythertest.default_test([p], \
|
||||||
int(options.match), \
|
int(options.match), \
|
||||||
int(options.bounds))
|
int(options.bounds))
|
||||||
(ra,rb,rp,nc,st) = parse(scout)
|
(ra,rb,rp,nc,st) = parse(scout)
|
||||||
attacks = attacks + ra
|
attacks = attacks + ra
|
||||||
bounds = bounds + rb
|
bounds = bounds + rb
|
||||||
proofs = proofs + rp
|
proofs = proofs + rp
|
||||||
claims = claims + nc
|
claims = claims + nc
|
||||||
states = states + st
|
states = states + st
|
||||||
|
|
||||||
return (attacks,bounds,proofs,claims,np,states)
|
return (attacks,bounds,proofs,claims,np,states)
|
||||||
|
|
||||||
# Max
|
# Max
|
||||||
class maxor:
|
class maxor:
|
||||||
"""Class for a dynamic maximum determination and corresponding formatting
|
"""Class for a dynamic maximum determination and corresponding formatting
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,dir=0,mymin=99999999, mymax=-99999999):
|
def __init__(self,dir=0,mymin=99999999, mymax=-99999999):
|
||||||
"""Init
|
"""Init
|
||||||
|
|
||||||
in:
|
in:
|
||||||
dir: bit 0 is set : notify of increase
|
dir: bit 0 is set : notify of increase
|
||||||
bit 1 is set : notify of decrease
|
bit 1 is set : notify of decrease
|
||||||
mymin: initial minimum
|
mymin: initial minimum
|
||||||
mymax: initial maximum
|
mymax: initial maximum
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.dir = dir
|
self.dir = dir
|
||||||
self.min = mymin
|
self.min = mymin
|
||||||
self.max = mymax
|
self.max = mymax
|
||||||
|
|
||||||
def reg(self,data):
|
def reg(self,data):
|
||||||
"""Store a new data element
|
"""Store a new data element
|
||||||
|
|
||||||
in:
|
in:
|
||||||
element to be stored
|
element to be stored
|
||||||
out:
|
out:
|
||||||
formatted element, plus increase/decrease
|
formatted element, plus increase/decrease
|
||||||
notifications according to initial settings.
|
notifications according to initial settings.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
res = ""
|
res = ""
|
||||||
if self.min >= data:
|
if self.min >= data:
|
||||||
self.min = data
|
self.min = data
|
||||||
if (self.dir & 2):
|
if (self.dir & 2):
|
||||||
res = res + "-"
|
res = res + "-"
|
||||||
if self.max <= data:
|
if self.max <= data:
|
||||||
self.max = data
|
self.max = data
|
||||||
if (self.dir & 1):
|
if (self.dir & 1):
|
||||||
res = res + "+"
|
res = res + "+"
|
||||||
if res == "":
|
if res == "":
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
return "[" + res + "]"
|
return "[" + res + "]"
|
||||||
|
|
||||||
# Main code
|
# Main code
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
scythertest.default_options(parser)
|
scythertest.default_options(parser)
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
scythertest.process_default_options(options)
|
scythertest.process_default_options(options)
|
||||||
|
|
||||||
print "G-sel\tAttack\tBound\tProof\tClaims\tScore1\tScore2\tStates\tBnd*Sts"
|
print "G-sel\tAttack\tBound\tProof\tClaims\tScore1\tScore2\tStates\tBnd*Sts"
|
||||||
print
|
print
|
||||||
|
|
||||||
ramax = maxor(1)
|
ramax = maxor(1)
|
||||||
rbmax = maxor(2)
|
rbmax = maxor(2)
|
||||||
rpmax = maxor(1)
|
rpmax = maxor(1)
|
||||||
score1max = maxor(1)
|
score1max = maxor(1)
|
||||||
score2max = maxor(1)
|
score2max = maxor(1)
|
||||||
statesmax = maxor(2)
|
statesmax = maxor(2)
|
||||||
boundstatesmax = maxor(2)
|
boundstatesmax = maxor(2)
|
||||||
|
|
||||||
for g in range(1,31):
|
for g in range(1,63):
|
||||||
if (g & 8) == 0:
|
if (g & 8) == 0 and (g & 4) == 0 :
|
||||||
(ra,rb,rp,nc,np,st) = test_goal_selector(g, options)
|
(ra,rb,rp,nc,np,st) = test_goal_selector(g, options)
|
||||||
|
|
||||||
# Scores: bounds are negative
|
# Scores: bounds are negative
|
||||||
score1 = ra + rp - rb
|
score1 = ra + rp - rb
|
||||||
score2 = ra + (3 * rp) - (2 * rb)
|
score2 = ra + (3 * rp) - (2 * rb)
|
||||||
boundstates = rb * st
|
boundstates = rb * st
|
||||||
|
|
||||||
res = str(g)
|
res = str(g)
|
||||||
|
|
||||||
def shows (res, mx, data):
|
def shows (res, mx, data):
|
||||||
return res + "\t" + str(data) + mx.reg(data)
|
return res + "\t" + str(data) + mx.reg(data)
|
||||||
|
|
||||||
res = shows (res, ramax, ra)
|
res = shows (res, ramax, ra)
|
||||||
res = shows (res, rbmax, rb)
|
res = shows (res, rbmax, rb)
|
||||||
res = shows (res, rpmax, rp)
|
res = shows (res, rpmax, rp)
|
||||||
res = res + "\t" + str(nc)
|
res = res + "\t" + str(nc)
|
||||||
res = shows (res, score1max, score1)
|
res = shows (res, score1max, score1)
|
||||||
res = shows (res, score2max, score2)
|
res = shows (res, score2max, score2)
|
||||||
res = shows (res, statesmax, st)
|
res = shows (res, statesmax, st)
|
||||||
res = shows (res, boundstatesmax, boundstates)
|
res = shows (res, boundstatesmax, boundstates)
|
||||||
|
|
||||||
print res
|
print res
|
||||||
print
|
print
|
||||||
print "Goal selector scan completed."
|
print "Goal selector scan completed."
|
||||||
|
|
||||||
# Only if main stuff
|
# Only if main stuff
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -1,98 +1,105 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# protocol list
|
# protocol list
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
import os;
|
||||||
|
|
||||||
def list_ppfix(list, prefix, postfix):
|
def list_ppfix(list, prefix, postfix):
|
||||||
newlist = []
|
return [ prefix + i + postfix for i in list]
|
||||||
for i in list:
|
|
||||||
newlist.append(prefix + i + postfix)
|
|
||||||
return newlist
|
|
||||||
|
|
||||||
def from_good_literature():
|
def from_good_literature():
|
||||||
list = [ \
|
list = [ \
|
||||||
"ccitt509-1c.spdl",
|
"ccitt509-1c.spdl",
|
||||||
"ccitt509-1.spdl",
|
"ccitt509-1.spdl",
|
||||||
"ccitt509-3.spdl",
|
"ccitt509-3.spdl",
|
||||||
"ccitt509-ban3.spdl",
|
"ccitt509-ban3.spdl",
|
||||||
"denning-sacco-lowe.spdl",
|
"denning-sacco-lowe.spdl",
|
||||||
"denning-sacco.spdl",
|
"denning-sacco.spdl",
|
||||||
"kaochow.spdl",
|
"kaochow.spdl",
|
||||||
"kaochow-v2.spdl",
|
"kaochow-v2.spdl",
|
||||||
"kaochow-v3.spdl",
|
"kaochow-v3.spdl",
|
||||||
"ksl-lowe.spdl",
|
"ksl-lowe.spdl",
|
||||||
"ksl.spdl",
|
"ksl.spdl",
|
||||||
"needham-schroeder-lowe.spdl",
|
"needham-schroeder-lowe.spdl",
|
||||||
"needham-schroeder-sk-amend.spdl",
|
"needham-schroeder-sk-amend.spdl",
|
||||||
"needham-schroeder-sk.spdl",
|
"needham-schroeder-sk.spdl",
|
||||||
"neumannstub-hwang.spdl",
|
"neumannstub-hwang.spdl",
|
||||||
"neumannstub.spdl",
|
"neumannstub.spdl",
|
||||||
"otwayrees.spdl",
|
"otwayrees.spdl",
|
||||||
"smartright.spdl",
|
"smartright.spdl",
|
||||||
"splice-as-cj.spdl",
|
"splice-as-cj.spdl",
|
||||||
"splice-as-hc.spdl",
|
"splice-as-hc.spdl",
|
||||||
"splice-as.spdl",
|
"splice-as.spdl",
|
||||||
"woo-lam-pi-f.spdl",
|
"woo-lam-pi-f.spdl",
|
||||||
"woo-lam-pi.spdl",
|
"woo-lam-pi.spdl",
|
||||||
"woo-lam.spdl",
|
"woo-lam.spdl",
|
||||||
"yahalom-lowe.spdl",
|
"yahalom-lowe.spdl",
|
||||||
"yahalom-paulson.spdl" ]
|
"yahalom-paulson.spdl" ]
|
||||||
|
|
||||||
return list_ppfix(list, "../spdl/SPORE/","")
|
return list_ppfix(list, "/home/cas/svn/ecss/protocols/spdl/SPORE/","")
|
||||||
|
|
||||||
def from_bad_literature():
|
def from_bad_literature():
|
||||||
list = [ \
|
list = [ \
|
||||||
"andrew-ban-concrete.spdl",
|
"andrew-ban-concrete.spdl",
|
||||||
"andrew-ban.spdl",
|
"andrew-ban.spdl",
|
||||||
"andrew-lowe-ban.spdl",
|
"andrew-lowe-ban.spdl",
|
||||||
"andrew.spdl",
|
"andrew.spdl",
|
||||||
"needham-schroeder.spdl",
|
"needham-schroeder.spdl",
|
||||||
"tmn.spdl",
|
"tmn.spdl",
|
||||||
"wmf-lowe.spdl",
|
"wmf-lowe.spdl",
|
||||||
"wmf.spdl",
|
"wmf.spdl",
|
||||||
"woo-lam-pi-1.spdl",
|
"woo-lam-pi-1.spdl",
|
||||||
"woo-lam-pi-2.spdl",
|
"woo-lam-pi-2.spdl",
|
||||||
"woo-lam-pi-3.spdl",
|
"woo-lam-pi-3.spdl",
|
||||||
"yahalom-ban.spdl",
|
"yahalom-ban.spdl",
|
||||||
"yahalom.spdl" ]
|
"yahalom.spdl" ]
|
||||||
|
|
||||||
return list_ppfix(list, "../spdl/SPORE/","")
|
return list_ppfix(list, "/home/cas/svn/ecss/protocols/spdl/SPORE/","")
|
||||||
|
|
||||||
def from_literature():
|
def from_literature():
|
||||||
return from_good_literature() + from_bad_literature()
|
|
||||||
|
def spdlfiletype (fn):
|
||||||
|
return fn.endswith(".spdl")
|
||||||
|
|
||||||
|
spdldir = "/home/cas/svn/ecss/protocols/spdl/SPORE/"
|
||||||
|
sl = os.listdir (spdldir)
|
||||||
|
sld = [ spdldir + i for i in filter (spdlfiletype, sl)]
|
||||||
|
##print sld
|
||||||
|
return sld
|
||||||
|
|
||||||
def from_others():
|
def from_others():
|
||||||
list = [ \
|
list = [ \
|
||||||
]
|
]
|
||||||
|
|
||||||
return list_ppfix(list, "../spdl/","")
|
return list_ppfix(list, "../spdl/","")
|
||||||
|
|
||||||
def from_all():
|
def from_all():
|
||||||
return from_literature() + from_others()
|
return from_literature() + from_others()
|
||||||
|
|
||||||
def select(type):
|
def select(type):
|
||||||
n = int(type)
|
n = int(type)
|
||||||
if n == 0:
|
if n == 0:
|
||||||
# 0 means all protocols
|
# 0 means all protocols
|
||||||
return from_all()
|
return from_all()
|
||||||
elif n == 1:
|
elif n == 1:
|
||||||
# 1 means from literature
|
# 1 means from literature
|
||||||
return from_literature()
|
return from_literature()
|
||||||
elif n == 2:
|
elif n == 2:
|
||||||
# 2 means from literature, no known attacks
|
# 2 means from literature, no known attacks
|
||||||
return from_good_literature()
|
return from_good_literature()
|
||||||
else:
|
else:
|
||||||
# Otherwise empty list
|
# Otherwise empty list
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for l in [from_literature(), from_others()]:
|
for l in [from_literature(), from_others()]:
|
||||||
for p in l:
|
for p in l:
|
||||||
print p
|
print p
|
||||||
print
|
print
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Scyther wrapper
|
# Scyther wrapper
|
||||||
#
|
#
|
||||||
# Standard tests
|
# Standard tests
|
||||||
#
|
#
|
||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
@ -20,29 +20,29 @@ g_extra = ""
|
|||||||
|
|
||||||
# status
|
# status
|
||||||
def error_status(status):
|
def error_status(status):
|
||||||
if status == 1 or status < 0:
|
if status == 1 or status < 0:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Parse output
|
# Parse output
|
||||||
def parse(scout):
|
def parse(scout):
|
||||||
results = {}
|
results = {}
|
||||||
lines = scout.splitlines()
|
lines = scout.splitlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
data = line.split()
|
data = line.split()
|
||||||
if len(data) > 6 and data[0] == 'claim':
|
if len(data) > 4 and data[0] == 'claim':
|
||||||
claim = " ".join(data[1:4])
|
claim = ",".join(data[1:2])
|
||||||
tag = data[6]
|
tag = data[5]
|
||||||
value = -1
|
value = -1
|
||||||
if tag == 'failed:':
|
if tag == 'Fail':
|
||||||
value = 0
|
value = 0
|
||||||
if tag == 'correct:':
|
if tag == 'Ok':
|
||||||
value = 1
|
value = 1
|
||||||
if value == -1:
|
if value == -1:
|
||||||
raise IOError, 'Scyther output for ' + commandline + ', line ' + line + ' cannot be parsed.'
|
raise IOError, 'Scyther output for ' + commandline + ', line ' + line + ' cannot be parsed.'
|
||||||
results[claim] = value
|
results[claim] = value
|
||||||
return results
|
return results
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Default tests
|
# Default tests
|
||||||
@ -50,131 +50,131 @@ def parse(scout):
|
|||||||
|
|
||||||
# Yield default protocol list (from any other one)
|
# Yield default protocol list (from any other one)
|
||||||
def default_protocols(plist):
|
def default_protocols(plist):
|
||||||
plist.sort()
|
plist.sort()
|
||||||
return ['../spdl/spdl-defaults.inc'] + plist
|
return ['/home/cas/svn/ecss/protocols/spdl/spdl-defaults.inc'] + plist
|
||||||
|
|
||||||
# Get the extra parameters
|
# Get the extra parameters
|
||||||
def get_extra_parameters():
|
def get_extra_parameters():
|
||||||
global g_extra
|
global g_extra
|
||||||
|
|
||||||
return g_extra
|
return g_extra
|
||||||
|
|
||||||
# Set the extra parameters
|
# Set the extra parameters
|
||||||
def set_extra_parameters(args):
|
def set_extra_parameters(args):
|
||||||
global g_extra
|
global g_extra
|
||||||
|
|
||||||
g_extra = args
|
g_extra = args
|
||||||
|
|
||||||
# Add the extra parameters
|
# Add the extra parameters
|
||||||
def add_extra_parameters(args):
|
def add_extra_parameters(args):
|
||||||
global g_extra
|
global g_extra
|
||||||
|
|
||||||
if args != "":
|
if args != "":
|
||||||
if g_extra != "":
|
if g_extra != "":
|
||||||
g_extra = g_extra + " "
|
g_extra = g_extra + " "
|
||||||
g_extra = g_extra + args
|
g_extra = g_extra + args
|
||||||
|
|
||||||
# Yield arguments, given a bound type:
|
# Yield arguments, given a bound type:
|
||||||
# 0: fast
|
# 0: fast
|
||||||
# 1: thorough
|
# 1: thorough
|
||||||
#
|
#
|
||||||
def default_arguments(plist,match,bounds):
|
def default_arguments(plist,match,bounds):
|
||||||
n = 2 + bounds
|
n = 2 + bounds
|
||||||
# These bounds assume at least two protocols, otherwise
|
# These bounds assume at least two protocols, otherwise
|
||||||
# stuff breaks.
|
# stuff breaks.
|
||||||
if n < 2:
|
if n < 2:
|
||||||
nmin = 2
|
nmin = 2
|
||||||
else:
|
else:
|
||||||
nmin = n
|
nmin = n
|
||||||
timer = 1
|
timer = 1
|
||||||
maxruns = 2
|
maxruns = 2
|
||||||
maxlength = 10
|
maxlength = 10
|
||||||
if bounds == 0:
|
if bounds == 0:
|
||||||
timer = 10 * (nmin**2)
|
timer = 10 * (nmin**2)
|
||||||
maxruns = 2*nmin
|
maxruns = 2*nmin
|
||||||
maxlength = 2 + maxruns * 4
|
maxlength = 2 + maxruns * 4
|
||||||
elif bounds == 1:
|
elif bounds == 1:
|
||||||
timer = 10 * (nmin**3)
|
timer = 10 * (nmin**3)
|
||||||
maxruns = 3*nmin
|
maxruns = 3*nmin
|
||||||
maxlength = 4 + maxruns * 6
|
maxlength = 4 + maxruns * 6
|
||||||
elif bounds == 2:
|
elif bounds == 2:
|
||||||
timer = 20 * 60 # 20 minutes
|
timer = 20 * 60 # 20 minutes
|
||||||
maxruns = 3*nmin
|
maxruns = 3*nmin
|
||||||
maxlength = 4 + maxruns * 6
|
maxlength = 4 + maxruns * 6
|
||||||
else:
|
else:
|
||||||
print "Don't know bounds method", bounds
|
print "Don't know bounds method", bounds
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
args = "--arachne"
|
args = ""
|
||||||
if timer > 0:
|
if timer > 0:
|
||||||
args = args + " --timer=%i" % timer
|
args = args + " --timer=%i" % timer
|
||||||
args = args + " --max-runs=%i --max-length=%i" % (maxruns, maxlength)
|
args = args + " --max-runs=%i --max-length=%i" % (maxruns, maxlength)
|
||||||
matching = "--match=" + str(match)
|
matching = "--match=" + str(match)
|
||||||
args = "--summary " + matching + " " + args
|
args = "--plain " + matching + " " + args
|
||||||
|
|
||||||
extra = get_extra_parameters()
|
extra = get_extra_parameters()
|
||||||
if extra != "":
|
if extra != "":
|
||||||
args = extra + " " + args
|
args = extra + " " + args
|
||||||
return args
|
return args
|
||||||
|
|
||||||
# Yield test results
|
# Yield test results
|
||||||
def default_test(plist, match, bounds):
|
def default_test(plist, match, bounds):
|
||||||
pl = default_protocols(plist)
|
pl = default_protocols(plist)
|
||||||
args = default_arguments(plist,match,bounds)
|
args = default_arguments(plist,match,bounds)
|
||||||
|
|
||||||
input = ""
|
input = ""
|
||||||
for fn in pl:
|
for fn in pl:
|
||||||
if len(fn) > 0:
|
if len(fn) > 0:
|
||||||
f = open(fn, "r")
|
f = open(fn, "r")
|
||||||
input = input + f.read()
|
input = input + f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Use Scyther
|
# Use Scyther
|
||||||
(status,scout) = evaluate(args,input)
|
(status,scout) = evaluate(args,input)
|
||||||
return (status,scout)
|
return (status,scout)
|
||||||
|
|
||||||
# Test, check for status, yield parsed results
|
# Test, check for status, yield parsed results
|
||||||
def default_parsed(plist, match, bounds):
|
def default_parsed(plist, match, bounds):
|
||||||
(status,scout) = default_test(plist, match, bounds)
|
(status,scout) = default_test(plist, match, bounds)
|
||||||
if error_status(status):
|
if error_status(status):
|
||||||
# Something went wrong
|
# Something went wrong
|
||||||
print "*** Error when checking [", plist, match, bounds, "]"
|
print "*** Error when checking [", plist, match, bounds, "]"
|
||||||
print
|
print
|
||||||
sys.exit()
|
sys.exit()
|
||||||
return parse(scout)
|
return parse(scout)
|
||||||
|
|
||||||
# Some default options for the scyther wrapper
|
# Some default options for the scyther wrapper
|
||||||
def default_options(parser):
|
def default_options(parser):
|
||||||
parser.add_option("-m","--match", dest="match",
|
parser.add_option("-m","--match", dest="match",
|
||||||
default = 0,
|
default = 0,
|
||||||
help = "select matching method (0: no type flaws, 2: \
|
help = "select matching method (0: no type flaws, 2: \
|
||||||
full type flaws")
|
full type flaws")
|
||||||
parser.add_option("-b","--bounds", dest="bounds",
|
parser.add_option("-b","--bounds", dest="bounds",
|
||||||
default = 0,
|
default = 0,
|
||||||
help = "bound type selection (0: quickscan, 1:thorough, 2: no time limit)")
|
help = "bound type selection (0: quickscan, 1:thorough, 2: no time limit)")
|
||||||
parser.add_option("-x","--extra", dest="extra",
|
parser.add_option("-x","--extra", dest="extra",
|
||||||
default = "",
|
default = "",
|
||||||
help = "add arguments to pass to Scyther")
|
help = "add arguments to pass to Scyther")
|
||||||
parser.add_option("-P","--program", dest="program",
|
parser.add_option("-P","--program", dest="program",
|
||||||
default = "",
|
default = "",
|
||||||
help = "define alternative scyther executable")
|
help = "define alternative scyther executable")
|
||||||
parser.add_option("-N","--no-cache", dest="nocache",
|
parser.add_option("-N","--no-cache", dest="nocache",
|
||||||
default = False,
|
default = False,
|
||||||
action = "store_true",
|
action = "store_true",
|
||||||
help = "do not use cache mechanism")
|
help = "do not use cache mechanism")
|
||||||
|
|
||||||
# Process the default options
|
# Process the default options
|
||||||
def process_default_options(options):
|
def process_default_options(options):
|
||||||
if options.program != "":
|
if options.program != "":
|
||||||
scytheroverride(options.program)
|
scytheroverride(options.program)
|
||||||
print "Using", options.program, "as Scyther executable."
|
print "Using", options.program, "as Scyther executable."
|
||||||
if options.extra != "":
|
if options.extra != "":
|
||||||
add_extra_parameters(options.extra)
|
add_extra_parameters(options.extra)
|
||||||
print "Added extra options, now:", get_extra_parameters()
|
print "Added extra options, now:", get_extra_parameters()
|
||||||
if options.nocache:
|
if options.nocache:
|
||||||
# Do not use cache
|
# Do not use cache
|
||||||
print "Warning: Disabling cache"
|
print "Warning: Disabling cache"
|
||||||
cacheoverride ()
|
cacheoverride ()
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
@ -182,131 +182,131 @@ def process_default_options(options):
|
|||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
def all_unless_given(plist):
|
def all_unless_given(plist):
|
||||||
if plist == []:
|
if plist == []:
|
||||||
# Get the list
|
# Get the list
|
||||||
import protocollist
|
import protocollist
|
||||||
return protocollist.from_all()
|
return protocollist.from_all()
|
||||||
else:
|
else:
|
||||||
return plist
|
return plist
|
||||||
|
|
||||||
# Scan for compilation errors or stuff like that
|
# Scan for compilation errors or stuff like that
|
||||||
|
|
||||||
def scan_for_results(options,args):
|
def scan_for_results(options,args):
|
||||||
# Select specific list
|
# Select specific list
|
||||||
plist = all_unless_given(args)
|
plist = all_unless_given(args)
|
||||||
# Now check all things in the list
|
# Now check all things in the list
|
||||||
for p in plist:
|
for p in plist:
|
||||||
# Test and gather output
|
# Test and gather output
|
||||||
(status,scout) = default_test([p], 0, 0)
|
(status,scout) = default_test([p], 0, 0)
|
||||||
print scout
|
print scout
|
||||||
|
|
||||||
print
|
print
|
||||||
print "Scan complete."
|
print "Scan complete."
|
||||||
|
|
||||||
def scan_for_errors(options,args):
|
def scan_for_errors(options,args):
|
||||||
# Select specific list
|
# Select specific list
|
||||||
plist = all_unless_given(args)
|
plist = all_unless_given(args)
|
||||||
# Now check all things in the list
|
# Now check all things in the list
|
||||||
errorcount = 0
|
errorcount = 0
|
||||||
for p in plist:
|
for p in plist:
|
||||||
# Test and gather output
|
# Test and gather output
|
||||||
(status,scout) = default_test([p], 0, 0)
|
(status,scout) = default_test([p], 0, 0)
|
||||||
error = False
|
error = False
|
||||||
if error_status(status):
|
if error_status(status):
|
||||||
error = True
|
error = True
|
||||||
else:
|
else:
|
||||||
if scout.rfind("ERROR") != -1:
|
if scout.rfind("ERROR") != -1:
|
||||||
error = True
|
error = True
|
||||||
if scout.rfind("error") != -1:
|
if scout.rfind("error") != -1:
|
||||||
error = True
|
error = True
|
||||||
if error:
|
if error:
|
||||||
print "There is an error in the output for", p
|
print "There is an error in the output for", p
|
||||||
errorcount = errorcount + 1
|
errorcount = errorcount + 1
|
||||||
|
|
||||||
if errorcount > 0:
|
if errorcount > 0:
|
||||||
print
|
print
|
||||||
print "Scan complete. Found", errorcount, "error(s) in", len(plist), "files."
|
print "Scan complete. Found", errorcount, "error(s) in", len(plist), "files."
|
||||||
|
|
||||||
# Scan for timeout protocols
|
# Scan for timeout protocols
|
||||||
#
|
#
|
||||||
# The idea is that some things will generate a timeout, and we would like
|
# The idea is that some things will generate a timeout, and we would like
|
||||||
# to know which ones. However, this can just be a problem of the time
|
# to know which ones. However, this can just be a problem of the time
|
||||||
# limit, and might not be caused by a loop at all. Therefore, some
|
# limit, and might not be caused by a loop at all. Therefore, some
|
||||||
# scanning is needed.
|
# scanning is needed.
|
||||||
|
|
||||||
def scan_for_timeouts(options,args):
|
def scan_for_timeouts(options,args):
|
||||||
|
|
||||||
def parse_timeout(status,scout):
|
def parse_timeout(status,scout):
|
||||||
if not error_status(status):
|
if not error_status(status):
|
||||||
if scout.rfind("time=") != -1:
|
if scout.rfind("time=") != -1:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_for_timeout(p):
|
def check_for_timeout(p):
|
||||||
# First a simple test
|
# First a simple test
|
||||||
(status,scout) = default_test([p], 0, 1)
|
(status,scout) = default_test([p], 0, 1)
|
||||||
if not parse_timeout(status,scout):
|
if not parse_timeout(status,scout):
|
||||||
# Well if there is no timeout here...
|
# Well if there is no timeout here...
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# More testing...
|
# More testing...
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Select specific list
|
# Select specific list
|
||||||
plist = all_unless_given(args)
|
plist = all_unless_given(args)
|
||||||
# Now check all things in the list
|
# Now check all things in the list
|
||||||
errorcount = 0
|
errorcount = 0
|
||||||
for p in plist:
|
for p in plist:
|
||||||
# Test and gather output
|
# Test and gather output
|
||||||
if check_for_timeout(p):
|
if check_for_timeout(p):
|
||||||
print "There is a timeout for", p
|
print "There is a timeout for", p
|
||||||
errorcount = errorcount + 1
|
errorcount = errorcount + 1
|
||||||
|
|
||||||
if errorcount > 0:
|
if errorcount > 0:
|
||||||
print
|
print
|
||||||
print "Scan complete. Found", errorcount, "timeout(s) in", len(plist), "files."
|
print "Scan complete. Found", errorcount, "timeout(s) in", len(plist), "files."
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Standalone usage
|
# Standalone usage
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
default_options(parser)
|
default_options(parser)
|
||||||
parser.add_option("-e","--errors", dest="errors",
|
parser.add_option("-e","--errors", dest="errors",
|
||||||
default = False,
|
default = False,
|
||||||
action = "store_true",
|
action = "store_true",
|
||||||
help = "detect compilation errors for all protocols [in list_all]")
|
help = "detect compilation errors for all protocols [in list_all]")
|
||||||
parser.add_option("-r","--results", dest="results",
|
parser.add_option("-r","--results", dest="results",
|
||||||
default = False,
|
default = False,
|
||||||
action = "store_true",
|
action = "store_true",
|
||||||
help = "scan for results for all protocols [in list_all]")
|
help = "scan for results for all protocols [in list_all]")
|
||||||
parser.add_option("-t","--timeouts", dest="timeouts",
|
parser.add_option("-t","--timeouts", dest="timeouts",
|
||||||
default = False,
|
default = False,
|
||||||
action = "store_true",
|
action = "store_true",
|
||||||
help = "scan for timeout errors for all protocols [in list_all]")
|
help = "scan for timeout errors for all protocols [in list_all]")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
# Globals
|
# Globals
|
||||||
process_default_options(options)
|
process_default_options(options)
|
||||||
|
|
||||||
# Subcases
|
# Subcases
|
||||||
if options.errors:
|
if options.errors:
|
||||||
scan_for_errors(options,args)
|
scan_for_errors(options,args)
|
||||||
elif options.results:
|
elif options.results:
|
||||||
scan_for_results(options,args)
|
scan_for_results(options,args)
|
||||||
elif options.timeouts:
|
elif options.timeouts:
|
||||||
scan_for_timeouts(options,args)
|
scan_for_timeouts(options,args)
|
||||||
else:
|
else:
|
||||||
# Not any other switch: just test the list then
|
# Not any other switch: just test the list then
|
||||||
if args == []:
|
if args == []:
|
||||||
print "Scyther default test needs at least one input file."
|
print "Scyther default test needs at least one input file."
|
||||||
sys.exit()
|
sys.exit()
|
||||||
(status,scout) = default_test(args, options.match, options.bounds)
|
(status,scout) = default_test(args, options.match, options.bounds)
|
||||||
print "Status:", status
|
print "Status:", status
|
||||||
print scout
|
print scout
|
||||||
|
|
||||||
# Only if main stuff
|
# Only if main stuff
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user