Exemple #1
0
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
Exemple #2
0
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 "" + data + ""
        if os.path.exists(stderrFile):
            data = util.ReadFile(stderrFile)
            if data:
                print "" + data + ""
Exemple #3
0
def CompareRunTimeError(resFile):
    report.Progress(4, "Searching for runtime error")
    actualResult = util.ReadFile(resFile)
    if actualResult == None:
        return None
    if actualResult.find("Run-Time Error") != -1:
        expectedResult = util.ReadFile(resFile)
        actualResult = re.sub("\s+", " ", actualResult).strip()
        expectedResult = re.sub("Run-Time Error[ 0-9]*:", "Run-Time Error ",
                                expectedResult)
        expectedResult = re.sub("\s+", " ", expectedResult).strip()
        return actualResult == expectedResult
    else:
        return None
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
def ExtractArgFileInfo(fullName):
  global modcls
  argFile = util.StripExt(fullName)+".arg"

  if os.path.exists(argFile):
    str = util.ReadFile(argFile)
    if str == None:
      return None

    match = re.match("^ *(.+)`(.+)\(\) *$", str, re.M)
    if match == None:
      match = re.match("^ *(.+)\.(.+)\(\) *$", str, re.M)
      if match == None:
        report.Error("Could parse argument file '" + argFile + "' with syntax MOD`OP()")
        return None
      else:
        modcls = match.group(1)
        op = match.group(2)
        return (None, (modcls, op))
    else:
      modcls = match.group(1)
      op = match.group(2)
  else:
    modcls = "A"
    op = "Test"

  return (modcls, op)
Exemple #7
0
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))
Exemple #8
0
def TranslateResultSpec(fullName):
    bn = util.ExtractName(fullName)
    testName = bn + ".arg.res"

    data = util.ReadFile(testName)
    if data == None:
        return None

    return TranslateResultCommon(data)
Exemple #9
0
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
Exemple #10
0
def GetPackage(fullName):
    data = util.ReadFile(fullName)
    if data == None:
        return ""

    regexp = re.compile("^package (.*)\s*;", re.M)
    match = regexp.search(data, 0)
    if match == None:
        return ""
    else:
        report.Progress(4,
                        "Found package " + match.group(1) + " in " + fullName)
        return match.group(1)
Exemple #11
0
def CompareRunTimeError(fullName, resFile):
  report.Progress(4,"Searching for runtime error")
  bn = util.ExtractName(fullName)
  actualResult = util.ReadFile(bn+".res")
  if actualResult == None:
    return None
  if string.find(actualResult, "Run-Time Error") != -1:
    #expectedResult = util.ReadFile(resFile)
    expectedResult = string.rstrip(util.ReadFile(resFile), "\n")
    ok = (string.find(expectedResult, "Run-Time Error") != -1)
    if ok:
      actualResult = string.strip(re.sub("\s+", " ", actualResult))
      expectedResult = re.sub("Run-Time Error[ 0-9]*: ", "Run-Time Error:", expectedResult)
      #expectedResult = string.strip(re.sub("\s+", " ", expectedResult))
      ok = (actualResult == expectedResult)

    if not ok:
      report.Error("Actual result is different from expected result for " + `fullName`,
                   "expected result : " + expectedResult + "\n" +
                   "actual result   : " + actualResult)
    return ok
  else:
    return None
Exemple #12
0
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)
Exemple #13
0
def ConvertLanguage(lang, fileName):
  newName = util.ExtractName(fileName) + ".vdm"  
  report.Progress(4, "Converting testcase to language " + lang + " (creating " + newName +")")
  
  data = util.ReadFile(fileName)
  if data == None:
    return false

  if IsLanguageSl(data):
    if (lang == 'pp'):
      report.Error("Input file: '" + fileName + "' is a SL file, but a PP file is required")
      return false
  else:
    if (lang == 'sl'):
      data = PP2SL(data)

  ok = util.WriteFile(newName, data)
  return ok
