本文整理汇总了Python中sut.state函数的典型用法代码示例。如果您正苦于以下问题:Python state函数的具体用法?Python state怎么用?Python state使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了state函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: savingTest
def savingTest():
global sut, fullPool, savedTest, savedFlag
if len(sut.newBranches()) > 0:
savedTest = sut.state()
savedFlag = True
if len(sut.newStatements()) > 0:
savedTest = sut.state()
savedFlag = True
return
示例4: main
def main():
global start,BUDGET,sut,COVERAGE_REPORT,savedcoverage,rgen,storedTest,act,ok,savedcoverage,running,savedcoverage,Num,faults,foundbug,savedTestState
while time.time()-start < BUDGET:
sut.restart()
if (savedcoverage != None) and (rgen.random() > 0.3):
print "Processing"
sut.backtrack(savedcoverage)
storedTest = False
print "First: AVL tree"
for s in xrange(0,100):
act = sut.randomEnabled(rgen)
ok = sut.safely(act)
if running:
if sut.newBranches() != set([]):
## print "ACTION:",a[0],tryStutter
for d in sut.newBranches():
print time.time()-start,len(sut.allBranches()),"New branch",d
if len(sut.newStatements()) > 0:
savedcoverage = sut.state()
storedTest = True
if(running):
print "New Statement",sut.newStatements()
if (not storedTest) and (i != None) and (i in sut.currStatements()):
savedcoverage = sut.state()
storedTest = True
Num += 1
if(faults):
if not ok:
foundbug += 1
print "Failed"
print sut.failure()
print "REDUCE"
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
filename = 'failure%d.test'%bugs_found
sut.saveTest(R,filename)
break
savedTestState = sut.state()
expandNewState()
if coverage:
sut.internalReport()
print foundbug,"FAILED"
print "ACTIVE",Num
print "RUNTIME",time.time()-start
示例5: 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()
示例6: mutate
def mutate(test,failureNum,start,timeout,running):
tcopy = list(test)
i = rgen.randint(0,len(tcopy))
sut.replay(tcopy[:i],catchUncaught = True)
e = sut.randomEnabled(rgen)
ok = sut.safely(e)
ifRunning((time.time()-start),running,e)
if not ok:
f1_mutate = sut.test()
failureNum = Failure(failureNum,f1_mutate)
trest = [e]
for s in tcopy[i+1:]:
if time.time()-start > timeout:
break
if s[1]():
trest.append(s)
ok=sut.safely(s)
newCovBran, newCovStat = ifRunning((time.time()-start),running,action)
if not ok:
f1_mutate = sut.test()
failureNum = Failure(failureNum,f1_mutate)
if newCovBran or newCovStat:
BFSstartState = sut.state()
failureNum = BFS(BFSstartState,failureNum,depthNum,lastCovTime,newCovTime)
break
tcopy = test[:i]+trest
return tcopy,failureNum
示例7: 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
示例8: checkAlg
def checkAlg():
global error, noerror,newseq,currseq,states
newseq=sut.newStatements()
c = sut.check()
if c:
if(not ((newseq in error) or (newseq in noerror))):
states.insert(ntest-1,sut.state())
noerror.append(sut.currStatements())
else:
error.append(sut.currStatements())
示例9: main
def main():
global start,BUDGET,sut,savedcoverage,rgen,storedTest,act,ok,savedcoverage,running,savedcoverage,Num,faults,foundbug,savedTestState
while time.time()-start < BUDGET:
sut.restart()
if (savedcoverage != None) and (rgen.random() > 0.4):
print "Processing"
sut.backtrack(savedcoverage)
storedTest = False
print "First: AVL tree"
for s in xrange(0,100):
act = sut.randomEnabled(rgen)
ok = sut.safely(act)
if len(sut.newStatements()) > 0:
savedcoverage = sut.state()
storedTest = True
if(running):
print "New Statement",sut.newStatements()
if (not storedTest) and (i != None) and (i in sut.currStatements()):
savedcoverage = sut.state()
storedTest = True
Num += 1
if(faults):
if not ok:
foundbug += 1
print "Failed"
print sut.failure()
print "REDUCE"
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
break
savedTestState = sut.state()
expandNewState()
print foundbug,"FAILED"
print "ACTIVE",Num
print "RUNTIME",time.time()-start
for s in sortedCoverage:
print s, coverageCount[s]
if (COVERAGE_REPORT):
sut.internalReport()
示例10: checkAlg
def checkAlg():
global error, noerror,newseq,currseq,states
#newseq = sut.randomEnableds(R, depth)
newseq=sut.newStatements()
c=sut.check()
if c:
if(not ((newseq in error) or (newseq in noerror))):
states.insert(ntest-1,sut.state())
noerror.append(sut.currStatements())
flags(newseq,c)
else:
error.append(sut.currStatements())
示例11: newState
def newState():
global rgen,sut,collected_test,storedTest,action_cnt,bugfound
for i in xrange(0,100):
action = sut.randomEnabled(rgen)
no_bug_found = sut.safely(action)
if len(sut.newStatements()) > 0:
collected_test = sut.state()
storedTest = True
print "new statement collected here",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
示例12: func1
def func1():
global sut,testSaving,testStored,srun,failCount,R,flag,actionsCount
flag = 0
if len(sut.newStatements()) > 0:
testSaving = sut.state()
testStored = True
print "Find statements:",sut.newStatements()
if (covrageLeast != None):
if (covrageLeast in sut.currStatements()) and (testStored == 0):
testSaving = sut.state()
testStored = True
actionsCount = actionsCount + 1
if (srun == 0):
failCount = failCount + 1
print "This is failure"
print sut.failure()
print "Now reducing.."
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
flag = 1
示例13: avlfunction
def avlfunction():
global storedTest,sortedCov,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
for s in xrange(0,depth):
act = sut.randomEnabled(rgen)
ok = sut.safely(act)
if running:
if len(sut.newBranches()) > 0:
print "ACTION:", act[0]
for d in sut.newBranches():
print time.time() - start, len(sut.allBranches()),"New branch",d
if len(sut.newStatements()) > 0:
savecoverage_test = sut.state()
storedTest = True
print "New state",sut.newStatements()
#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 faults:
if not ok:
bugs_found += 1
print "FAILURE"
print sut.failure()
R = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(R)
print sut.failure()
filename = 'failure%d.test'%bugs_found
sut.saveTest(R,filename)
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])
示例14: tester
def tester():
global sut,act,n,test,para,lCovered,actNum,bugs,M,flag
act = sut.randomEnabled(rgen)
flag = 0
n = sut.safely(act)
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 "Emerge a bug!"
print sut.failure()
M = sut.reduce(sut.test(),sut.fails, True, True)
sut.prettyPrintTest(M)
print sut.failure()
flag = 1
示例15: loopBug
def loopBug():
global Stest,rgen,sut,depth,LCov,actCount,running,faults,j,bugs
if Stest != None:
if rgen.random() > 0.4:
sut.backtrack(Stest)
test = False
for s in xrange(0,depth):
act = sut.randomEnabled(rgen)
ok = sut.safely(act)
if len(sut.newBranches()) > 0:
Stest = sut.state()
test = True
if (not test):
if (LCov!= None):
if (LCov in sut.currBranches()):
Stest = sut.state()
test = True
actCount += 1
if running == 1:
if sut.newBranches() != set([]):
print "ACTION:",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 FAILURES and It IS STORING IN FILES:"
j += 1
bugs += 1
fault = sut.failure()
failurename = 'failure' + str(bugs) + '.test'
sut.saveTest(sut.test(), failurename)
print "The bug's number found is" ,j
sut.restart()