本文整理汇总了Python中sut.randomEnabled函数的典型用法代码示例。如果您正苦于以下问题:Python randomEnabled函数的具体用法?Python randomEnabled怎么用?Python randomEnabled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randomEnabled函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: randomAction
def randomAction():
global actCount, bugs,newseq,currseq
act = sut.randomEnabled(R)
actCount += 1
ok = sut.safely(act)
if running:
if len(sut.newBranches()) > 0:
print "ACTION:",sut.randomEnabled(random.Random(seed))[0]
for b in sut.newBranches():
print time.time() - start, len(sut.allBranches()),"New branch",b
for s1 in sut.newStatements():
print time.time() - start, len(sut.allStatements()),"New statement",s1
if not ok:
bugs += 1
print "FOUND A FAILURE"
if faults:
f = sut.reduce(sut.test(), sut.fails, True, True)
sut.prettyPrintTest(f)
currseq.append((f,set(sut.currStatements())))
print("SHOW FAULT")
file = 'failure' + str(actCount) + '.test'
sut.saveTest(sut.test(), file)
sut.restart()
print sut.failure()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:29,代码来源:tester2.py
示例2: randomAction
def randomAction():
global actCount, bugs, coverageCount, belowMean,lastAddCoverage
act = sut.randomEnabled(random.Random())
actCount += 1
ok = sut.safely(act)
if running:
if len(sut.newBranches()) > 0:
print "ACTION:",sut.randomEnabled(random.Random(seed))[0]
for b in sut.newBranches():
print time.time() - start, len(sut.allBranches()),"New branch",b
for s1 in sut.newStatements():
print time.time() - start, len(sut.allStatements()),"New statement",b
if not ok or not sut.check():
bugs += 1
print "FOUND A FAILURE"
if faults:
print("SHOW FAULT")
print sut.failure()
error.append(sut.test())
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
sut.restart()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:28,代码来源:tester1.py
示例3: action
def action():
global actCount, bugs, failPool
act = sut.randomEnabled(rgen)
actCount += 1
ok = sut.safely(act)
if running == 1:
if len(sut.newBranches()) > 0:
print "ACTION:", act[0]
for b in sut.newBranches():
print time.time() - start, len(sut.allBranches()), "New branch", b
for s in sut.newStatements():
print time.time() - start, len(sut.allStatements()),"New statement",s
if not ok:
if faults:
bugs += 1
print "FOUND A FAILURE"
print sut.failure()
print "REDUCING"
failPool.append(sut.test())
collectCoverage()
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
fname="failure" + str(bugs) + ".test"
sut.saveTest(sut.test(),fname)
errorSeqs.append(sut.currStatements())
sut.restart()
else:
expand()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:32,代码来源:tester2.py
示例4: randomAction
def randomAction():
global actCount, bugs, fails, errCount, newCount
sawNew = False
act = sut.randomEnabled(seeds)
actCount += 1
ok = sut.safely(act)
propok = sut.check()
if running:
if sut.newBranches() != set([]):
for b in sut.newBranches():
print time.time()-start,len(sut.allBranches()),"New branch",b
sawNew = True
newCount += 1
else:
sawNew = False
if not ok or not propok:
if faults:
bugs += 1
fail.append(sut.test())
saveCover()
sut.restart()
print "FAILURE FOUND.....FAILURES ARE STORING IN FILES"
errCount += 1
fault = sut.failure()
fname = 'failure' + str(bugs) + '.test'
sut.saveTest(sut.test(), fname)
sut.restart()
else:
expandPool()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:33,代码来源:finaltester.py
示例5: tester
def tester():
global sut,act,n,test,para,lCovered,actNum,bugs,M,flag, filename
act = sut.randomEnabled(rgen)
flag = 0
n = sut.safely(act)
if running:
if sut.newBranches() != set([]):
for d in sut.newBranches():
print time.time() - start, len(sut.allBranches()),"New branch",d
if len(sut.newStatements()) > 0:
test = sut.state()
para = True
print sut.newStatements()
if (para == False):
if (lCovered != None):
if (lCovered in sut.currStatements()):
test = sut.state()
para = True
actNum += 1
if (n == 0):
bugs += 1
print "A failure has been found!", bugs
print sut.failure()
M = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(M)
print sut.failure()
filename ='failure%d.test'%bugs
sut.saveTest(M,filename)
flag = 1
开发者ID:agroce,项目名称:cs569sp16,代码行数:29,代码来源:tester2.py
示例6: randomAction
def randomAction():
global bug_no, time_start, allAction, ii
action = sut.randomEnabled(rand)
ok = sut.safely(action)
elapsed = time.time() - time_start
if RUNNING_DETAIL:
if len(sut.newBranches()) > 0:
print "ACTION:", action[0]
for b in sut.newBranches():
print elapsed, len(sut.allBranches()), "New branch", b
if not ok: # found a bug
bug_no += 1
print "FOUND A BUG! #", bug_no
print sut.failure()
print("REDUCING")
reduce = sut.reduce(sut.test(), sut.fails, True, True)
sut.prettyPrintTest(reduce)
print(sut.failure())
# write the bug to file if FAULT_ARGUMENT is enabled
if (FAULT_CHECK):
f = open((failure_file + str(bug_no) + ".test"), "w")
print >> f, sut.failure()
# print sequence that causes failure
j = 0
for (s_reduces, _, _) in reduce:
steps_reduce = "# STEP " + str(j)
print >> f, sut.prettyName(s_reduces).ljust(80 - len(steps_reduce), ' '), steps_reduce
j += 1
f.close()
print "time: ", time.time() - time_start
return ok
开发者ID:Cianna,项目名称:cs569sp16,代码行数:33,代码来源:tester1.py
示例7: newState
def newState():
global rgen,sut,collected_test,storedTest,action_cnt,bugfound
for i in xrange(0,DEPTH):
action = sut.randomEnabled(rgen)
no_bug_found = sut.safely(action)
if RUNNING:
if sut.newBranches() != set([]):
for d in sut.newBranches():
print time.time() - start,len(sut.allBranches()),"New Branches",d
if len(sut.newStatements()) > 0:
collected_test = sut.state()
storedTest = True
print "new statement:",sut.newStatements()
if (not storedTest) and (lst_coverage != None) and (lst_coverage in sut.currStatements()):
collected_test = sut.state()
storedTest = True
action_cnt += 1
if not no_bug_found:
bugfound += 1
print "A failure happened here."
rds = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(rds)
print sut.failure()
break
开发者ID:agroce,项目名称:cs569sp16,代码行数:25,代码来源:tester1.py
示例8: mutate
def mutate(test):
global bugs
tcopy = list(test)
#randomly choose part of the chosen case
i = rgen.randint(0,len(tcopy))
#replay to be the chosen state
sut.replay(tcopy[:i],catchUncaught = True)
e = sut.randomEnabled(rgen)
#check whether it is correct
ok = sut.safely(e)
if not ok:
bugs = bugs+1
errors.append(sut.currStatements())
fault_collection()
trest = [e]
for s in tcopy[i+1:]:
if s[1]():
trest.append(s)
sut.safely(s)
tcopy = test[:i]+trest
#if we find new branches
if len(sut.newCurrBranches()) != 0:
print "NEW BRANCHES DUE TO MUTATION:",sut.newCurrBranches()
return tcopy
开发者ID:agroce,项目名称:cs569sp16,代码行数:29,代码来源:finaltester.py
示例9: appendAndExecuteSeq
def appendAndExecuteSeq(seq, n, eseqs, nseqs):
ok = False
propok = False
classTable = dict.fromkeys(sut.actionClasses(), 0)
timeover = time.time() - start >= timeout
while n > 0:
n -= 1
a = sut.randomEnabled(rgen)
seq.append(a)
if equal(seq, eseqs) or equal(seq, nseqs):
continue
ok = sut.safely(a)
propok = sut.check()
classTable[sut.actionClass(a)] += 1
if running:
argRunning(a)
if contract(ok, propok, seq, eseqs):
break
timeover = time.time() - start >= timeout
if timeover:
return (ok, propok, classTable, timeover)
return (ok, propok, classTable, timeover)
开发者ID:agroce,项目名称:cs569sp16,代码行数:29,代码来源:finaltester.py
示例10: action
def action():
global actCount, bugs, failPool
act = sut.randomEnabled(rgen)
actCount += 1
ok = sut.safely(act)
if running == 1:
if len(sut.newBranches()) > 0:
print "ACTION:", act[0]
for b in sut.newBranches():
print time.time() - start, len(sut.allBranches()), "New branch", b
if faults:
if not ok:
bugs += 1
print "FOUND A FAILURE"
print sut.failure()
print "REDUCING"
failPool.append(sut.test())
collectCoverage()
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
f = open(("failure" + str(bugs) + ".test"),"w")
f.writelines(str(sut.failure()))
f.close()
sut.restart()
else:
expand()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:31,代码来源:tester1.py
示例11: randomAction
def randomAction():
global actCount,bugs,j,running,actCount,r
test = False
for b in xrange(0,depth):
act = sut.randomEnabled(r)
# actCount += 1
ok = sut.safely(act)
Scheck = sut.check()
if len(sut.newBranches()) > 0:
Stest = sut.state()
test = True
if (not test) and (LCov != None) and (LCov in sut.currBranches()):
Stest = sut.start()
test = True
actCount += 1
if running == 1:
if sut.newBranches() != set([]):
print "ACTIONS:", act[0]
for b in sut.newBranches():
print time.time()-start,len(sut.allBranches()),"New branch",b
if faults == 1:
if not ok:
print "FOUND A FAILURE"
j += 1
bugs += 1
fault = sut.failure()
failurename = 'failure' + str(bugs) + '.test'
sut.saveTest(sut.test(), failurename)
print"the bugs is ",j
sut.restart()
开发者ID:agroce,项目名称:cs569sp16,代码行数:34,代码来源:tester2.py
示例12: randomAct
def randomAct():
global actCount, bugs, R
act = None
act = sut.randomEnabled(R)
actCount += 1
ok = sut.safely(act)
if (not ok):
failure()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:9,代码来源:finaltester.py
示例13: randomAction
def randomAction():
global actCount, bugs, failPool
act = sut.randomEnabled(rgen)
actCount += 1
ok = sut.safely(act)
if not ok:
failures()
else:
Statement()
return ok
开发者ID:Cianna,项目名称:cs569sp16,代码行数:10,代码来源:tester1.py
示例14: randomAct
def randomAct():
global sut, actCount, R
act = sut.randomEnabled(R)
actCount += 1
ok = sut.safely(act)
propok = sut.check()
if (not ok) or ((not propok) and (config.check)):
failure()
else:
savingTest()
return ok
开发者ID:agroce,项目名称:cs569sp16,代码行数:11,代码来源:mytester.py
示例15: main
def main():
global config,rgen,actCount,failCount,ntests,coverageCount
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
rgen = random.Random(config.seed)
actCount = 0
failCount = 0
coverageCount = {}
start = time.time()
ntests = 0
while True:
elapsed = time.time() - start
if elapsed > config.timeout:
print "STOPPING TEST DUE TO TIMEOUT, TERMINATED AT LENGTH",ntests
break
for i in xrange(0, config.depth):
sut.restart()
ntests += 1
for j in xrange(0, config.width):
act = sut.randomEnabled(rgen)
actCount += 1
ok = sut.safely(act)
if not ok:
failCount += 1
print "FOUND A FAILURE"
collectCoverage()
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
break
if config.running:
if sut.newBranches() != set([]):
for b in sut.newBranches():
print time.time()-start, len(sut.allBranches()), "New branch", b
if sut.newStatements() != set([]):
for s in sut.newStatements():
print time.time()-start,len(sut.allStatements()),"New statement",s
collectCoverage()
if config.faults:
print "TOTAL FAULTS", failCount
if config.coverage:
print len(sut.allBranches()),"BRANCHES COVERED"
print len(sut.allStatements()),"STATEMENTS COVERED"
print "TOTAL ACTIONS",actCount
print "TOTAL RUNTIME",time.time()-start
开发者ID:Cianna,项目名称:cs569sp16,代码行数:54,代码来源:tester1.py
示例16: main
def main():
global config,rgen,actCount,failCount,ntests,fullPool
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
rgen = random.Random(config.seed)
actCount = 0
failCount = 0
fullPool = []
start = time.time()
ntests = 0
while time.time() - start < config.timeout:
ntests += 1
sut.restart()
for d in xrange(0, config.depth):
act = sut.randomEnabled(rgen)
actCount += 1
ok = sut.safely(act)
expandPool()
if config.running:
if sut.newBranches() != set([]):
for b in sut.newBranches():
print time.time()-start, len(sut.allBranches()), "New branch", b
if sut.newStatements() != set([]):
for s in sut.newStatements():
print time.time()-start, len(sut.allStatements()),"New statement",s
if not ok:
failCount += 1
if config.faults:
failureHandle(failCount)
print "FOUND A FAILURE"
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
sut.restart()
break
if time.time() - start > config.timeout:
print "STOPPING TEST DUE TO TIMEOUT, TERMINATED AT LENGTH",ntests
break
if config.faults:
print "TOTAL FAULTS", failCount
if config.coverage:
sut.internalReport()
print "TOTAL ACTIONS",actCount
print "TOTAL RUNTIME",time.time()-start
开发者ID:agroce,项目名称:cs569sp16,代码行数:53,代码来源:tester1.py
示例17: main
def main():
global running,start,TIMEBUDGET,sut,testSaving,gene,testStored,act,srun,flag,coverageCount,covrSort,calculateWei,allCoverage,cW,coverageWM,failCount,actionsCount,sd
#global running,possible
global config
#global lastAddCoverage
belowMeanCoverage = set([])
fullPoll = []
parsed_args, parser = parse_args()
config = make_config(parsed_args, parser)
while time.time()-start < TIMEBUDGET:
sut.restart()
if (testSaving != None) and (gene.random() > 0.3):
sut.backtrack(testSaving)
testStored = False
#print "Firstly test the AVL tree"
for s in xrange(0,config.depth):
act = sut.randomEnabled(gene)
srun = sut.safely(act)
if config.running:
if sut.newBranches() != set([]):
for d in sut.newBranches():
print time.time()-start,len(sut.allBranches()),"New branch",d
findFail()
if flag == 1:
break
for sa in sut.currStatements():
if sa not in coverageCount:
coverageCount[sa] = 0
coverageCount[sa] = coverageCount[sa] + 1
covrSort = sorted(coverageCount.keys(), key=lambda x: coverageCount[x])
#coverSum = sum(coverageCount.values())
#coverMean = coverSum / (1.0*len(coverageCount))
#print "the mean of coverage is:",coverMean
#for st in covrSort:
#print st, coverageCount[st]
# if coverageCount[st]<coverMean:
# belowMeanCoverage.add(st)
# else:
# break
#print len(belowMeanCoverage), "statement below the mean coverage out of the total coverage:",len(coverageCount)
for st in covrSort:
if st*(allCoverage - coverageCount[st]) >25:
coverageWM.append(st*(allCoverage - coverageCount[st]))
print "Now I have the statement below coverage:", st
for sd in covrSort:
print sd,coverageCount[sd]
sut.internalReport()
print failCount,"FAILED"
print len(sut.allBranches()),"BRANCH"
print actionsCount,"TOTAL ACTIONS"
print time.time()-start,"TOTAL RUNTIME"
开发者ID:agroce,项目名称:cs569sp16,代码行数:52,代码来源:tester2.py
示例18: mutate
def mutate(test):
tcopy = list(test)
i = rgen.randint(0,len(tcopy))
sut.replay(tcopy[i:])
e = sut.randomEnabled(rgen)
ok = sut.safely(e)
elapsed = time.time() - start
if RUNNING: #should branch coverage be produced
if sut.newBranches() != set([]):
for b in sut.newBranches():
print elapsed,len(sut.allBranches()),"New branch",b
if not ok: #found a bug, report it
bugs+=1
print "Found a FAILURE"
#sut.prettyPrintTest(sut.test())
print sut.failure()
print "REDUCING"
R = sut.reduce(sut.test(), sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
if FAULT: #save test to a file if FAULT is enabled
filename = "failure" + str(bugs) + ".test"
sut.saveTest(R,filename)
trest = [e]
for s in tcopy[i+1:]:
if s[1]():
trest.append(s)
ok = sut.safely(s)
if not ok: #found a bug, report it
bugs+=1
print "Found a FAILURE"
#sut.prettyPrintTest(sut.test())
print sut.failure()
print "REDUCING"
R = sut.reduce(sut.test(), sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
if FAULT: #save test to a file if FAULT is enabled
filename = "failure" + str(bugs) + ".test"
sut.saveTest(R,filename)
tcopy = test[i:] +trest
return tcopy
开发者ID:agroce,项目名称:cs569sp16,代码行数:52,代码来源:mytester.py
示例19: mutate
def mutate(test, r, bugs):
tcopy = list(test)
i = r.randint(0,len(tcopy))
act = sut.randomEnabled(r)
isGood = sut.safely(act)
if not isGood:
bugs += 1
failures(sut)
sut.restart()
else:
trest = [act]
for s in tcopy[i+1:]:
if s[1]():
trest.append(s)
sut.safely(s)
tcopy = test[:i]+trest
return tcopy
开发者ID:agroce,项目名称:cs569sp16,代码行数:17,代码来源:tester2.py
示例20: newFunction
def newFunction():
global savecoverage_test,rgen,depth,explore,savecoverage_test,Number,sut,BUDGET,seed,width,faults,coverage,running,bugs_found,Cover_percent,Coverage_W,Least,weight,Coverage_all,start
sut.restart()
if (savecoverage_test != None) and (rgen.random() > explore):
print "processing"
sut.backtrack(savecoverage_test)
storedTest = False
print "part1: AVL"
for s in xrange(0,100):
act = sut.randomEnabled(rgen)
ok = sut.safely(act)
if len(sut.newStatements()) > 0:
savecoverage_test = sut.state()
storedTest = True
print "New state",sut.newStatements()
if (not storedTest) and (Least != None) and (Least in sut.currStatements()):
#print "SAW LEAST COVERED STATEMENT, STORING TEST"
savecoverage_test = sut.state()
storedTest = True
Number += 1
if not ok:
bugs_found += 1
print "FAILURE"
#sut.prettyPrintTest(sut.test())
print sut.failure()
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
break
for s in sut.currStatements():
if s not in Cover_percent:
Cover_percent[s] = 0
Cover_percent[s] += 1
sortedCov = sorted(Cover_percent.keys(), key=lambda x: Cover_percent[x])
# go through the sortedCov and assign weights on them
print "part2: coverage"
# weight is calculated by: coverage * (mean - Cover_percent),
# the greater the difference between the mean and the coverage count,
# the larger your weight will be
for t in sortedCov:
weight = (Coverage_all - Cover_percent[t])
weightedCov = t*weight
if weightedCov > 20:
Coverage_W.append(weightedCov)
print "Coverage:", t
开发者ID:Cianna,项目名称:cs569sp16,代码行数:45,代码来源:tester1.py
注:本文中的sut.randomEnabled函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论