Exemplo n.º 1
0
	def filterUsingPolicy(self, posExps, fInfos, policy):
		isFilterPolicy = util.isFilterPolicy(policy)
		isCovPolicy = util.isCoveragePolicy(policy)

		fIdToInfoMap = util.getFIdToInfoMap(fInfos)

		filteredPosExps1 = []
		if isFilterPolicy:
			for posExp in posExps:
				posExp = posExp.rstrip("\n")
				posExpFIds = posExp.split(" ")
				if policy.filter(fIdToInfoMap[posExpFIds[-1]]):
					filteredPosExps1.append(posExp)
		else:
			filteredPosExps1 = posExps
				
		filteredPosExps2 = []		
		if isCovPolicy:
			idsAlreadyInjected = []
			fIdToCovIdMap = {}
		
			f = open(util.injFIdsFile, "r")
			injFIds = f.readlines()
			f.close()

			for injFId in injFIds:
				covId = util.getCovId(injFId.strip("\n"), fIdToCovIdMap, policy, fIdToInfoMap)
				idsAlreadyInjected.append(covId)


			for posExp in filteredPosExps1:
				posExp = posExp.rstrip("\n")
				posExpFIds = posExp.split(" ")
				lastFId = posExpFIds[-1]
				
				lastCovId = util.getCovId(lastFId, fIdToCovIdMap, policy, fIdToInfoMap)
				if lastCovId not in idsAlreadyInjected:
					filteredPosExps2.append(posExp)
		else:
			filteredPosExps2 = filteredPosExps1

		return filteredPosExps2			
Exemplo n.º 2
0
	def generateFailPtsToExplore (self, posExpsFile, injFIdsFile, fInfos, policies, useEqvCl, 
			clsLast, outFile):
		if not os.path.exists(posExpsFile):
			return

		posExpsF = open(posExpsFile, 'r')	
		posExps = posExpsF.readlines()
		posExpsF.close()

		posExps = self.filterNoise(posExps, fInfos)

		fltExps = posExps
		covPols = []
		for policy in policies:
			fltExps = self.filterUsingPolicy(fltExps, fInfos, policy)
			isCovPolicy = util.isCoveragePolicy(policy)
			if isCovPolicy:
				covPols.append(policy)

		clsExps = fltExps
		if useEqvCl:
			self.eqvCls.getEqvClsForRFIds(clsExps)
			lFIdToPrevFIdsMap = {}
			l = 0

			for clsExp in clsExps:
				clsExp = clsExp.rstrip("\n")
				clsExpFIds = clsExp.split(" ")
				l = len(clsExpFIds)
				if(l <= 1):
					lFIdToPrevFIdsMap[clsExp] = []
				else:	
					lFId = clsExpFIds[-1]
					prevFIds = " ".join(clsExpFIds[0:l-1])
					if(lFId in lFIdToPrevFIdsMap.keys()):
						listOfPrevFIdsSets = lFIdToPrevFIdsMap[lFId]
						foundEqvCls = False
						for s in listOfPrevFIdsSets:
							if(self.isEqv(prevFIds, s)):
								s.add(prevFIds)
								foundEqvCls = True
								break
								
						if (not foundEqvCls):
							listOfPrevFIdsSets.append(set([prevFIds]))

					else:
						lFIdToPrevFIdsMap[lFId] = [set([prevFIds])]


			clsExps = self.getEqvClsOfExps(lFIdToPrevFIdsMap, useEqvCl, clsExps)	

		else:
			if clsLast:
				policy = None
				fIdToCovIdMap = {}
				fIdToInfoMap = util.getFIdToInfoMap(fInfos)
				n = len(covPols)
				if n != 0:
					assert (n == 1)
					policy = covPols[0]

				lFIdToExpsMap = {}
				for clsExp in clsExps:
					clsExp = clsExp.rstrip("\n")
					clsExpFIds = clsExp.split(" ")
					lFId = clsExpFIds[-1]
					
					if n != 0:
						lFId = util.getCovId(lFId, fIdToCovIdMap, policy, fIdToInfoMap) 
					
					
					if lFId in lFIdToExpsMap:
						sExps = lFIdToExpsMap[lFId]
						sExps.add(clsExp)
					else:
						lFIdToExpsMap[lFId] = set([clsExp])
				
				newClsExps = []
				for l, s in lFIdToExpsMap.items():
					for exp in s:
						newClsExps.append(exp.rstrip("\n")+"\n")
					newClsExps.append("-----------------------------------------------------------\n")
				clsExps = newClsExps	


			else:	
				newClsExps = []
				for clsExp in clsExps:
					newClsExps.append(clsExp.rstrip("\n")+"\n")
					newClsExps.append("-----------------------------------------------------------\n")
				clsExps = newClsExps


		self.printEqvClsOfExps(clsExps, outFile)