当前位置: 首页>>代码示例>>Python>>正文


Python sut.backtrack函数代码示例

本文整理汇总了Python中sut.backtrack函数的典型用法代码示例。如果您正苦于以下问题:Python backtrack函数的具体用法?Python backtrack怎么用?Python backtrack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了backtrack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    global flag,timeout,sut,test,para,currStatements,coverageNum,sortedCov,weight,weightedCov,coverageWBM,bugs,actNum,start
    while time.time()-start < timeout:
        sut.restart()
        if (test != None):
            if (rgen.random() > exp):
                sut.backtrack(test)
        para = False
        for s in xrange(0,lenth):
            tester()
            if flag == 1:
                break
        for s in sut.currStatements():
            if s not in coverageNum:
                coverageNum[s] = 0
            coverageNum[s] += 1
        sortedCov = sorted(coverageNum.keys(), key=lambda x: coverageNum[x])
        for c in sortedCov:
            weightedCov = c * (lenth - coverageNum[c])
            if weightedCov > 20:
                coverageWBM.append(weightedCov)
                print c
    sut.internalReport()
    for s in sortedCov:
        print s, coverageNum[s]


    print bugs,"Failures have been found"
    print "TOTAL ACTIONS",actNum
    print "TOTAL RUNTIME",time.time()-start
开发者ID:agroce,项目名称:cs569sp16,代码行数:30,代码来源:tester2.py

示例2: main

def main():
    global flag,timeout,sut,test,para,currStatements,coverageNum,sortedCov,weight,weightedCov,coverageWeightedBelowMean,bugs,actNum,start
    while time.time()-start < timeout:
        sut.restart()
        if (test != None):
            if (rgen.random() > 0.4):
                sut.backtrack(test)
        para = False

        print "Testing"
        for s in xrange(0,100):
            tester()
            if flag == 1:
                break
        for s in sut.currStatements():
            if s not in coverageNum:
                coverageNum[s] = 0
            coverageNum[s] += 1
        sortedCov = sorted(coverageNum.keys(), key=lambda x: coverageNum[x])
        print "Coverage"
        for c in sortedCov:
            weight = (100 - coverageNum[c])
            weightedCov = c * weight
            if weightedCov > 25:
                coverageWeightedBelowMean.append(weightedCov)
                print c

    sut.internalReport()
    for s in sortedCov:
        print s, coverageNum[s]

    print bugs,"BUGS"
    print "TOTAL ACTIONS",actNum
    print "TOTAL RUNTIME",time.time()-start
开发者ID:Cianna,项目名称:cs569sp16,代码行数:34,代码来源:tester1.py

示例3: phase2

def phase2(randomPool, selectPool):
    global ntest
    DEPTH = opts.depth
    print "PHASE 2: Starting\t(FILTER SET:", len(selectStatements),"DEPTH:",DEPTH,"tests)"
    phase_start = time.time()
    phase_test = ntest

    mean = calculateMean(selectStatements)
    initialMean = mean

    while mean < threshold and (time.time() - start) < opts.timeout:
        sut.restart()
        test = selectPool.getRandom()
        #sut.replay(test[0])
        sut.backtrack(test[1])
        ntest += 1
        if opts.progress and ntest % 10:
            update_progress((mean - initialMean)/threshold)
        for s in xrange(0,DEPTH):
            if not randomAction(selectPool):
                break
        mean = calculateMean(selectStatements)
        collectCoverage() # collecting coverage at the end of each test
    if opts.progress:
        update_progress(1.0)
    
    interval = time.time()-phase_start
    print "PHASE 2: Ending\t\t(EXECUTED:",(ntest - phase_test),"tests, USED:",round(interval,5),"seconds)"
    print "-------------------------------------------"
开发者ID:agroce,项目名称:cs569sp16,代码行数:29,代码来源:tester1.py

示例4: main

def main():				
	global ntests,start
	while time.time()-start < timeout:
		
		for ts in xrange(0,width):
			sut.restart()
			ntests += 1
			if (Stest != None ) and (r.random() > 0.6):
				sut.backtrack(Stest)
		
			randomAction()
		
		for b in sut.currBranches():
			if b not in covCount:
				covCount[b] = 0
			covCount[b] += 1
			sortedCov = sorted(covCount.keys(), key = lambda x: covCount[x]) 
			LCov = sortedCov[0]
		
    		if time.time()-start > timeout:
        		print "THE TEST IS STOPPED SINCE TIMEOUT"
        		break 

	sortedCov = sorted(covCount.keys(), key = lambda x: covCount[x])		

	if coverage:
		print"Show Coverage"
        	sut.internalReport()
	
	print ntests,"TOTAL TESTS"    
	print "TOTAL BUGS",bugs
	print "TOTAL ACTIONS",actCount
	print "TOTAL RUNTIME",time.time()-start
开发者ID:agroce,项目名称:cs569sp16,代码行数:33,代码来源:tester2.py

示例5: expandNewState

def expandNewState():
    global sut,Coverage,sortedCov,weight,weightedCov,BelowCoverage
    for s in sut.currStatements():
        if s not in Coverage:
            Coverage[s] = 0
        Coverage[s] += 1
    sortedCov = sorted(Coverage.keys(), key=lambda x: Coverage[x])
    print "Second: coverage"
    for t in sortedCov:
        weight = (100 - Coverage[t])
        weightedCov = t*weight
        if weightedCov > 20:
            BelowCoverage.append(weightedCov)
            print "Cov:", t
            sut.backtrack(sut.state())
开发者ID:Cianna,项目名称:cs569sp16,代码行数:15,代码来源:tester.py

