def GetIdSet(): stmtids = cmdline.LookUp('stmt-transform-ids') exprids = cmdline.LookUp('expr-transform-ids') stmtidset = '{mk_XF`SXFId(a)|a in set ' + stmtids + ' }' expridset = '{mk_XF`EXFId(a)|a in set ' + exprids + ' }' idunion = stmtidset + ' union ' + expridset return {'<<SID>>': idunion}
def PrintCmdOutput(stdoutFile, stderrFile): if (cmdline.LookUp('debug-level') >= 5 or cmdline.LookUp('debug-level') == -1): if os.path.exists(stdoutFile): data = util.ReadFile(stdoutFile) if data: print "[07m[34m" + data + "[30m[0m" if os.path.exists(stderrFile): data = util.ReadFile(stderrFile) if data: print "[07m[31m" + data + "[30m[0m"
def RunCommand(cmd, okExit=None, diagnosis=None, giveMeOutput = false, expectErr = false): report.Progress(4,"Running command: " + cmd) stdout = "" stderr = None if IsWindowsOS(): cmd = "(" + cmd + ")" else: cmd = cmd #+ " 2>&1" output = os.popen(cmd) stdout = output.read() exitCode = output.close() if exitCode == None: exitCode = 0 if cmdline.LookUp('show-errors-in-progress'): if stdout != None and stdout != "": report.Progress(1, "*** Standard output\n" + stdout + "\n***") if stderr != None and stderr != "": report.Progress(1, "*** Standard error\n" + stderr + "\n***") if (exitCode != okExit and okExit != None): report.Error("Command '" + cmd + "' returned with exit code "+ str(exitCode) + " different from " + str(okExit), diagnosis, stdout, stderr) else: if stderr != None and stderr != "" and not expectErr: report.Error("Command '" + cmd + "' generated the following on standard error", None, None, stderr) return (exitCode, stdout, stderr)
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 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 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 ParseJavaFile(javafiles, lang): javamain = cmdline.LookUp('java2vdm-parser') options = " " resultFile = parseRes cmd = javamain + options + javafiles (exitCode, dummy1, dummy2) = util.RunCommand(cmd, 0, "Problem parsing Java File", true) ok = (exitCode == 0) if ok: ok = VerifyPresenceOfGeneratedFiles(resultFile) # # Find errors in parser output # if ok: if dummy1.find("Error detected") != -1: ok = false if ok: ok = VerifyPresenceOfGeneratedFiles(resultFile) if not ok: report.Error("Parser failed to produce '" + resultFile + "' ", "") if not ok: report.Error("Parser failed '" + testName + "' ", dummy1) return ok
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): # 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() AddTestsFromHierarchy(cmdline.GetTestCases('java2vdm'), lang) while (testCases != []): test = testCases[0] report.setTestCaseName(test) if (total % jobSize) == 1: report.Progress( 2, "Handling test cases " + str(total) + "..." + str(total + jobSize - 1)) ok = RunImplTestCase(test, lang) total = total + 1 GetNextTest() return
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 execute(): for env in setup.availableTestenv: if cmdline.RunTestEnv(env): report.SetTestEnvName(env) for lang in setup.availableLanguages: if cmdline.LookUp('Language')[lang]: report.SetLanguage(lang) for type in ['spec', 'impl']: if cmdline.LookUp('Run-Type')[type]: report.SetRunType(type) report.Progress( 1, "Running " + env + " - " + type + ". test case for " + lang) if (env == 'tc'): tcrun.execute(lang, type) elif (env == 'ip'): iprun.execute(lang, type) elif (env == 'cpp'): cpprun.execute(lang, type) elif (env == 'java'): javarun.execute(lang, type) elif (env == 'api'): apirun.execute(lang, type) elif (env == 'debug'): debugrun.execute(lang, type) elif (env == 'parser'): parserrun.execute(lang, type) elif (env == 'rose'): roserun.execute(lang, type) elif (env == 'metaiv'): metaivrun.execute(lang, type) elif (env == 'rtf'): rtfrun.execute(lang, type) elif (env == 'java2vdm'): java2vdmrun.execute(lang, type) elif (env == 'j2vtf'): j2vtfrun.execute(lang, type) elif (env == 'pog'): pogrun.execute(lang, type)
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): for dtc in ['dtcon','dtcoff']: if cmdline.LookUp('IP-Type')[dtc]: report.SetIPType(dtc) report.Progress(1, "Running interpreter with " + dtc) util.SetProfileBaseName("gmon-ip-"+lang+"-"+type+"-"+dtc+"-"+cmdline.StartDate()) RegisterExpansionSet(lang, dtc, type) if (type == 'spec'): executeSpec(lang, dtc) else: executeImpl(lang, dtc)
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 RunCommand(cmd, okExit=None, diagnosis=None, giveMeOutput=false, expectErr=false): report.Progress(4, "Running command: " + cmd) stdout = "" stderr = None if IsWindowsOS(): # To ensure that environment variables given on the commandline works, we have to # call the sh commands explicit. # cmd = "(" + cmd + ") > "+ stdoutFile + " 2> " + stderrFile + " < nul" cmd = "(" + cmd + ")" else: cmd = cmd #+ " 2>&1" # p = popen2.Popen3(cmd, true) # p.tochild.close() # returnPid,exitCode = os.waitpid(p.pid, os.WNOHANG) # p.fromchild.close() # if p.childerr != None: # stderr = p.childerr.read() # else: # stdout = p.fromchild.read() output = os.popen(cmd) stdout = output.read() exitCode = output.close() if exitCode == None: exitCode = 0 if cmdline.LookUp('show-errors-in-progress'): if stdout != None and stdout != "": report.Progress(1, "*** Standard output\n" + stdout + "\n***") if stderr != None and stderr != "": report.Progress(1, "*** Standard error\n" + stderr + "\n***") if (exitCode != okExit and okExit != None): report.Error( "Command " + ` cmd ` + " returned with exit code " + ` exitCode ` + " different from " + ` okExit `, diagnosis, stdout, stderr) else: if stderr != None and stderr != "" and not expectErr: report.Error( "Command " + ` cmd ` + " generated the following on standard error", None, None, stderr) return (exitCode, stdout, stderr)
def SetProfileBaseName(nm): if cmdline.LookUp('Enable-Profiling'): global profileDir, profileCounter profileDir = nm profileCounter = 0 try: os.mkdir(nm) except os.error, (no, msg): report.Error("Error when making directory " + nm + ": " + msg + "\nProfiling disabled") profileDir = None return false util.DeleteFiles(["gmon.out"]) return true
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 execute(lang, type): # if lang == 'rt': # report.Progress(3,"Skipping rt for type checker - not applicable") # return for posdef in ['pos', 'def']: if cmdline.LookUp('TC-Type')[posdef]: report.setTypeTestType(posdef) report.Progress(1, "Running " + posdef + " test cases") util.SetProfileBaseName("gmon-tc-" + lang + "-" + type + "-" + posdef + "-" + cmdline.StartDate()) RegisterExpansionSet(lang, type, posdef) if (type == 'spec'): executeSpec(lang, posdef) else: executeImpl(lang, posdef)
def Error(msg, diagnosis=None, stdout=None, stderr=None): global firstMessage, errStream if firstMessage == true: Header() firstMessage = false errStream.write("Message:\n ") errStream.write(msg + "\n") if cmdline.LookUp('show-errors-in-progress'): Progress(1, "*** " + msg + " ***") if diagnosis: errStream.write("Possible diagnosis:\n") for line in string.split(diagnosis, "\n"): errStream.write(" " + line + "\n") if stdout: errStream.write("Standard output:\n ") for line in string.split(stdout, "\n"): errStream.write(" " + line + "\n") if stderr: errStream.write("Standard error:\n ") for line in string.split(stderr, "\n"): errStream.write(" " + line + "\n") errStream.write("\n\n\n") errStream.flush() if currentTestEnv == 'tc': SetValueInMap(errorCases, [ currentTestEnv, currentRunType, currentLanguage, currentTypeCheckType ], [], lambda x: x + [currentTestCaseName]) elif currentTestEnv == 'ip': SetValueInMap( errorCases, [currentTestEnv, currentRunType, currentLanguage, currentIPType], [], lambda x: x + [currentTestCaseName]) else: SetValueInMap(errorCases, [currentTestEnv, currentRunType, currentLanguage], [], lambda x: x + [currentTestCaseName])
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 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 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 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 = string.split(data, "\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 = string.strip(re.sub( '\s+', ' ', cmd)) # 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 + "-- " + ` test ` + "(in line " + ` line ` + "):\n" # print cmd + "\n" # parse and execute the command last = toolMediator.ParseCommand(cmd, name, line) lines = string.split(last, '\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 = string.strip(re.sub('\n', ',', last)) 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 " + ` line ` + "\n" except ToolboxAPI.APIError, e: 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"
def execute(lang, testType): expSet = resfile.MakeStdExpansionSet('api', lang, testType) resfile.RegisterExpansionSet(expSet) util.SetProfileBaseName("gmon-api-" + lang + "-" + testType + "-" + cmdline.StartDate()) if lang == 'sl': vdmServer = os.path.expanduser(cmdline.LookUp('api-sl-server')) else: vdmServer = os.path.expanduser(cmdline.LookUp('api-pp-server')) start_toolbox = cmdline.LookUp('api-run-start-toolbox') server_args = cmdline.LookUp('server-init-args').split(" ") # corba-init-args is used to pass arguments to the orb client_args = cmdline.LookUp('corba-init-args').split() orb = CORBA.ORB_init(client_args, CORBA.ORB_ID) if start_toolbox == 'yes': pid = os.fork() if pid == 0: report.Progress( 3, "Trying to start " + lang + "-toolbox: " + vdmServer) cmd = vdmServer + " " + "".join( server_args) + " > tb_output.tmp 2>&1" os.system(cmd) report.Error("Startup of Toolbox failed!") return false _exit(-1) waittime = 5 print("Waiting " + str(waittime) + " seconds for " + lang + "-server to start up...") time.sleep(waittime) if "VDM_OBJECT_LOCATION" in environ: location = environ["VDM_OBJECT_LOCATION"] else: if "HOME" in environ: location = environ["HOME"] else: location = "~" if lang == 'sl': location = location + '/vdmref.ior' else: location = location + '/vppref.ior' try: stringified_ior = open(os.path.expanduser(location)).read() except IOError: report.Error("Could not find IOR file " + location + "! Please start " + lang + "-Toolbox!") if start_toolbox == 'yes': os.kill(pid, 9) os.system("tset") return false try: vdmApp = orb.string_to_object(stringified_ior) except CORBA.COMM_FAILURE: _, ex, _ = sys.exc_info() print("CORBA.COMM_FAILUR") print(ex) vdmApp = None except CORBA.MARSHAL: _, ex, _ = sys.exc_info() print("CORBA.MARSHAL") print(ex) # vdmApp = None if vdmApp is None: report.Error("Nil object reference!") if start_toolbox == 'yes': os.kill(pid, 9) return false # check if vdmApp has correct type try: if not vdmApp._is_a('IDL:ToolboxAPI/VDMApplication:1.0'): report.Error("This is not a 'VDMApplication'-server!") if start_toolbox == 'yes': os.kill(pid, 9) return false except CORBA.COMM_FAILURE: report.Error("No connection to 'VDMApplication'-object!") if start_toolbox == 'yes': os.kill(pid, 9) return false # narrow vdmApp and get typecode vdmApp = vdmApp._narrow(ToolboxAPI.VDMApplication) tc = CORBA.TypeCode('IDL:ToolboxAPI/VDMApplication:1.0') # check if server is the one we want (SL or PP) try: toolType = vdmApp._get_Tool() if (lang == 'sl' and toolType == ToolboxAPI.PP_TOOLBOX) or \ (lang == 'pp' and toolType == ToolboxAPI.SL_TOOLBOX): report.Error(vdmServer + " is not a " + lang + "-server") if start_toolbox == 'yes': os.kill(pid, 9) return false else: print(vdmServer + " is a " + lang + "-server") clientID = vdmApp.Register() # run the testcases if not RunTestCases(lang, vdmApp, clientID): vdmApp.Unregister(clientID) if start_toolbox == 'yes': os.kill(pid, 9) return false except CORBA.COMM_FAILURE: report.Error("CORBA Communication error") vdmApp.Unregister(clientID) if start_toolbox == 'yes': os.kill(pid, 9) return false # clean up time.sleep(1) vdmApp.Unregister(clientID) if start_toolbox == 'yes': os.kill(pid, 9) os.system("tset") return true
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"])
def Progress(level, msg): if (cmdline.LookUp('debug-level') >= level or cmdline.LookUp('debug-level') == -1): print " " * 2 * (level - 1) + msg
def IgnoreFile(file): global ignoreFilesList if cmdline.LookUp('show-errors-in-progress'): Progress(1, "*** Ignoring file: " + file + " ***") if ignoreFilesList.count(file) == 0: ignoreFilesList.append(file)
def GenTestDir(): return cmdline.LookUp('java-gentestdir')
def KeepFile(ok): return cmdline.LookUp( 'keep') or not ok and cmdline.LookUp('keep-when-error')