def executeImpl(lang, posdef): # counter to indicate progress total = 1 # jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('tc', lang, 'impl') name = gentestcases.NextTestCase() while (name != None): report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress( 2, "Handling test cases " + ` total ` + "..." + ` total + jobSize - 1 `) report.Progress(3, "Running " + name) ok = RunImplTestCase(name, lang, posdef) if util.CleanFile(ok): bn = util.ExtractName(name) util.DeleteFiles([bn + ".vdm"]) name = gentestcases.NextTestCase() total = total + 1 util.MoveProfile()
def execute(lang, type): global ext, binext # ok = convert.SetupSpecification(lang, 'j2vtf') # if not ok: # report.Error("ABORTING specification test for " + `lang`) # return #counter to indicate progress total = 1 #setting the coverage file coverageFile = "rtinfo.ast" #Set expected results expSet = resfile.MakeStdExpansionSet('j2vtf', lang, type) resfile.RegisterExpansionSet(expSet) #jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') #initialize the extraction of test cases gentestcases.StartSearch('j2vtf', lang, type) name = gentestcases.NextTestCase() while (name != None): #setting report report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress( 2, "Handling test cases " + ` total ` + "..." + ` total + jobSize - 1 `) report.Progress(3, "Running " + name) ok = convert.ConvertLanguage(lang, name) if ok: ok = PrepareSpecCase(name, lang) if ok: ok = RunTestCase(name, lang, type, coverageFile) #cleaning up if ok: if util.CleanFile(ok): baseName = util.ExtractName(name) util.DeleteFiles([ baseName + ".vdm", baseName + ".ast", baseName + ".arg", baseName + ".debug", baseName + ".res", baseName + ".arg.res", baseName + ".arg.pt", "debug.arg" ]) #else: # break #generates next test case name = gentestcases.NextTestCase() total = total + 1
def RunTestCases(lang, vdmApp, clientID): toolMediator = ToolMediator(vdmApp, clientID) total = 1 # jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('api', lang, 'impl') name = gentestcases.NextTestCase() while (name != None): report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress( 2, "Handling test cases " + str(total) + "..." + str(total + jobSize - 1)) report.Progress(3, "Running " + name) ok = RunApiTestCase(name, lang, toolMediator) if util.CleanFile(ok): bn = util.ExtractName(name) util.DeleteFiles([bn + ".vdm"]) name = gentestcases.NextTestCase() total = total + 1 return true
def executeImpl(lang, dtc): # counter to indicate progress total = 1 # jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('ip', lang, 'impl') name = gentestcases.NextTestCase() while (name != None): report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress(2, "Handling test cases " + str(total) + "..." + str(total + jobSize-1)) report.Progress(3, "Running " + name) ok = PrepareImplCase(name, lang) if ok: ok = RunImplTestCase(name, lang,dtc) if util.CleanFile(ok): util.RemoveTestFiles(name,[".vdm",".res",".arg"]) name = gentestcases.NextTestCase() total = total +1 util.MoveProfile()
def executeImpl(lang): global srcext, binext # counter to indicate progress total = 1 # jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('cpp', lang, 'impl') name = gentestcases.NextTestCase() while (name != None): report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress(2, "Handling test cases " + `total` + "..." + `total + jobSize-1`) report.Progress(3, "Running " + name) (ok, modules) = RunImplTestCase(name, lang) if util.CleanFile(ok): bn = util.ExtractName(name) util.DeleteFiles([bn+".vdm",bn+".res", "icode." + srcext, "icode" + binext,"CGBase." + srcext, "CGBase.h", "CGBase.obj", "icode.obj", "compare.arg", "compare.vdm"]) if modules: for mod0 in modules: mod = string.replace(mod0, "_", "_u") util.DeleteFiles([mod+"." + srcext, mod+".h", mod+"_anonym." + srcext, mod+"_anonym.h",mod+"_userdef.h", mod + ".obj"]) name = gentestcases.NextTestCase() total = total +1
def PrepareSpecCase(fullName, lang): report.Progress(3, "preparing " + fullName) report.setTestCaseName(fullName) ok = convert.ConvertLanguage(lang, fullName) if ok: parser = cmdline.LookUpWildCard('cpp', lang, 'spec', 'parser') ok = convert.VDM2AST(fullName, parser, true) if ok: ok = convert.CreateOptionsFile(fullName) if ok: convert.CreateDebugFile(fullName, "debug-file-cpp", {'<<CGKIND>>' : '<CPP>'} ) if ok: ok = convert.CreateArgFile(fullName, "arg-file-cpp", {'<<CGKIND>>' : '<CPP>'} ) if ok: ok = convert.AppendToDotVdmtest(fullName) # Clean up if test case failed if not ok and util.CleanFile(ok): baseName = util.ExtractName(fullName) util.DeleteFiles([baseName+".vdm", baseName+".ast", baseName+".arg", baseName+".debug", "debug.arg"]) return ok
def executeImpl(lang): # counter to indicate progress total = 1 # jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('java', lang, 'impl') name = gentestcases.NextTestCase() while (name != None): report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress( 2, "Handling test cases " + str(total) + "..." + str(total + jobSize - 1)) report.Progress(3, "Running " + name) (ok, modules) = RunImplTestCase(name, lang) if util.CleanFile(ok): bn = util.ExtractName(name) util.DeleteFiles([ bn + ".vdm", bn + ".res", "TMAIN.java", "compare.arg", "compare.vdm" ]) if modules: for mod in modules: util.DeleteFiles([ mod + ".java", "external_" + mod + ".java", mod + ".class" ]) name = gentestcases.NextTestCase() total = total + 1
def PrepareSpecCase(name, lang): report.Progress(3, "Preparing " + name) report.setTestCaseName(name) parser = cmdline.LookUpWildCard('j2vtf', lang, 'spec', 'parser') ok = convert.VDM2AST(name, parser, false) if ok: ok = convert.CreateOptionsFile(name) if ok: extra = GetIdSet() ok = convert.CreateDebugFile(name, "debug-file-j2vtf", extra) if ok: ok = convert.CreateArgFile(name, "arg-file-j2vtf", extra) util.DeleteFiles([".vdmtest"]) if ok: ok = convert.AppendToDotVdmtest(name) # Clean up if preparation failed if not ok and util.CleanFile(ok): baseName = util.ExtractName(name) util.DeleteFiles([ baseName + ".arg", baseName + ".ast", baseName + ".debug", "debug.arg" ]) return ok
def CompareResult(fullName, outputFile, resFile, interpreter, structTest=true): report.Progress( 4, "Comparing result for " + ` fullName ` + " using diff method") # compare the results using normal "diff" actualResult = util.ReadFile(outputFile) expectedResult = util.ReadFile(resFile) # Remove duplicate white spaces and line breaks, spaces around commas and parenthesis. actualResult = string.strip(re.sub("\s+", " ", actualResult)) expectedResult = string.strip(re.sub("\s+", " ", expectedResult)) actualResult = string.strip(re.sub("\s*,\s*", ",", actualResult)) expectedResult = string.strip(re.sub("\s*,\s*", ",", expectedResult)) actualResult = string.strip(re.sub("\s*\(\s*", "(", actualResult)) expectedResult = string.strip(re.sub("\s*\(\s*", "(", expectedResult)) actualResult = string.strip(re.sub("\s*\)\s*", ")", actualResult)) expectedResult = string.strip(re.sub("\s*\)\s*", ")", expectedResult)) if actualResult == expectedResult: return true # Hmmm we need to try to compare using VDMDE then. if structTest and interpreter != None: report.Progress( 4, "Comparing result for " + ` fullName ` + " by build VDM value") # template = util.ReadFile(setup.BaseDir+"/../pogtestcases/compare-pog.vdm") template = util.ReadFile(setup.BaseDir + "/templates/compare-pog.vdm") if template == None: return false data = util.SubString('<<EXPECTED_RESULT>>', expectedResult, template) data = util.SubString('<<ACTUAL_RESULT>>', actualResult, data) ok = util.WriteFile("compare.vdm", data) if not ok: return false ok = util.WriteFile(".vdmtest", "compare.arg") # util.CopyFile(setup.BaseDir+"/../pogtestcases/compare-pog.arg","compare.arg") # util.CopyFile(setup.BaseDir+"/general-files/compare.arg","compare.arg") util.CopyFile(setup.BaseDir + "/general-files/compare-pog.arg", "compare.arg") # cmd = interpreter + " -a -b compare.vdm" cmd = interpreter + " -i compare.arg compare.vdm" (exitcode, dummy1, dummy2) = util.RunCommand(cmd) ok = (exitcode == 0) else: ok = false if not ok: report.Error( "Actual result is different from expected result for " + ` fullName `, "expected result : " + expectedResult + "\n" + "actual result : " + actualResult) if util.CleanFile(ok): util.DeleteFiles(["comapre.arg"]) return ok
def execute(lang, type): global ext, binext #counter to indicate progress total = 1 #os type if util.IsWindowsOS() and os.environ.get('OSTYPE') == 'win32': ext = "cpp" binext = ".exe" else: ext = "cc" #main() file compiler = cmdline.LookUpWildCard('metaiv', lang, type, 'compiler') flags = cmdline.LookUpWildCard('metaiv', lang, type, 'cflags') MakeDriverAndObjectFiles("driver." + ext, compiler, flags) #Set expected results expSet = resfile.MakeStdExpansionSet('metaiv', lang, 'impl') resfile.RegisterExpansionSet(expSet) #jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') #initialize the extraction of test cases gentestcases.StartSearch('metaiv', lang, type) name = gentestcases.NextTestCase() while (name != None): #setting report report.setTestCaseName(name) if (total % jobSize) == 1: report.Progress(2, "Handling test cases " + str(total) + "..." + str(total + jobSize - 1)) report.Progress(3, "Running " + name) ok = RunTestCase(name, lang, type) #cleaning up if ok: if util.CleanFile(ok): baseName = util.ExtractName(name) util.DeleteFiles([baseName + ".res"])#, "driver" + binext]) else: break #generates next test case name = gentestcases.NextTestCase() total = total + 1
def PrepareSpecCase(fullName, lang, dtc): report.Progress(3, "preparing " + fullName) report.setTestCaseName(fullName) ok = convert.ConvertLanguage(lang, fullName) if ok: parser = cmdline.LookUpWildCard('ip', lang, 'spec', 'parser', dtc) ok = convert.VDM2AST(fullName, parser, false) if ok: ok = convert.CreateOptionsFile(fullName) argStr = CreateArgumentAst(fullName, lang) if argStr == None: ok = false if dtc == 'dtcon': dtcbool = 'true' else: dtcbool = 'false' if ok: convert.CreateDebugFile(fullName, "debug-file-ip", { '<<ARG>>': argStr, '<<DTC>>': dtcbool }) if ok: ok = convert.CreateArgFile(fullName, "arg-file-ip", { '<<ARG>>': argStr, '<<DTC>>': dtcbool }) if ok: ok = convert.AppendToDotVdmtest(fullName) # Clean up if test case failed if not ok and util.CleanFile(ok): baseName = util.ExtractName(fullName) util.DeleteFiles([ baseName + ".vdm", baseName + ".ast", baseName + ".arg", baseName + ".debug" ]) return ok
def PrepareSpecCase(name, lang, posdef): report.Progress(3, "preparing " + name) report.setTestCaseName(name) ok = convert.ConvertLanguage(lang, name) if ok: parser = cmdline.LookUpWildCard('tc', lang, 'spec', 'parser', posdef) ok = convert.VDM2AST(name, parser, false) if ok: ok = convert.CreateOptionsFile(name) if posdef == 'pos': posdefStr = '<POS>' else: posdefStr = '<DEF>' if ok: convert.CreateDebugFile(name, "debug-file-tc", {'<<POSDEF>>': posdefStr}) if ok: ok = convert.CreateArgFile(name, "arg-file-tc", {'<<POSDEF>>': posdefStr}) if ok: ok = convert.AppendToDotVdmtest(name) # Clean up if test case failed if not ok and util.CleanFile(ok): baseName = util.ExtractName(name) util.DeleteFiles([ baseName + ".vdm", baseName + ".ast", baseName + ".arg", baseName + ".debug" ]) return ok
def executeSpec(lang): ok = convert.SetupSpecification(lang, 'cpp') if not ok: report.Error("ABORTING specification test for " + `lang`) return # counter to indicate progress total = 1 # number of spec. files to run in one vdmde execution jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('cpp', lang, 'spec') # indicates if any spec test case produced an error. anyError = false # Initialize coverage file #coverageFile = "coverage-cpp-"+lang+"-"+cmdline.StartDate() coverageFile = "rtinfo.ast" while ( true ): testCases = gentestcases.NextTestCases(jobSize) if testCases == []: break startIndex = total endIndex = total+len(testCases) -1 report.Progress(2, "Handling test cases " + `startIndex` + "..." + `endIndex`) # Prepare the next test run - the parameter `spec-job-size' tells how # many testcases should be executed in each run. names = [] util.DeleteFiles([".vdmtest"]) for name in testCases: # prepare test cases. ok = PrepareSpecCase(name, lang) anyError = not ok or anyError if ok: names.append(name) # Get ready for next iteration. total = total +1 # Run the test cases if names != []: report.Progress(3, "Running test cases " + `startIndex` + "..." + `endIndex`) report.setTestCaseName("testcase " + `startIndex` + "..." + `endIndex`) okNames = RunSpecTestCases(names, lang, coverageFile) util.MoveProfile() # Clean Up. for testName in names: ok = (okNames.count(testName) > 0) if util.CleanFile(ok): baseName = util.ExtractName(testName) util.DeleteFiles([baseName+".vdm", baseName+".ast", baseName+".arg", baseName+".arg.res", baseName+".debug", baseName+".arg.pt","debug.arg",baseName+".res"]) anyError = anyError or not ok # Clean up .vdmde and .vdmtest if util.CleanFile(not anyError): util.DeleteFiles([".vdmde",".vdmtest"])
def CompareResult(fullName, outputFile, resFile, interpreter, structTest=true): # compare the results using normal "diff" actualResult = util.ReadFile(outputFile) expectedResult = util.ReadFile(resFile) # Remove duplicate white spaces and line breaks, spaces around commas and parenthesis. actualResult = re.sub("\s+", " ", actualResult).strip() expectedResult = re.sub("\s+", " ", expectedResult).strip() actualResult = re.sub("\s*,\s*", ",", actualResult).strip() expectedResult = re.sub("\s*,\s*", ",", expectedResult).strip() actualResult = re.sub("\s*\(\s*", "(", actualResult).strip() expectedResult = re.sub("\s*\(\s*", "(", expectedResult).strip() actualResult = re.sub("\s*\)\s*", ")", actualResult).strip() expectedResult = re.sub("\s*\)\s*", ")", expectedResult).strip() if actualResult == expectedResult: return true # Expected Result is Run Time Error if expectedResult.startswith("Run-Time Error"): report.Error( "Actual result is different from expected result for '" + fullName + "'", "expected result : " + expectedResult + "\n" + "actual result : " + actualResult) return false if expectedResult.startswith( "<UTIL.NumberToInt>:") or actualResult.startswith( "<UTIL.NumberToInt>:"): report.Error( "Actual result is different from expected result for '" + fullName + "'", "expected result : " + expectedResult + "\n" + "actual result : " + actualResult) return false if expectedResult.startswith( "The construct is not supported:") or actualResult.startswith( "The construct is not supported:"): report.Error( "Actual result is different from expected result for '" + fullName + "'", "expected result : " + expectedResult + "\n" + "actual result : " + actualResult) return false report.Progress( 4, "Comparing result for '" + fullName + "' using diff method") # Hmmm we need to try to compare using VDMDE then. if structTest and interpreter != None: report.Progress( 4, "Comparing result for '" + fullName + "' by build VDM value") template = util.GetTemplate("compare-result") if template == None: return false data = util.SubString('<<EXPECTED_RESULT>>', expectedResult, template) data = util.SubString('<<ACTUAL_RESULT>>', actualResult, data) ok = util.WriteFile("compare.vdm", data) if not ok: return false util.CopyFile(setup.BaseDir + "/general-files/compare.arg", "compare.arg") cmd = interpreter + " -i compare.arg compare.vdm" (exitcode, dummy1, dummy2) = util.RunCommand(cmd) ok = (exitcode == 0) else: ok = false if not ok: report.Error( "Actual result is different from expected result for '" + fullName + "'", "expected result : " + expectedResult + "\n" + "actual result : " + actualResult) if util.CleanFile(ok): util.DeleteFiles(["comapre.arg"]) return ok
def PrepareSpecCaseDir(dirName, lang): global runJavacBeforeParser testName = GetTestName(dirName) fullName = os.getcwd() # # Produce a list of java files in dirName # and put it testCases # AddTestsFromHierarchy(dirName, lang) util.DeleteFiles([parseRes]) util.RemoveTestFiles(testName, [ ".arg.pt", ".arg.res", ".arg.err", ".res.arg", ".arg.msg", "vpp.arg", ".res", ".debug", ".ast" ]) ok = convert.CreateOptionsFile(fullName) if runJavacBeforeParser == "yes": ok = CompileJavaFiles(dirName) if not ok: return false javafiles = " " javafiles = javafiles + setup.BaseDir + "/../j2v-test/Object.java " javafiles = javafiles + setup.BaseDir + "/../j2v-test/Exception.java " javafiles = javafiles + setup.BaseDir + "/../j2v-test/String.java " javafiles = javafiles + setup.BaseDir + "/../j2v-test/Character.java " # # Iterate over the list of java files in the dirName (except MAIN.java) # and runs javamain # mainJava = dirName + "/" + "MAIN.java" while ok and (testCases != []): test = GetNextTest() if os.path.abspath(test) != os.path.abspath(mainJava): javafiles = javafiles + test + " " # javafiles = javafiles + setup.BaseDir+"/../j2v-test/Object.java " # javafiles = javafiles + setup.BaseDir+"/../j2v-test/Exception.java " # javafiles = javafiles + setup.BaseDir+"/../j2v-test/String.java " # # Run java parser to get CPP`Files # if not ParseJavaFile(javafiles, lang): ok = false if ok: ast = util.ReadFile(parseRes) if ok: ok = util.WriteFile(testName + ".ast", ast) if ok: convert.CreateDebugFile(dirName, "debug-file-java2vdm", {}) if ok: ok = convert.CreateArgFile(dirName, "arg-file-java2vdm", {}) if ok: ok = convert.AppendToDotVdmtest(dirName) # Clean up if test case failed if not ok and util.CleanFile(ok): util.DeleteFiles([ testName + ".vdm", testName + ".ast", testName + ".arg", testName + ".debug", "debug.arg" ]) return ok
def RunApiTestCase(name, lang, toolMediator): data = util.ReadFile(name) baseName = util.ExtractName(name) neutralName = re.sub('.*/', '', name) # path neutralized! result = baseName + ":\n" last = "" symTable = {} symTable['GENPATH'] = os.path.expanduser(cmdline.LookUp('api-gen-path')) symTable['SOURCEPATH'] = os.path.expanduser( cmdline.LookUp('api-source-path')) print(symTable['GENPATH']) print(symTable['SOURCEPATH']) commands = data.split("\n") line, test = 0, 0 empty = re.compile('^\s*(#.*)|(\s*)$') interactive_mode = cmdline.LookUp('api-run-interactive') for cmd in commands: print("Command: " + cmd) if interactive_mode == 'yes': print("Press <return>") raw_input() line = line + 1 # don't process empty lines if not empty.match(cmd): test = test + 1 try: cmd = re.sub('\$\$', last, cmd) # replace $$ by last result cmd = re.sub('\s+', ' ', cmd).strip() # replace multiple spaces by one cmd = re.sub('\s*\(\s*', '(', cmd) # delete spaces around parentheses cmd = re.sub('\s*\)\s*', ')', cmd) cmd = re.sub('\s*\[\s*', '[', cmd) # delete spaces around parentheses cmd = re.sub('\s*\]\s*', ']', cmd) cmd = re.sub('\s*,\s*', ',', cmd) # delete spaces around commas cmd = re.sub('\s*=\s*', '=', cmd) # delete spaces around = # find variable assignment m = re.compile('^\$(?P<lval>\w+)=(?P<rval>.*)$').match(cmd) if m != None: lval = m.group('lval') cmd = m.group('rval') else: lval = "" # find variable usages and replace them by value m = re.compile('^.*\$(?P<id>\w+).*$').match(cmd) if m != None: while m != None: var = "\$" + m.group('id') try: repl = symTable[m.group('id')] except KeyError: raise Syntax("Unknown variable name $" + var) cmd = re.sub(var, repl, cmd) m = re.compile('^.*\$(?P<id>\w+).*$').match(cmd) result = result + "-- " + str(test) + "(in line " + str( line) + "):\n" # print (cmd) # parse and execute the command last = toolMediator.ParseCommand(cmd, name, line) lines = last.split('\n') pathexp = re.compile('^.*/(.*\.(vdm|vpp|api))$') for l in lines: # neutralize path result = result + pathexp.sub(r'\1', l) + "\n" last = re.sub('\n$', '', last) last = re.sub('\n', ',', last).strip() if lval != "": symTable[lval] = last except CORBA.COMM_FAILURE: raise CORBA.COMM_FAILURE except CORBA.BAD_PARAM: result = result + "CORBA.BAD_PARAM in " + neutralName + ", line " + str( line) + "\n" except ToolboxAPI.APIError: _, e, _ = sys.exc_info() result = result + "APIError in " + neutralName + ", line " + str( line) + ": " + e.msg + "\n" except VDM.VDMError: _, e, _ = sys.exc_info() result = result + "VDMError in " + neutralName + ", line " + str( line) + ": " + str(e.err) + "\n" except Syntax: _, e, _ = sys.exc_info() result = result + "Syntax error in " + neutralName + ", line " + str( line) + ": " + e.GetMessage() + "\n" except CORBA.UserException: result = result + "CORBA.UserException: in " + baseName + ".api, line " + str( line) + "\n" except CORBA.SystemException: _, e, _ = sys.exc_info() print(e) result = result + "CORBA.SystemException: in " + baseName + ".api, line " + str( line) + "\n" except Exception: _, e, _ = sys.exc_info() print("Python exception") print(e.args) result = result + "Python exception in " + baseName + ".api, line " + str( line) + "\n" except: result = result + "Unknown exception in " + baseName + ".api, line " + str( line) + "\n" ok = util.WriteFile(baseName + ".tmp", result) if ok: resFile = resfile.FindResFile(name) ok = (resFile != None) if ok: ok = resfile.CompareResult(name, baseName + ".tmp", resFile, None) if util.CleanFile(ok): util.DeleteFiles([baseName + ".tmp"]) return ok
def executeSpec(lang): if not util.IsWindowsOS(): ok = convert.SetupSpecification(lang, "java2vdm") if not ok: report.Error("ABORTING specification test for " + lang) # counter to indicate progress total = 1 # jobSize is used to give a low level of outputting jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases from javacg-code and java2vdm. StartCollectionOfTests() # indicates if any spec test case produced an error. anyError = false # Initialize coverage file coverageFile = "coverage-java2vdm-" + lang + "-" + cmdline.StartDate() oneTestCase = cmdline.LookUp('java2vdm-test-case') if oneTestCase != "": testCasesDirectories.append(oneTestCase) else: AddTestDirectoriesFromHierarchy(cmdline.GetTestCases('java2vdm'), lang) while (true): cases = NextTestCasesDir(jobSize) if (cases == []): break startIndex = total endIndex = total + len(testCasesDirectories) - 1 report.Progress( 2, "Handling test cases " + str(startIndex) + "..." + str(endIndex)) # Prepare the next test run - the parameter 'spec-job-size' tells how # many testcases should be executed in each run. names = [] util.DeleteFiles([".vdmtest"]) for case in cases: # prepare test cases. ok = PrepareSpecCaseDir(case, lang) anyError = not ok or anyError if ok: names.append(case) # Get ready for next iteration. total = total + 1 # Run the test cases if names != []: report.Progress( 3, "Running test cases " + str(startIndex) + "..." + str(endIndex)) report.setTestCaseName("testcase " + str(startIndex) + "..." + str(endIndex)) (okNames, modules) = RunSpecTestCases(names, lang, coverageFile) # Clean Up. for testName in names: ok = (okNames.count(testName) > 0) baseName = GetTestName(testName) if util.CleanFile(ok): util.DeleteFiles([ baseName + ".vdm", baseName + ".ast", baseName + ".arg", baseName + ".arg.res", baseName + ".debug", baseName + ".opt", baseName + ".res.exp", baseName + ".arg.pt", "debug.arg", baseName + ".res" ]) util.DeleteFiles(["vpp.arg"]) anyError = anyError or not ok #clean directories filesToDelete = [] FID = os.popen("find" + " -type f ") line = FID.readline() while (line != ''): if line[len(line) - 4:].strip() == 'vpp' or line[len(line) - 6:].strip() == 'class': filesToDelete.append(line[:-1]) line = FID.readline() util.DeleteFiles(filesToDelete) for f in os.listdir(os.getcwd()): if os.path.isdir(f): os.system("rmdir " + f) #Clean up .vdmde and .vdmtest if util.CleanFile(not anyError): util.DeleteFiles([".vdmde", ".vdmtest", parseRes, "nuloptions"]) if not util.IsWindowsOS(): util.SymLink(coverageFile, "rtinfo.ast") return
result = result + "APIError in " + neutralName + ", line " + ` line ` + ": " + e.msg + "\n" except VDM.VDMError, e: result = result + "VDMError in " + neutralName + ", line " + ` line ` + ": " + ` e.err ` + "\n" except Syntax, e: result = result + "Syntax error in " + neutralName + ", line " + ` line ` + ": " + e.GetMessage( ) + "\n" except CORBA.UserException: result = result + "CORBA.UserException: in " + baseName + ".api, line " + ` line ` + "\n" except CORBA.SystemException, e: print e result = result + "CORBA.SystemException: in " + baseName + ".api, line " + ` line ` + "\n" except Exception, e: print "Python exception" print e.args result = result + "Python exception in " + baseName + ".api, line " + ` line ` + "\n" except: result = result + "Unknown exception in " + baseName + ".api, line " + ` line ` + "\n" ok = util.WriteFile(baseName + ".tmp", result) if ok: resFile = resfile.FindResFile(name) ok = (resFile != None) if ok: ok = resfile.CompareResult(name, baseName + ".tmp", resFile, None) if util.CleanFile(ok): util.DeleteFiles([baseName + ".tmp"]) return ok
def executeSpec(lang): modules = None ok = convert.SetupSpecification(lang, 'java') if not ok: report.Error("ABORTING specification test for '" + lang + "'") return # counter to indicate progress total = 1 # number of spec. files to run in one vdmde execution jobSize = cmdline.LookUp('spec-job-size') # Initialize the extraction of test cases. gentestcases.StartSearch('java', lang, 'spec') # indicates if any spec test case produced an error. anyError = false # Initialize coverage file coverageFile = "coverage-java-" + lang + "-" + cmdline.StartDate() while (true): testCases = gentestcases.NextTestCases(jobSize) if testCases == []: break startIndex = total endIndex = total + len(testCases) - 1 report.Progress( 2, "Handling test cases " + str(startIndex) + "..." + str(endIndex)) # Prepare the next test run - the parameter 'spec-job-size' tells how # many testcases should be executed in each run. names = [] util.DeleteFiles([".vdmtest"]) for name in testCases: # prepare test cases. ok = PrepareSpecCase(name, lang) anyError = not ok or anyError if ok: names.append(name) # Get ready for next iteration. total = total + 1 # Run the test cases if names != []: report.Progress( 3, "Running test cases " + str(startIndex) + "..." + str(endIndex)) report.setTestCaseName("testcase " + str(startIndex) + "..." + str(endIndex)) (okNames, modules) = RunSpecTestCases(names, lang, coverageFile) util.MoveProfile() baseName = util.ExtractName(name) if util.GenTestDir(): util.MakeDir(baseName) files = [ baseName + ".vdm", baseName + ".ast", baseName + ".arg", baseName + ".arg.res", baseName + ".debug", baseName + ".opt", baseName + ".arg.pt", "debug.arg", baseName + ".res" ] for mod in modules: files = files + [ mod + ".java", "external_" + mod + ".java", mod + ".java.bak" ] util.DeleteFiles( [mod + ".class", mod + "$" + mod + "Sentinel.class"]) for file in files: util.CopyFileIfExists(file, baseName + "/" + file) # Clean Up. for testName in names: ok = (okNames.count(testName) > 0) if util.CleanFile(ok): util.DeleteFiles([ baseName + ".vdm", baseName + ".ast", baseName + ".arg", baseName + ".arg.res", baseName + ".debug", baseName + ".opt", baseName + ".arg.pt", "debug.arg", baseName + ".res" ]) anyError = anyError or not ok if util.CleanFile(not anyError): util.DeleteFiles(["TMAIN.java", "TMAIN.class"]) if modules != None: for mod in modules: util.DeleteFiles([ mod + ".java", "external_" + mod + ".java", mod + ".class", mod + "$" + mod + "Sentinel.class", mod + ".java.bak" ]) # Clean up .vdmde and .vdmtest if util.CleanFile(not anyError): util.DeleteFiles([".vdmde", ".vdmtest"])