示例6: 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()
    R.seed(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:
                    error.append(sut.currStatements())
                    break
                checkAlg()

    #if not error ==[]:
    #    print "SHOW ERROR SEQUENCE"
    #    print error
    #    f = open(("error" + str(actCount) + ".test"), 'w')
    #    f.write(str(error))
    #    f.close()
    #else:
    #    print "Data in noerror sequence"
        # print noerror


    if coverage:
        sut.internalReport()

    print "TOTAL BUGS", bugs
    print "TOTAL ACTIONS",actCount
    print "TOTAL RUNTIME",time.time()-start
开发者ID:agroce,项目名称:cs569sp16,代码行数:48,代码来源:finaltester.py

示例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
开发者ID:Cianna,项目名称:cs569sp16,代码行数:45,代码来源:tester1.py

示例8: 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
开发者ID:agroce,项目名称:cs569sp16,代码行数:44,代码来源:mytester.py

示例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()
开发者ID:Cianna,项目名称:cs569sp16,代码行数:42,代码来源:tester.py

示例10: newFunction

def newFunction():
	global storedTest,savecoverage_test,start,BUDGET,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: test the AVL tree"
	avlfunction()
	print "part2: processing the coverage"
	
	for t in sortedCov:
		weight = (Coverage_all - Cover_percent[t])
		#weightedCov = t*weight
		#if weightedCov < 20:
		if time.time() - start > BUDGET:
			return
		if weight > 80:
			Coverage_W.append(t)
			print "Coverage:", t
开发者ID:agroce,项目名称:cs569sp16,代码行数:20,代码来源:tester2.py

示例11: 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
    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,100):
            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
            func1()
            if flag == 1:
                break
        for s in sut.currStatements():
            if s not in coverageCount:
                coverageCount[s] = 0
            coverageCount[s] = coverageCount[s] + 1
        covrSort = sorted(coverageCount.keys(), key=lambda x: coverageCount[x])
        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,代码行数:39,代码来源:tester1.py

示例12: 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()
开发者ID:agroce,项目名称:cs569sp16,代码行数:37,代码来源:finaltester.py

示例13: BFS

def BFS(state,failureNum,depthNum,lastCovTime,newCovTime):
	queue = [state]
	d=0
	BfsBugCount=0
	newCovBran=False
	newCovStat=False
	while depthNum + d < depth and time.time()-start <= timeout/rtTimePara and (newCovBran==False and newCovStat==False):
		d+=1
		frontier = []
		for s2 in queue[:width]:
			if time.time()-start > timeout/rtTimePara:
				break
			sut.backtrack(s2)
			allEnabled = sut.enabled()
			rgen.shuffle(allEnabled)
			for a in allEnabled[:5]:
				if time.time()-start > timeout/rtTimePara:
					break
				ok = sut.safely(a)
				newCovBran, newCovStat = ifRunning((time.time()-start),running,a)
				sss = sut.state()
				if sss not in visited:
					visited.append(sss)
					frontier.append(sss)
				if not ok:
					f1_bfs = sut.test()
					failureNum = Failure(failureNum,f1_bfs)
					BfsBugCount+=1
					if BfsBugCount==BfsBugNum:
						BfsBugCount=0
						break
				if newCovBran or newCovStat:
					lastCovTime = time.time()
					newCovTime = 0
					break
				else:
					newCovTime = time.time() - lastCovTime
				sut.backtrack(s2)
			else:
				sut.backtrack(s2)
				continue
			break
		rgen.shuffle(frontier)
		queue = frontier
	return failureNum
开发者ID:agroce,项目名称:cs569sp16,代码行数:45,代码来源:finaltester.py

示例14: xrange

dep=0
regn = random.Random()
queue_q = [sut.state()]  
ran_queue = []
visited = []
start_time_1 = time.time()


while time.time() - start_time_1 < TIMEOUT:
	# for dep in xrange(1,DEPTH):
		dep = dep +1 
		queue_list =[]
		inside_time = time.time()
		for x in queue_q:
			ran_queue.append(x)
			sut.backtrack(x)
			list_actions = sut.enabled()
			regn.shuffle(list_actions)		
			for a in list_actions:
				if time.time() - inside_time >= average_time_dep:
					break
				Find_bugs(a)	
				s2 = sut.state()
				if s2 not in ran_queue:	
					ran_queue.append(s2)
					queue_list.append(s2)	
				sut.backtrack(x)	
			for s in sut.currStatements():
				if s not in coverage_counter:
					coverage_counter[s]=0
				coverage_counter[s] = coverage_counter[s] + 1	
开发者ID:Cianna,项目名称:cs569sp16,代码行数:31,代码来源:tester.py

示例15:

    print "DEPTH",d,"QUEUE SIZE",len(queue),"VISITED SET",len(visited)
    d += 1
    start = time.time()
    scount = 0
    max=0

    # first cycle
    for s in queue:

        elapsedTM = time.time() - startTM
        if elapsedTM>=timeout:
            break  

        scount += 1
        sut.backtrack(s)
        possible = sut.enabled()  # past guard action. enable: name guard act
        rgen.shuffle(possible)
        
        pos=len(possible)  #calculate # of children
        poslist=[]

        #second cycle
        for act in possible:

            elapsedTM = time.time() - startTM
            if elapsedTM>=timeout:
                break   
            elapsed = time.time() - start
            if (elapsed >= layer):
                break
开发者ID:Cianna,项目名称:cs569sp16,代码行数:30,代码来源:tester1.py


注:本文中的sut.backtrack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。