class genTestcaselist():
def __init__(self,pjPath):
self.testCaselist = []
self.testCfglist = []
self.msgCtrlObj = setEnvMsg("Analysis testcase and testlist infomation")
self.projPath = pjPath
self.cfgObj = getTestConfig()
self.testCount = 0
self.waveCtrl = False
self.seedWorkCtrl = False
self.compVarList = []
self.compvarCount = 0
def genTestcase(self):
if options.testCfgName!=None:
for cfgName in options.testCfgName:
if cfgName not in self.testCfglist:
self.testCfglist.append(cfgName)
if options.countCtrl:
self.waveCtrl = False
self.seedWorkCtrl = True
if len(self.testCfglist)==0:
self.testCfglist.append(options.caseCfgName)
for testName in options.testNameCtrl:
if os.path.exists(self.projPath+"/"+testName)==False and options.testCheckCtrl==1:
self.msgCtrlObj.fatalMsgPrint("No exist " + testName + " in " + self.projPath)
else:
for cfgName in self.testCfglist:
if options.testCheckCtrl==0:
self.cfgObj.getCfgInfo(self.projPath+"/",cfgName)
else:
self.cfgObj.getCfgInfo(self.projPath+"/"+testName,cfgName)
curCompVar = self.cfgObj.getCompOpts()
if self.compVarList.count(curCompVar)==0:
self.compVarList.append(curCompVar)
self.compvarCount = self.compVarList.index(curCompVar)
curTestCfgName = self.cfgObj.getCfgFileName()
simVarList = self.cfgObj.getSimOpts()
preVarList = self.cfgObj.getPreSimProc()
postVarList = self.cfgObj.getPostSimProc()
falseErrVarList = self.cfgObj.getFalseErr()
expectErrVarList = self.cfgObj.getExpectErr()
falseWarnVarList = self.cfgObj.getFalseWarn()
expectWarnVarList = self.cfgObj.getExpectWarn()
for curCountVal in range(0,options.countCtrl):
if options.seedCtrl:
curSeedData = options.seedCtrl.pop(0)
else:
randSeedObj = genRandSeed()
curSeedData = randSeedObj.genRandData()
curTestcaseInfo = [testName,curSeedData,curTestCfgName,self.compvarCount,self.compVarList[self.compvarCount],simVarList,preVarList,postVarList,falseErrVarList,expectErrVarList,falseWarnVarList,expectWarnVarList]
self.testCaselist.append(curTestcaseInfo)
self.testCount += 1
else:
testNameList = options.testNameCtrl[:]
testcaseCount = len(testNameList)
if options.seedCtrl!=None:
seedCount = len(options.seedCtrl)
else:
seedCount = 1
if len(self.testCfglist)==0:
self.testCfglist.append(options.caseCfgName)
testCfgCount = len(self.testCfglist)
if testcaseCount == 1:
self.waveCtrl = options.waveCtrl
curTestcase = testNameList.pop(0)
if os.path.exists(self.projPath+"/"+curTestcase)==False and options.testCheckCtrl==1:
self.msgCtrlObj.fatalMsgPrint("No exist " + curTestcase + " in " + self.projPath)
else:
seedCountCtrl = int(math.ceil(float(seedCount)/float(testCfgCount)))
for cfgName in self.testCfglist:
if options.testCheckCtrl==0:
self.cfgObj.getCfgInfo(self.projPath+"/",cfgName)
else:
self.cfgObj.getCfgInfo(self.projPath+"/"+curTestcase,cfgName)
curCompVar = self.cfgObj.getCompOpts()
if self.compVarList.count(curCompVar)==0:
self.compVarList.append(curCompVar)
self.compvarCount = self.compVarList.index(curCompVar)
curTestCfgName = self.cfgObj.getCfgFileName()
simVarList = self.cfgObj.getSimOpts()
preVarList = self.cfgObj.getPreSimProc()
postVarList = self.cfgObj.getPostSimProc()
falseErrVarList = self.cfgObj.getFalseErr()
expectErrVarList = self.cfgObj.getExpectErr()
falseWarnVarList = self.cfgObj.getFalseWarn()
expectWarnVarList = self.cfgObj.getExpectWarn()
for seedIdx in range(0,seedCountCtrl):
if options.seedCtrl:
curSeedData = options.seedCtrl.pop(0)
else:
randSeedObj = genRandSeed()
curSeedData = randSeedObj.genRandData()
curTestcaseInfo = [curTestcase,curSeedData,curTestCfgName,self.compvarCount,self.compVarList[self.compvarCount],simVarList,preVarList,postVarList,falseErrVarList,expectErrVarList,falseWarnVarList,expectWarnVarList]
self.testCaselist.append(curTestcaseInfo)
self.testCount += 1
if self.testCount>1:
self.seedWorkCtrl = True
else:
self.seedWorkCtrl = options.seedWorkCtrl
else:
self.waveCtrl = options.waveCtrl
for testName in options.testNameCtrl:
if os.path.exists(self.projPath+"/"+testName)==False and options.testCheckCtrl==1:
self.msgCtrlObj.fatalMsgPrint("No exist " + testName + " in " + self.projPath)
else:
if len(self.testCfglist):
cfgName = self.testCfglist.pop(0)
else:
cfgName = options.caseCfgName
if options.testCheckCtrl==0:
self.cfgObj.getCfgInfo(self.projPath+"/",cfgName)
else:
self.cfgObj.getCfgInfo(self.projPath+"/"+testName,cfgName)
curCompVar = self.cfgObj.getCompOpts()
if self.compVarList.count(curCompVar)==0:
self.compVarList.append(curCompVar)
self.compvarCount = self.compVarList.index(curCompVar)
curTestCfgName = self.cfgObj.getCfgFileName()
simVarList = self.cfgObj.getSimOpts()
preVarList = self.cfgObj.getPreSimProc()
postVarList = self.cfgObj.getPostSimProc()
falseErrVarList = self.cfgObj.getFalseErr()
expectErrVarList = self.cfgObj.getExpectErr()
falseWarnVarList = self.cfgObj.getFalseWarn()
expectWarnVarList = self.cfgObj.getExpectWarn()
if options.seedCtrl:
curSeedData = options.seedCtrl.pop(0)
else:
randSeedObj = genRandSeed()
curSeedData = randSeedObj.genRandData()
curTestcaseInfo = [testName,curSeedData,curTestCfgName,self.compvarCount,self.compVarList[self.compvarCount],simVarList,preVarList,postVarList,falseErrVarList,expectErrVarList,falseWarnVarList,expectWarnVarList]
self.testCaselist.append(curTestcaseInfo)
self.testCount += 1
if self.testCount>1:
self.seedWorkCtrl = True
else:
self.seedWorkCtrl = options.seedWorkCtrl
def genTestlist(self):
curTestname = ""
curCount = ""
curTestCfg = ""
curCompVar = ""
simVar = ""
seedVar = ""
lineInfo = ""
fileHandle = open(options.testListFile,'r')
self.waveCtrl = False
self.seedWorkCtrl = True
while True:
lineContext = fileHandle.readline()
if not lineContext:
break
lineInfo = lineContext.strip()
if len(lineInfo)==0:
continue
reInfo = "^\s*#.*"
lineObj= re.match(reInfo,lineContext)
if lineObj:
continue
else:
testInfoQueue = lineContext.split(";")
if len(testInfoQueue)<=2:
self.msgCtrlObj.fatalMsgPrint("Regression list include testcase and count, current line: %0s"%(lineContext))
curTestname = testInfoQueue[0].strip()
curCount = testInfoQueue[1].strip()
if len(testInfoQueue)>2:
curTestCfg = testInfoQueue[2].strip()
if len(testInfoQueue)>3:
curCompVar = testInfoQueue[3].strip()
if len(testInfoQueue)>4:
simVar = testInfoQueue[4].strip()
#support multi seed
if len(testInfoQueue)>5:
seedVar = testInfoQueue[5].strip()
seedTempVar = re.sub(' +',' ',seedVar)
seedVarList = seedTempVar.split(' ')
if os.path.exists(self.projPath+"/"+curTestname)==False and options.testCheckCtrl==1:
self.msgCtrlObj.fatalMsgPrint("No exist " + curTestname + " in " + self.projPath)
else:
testMacroVarList = []
noMacroVarList = []
compMacroVar = ""
compNoMacroVar = ""
if curTestCfg:
testCfgFile = curTestCfg
elif options.testCfgName!=None:
testCfgFile = options.testCfgName.pop(0)
else:
testCfgFile = options.caseCfgName
if options.testCheckCtrl==0:
self.cfgObj.getCfgInfo(self.projPath+"/",testCfgFile)
else:
self.cfgObj.getCfgInfo(self.projPath+"/"+curTestname,testCfgFile)
#test.cfg compile parameter
testCompVar = self.cfgObj.getCompOpts()
compOptsVar = re.sub(' +',' ',testCompVar)
CompVarList = compOptsVar.split(' ')
CompVarList.sort()
for macroVar in CompVarList:
if macroVar:
macroObj = re.match('\+define\+',macroVar)
if macroObj:
macroTmpVar = re.sub('\+define\+','',macroVar)
macroVarList = macroTmpVar.split('+')
macroVarList.sort()
for compVar in macroVarList:
if compVar not in testMacroVarList:
testMacroVarList.append(compVar)
else:
compVar = re.sub(':',' ',macroVar)
noMacroVarList.append(compVar)
#List compile parameter
testCompVar = curCompVar
compOptsVar = re.sub(' +',' ',testCompVar)
CompVarList = compOptsVar.split(' ')
CompVarList.sort()
for macroVar in CompVarList:
if macroVar:
macroObj = re.match('\+define\+',macroVar)
if macroObj:
macroTmpVar = re.sub('\+define\+','',macroVar)
macroVarList = macroTmpVar.split('+')
macroVarList.sort()
for compVar in macroVarList:
if compVar not in testMacroVarList:
testMacroVarList.append(compVar)
else:
compVar = re.sub(':',' ',macroVar)
noMacroVarList.append(compVar)
#Merge all compile parameter
if len(testMacroVarList):
compMacroVar = "+define+" + "+".join(testMacroVarList)
if len(noMacroVarList):
compNoMacroVar = " ".join(noMacroVarList)
if compMacroVar or compNoMacroVar:
compMacroVar = compMacroVar + " " + compNoMacroVar
if self.compVarList.count(compMacroVar)==0:
self.compVarList.append(compMacroVar)
self.compvarCount = self.compVarList.index(compMacroVar)
#Sim paramter
simVarList = self.cfgObj.getSimOpts()
if simVar:
simVarList = simVarList.strip() + " " + simVar
curTestCfgName = self.cfgObj.getCfgFileName()
preVarList = self.cfgObj.getPreSimProc()
postVarList = self.cfgObj.getPostSimProc()
falseErrVarList = self.cfgObj.getFalseErr()
expectErrVarList = self.cfgObj.getExpectErr()
falseWarnVarList = self.cfgObj.getFalseWarn()
expectWarnVarList = self.cfgObj.getExpectWarn()
for curCountVal in range(0,int(curCount)):
if curCountVal>=len(seedVarList):
randSeedObj = genRandSeed()
curSeedData = randSeedObj.genRandData()
elif seedVarList[curCountVal]:
curSeedData = int(seedVarList[curCountVal])
else:
randSeedObj = genRandSeed()
curSeedData = randSeedObj.genRandData()
curTestcaseInfo = [curTestname,curSeedData,curTestCfgName,self.compvarCount,self.compVarList[self.compvarCount],simVarList,preVarList,postVarList,falseErrVarList,expectErrVarList,falseWarnVarList,expectWarnVarList]
self.testCaselist.append(curTestcaseInfo)
self.testCount += 1
fileHandle.close()
def getTestList(self):
return self.testCaselist
def getWaveCtrl(self):
return self.waveCtrl
def getSeedPathCtrl(self):
return self.seedWorkCtrl
def getTestcaseCount(self):
return self.testCount
def getCompVar(self):
return self.compVarList
#TODO generate all verif files
class genPostSimulationFile():
def __init__(self):
self.postFile = []
self.postRtlFile = []
self.postEnvFile = []
self.msgCtrlObj = setEnvMsg("Generate final simulation file list")
def writePostFile(self):
if options.splitCompileCtrl:
#RTL
curPostFileName = "rtl_" + options.postFileName
if len(self.postRtlFile)==0:
self.msgCtrlObj.fatalMsgPrint("Compile rtl_file_post.f empty...")
else:
postFileID = open(options.postFileName,"w")
writeFileID = open(curPostFileName,"w")
for lineStr in self.postRtlFile:
writeFileID.write(lineStr + "\n")
postFileID.write(lineStr + "\n")
writeFileID.close()
#ENV
curPostFileName = "env_" + options.postFileName
if len(self.postEnvFile)==0:
self.msgCtrlObj.fatalMsgPrint("Compile env_file_post.f empty...")
else:
writeFileID = open(curPostFileName,"w")
for lineStr in self.postEnvFile:
writeFileID.write(lineStr + "\n")
postFileID.write(lineStr + "\n")
writeFileID.close()
postFileID.close()
else:
if len(self.postFile)==0:
self.msgCtrlObj.fatalMsgPrint("Compile file_post.f empty...")
else:
writeFileID = open(options.postFileName,"w")
for lineStr in self.postFile:
writeFileID.write(lineStr + "\n")
writeFileID.close()
def genExpandFile(self,rfileID,postFiles):
while True:
lineContext = rfileID.readline()
if not lineContext:
break
reInfo = "\${?" + options.projTopName + "}?"
projObj = re.search(reInfo,lineContext)
lineAfterSub = re.sub(reInfo,os.environ[options.projTopName],lineContext)
if projObj:
reInfo = "\s*-f"
fileObj = re.match(reInfo,lineAfterSub)
if fileObj:
postFiles.append("//Expand " + lineAfterSub)
reInfo = "\s*-f"
lineAfterSub = re.sub(reInfo,"",lineAfterSub)
fID = open(lineAfterSub.strip(),"r")
self.genExpandFile(fID,postFiles)
fID.close()
else:
postFiles.append(lineAfterSub.strip())
else:
postFiles.append(lineAfterSub.strip())
def genPostFile(self):
if options.splitCompileCtrl:
#RTL files
if options.rtlFileCtrl !=None:
readFileID = open(options.rtlFileCtrl,"r")
self.genExpandFile(readFileID,self.postRtlFile)
readFileID.close()
else:
readFileID = open(glbBlockPath + "/" + options.fileDirName + "/" + options.rtlFileNameCtrl + ".f","r")
self.genExpandFile(readFileID,self.postRtlFile)
readFileID.close()
#ENV files
if options.envFileCtrl !=None:
readFileID = open(options.envFileCtrl,"r")
self.genExpandFile(readFileID,self.postEnvFile)
readFileID.close()
else:
readFileID = open(glbBlockPath + "/" + options.fileDirName + "/" + options.envFileNameCtrl + ".f","r")
self.genExpandFile(readFileID,self.postEnvFile)
readFileID.close()
else:
if options.fileSimList !=None:
readFileID = open(options.fileSimList,"r")
self.genExpandFile(readFileID,self.postFile)
readFileID.close()
else:
readFileID = open(glbBlockPath + "/" + options.fileDirName + "/" + options.fileListName + ".f","r")
self.genExpandFile(readFileID,self.postFile)
readFileID.close()
最新发布