def RunImplTestCase(fullName, lang, posdef): ok = convert.ConvertLanguage(lang, fullName) # Remove the files we expect output in to if ok: util.RemoveTestFiles(fullName, [".arg.res"]) # Run the test if ok: interpreter = cmdline.LookUpWildCard('tc', lang, 'impl', 'interpreter', posdef) if posdef == 'pos': defFlg = "" else: defFlg = " -d " localName = util.ExtractName(fullName) + ".vdm" resName = util.ExtractName(fullName) + ".arg.res" cmd = interpreter + defFlg + " -t -f " + localName + " 2>" + resName # Now run the interpreter (exitCode, stdout, stderr) = util.RunCommand(cmd, None, None, true, true) # Ensure that the interpreter actually did type check anything. # That is in contract to if it stoped due to a syntax error or a core dump. # if re.search("Type checking [^\n]* done", stdout) == None: # report.Error("text 'type check ... done' not found on stdout while running the type checker", # "This might be due to a core dump, a syntax error or the like\n" + # "This does anyway indicate that the type checking was never done", # stdout, stderr) # ok = false if ok: expResName = resfile.FindResFile(fullName) # read the result from the result file, and translate it to a list of numbers # result = TranslateResultImpl(stdout) result = TranslateResultImpl(util.ReadFile(resName)) if result == None: ok = false if ok: if expResName == None: print("Not validating result (2)") if util.KeepFile(false): WriteResult(fullName, result) ok = false if ok: # Validate the result. report.Progress( 4, "Validating result with result file: '" + expResName + "'") ok = ValidateResult(fullName, expResName, result, stdout, stderr) if util.KeepFile(ok): WriteResult(fullName, result) return ok
def StripSemValue(fullName, lang, dtc): interpreter = cmdline.LookUpWildCard('ip', lang, 'spec', 'sem-backend', dtc) inNm = util.ExtractName(fullName) + ".arg.res" outNm = util.ExtractName(fullName) + ".res" cmd = interpreter + " < " + inNm + " > " + outNm return util.RunCommand(cmd, 0, "Error while stripping semantic values")
def StripSemValue(fullName, lang, dtc): interpreter = cmdline.LookUpWildCard('pog', lang, 'spec', 'sem-backend') inNm = util.ExtractName(fullName) + ".arg.res" outNm = util.ExtractName(fullName) + ".res" # cmd = interpreter + " < " + inNm + " > " + outNm # return util.RunCommand(cmd, 0, "Error while stripping semantic values") return util.WriteFile(outNm, util.ReadFile(inNm))
def RunImplTestCase(fullName, lang, dtc): # Remove the files we expect output in to util.RemoveTestFiles(fullName, [".arg.res"]) # Run the test interpreter = cmdline.LookUpWildCard('pog', lang, 'impl', 'interpreter') localName = util.ExtractName(fullName) + ".vdm" outputFile = util.ExtractName(fullName) + ".res" argFile = util.ExtractName(fullName) + ".arg" ok = SetupArgFile(fullName, lang) if not ok: return false if dtc == 'dtcon': dtccmd = "-DPIQ" else: dtccmd = "" cmd = interpreter + " -G -O " + outputFile + " " + localName util.DeleteFiles([outputFile]) # Now run the interpreter (exitCode, stdout, stderr) = util.RunCommand(cmd, None, None, true) expResultFile = resfile.FindResFile(fullName) if expResultFile == None: ok = false if ok: if exitCode != 0: ## Maybe a runtime error occured. # Note the order of the next binary expression ensures that # CompareRunTimeError is executed even though no expected result was # found! This is necesary as this function generates the result one # can copy in place ok = CompareRunTimeError(fullName, expResultFile, stdout) and ok return ok # Was output produced? if not os.path.exists(outputFile): report.Error( ` cmd ` + " didn't produce the expected result file: " + ` outputFile `, "Either command was malformed, or the interpreter crashed.") return false interpreter = cmdline.LookUpWildCard('pog', lang, 'impl', 'spec-compare') # ok = resfile.CompareResult(fullName, outputFile, expResultFile, interpreter) ok = CompareResult(fullName, outputFile, expResultFile, interpreter) return ok
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 CreateDebugFile(fileName, templateName, extra): base = util.ExtractName(fileName) astFile = base + ".ast" debugFile = base + ".debug" report.Progress(4, "Creating debug (" + debugFile +")") ast = util.ReadFile(astFile) if ast == None: return false template = util.GetTemplate(templateName) if template == None: return false data = util.SubString("<<AST>>", ast, template) for key in extra.keys(): data = util.SubString(key, extra[key], data) ok = util.WriteFile(debugFile, data) if not ok: return false # Make a symlink from the debug file til debug.arg ok = util.SymLink(debugFile, "debug.arg") return ok
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 RunTestCase(name, lang, type): baseName = util.ExtractName(name) #compile and run compiler = cmdline.LookUpWildCard('metaiv', lang, type, 'compiler') flags = cmdline.LookUpWildCard('metaiv', lang, type, 'cflags') cmd = compiler + " -o driver driver.cc " + name + " " + flags (exitCode, dummy1, dummy2) = util.RunCommand(cmd, 0, "Problem whith compiling") ok = (exitCode == 0) if ok: if not os.path.exists("driver"): report.Error("Driveri binary is not created") (exitCode, stdout, stderr) = util.RunCommand("./driver" + binext, 0, "Error running c++ generated c++ binary", true) ok = (exitCode == 0) #compare results with expected result files if ok: ok = util.WriteFile(baseName + ".res", stdout) else: report.Error("Output", None, stdout, stderr) if ok: resFile = resfile.FindResFile(name) ok = (resFile != None) if ok: resfile.CompareResult(name, baseName + ".res", resFile, None) return ok
def CodeGenerateImpl(fullName, lang, modules): localName = util.ExtractName(fullName) + ".vdm" # Clean out the files we expect as output from the code generation. for mod in modules: util.DeleteFiles([mod + ".java", "external_" + mod + ".java"]) exitCode0 = os.system("rm -f ./quotes/* ./*.class") CopyFilesForMerging(fullName, modules) # Run the code generation interpreter = cmdline.LookUpWildCard('java', lang, 'impl', 'code-generator') options = convert.ParseOptionsFile(fullName) cmd = interpreter + options + " -j -e -P " + localName #cmd = interpreter + options + " -j -e -P -L " + localName (exitCode, dummy1, dummy2) = util.RunCommand( cmd, 0, "Problem code generating specification, " + "maybe syntax or type error in test case") ok = (exitCode == 0) if ok: ok = VerifyPresenceOfGeneratedFiles(fullName, modules) return ok
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 RunTestCase(name, lang, type, coverageFile): stdout = None stderr = None baseName = util.ExtractName(name) report.setTestCaseName(name) ok = true #run the test cases cmd = cmdline.LookUpWildCard('cpp', lang, 'spec', 'interpreter') cmd = cmd + " -D -P -a -b -R " + coverageFile exitCode = util.RunCommand( cmd, 0, "Possible core dump while interpreting specification.") # See if a result file was created if ok: if not os.path.exists(baseName + ".arg.res"): report.Error("No result file generated for test case " + name, "Maybe it failed before") ok = false if ok: resFile = resfile.FindResFile(name) ok = (resFile != None) if ok: ok = resfile.CompareResult(name, baseName + ".arg.res", resFile, None) 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 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 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 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 CodeGenerateImpl(fullName, lang, modules): global srcext localName = util.ExtractName(fullName) + ".vdm" # Clean out the files we expect as output from the code generation. for mod0 in modules: mod = mod0.replace("_", "_u") util.DeleteFiles([ mod + "." + srcext, mod + ".h", mod + "_anonym." + srcext, mod + "_anonym.h", mod + "_userdef.h" ]) # Run the code generation interpreter = cmdline.LookUpWildCard('cpp', lang, 'impl', 'code-generator') cmd = interpreter + " -c -P " + localName (exitCode, dummy1, dummy2) = util.RunCommand( cmd, 0, "Problem code generating specification, maybe syntax or type error in test case" ) ok = (exitCode == 0) if ok: ok = VerifyPresenceOfGeneratedFiles(fullName, modules) return ok
def TranslateResultSpec(fullName): bn = util.ExtractName(fullName) testName = bn + ".arg.res" data = util.ReadFile(testName) if data == None: return None return TranslateResultCommon(data)
def CreateArgFile(fileName, templateName, extra): argFile = util.ExtractName(fileName) + ".arg" astFile = util.ExtractName(fileName) + ".ast" report.Progress(4, "Creating arg file (" + argFile +")") template = util.GetTemplate(templateName) if template == None: return false ast = util.ReadFile(astFile) if ast == None: return false data = util.SubString('<<AST>>', ast, template) for key in extra.keys(): data = util.SubString(key, extra[key], data) ok = util.WriteFile(argFile, data) return ok
def RunSpecTestCases(fullNames, lang, coverageFile): # remove files we expect output in to. for fullName in fullNames: util.RemoveTestFiles(fullName, [".arg.pt", ".arg.res", ".arg.err", ".arg.msg"]) exitCode0 = os.system("rm -f quotes/*.java") # run the test cases cmd = cmdline.LookUpWildCard('java', lang, 'spec', 'code-generator') cmd = cmd + " -D -a -b -R " + coverageFile exitCode = util.RunCommand( cmd, 0, "Possible core dump while interpreting specification.") okNames = [] # Now validate the results for fullName in fullNames: bn = util.ExtractName(fullName) semResName = bn + ".arg.res" resName = bn + ".res" report.setTestCaseName(fullName) ok = true if ok: # Find the module or class names of the input specification. modules = convert.ModulesInSpecification(fullName, lang) if modules == None: ok = false # Clean out the files we expect as output from the code generation. for mod in modules: util.DeleteFiles([mod + ".java", "external_" + mod + ".java"]) # See if a result file was created if ok: if not os.path.exists(semResName): report.Error( "No result file generated for test case " + fullName, "Maybe the code generation failed for " + "one of the previous test cases") ok = false convert.ExtractArgFileInfo(fullName) if ok: ok = ExtractSourceFiles(fullName, lang, modules) if ok: ok = CompileRunAndCompare(fullName, lang, 'spec', modules) if ok: okNames.append(fullName) return (okNames, modules)
def RunSpecTestCases(fullNames, lang, dtc, coverageFile): # remove files we expect output in to. for fullName in fullNames: util.RemoveTestFiles(fullName, [".arg.pt", ".arg.res", ".arg.err", ".arg.msg"]) # run the test cases interpreter = cmdline.LookUpWildCard('pog', lang, 'spec', 'interpreter') # cmd = interpreter + " -a -b -R " + coverageFile + " ../pog/test.vdm" cmd = interpreter + " -a -b -R " + coverageFile exitCode = util.RunCommand(cmd, 0, "Possible core dump while interpreting specification.") okNames = [] # Now validate the results for fullName in fullNames: bn = util.ExtractName(fullName) semResName = bn + ".arg.res" resName = bn + ".res" errName = bn + ".arg.msg" report.setTestCaseName(fullName) # See if a result file was created if not os.path.exists(semResName) and not os.path.exists(errName): report.Error("No result or error file generated for test case " + fullName, "Maybe the interpreting toolbox failed for one of the previous test cases") continue # Find expected result file ok = true expResultFile = FindResFile(fullName) if expResultFile == None: ok = false if os.path.exists(errName): # See if an error file is generated. data = util.ReadFile(errName) if data == None: continue # Note the order of the next binary expression ensures that # CompareRunTimeError is executed even though no expected result was # found! This is necesary as this function generates the result one # can copy in place ok = CompareRunTimeError(fullName, expResultFile, data) and ok else: # Strip sem values ok = ok and StripSemValue(fullName, lang, dtc) # validate expected result then if ok: interpreter = cmdline.LookUpWildCard('pog', lang, 'spec', 'spec-compare') ok = CompareResult(fullName, resName, expResultFile, interpreter) if ok: okNames.append(fullName) return okNames
def ExtractSourceFiles(fullName, lang, modules): resName = util.ExtractName(fullName) + ".arg.res" cmd = cmdline.LookUpWildCard('cpp', lang, 'spec', 'extract-source-backend') cmd = cmd + " cpp " + resName (exitCode, dummy1, dummy2) = util.RunCommand(cmd, 0, "Problem extracting source files from output from C++ code generator specification") ok = (exitCode == 0) if ok: ok = VerifyPresenceOfGeneratedFiles(fullName, modules) return ok
def RunSpecTestCases(names, lang, posdef, coverageFile): # remove files we expect output in to. for fullName in names: util.RemoveTestFiles(fullName, [".arg.pt", ".arg.res"]) # run the test cases interpreter = cmdline.LookUpWildCard('tc', lang, 'spec', 'interpreter', posdef) cmd = interpreter + " -a -b -I -D -P -R " + coverageFile exitCode = util.RunCommand( cmd, 0, "Possible core dump while interpreting specification.", false, true) okNames = [] # Now validate the results for fullName in names: bn = util.ExtractName(fullName) resName = bn + ".arg.res" report.setTestCaseName(fullName) # See if a result file was created if not os.path.exists(resName): report.Error( "No result generated for test case " + fullName, "Maybe the interpreting toolbox failed for one of the previous test cases" ) continue # read the result from the result file, and translate it to a list of numbers result = TranslateResultSpec(fullName) if result == None: continue # Find the expected result file expResName = resfile.FindResFile(fullName) if expResName == None: if util.KeepFile(false): WriteResult(fullName, result) continue # Validate the result. report.Progress( 4, "Validating result with result file: " + ` expResName `) ok = ValidateResult(fullName, expResName, result, None, None) if ok: okNames.append(fullName) if util.KeepFile(ok): WriteResult(fullName, result) return okNames
def CompileRunAndCompare(fullName, lang, type, modules): global packageMap baseName = util.ExtractName(fullName) ok = true if ok: ok = CreateArgFile(fullName, lang, modules) standardlibs = convert.GetStandardLibs() libdir = os.path.expandvars(cmdline.LookUp('java-stdlib-dir')) for lib in standardlibs: libfile = lib + ".java" util.CopyFile(libdir + "/" + libfile, libfile) if ok: ok = CompileJavaFiles(fullName, lang, type, modules) interpreter = os.path.expandvars( cmdline.LookUpWildCard('java', lang, type, 'interpreter')) if ok: # Execute the binary flags = os.path.expandvars( cmdline.LookUpWildCard('java', lang, type, 'rtflags')) (exitCode, stdout, stderr) = util.RunCommand(interpreter + " " + flags + " TMAIN", 0, "Error running Java " + "generated binary", true) print("java " + flags + " TMAIN run") ok = (exitCode == 0) if ok: ok = util.WriteFile(baseName + ".res", stdout) if ok: resFile = resfile.FindResFile(fullName) ok = (resFile != None) if ok: ok = CompareRunTimeError(fullName, resFile) lib = "" if ok == None: # It was not a runtime error interpreter = lib + cmdline.LookUpWildCard('java', lang, type, 'spec-compare') # Compare the result ok = resfile.CompareResult(fullName, baseName + ".res", resFile, interpreter) 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 VDM2AST(fileName, parser, typeCheck): base = util.ExtractName(fileName) vdmFile = base + ".vdm" astFile = base + ".ast" report.Progress( 4, "Converting testcase from VDM to AST (creating " + astFile + ")") # First delete the m4pp file. if (os.path.exists("m4pp")): try: os.unlink("m4pp") except os.error, (no, msg): report.Error("Error while removing 'm4pp': " + msg) return false
def SetupArgFile(fullName,lang): argNm = util.StripExt(fullName)+".arg" localNm = util.ExtractName(fullName)+".arg" if os.path.exists(argNm): data = util.ReadFile(argNm) if data == None: return false if lang != 'sl': data = re.sub("^(.*)`(.*)\s*$", "new \\1().\\2", data, re.M) util.DeleteFiles([localNm]) return util.WriteFile(localNm, data) else: argFile = sys.path[0]+"/ip-files/iprun-" + lang + ".arg" return util.CopyFile(argFile,localNm)
def RunSpecTestCases(fullNames, lang, coverageFile): # remove files we expect output in to. for fullName in fullNames: util.RemoveTestFiles(fullName, [".arg.pt", ".arg.res", ".arg.err", ".arg.msg"]) # run the test cases #cmd = "LD_LIBRARY_PATH=/usr/local/omniORB/lib " #cmd = cmd + cmdline.LookUpWildCard('cpp', lang, 'spec', 'interpreter') cmd = cmdline.LookUpWildCard('cpp', lang, 'spec', 'interpreter') cmd = cmd + " -D -P -a -b -R " + coverageFile exitCode = util.RunCommand( cmd, 0, "Possible core dump while interpreting specification.") okNames = [] # Now validate the results for fullName in fullNames: bn = util.ExtractName(fullName) semResName = bn + ".arg.res" resName = bn + ".res" report.setTestCaseName(fullName) ok = true if ok: # Find the module or class names of the input specification. modules = convert.ModulesInSpecification(fullName, lang) if modules == None: ok = false # See if a result file was created if ok: if not os.path.exists(semResName): report.Error( "No result file generated for test case " + fullName, "Maybe the code generation failed for one of the previous test cases" ) ok = false if ok: ok = ExtractSourceFiles(fullName, lang, modules) if ok: ok = CompileRunAndCompare(fullName, lang, 'spec', modules) if ok: okNames.append(fullName) return okNames
def VDM2AST(fileName,parser, typeCheck): base = util.ExtractName(fileName) vdmFile = base + ".vdm" astFile = base + ".ast" report.Progress(4, "Converting testcase from VDM to AST (creating " + astFile + ")") # First delete the m4pp file. if (os.path.exists("m4pp")): try: os.unlink("m4pp") except os.error: _, (_, msg), _ = sys.exc_info() report.Error("Error while removing 'm4pp': " + msg) return false # run the parser if typeCheck: cmd = parser + " -ta " + vdmFile else: cmd = parser + " -pa " + vdmFile (exitCode, stdout, stderr) = util.RunCommand(cmd, 0, "Error in input file (" + vdmFile +"), possible syntax error") if exitCode != 0: return false # verify that a m4pp file has been created. if not os.path.exists("m4pp"): report.Error("command '" + cmd + "' didn't produce a m4pp file, though return code was 0", "Command may not be a vdmde command with -pa flag") return false # Finally move m4pp to 'astFile' if (os.path.exists(astFile)): try: os.unlink(astFile) except os.error: _, (_, msg), _ = sys.exc_info() report.Error("Error while removing " + astFile + ": " + msg) return false try: os.rename('m4pp', astFile) except os.error: _, (_, msg), _ = sys.exc_info() report.Error("Couldn't move file 'm4pp' to " + astFile + ": " + msg) return false return true
def CompileJavaFiles(fullName, lang, type, modules): baseName = util.ExtractName(fullName) # Find the compiler to use compiler = os.path.expandvars( cmdline.LookUpWildCard('java', lang, type, 'compiler')) # figure out the names of all the Java files javaFiles = "TMAIN.java" for mod in modules: if os.path.exists(mod + ".java"): javaFiles = javaFiles + " " + mod + ".java" else: package = convert.GetModCls() packageStrings = package.split('.') packageDir = util.join(packageStrings, '/') if os.path.exists(packageDir + ".java") and not packageDir in modules: print("-------> here") javaFiles = javaFiles + " " + packageDir + ".java" if os.path.exists("external_" + mod + ".java"): javaFiles = javaFiles + " external_" + mod + ".java" # Find the flags for the compiler flags = os.path.expandvars( os.path.expanduser(cmdline.LookUpWildCard('java', lang, type, 'cflags'))) # First delete the binary. util.DeleteFiles(["TMAIN.class"]) # build the command and execute it. cmd = compiler + " -d . " + flags + " " + javaFiles (exitCode, dummy1, dummy2) = util.RunCommand(cmd, 0, "Problem when compiling generated code") ok = (exitCode == 0) if ok: if not os.path.exists("TMAIN.class"): report.Error( "TMAIN.class was not created as a result of compiling the generated Java files" ) return false return ok
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