Beispiel #1
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
Beispiel #2
0
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()
Beispiel #3
0
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
Beispiel #4
0
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)
Beispiel #5
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
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