Exemple #14
0
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
Exemple #15
0
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
Exemple #16
0
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
Exemple #17
0
def RunSpecTestCases(fullNames, lang, coverageFile):
    global vdmde, speccompare, backend, javac, java, vppde
    global staticSemanticsOnly, parserOnly

    testvdm = "test-j2v.vdm"

    if parserOnly == "yes":
        testvdm = "test-javamain.vdm"

    if staticSemanticsOnly == "yes":
        testvdm = "test-jss.vdm"

    testvdm = setup.BaseDir + "/../j2v-test/" + testvdm

    cmd = vdmde + " -DP -a -b -R " + coverageFile + " " + testvdm
    (exitCode, dummy1, dummy2) = util.RunCommand(
        cmd, 0, "Possible core dump while interpreting specification.", true)
    ok = exitCode == 0
    if exitCode != 0:
        report.Error("Toolbox returns an error ", "'" + dummy1 + "'")

    if ok and dummy1.find("Run-Time Error") != -1:
        report.Error(
            "Toolbox returns an run-time error. Look for the latest .arg.err file ",
            "")

    modules = []

    if parserOnly == "no" and ok:
        #
        #   Run backend for the VDM++ AS value to get
        #   VDM++ concrete syntax
        #
        for fullName in fullNames:
            bn = GetTestName(fullName)
            semResName = bn + ".arg.res"

            if not os.path.exists(semResName):
                continue

            if staticSemanticsOnly == "yes":
                util.CopyFile(semResName, fullName + "/" + semResName)

            report.setTestCaseName(fullName)

            modules.append(fullName)
            #
            #     The second arg should be directory where to put all
            #     generated .vpp
            #
            if staticSemanticsOnly == "no":
                if AS2CS(semResName, os.getcwd()):
                    #
                    #       Run java to produce expected result
                    #
                    expRes = os.getcwd() + "/" + GetTestName(
                        fullName) + ".res.exp"
                    #
                    #       If test directory contains its own MAIN.java, use it,
                    #       otherwise, use the generic MAIN.java in the current dir
                    #
                    j2vutilJava = setup.BaseDir + "/../j2v-test/J2VUTIL.java"
                    genericMainJava = setup.BaseDir + "/../j2v-test/MAIN.java"

                    mainJava = fullName + "/MAIN.java"
                    if not os.path.exists(mainJava):
                        mainJava = genericMainJava

                    javaFiles = fullName + "/*.java " + mainJava + " " + j2vutilJava + " "
                    #
                    #       Compile MAIN.java and J2VUTIL.java using
                    #       classes of test java files prepared earlier
                    #

                    if not util.IsWindowsOS():
                        cmd = javac + " -d " + os.getcwd() + " " + javaFiles
                    else:
                        cmd = javac + " -classpath ./VDM.jar -d ./ " + javaFiles
                    (exitCode, dummy1,
                     dummy2) = util.RunCommand(cmd, 0,
                                               "Javac returns errors. ")
                    if exitCode != 0:
                        break

                    if not util.IsWindowsOS():
                        cmd = java + " -classpath $CLASSPATH:" + os.getcwd(
                        ) + " MAIN"
                    else:
                        cmd = java + " MAIN"
                    (exitCode, dummy1,
                     dummy2) = util.RunCommand(cmd, 0, "Java returns errors. ",
                                               true)
                    if exitCode != 0:
                        break

                    if not util.WriteFile(expRes, dummy1):
                        break
    #
    #       Run vppde to produce the result itself
    #
                    prefix = os.getcwd() + "/" + GetTestName(fullName)
                    res = bn + ".res"
                    vpparg = "vpp.arg"
                    #
                    #       Create arg file
                    #
                    util.WriteFile(vpparg, "new A().Test()")

                    objectVpp = setup.BaseDir + "/../j2v-test/Object.vpp"
                    vppFiles = ""

                    if not util.IsWindowsOS():
                        FID = os.popen("find " + os.getcwd() +
                                       " -type f -name \*.vpp")
                    else:
                        FID = os.popen("find ./ -type f -name \*.vpp")
                    line = FID.readline()
                    while (line != ''):
                        vppFiles = vppFiles + line[:-1] + " "
                        line = FID.readline()
                    vppFiles = vppFiles + " " + objectVpp

                    cmd = vppde + " -iD -O " + res + " " + vpparg + " " + vppFiles
                    (exitCode, dummy1,
                     dummy2) = util.RunCommand(cmd, 0,
                                               "Vppde returns errors. ", true)
                    if exitCode != 0:
                        report.Error("Vppde returns errors " + fullName, "")

            filesToDelete = []
            FID = os.popen("ls *.vpp *.class 2>/dev/null")
            line = FID.readline()
            while (line != ''):
                filesToDelete.append(line[:-1])
                line = FID.readline()
            util.DeleteFiles(filesToDelete)

        okNames = []
#
# Now validate the results
#
    for fullName in fullNames:
        argErr = bn + ".arg.err"
        semResName = bn + ".arg.res"
        resName = bn + ".res"

        expSemResName = fullName + "/" + bn + ".arg.res.exp"
        expResName = bn + ".res.exp"
        report.setTestCaseName(fullName)
        ok = true

        if ok and staticSemanticsOnly == "no" and parserOnly == "no":
            if not os.path.exists(resName):
                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:
            if staticSemanticsOnly == "no" and parserOnly == "no":
                if os.path.exists(expResName):
                    ok = resfile.CompareResult(bn, resName, expResName,
                                               speccompare, false)
            else:

                if staticSemanticsOnly == "yes" and parserOnly == "no":
                    if os.path.exists(semResName):
                        ok = resfile.CompareResult(bn, semResName,
                                                   expSemResName, speccompare,
                                                   false)
                else:
                    report.Error(
                        "No result file generated for test case " + fullName,
                        "Look for the latest .arg.err file ")
                    ok = false

                if parserOnly == "yes":
                    if os.path.exists(argErr):
                        errorText = util.ReadFile(argErr)
                        if errorText != "":
                            report.Error("Parser failure " + fullName,
                                         errorText)

        if ok:
            okNames.append(fullName)

    return (okNames, modules)
