本文整理汇总了Python中sut.sut函数的典型用法代码示例。如果您正苦于以下问题:Python sut函数的具体用法?Python sut怎么用?Python sut使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sut函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv):
global sut, rgen, ntest, nbug, coverageCount, start, selectStatements, threshold
parse_options(argv)
# GLOBAL VARIABLES
sut = sut.sut()
rgen = random.Random(opts.seed)
ntest = 0
nbug = 0
coverageCount = {}
selectStatements = {}
threshold = 0
start = time.time()
# PHASES
phaseLimit = 0
if opts.timeout < 30:
phaseLimit = int(round(opts.timeout/3*2))
else:
phaseLimit = int(round(opts.timeout/10))
while (time.time() - start) < (0.95 * opts.timeout):
randomPool = phase1(phaseLimit)
selectPool = filterPool(randomPool)
phase2(randomPool, selectPool)
print "FULL POOL:",len(randomPool),", SELECT POOL:",len(selectPool)
print "EXECUTED:",ntest,"tests"
print "BUGS:",nbug
print "TOTAL ELAPSED:",round(time.time() - start,5),"seconds"
if (opts.coverage):
sut.internalReport()
示例2: main
def main():
global start,sut,R,noerror,error,actCount, bugs,ntest,newseq,currseq,states
actCount = 0
bugs = 0
start = time.time()
noerror = []
error = []
newseq = []
ntest=0
currseq=[]
sut = sut.sut()
R = random.Random(seed)
states = [sut.state()]
print "STARTING PHASE 1"
while(time.time() < start + timeout):
for st in states:
ntest+=1
if (time.time() > start + timeout):
break
sut.restart()
sut.backtrack(st)
for s in xrange(0, depth):
if (time.time() > start + timeout):
break
ok = randomAction()
if not ok:
break
checkAlg()
if coverage:
sut.internalReport()
print "TOTAL BUGS", bugs
print "TOTAL ACTIONS",actCount
print "TOTAL RUNTIME",time.time()-start
示例3: main
def main():
global start,config,sut,R,nonerror,error,file_name,num
num = 0
file_name = 'failurefile'
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
print('Random testing using config={}'.format(config))
sut = SUT.sut()
R = random.Random(config.seed)
start = time.time()
elapsed = time.time() - start
states = [sut.state()]
nonerror = []
error = []
news = None
while(time.time() < start + config.timeout):
for s in states:
sut.restart()
sut.backtrack(s)
for w in xrange(0, config.width):
for d in xrange(0, config.depth):
ok = check_action()
news = sut.newStatements()
if not ok:
break
if((len(news)>0) and (not ((news in error) or (news in nonerror)))):
states.insert(0,sut.state())
nonerror.append(sut.currStatements())
if config.coverage:
sut.internalReport()
print "Bugs ",num
示例4: __init__
def __init__(self, pid):
self.pid = pid # unique id for this pool
self.sut = SUT.sut() # SUT object
self.nseqs = [[]] # list of non-error sequences
self.eseqs = [] # list of error sequences
self.covered = dict() # dictionary, key: coverage by this pool, value: frequency of coverage by this pool
self.time = 0.0 # how many seconds this pool is used in feedback()
self.count = 0 # how many times this pool is selected in select_pool()
self.score = 0.0 # score of this pool
self.uniqueness = 0.0 # uniqueness of this pool
示例5: main
def main():
global config, R, sut, bugs, actCount, branchCount, statementCount, ntest, start
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
print('Testing using config={}'.format(config))
R = random.Random(config.seed)
sut = sut.sut()
sut.silenceCoverage()
bugs = 0
actCount = 0
coverageCount = {}
branchCount = {}
statementCount = {}
ntest = 0
start = time.time()
elapsed = time.time() - start
print "Starting Test"
while elapsed < config.timeout:
sut.restart()
ntest += 1
for i in xrange(0, config.depth):
if not randomAct():
break
elapsed = time.time() - start
if config.running:
showRunning()
elapsed = time.time() - start
if elapsed > config.timeout:
print "Stopping test [TIMEOUT]"
break
collectCoverage()
elapsed = time.time() - start
print "Finishing Test"
if time.time() - start > config.timeout:
print "[TIMEOUT]"
printCoverage()
if config.coverage:
sut.internalReport()
print "Covered", len(sut.allBranches()), "branches"
print "Covered", len(sut.allStatements()), "statements"
print "Failed", bugs, "times"
print "Total tests", ntest
print "Total actions", actCount
print "Total runtime", time.time() - start
示例6: main
def main():
global start,sut,R,noerror,error,reduceTime,actCount, bugs,ntest,newseq,currseq,states, beforeReduceS, beforeReduceB,quickCount
actCount = 0
bugs = 0
start = time.time()
noerror = []
error = []
newseq = []
ntest=0
currseq=[]
sut = sut.sut()
reduceTime = 0.0
R = random.Random()
R.seed(seed)
beforeReduceS = set(sut.allStatements())
beforeReduceB = set(sut.allBranches())
states = [sut.state()]
quickCount=0
print "STARTING PHASE 1"
while(time.time() < start + timeout):
for st in states:
ntest+=1
if (time.time() > start + timeout):
break
sut.restart()
sut.backtrack(st)
for s in xrange(0, depth):
if (time.time() > start + timeout):
break
ok = randomAction()
if not ok:
break
checkAlg()
if coverage:
sut.internalReport()
if quickTests==1:
#if (sut.newCurrBranches() != set([])) or (sut.newCurrStatements() != set([])):
handle_failure(sut.test(), "NEW COVERAGE", False, newCov=True)
print "TOTAL BUGS", bugs
print "TOTAL ACTIONS",actCount
print "TOTAL RUNTIME",time.time()-start
示例7: main
def main():
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
print('Random variation of beam search using config={}'.format(config))
R = random.Random(config.seed)
start = time.time()
elapsed = time.time()-start
failCount = 0
t = SUT.sut()
if config.logging != None:
t.setLog(config.logging)
tacts = t.actions()
ntests = 0
while (config.maxtests == -1) or (ntests < config.maxtests):
ntests += 1
t.restart()
test = []
for s in xrange(0,config.depth):
count = 0
newCover = False
acts = tacts
old = t.state()
while (count <= config.width):
count += 1
while True:
p = R.randint(0,len(acts)-1)
a = acts[p]
if a[1]():
break
acts = acts[:p] + acts[p+1:]
test.append(a)
stepOk = t.safely(a)
if (not config.uncaught) and (not stepOk):
handle_failure(test, "UNCAUGHT EXCEPTION", False)
if not config.multiple:
print "STOPPING TESTING DUE TO FAILED TEST"
break
if (not config.ignoreprops) and (not t.check()):
handle_failure(test, "PROPERLY VIOLATION", True)
if not config.multiple:
print "STOPPING TESTING DUE TO FAILED TEST"
break
elapsed = time.time() - start
if t.newBranches() != set([]):
if config.running:
print "ACTION:",a[0]
for b in t.newBranches():
print elapsed,len(t.allBranches()),"New branch",b
break # Continue with this choice if new branch exposed
if elapsed > config.timeout:
break
test = test[:-1]
t.backtrack(old)
if elapsed > config.timeout:
print "STOPPING TEST DUE TO TIMEOUT, TERMINATED AT LENGTH",len(test)
break
if (not config.multiple) and (failCount > 0):
break
if elapsed > config.timeout:
print "STOPPING TESTING DUE TO TIMEOUT"
break
if not config.nocover:
print t.report(config.coverfile),"PERCENT COVERED"
if config.html:
t.htmlReport(config.html)
print ntests, "EXECUTED"
if config.multiple:
print failCount,"FAILED"
if not config.nocover:
print len(t.allBranches()),"BRANCHES COVERED"
print len(t.allStatements()),"STATEMENTS COVERED"
示例8: len
savedTest = None
failureCount = 0
actioncount = 0
testsCovered = []
option = parser.parse_args() # a object named pointer is made for this
SEED = option.SEED
TIMEOUT = option.TIMEOUT
DEPTH = option.DEPTH
WIDTH = option.WIDTH
FAULT_CHECK = option.FAULT_CHECK
COVERAGE_REPORT = option.COVERAGE_REPORT
DETAIL_OF_RUNNING = option.DETAIL_OF_RUNNING
#INITIAL_POP = option.INITIAL_POP
rgen = random.Random()
rgen.seed(SEED)
sut = sut.sut() #this will reset the system state
start = time.time() #this will start the system time
if len(sut.newStatements()) > 0:
savedTest = sut.state()
storedTest = True
print "FOUND NEW STATEMENTS",sut.newStatements()
while time.time()-start < TIMEOUT:
for f in xrange(0,DEPTH):
action = sut.randomEnabled(rgen)
for f in xrange(0,WIDTH):
action = sut.randomEnabled(rgen)
示例9: parse_args
import os
import sys
current_working_dir = os.getcwd()
sys.path.append(current_working_dir)
from collections import namedtuple
import sut as SUT
import random
import time
import traceback
import argparse
sut = SUT.sut()
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('timeout', type=int, default=60, help='Timeout in seconds. (60 default)')
parser.add_argument('seed', type=int, default=None, help='Random seed. (default = None)')
parser.add_argument('depth', type=int, default=100, help='Maximum search depth. (100 default)')
parser.add_argument('width', type=int, default=10000, help='Maximum memory. (10000 default)')
parser.add_argument('faults', type=int, default=0, choices=[0, 1], help='Check for faults or not. 1 for check, 0 for do not check (0 default)')
parser.add_argument('coverage', type=int, default=0, choices=[0, 1] ,help='report coverage or not. 1 for report, 0 for do not report(0 default)')
parser.add_argument('running', type=int, default=0, choices=[0, 1], help='Produce running branch coverage report.')
parsed_args = parser.parse_args(sys.argv[1:])
return (parsed_args, parser)
示例10: main
def main():
global failCount,sut,config,reduceTime,quickCount,repeatCount,failures,cloudFailures,R,opTime,checkTime,guardTime,restartTime,nops,ntests
global fullPool,activePool,branchCoverageCount,statementCoverageCount,localizeSFail,localizeBFail
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
print('Random testing using config={}'.format(config))
R = random.Random(config.seed)
start = time.time()
elapsed = time.time()-start
failCount = 0
quickCount = 0
repeatCount = 0
failures = []
cloudFailures = []
if config.gendepth != None:
failCloud = {}
allClouds = {}
if config.exploit != None:
fullPool = []
activePool = []
if config.quickAnalysis or (config.exploit != None):
branchCoverageCount = {}
statementCoverageCount = {}
if config.uniqueValuesAnalysis:
handledValues = {}
uniquef = open("unique.corpus",'w')
allUniquePaths = []
sut = SUT.sut()
if config.relax:
sut.relax()
if config.readQuick:
print "REPLAYING QUICK TESTS"
sqrtime = time.time()
for f in glob.glob("quicktest.*"):
fn = int(f.split("quicktest.")[1])
if fn >= quickCount:
quickCount = fn + 1
t = sut.loadTest(f)
sut.replay(t,catchUncaught=True,checkProp=(not config.ignoreprops))
print "EXECUTION TIME:",time.time()-sqrtime
print "BRANCH COVERAGE:",len(sut.allBranches())
print "STATEMENT COVERAGE:",len(sut.allStatements())
if config.logging != None:
sut.setLog(config.logging)
if config.profile:
profileTime = {}
profileCount = {}
for a in set(map(sut.actionClass, sut.actions())):
profileTime[a] = 0.0
profileCount[a] = 0
if config.markov != None:
nactions = len(sut.actions())
mprobs = {}
prefix = []
probs = []
inProbs = False
readSize = False
for l in open(config.markov):
if not readSize:
markovN = int(l)
readSize = True
elif "START CLASS" in l:
if (prefix != []):
mprobs[tuple(prefix)] = probs
prefix = []
probs = []
inProbs = False
elif inProbs:
ls = l.split("%%%%")
prob = float(ls[0])
ac = ls[1][1:-1]
probs.append((prob,ac))
elif "END CLASS" in l:
inProbs = True
else:
prefix.append(l[:-1])
tacts = sut.actions()
a = None
sawNew = False
nops = 0
ntests = 0
reduceTime = 0.0
opTime = 0.0
checkTime = 0.0
guardTime = 0.0
#.........这里部分代码省略.........
示例11: __init__
def __init__(self):
#initiialize lists
self.errorSeqs = []
self.nonErrorSeqs = []
self.sut = sut.sut()
示例12: main
def main():
mytester = simplerRandomTester(sys.argv[1:])
mysut = SUT.sut()
mysut.testWith(mytester)
示例13: __init__
def __init__(self):
self.errorSeqs = []
self.nonErrorSeqs = []
self.sut = sut.sut()
示例14: main
def main():
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
print('BFS exploration using config={}'.format(config))
R = random.Random(config.seed)
start = time.time()
elapsed = time.time()-start
failCount = 0
maxDepth = 0
maxQueue = 0
t = SUT.sut()
if config.logging != None:
t.setLog(config.logging)
queue = []
visited = []
test = []
t.restart()
queue.append((t.state(), test))
while (queue != []):
if len(queue) > maxQueue:
maxQueue = len(queue)
(s, test) = queue[0]
queue = queue[1:]
if len(test) > maxDepth:
maxDepth = len(test)
print "REACHED DEPTH",maxDepth,"QUEUE SIZE",len(queue)+1
if len(test) == config.depth:
continue
t.backtrack(s)
shuffleActs = t.enabled()
if not config.deterministic:
R.shuffle(shuffleActs)
for c in shuffleActs:
stepOk = t.safely(c)
test.append(c)
thisBug = False
if (not config.uncaught) and (not stepOk):
handle_failure(test, "UNCAUGHT EXCEPTION", False)
if not config.multiple:
print "STOPPING TESTING DUE TO FAILED TEST"
thisBug = True
if (not config.ignoreprops) and (not t.check()):
handle_failure(test, "PROPERLY VIOLATION", True)
if not config.multiple:
print "STOPPING TESTING DUE TO FAILED TEST"
thisBug = True
ns = t.state()
if not thisBug:
if config.novisited or (ns not in visited):
if (random.random() < config.forget) and (not (queue == [])):
break
if len(queue) >= config.breadth:
break
if not config.novisited:
visited.append(s)
if config.verbose:
print len(visited), "NEW STATE:"
print s
queue.append((ns, test))
elif not config.multiple:
break
elapsed = time.time() - start
if config.running:
if t.newBranches() != (set([])):
print "ACTION:",action
for b in t.newBranches():
print elapsed,len(t.allBranches()),"New branch",b
if elapsed > config.timeout:
print "STOPPING EXPLORATION DUE TO TIMEOUT, TERMINATED AT LENGTH",len(test)
break
t.backtrack(s)
test = test[:-1]
if (not config.multiple) and (failCount > 0):
break
if elapsed > config.timeout:
print "STOPPING TESTING DUE TO TIMEOUT"
break
if not config.nocover:
print t.report(config.coverfile),"PERCENT COVERED"
if config.html:
t.htmlReport(config.html)
print len(visited), "STATES VISITED"
print maxDepth,"MAX SEARCH DEPTH"
print maxQueue,"MAX QUEUE SIZE"
if config.multiple:
print failCount,"FAILED"
if not config.nocover:
print len(t.allBranches()),"BRANCHES COVERED"
print len(t.allStatements()),"STATEMENTS COVERED"
示例15: main
def main():
global failCount,t,config,reduceTime,quickCount,repeatCount,failures,cloudFailures,R,opTime,checkTime,guardTime,restartTime,nops,ntests
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
print('Random testing using config={}'.format(config))
R = random.Random(config.seed)
start = time.time()
elapsed = time.time()-start
failCount = 0
quickCount = 0
repeatCount = 0
failures = []
cloudFailures = []
if config.gendepth != None:
failCloud = {}
allClouds = {}
t = SUT.sut()
if config.logging != None:
t.setLog(config.logging)
tacts = t.actions()
a = None
sawNew = False
nops = 0
ntests = 0
reduceTime = 0.0
opTime = 0.0
checkTime = 0.0
guardTime = 0.0
restartTime = 0.0
checkResult = True
if config.total:
fulltest = open("fulltest.txt",'w')
if config.verbose:
print "ABOUT TO START TESTING"
sys.stdout.flush()
while (config.maxtests == -1) or (ntests < config.maxtests):
if config.verbose:
print "STARTING TEST",ntests
sys.stdout.flush()
ntests += 1
startRestart = time.time()
t.restart()
restartTime += time.time() - startRestart
test = []
if config.total:
fulltest.write("<<RESTART>>\n")
if config.replayable:
currtest = open("currtest.txt",'w')
for s in xrange(0,config.depth):
if config.verbose:
print "GENERATING STEP",s
startGuard = time.time()
acts = tacts
while True:
elapsed = time.time() - start
if elapsed > config.timeout:
break
tryStutter = (a != None)
if tryStutter:
if (config.stutter == None) and (not config.greedyStutter):
tryStutter = False
if tryStutter:
if (config.stutter == None) or (R.random() > config.stutter):
tryStutter = False
if (config.greedyStutter) and sawNew:
print "TRYING TO STUTTER DUE TO COVERAGE GAIN"
tryStutter = True
if not tryStutter:
if len(acts) == 1:
p = 0
else:
p = R.randint(0,len(acts)-1)
a = acts[p]
if a[1]():
break
else:
a = None
acts = acts[:p] + acts[p+1:]
guardTime += time.time()-startGuard
elapsed = time.time() - start
if elapsed > config.timeout:
#.........这里部分代码省略.........