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 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 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 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 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(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 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 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 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 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 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 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('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 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 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 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 execute(lang, type): global vdmde, speccompare, backend, javac, java, vppde global parserOnly, runJavacBeforeParser, staticSemanticsOnly expSet = resfile.MakeStdExpansionSet('java2vdm', lang, 'impl') expSet = resfile.AppendToExpandsionSet(expSet, '', ['dtcoff', 'dtcon']) resfile.RegisterExpansionSet(expSet) javac = cmdline.LookUpWildCard('java', lang, 'spec', 'compiler') java = cmdline.LookUpWildCard('java', lang, 'spec', 'interpreter') vppde = cmdline.LookUpWildCard('java', 'pp', 'impl', 'code-generator') vdmde = cmdline.LookUpWildCard('java', 'sl', 'impl', 'code-generator') speccompare = vdmde backend = cmdline.LookUp('java2vdm-backend') staticSemanticsOnly = cmdline.LookUp('java2vdm-static-semantics-only') runJavacBeforeParser = cmdline.LookUp('java2vdm-javac-before-parser') parserOnly = cmdline.LookUp('java2vdm-java-parser-only') if (type == 'spec'): executeSpec(lang) else: executeImpl(lang)
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 CompileRunAndCompare(fullName, lang, type, modules): baseName = util.ExtractName(fullName) ok = true stdout = None stderr = None if ok: CreateUserdefFile(modules) if ok: ok = CreateArgFile(fullName, lang, modules) if ok: ok = CompileCPPFiles(fullName, lang, type, modules) if ok: # Execute the binary (exitCode, stdout, stderr) = util.RunCommand("icode", 0, "Error running c++ generated binary", true) ok = (exitCode == 0) if ok: ok = util.WriteFile(baseName + ".res", stdout) else: report.Error("Output", None, stdout, stderr) if ok: resFile = resfile.FindResFile(fullName) ok = (resFile != None) if ok: ok = CompareRunTimeError(fullName, resFile) if ok == None: # It was not a runtime error interpreter = cmdline.LookUpWildCard('cpp', lang, type, 'spec-compare') # Compare the result ok = resfile.CompareResult(fullName, baseName + ".res", resFile, interpreter) 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 CompileCPPFiles(fullName, lang, type, modules): global srcext, objext, binext baseName = util.ExtractName(fullName) # Find the compiler to use if util.UsesVisualStudio(): compiler = 'cl.exe /nologo' else: compiler = cmdline.LookUpWildCard('cpp', lang, type, 'compiler') # figure out the names of all the CC files ccFiles = "icode." + srcext if lang != 'sl': ccFiles = ccFiles + " CGBase." + srcext for mod0 in modules: mod = string.replace(mod0, "_", "_u") ccFiles = ccFiles + " " + mod + "." + srcext # If there were any dl classes specified, add the corresponding files to # be linked against. # FIXME: Only works on Linux now (assumes xxx.so uselib). linkFiles = "" uselibs = convert.GetUselibs() regexp = re.compile("(.*).so", re.M) for ul in uselibs: match = regexp.search(ul,1) if match == None: report.Progress(4, "uselib " + ul + " has unexpected format - skipping") else: if util.UsesVisualStudio(): dllib = match.group(1) + ".obj" else: dllib = match.group(1) + ".o" linkFiles = linkFiles + dllib + " " # Find the flags for the compiler flags = os.path.expandvars(cmdline.LookUpWildCard('cpp', lang, type, 'cflags')) # Append language define. if lang == 'sl': flags = " -DVDMSL " + flags else: flags = " -DVDMPP " + flags flags = flags + " -D__" + string.replace(baseName, "-", "_") + "__" # Append link path to the directory containing the source file, as # this directory may also contain the extra _userimpl.cc file. if util.UsesVisualStudio(): flags = flags + " /IC:/cygwin" + os.path.dirname(fullName) else: flags = flags + " -I" + os.path.dirname(fullName) # First delete the binary. if util.UsesVisualStudio(): util.DeleteFiles(["icode.exe", "icode.exe.manifest", "math.h"]) else: util.DeleteFiles(["icode"]) # build the command and execute it. if util.UsesVisualStudio(): cmd = compiler + " -c " + ccFiles + " " + flags else: cmd = compiler + " -o icode " + ccFiles + " " + linkFiles + flags (exitCode, dummy1, dummy2) = util.RunCommand(cmd, 0, "Problem when compiling generated code") ok = (exitCode == 0) if util.UsesVisualStudio(): if ok: objFiles = "icode." + objext if lang != 'sl': objFiles = objFiles + " CGBase." + objext for mod0 in modules: mod = string.replace(mod0, "_", "_u") objFiles = objFiles + " " + mod + "." + objext libdir = os.path.expandvars(os.path.expanduser(cmdline.LookUp('cpp-lib-dir'))) #cmd = "link.exe /INCREMENTAL:NO /NOLOGO /out:icode.exe " + objFiles + " " + linkFiles + "vdm.lib CG.lib user32.lib" cmd = "link.exe /INCREMENTAL:NO /NOLOGO /out:icode.exe " + objFiles + " " + linkFiles + "/LIBPATH:C:/cygwin" + libdir + " CG.lib vdm.lib user32.lib" (exitCode, dummy1, dummy2) = util.RunCommand(cmd, 0, "Problem when compiling generated code") ok = (exitCode == 0) if ok: if not os.path.exists("icode" + binext): report.Error("icode binary was not created as a result of compiling the generated C++ files") return false return ok
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 = cmdline.LookUp('java-stdlib-dir') 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) for mod in packageMap.keys(): packagePaths = string.split(packageMap[mod], '.') packageDir = string.join(packagePaths, '/') if not os.path.exists(packageDir): os.makedirs(packageDir) report.Progress(4, "cp " + mod + "*.class " + packageDir + "/.") exitCode = os.system("cp " + mod + "*.class " + packageDir + "/.") interpreter = os.path.expandvars( cmdline.LookUpWildCard('java', lang, type, 'interpreter')) if ok: # Execute the binary #flags = cmdline.LookUpWildCard('java',lang,type,'rtflags') flags = os.path.expandvars( cmdline.LookUpWildCard('java', lang, type, 'rtflags')) #if util.IsWindowsOS(): # flags = string.replace(flags, ":", ";") (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