Exemple #18
0
def GetTemplate(name):
    global templates
    if not templates.has_key(name):
        templates[name] = util.ReadFile(setup.BaseDir + "/templates/" + name)
    return templates[name]
Exemple #19
0
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"
Exemple #20
0
 def GetKey(self, version_number):
     return util.ReadFile(os.path.join(self._location, str(version_number)))
Exemple #21
0
 def GetMetadata(self):
     return util.ReadFile(os.path.join(self._location, "meta"))
Exemple #22
0
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
Exemple #23
0
def ModulesInSpecification(fullName, lang):
  global uselibs, standardlibs
  localName = util.ExtractName(fullName)+".vdm"
  
  data = util.ReadFile(localName)
  if data == None:
    return None
  
  if lang == 'sl':
    keyword = 'module '
  else:
    keyword = 'class '

  regexp = re.compile("^\s*" + keyword + "\s*(\w+)", re.M)

  index = 0
  result = []
  finished = 0
  standardlibs = []

  while finished != 1:
    match = regexp.search(data, index)
    if match == None:
      if result == []:
        report.Error("Could find any module or class in specification file '" + fullName + "'")
        return None
      finished = 1
    else:
      report.Progress(4,"Found module " + match.group(1))
      if IsStandardLib(match.group(1)):
        standardlibs.append(match.group(1))
      result.append(match.group(1))
      index = match.end()

  # If this is VDM-SL, return immediately, as we do not yet support
  # dlmodules in the test environment. FIXME
  if lang == 'sl':
    return result

  # Accumulate those modules that are dlclasses in uselibs
  keyword = 'dlclass'
  regexp1 = re.compile("^\s*" + keyword + "\s*(\w+)", re.M)
  regexp2 = re.compile("^\s*" + "uselib" + "\s*(\".+\")", re.M)

  index = 0
  finished = 0
  uselibs = []

  while finished != 1:
    match = regexp1.search(data, index)
    if match == None:
      finished = 1
    else:
      report.Progress(4,"Found dlclass " + match.group(1))
      result.append(match.group(1))
      uselib = regexp2.search(data, match.start())
      if uselib == None:
        report.Progress(4,"No uselib found for dlclass " + match.group(1))
      else:
        uselibs.append(uselib.group(1))
      index = match.end()
  return result
Exemple #24
0
def ParseOptionsFile(fileName):
  filestem = util.StripExt(fileName)
  optionsFileName = filestem + '.opt'
  if not os.path.exists(optionsFileName):
    return ""

  report.Progress(4, "Parsing " + optionsFileName)
  data = util.ReadFile(optionsFileName)
  startIndex = data.find("SetOptions")
  if startIndex == -1:
    report.Error("Unable to parse options file (1)")
    return ""

  reStart = re.compile("==\s+");
  startMatch = reStart.search(data, startIndex)
  if startMatch == None:
    report.Error("Unable to parse options file (2)")
    return ""

  startIndex = startMatch.start()
  reEnd = re.compile(";?\s*end\s+OPTIONS", re.M)
  endMatch = reEnd.search(data, startIndex)

  if endMatch == None: #Ill formed options file
    report.Error("Unable to parse options file (3)")
    return ""

  interfacesFlag = "-U"
  interfaceSeparator = ','
  packageFlag = "-z"
  
  endIndex = endMatch.start() - 1
  commands = re.split(';',data[startIndex:endIndex])
  commstring = ""
  for comm in commands:
    report.Progress(4, "**> command is" + comm)
    reComName = re.compile("CGMAIN`(\w+)")
    commMatch = reComName.search(comm,0)
    if commMatch != None:
      commandName = commMatch.group(1)
      if commandName == "set_interfaces":
        reArgs = re.compile("mk_AS`Name\(\[\"(\w+)\"],-1\)")
        args = comm[commMatch.end()+1:]
        arglist = ""
        nextArg = reArgs.search(args,0)
        while nextArg != None:
          if arglist == "":
            arglist = " " + nextArg.group(1)
          else:
            arglist = arglist + interfaceSeparator + nextArg.group(1)
          nextArg = reArgs.search(args, nextArg.end()+1)
        commstring =  commstring + ' ' + interfacesFlag + arglist
      elif commandName == "set_package_option":
        report.Progress(4, "Command is set_package_option")
        reArgs = re.compile("\"([\.\w]*)\"")
        args = comm[commMatch.end()+1:]
        arg = reArgs.search(args, 0)
        if arg != None:
          commstring = commstring + ' ' + packageFlag + " " + arg.group(1)
        else:
          report.Error("args didn't match: " + args)
      else:
        print ("Unknown option " + comm)
    else:
      report.Error("Command didn't match: " + comm) 
  report.Progress(4, "Finished parsing " + optionsFileName)
  return commstring