Пример #1
0
def AddTestDirectoriesFromHierarchy(root, lang):
    global testCasesDirectories, parserOnly, staticSemanticsOnly

    if (parserOnly == "yes" or staticSemanticsOnly == "yes"):
        pattern = "arg.res.exp"
    else:
        pattern = "exp"

    testCandidates = []

    if not util.IsWindowsOS():
        FID = os.popen("find " + root[0] + " -type d -name \*  2>/dev/null")
    else:
        FID = os.popen("find " + root[0] + " -type d -name \"*\" ")

    line = FID.readline()
    while (line != ''):
        testCandidates.append(line[:-1])
        line = FID.readline()

    for candidate in testCandidates:
        if not util.IsWindowsOS():
            FID = os.popen("ls " + candidate + "/*." + pattern +
                           " 2>/dev/null")
        else:
            FID = os.popen("ls " + candidate + "/*." + pattern + " ")

        line = FID.readline()
        if line != '':
            testCasesDirectories.append(candidate)
Пример #2
0
def GetTestName(dirName):
    if not util.IsWindowsOS():
        namelist = re.split("/", os.path.abspath(dirName))
    else:
        p = util.SubString('\\', "/", os.path.abspath(dirName))
        namelist = re.split("/", p)
    namelist.reverse()
    return namelist[0]
Пример #3
0
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
Пример #4
0
def SetupSpecification(lang, env):
  report.Progress(2, "Creating *.vdm" + lang + " files and .vdmde")


  ### Create the .vdmsl or vdmpp files
  if (env == 'tc'):
    specDir = cmdline.LookUp('tc-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-tc-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-tc-pp'
    else:
      dotVdm = '.vdmde-tc-rt'
  elif (env == 'ip'):
    specDir = cmdline.LookUp('ip-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-dyn-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-dyn-pp'
    else:
      dotVdm = '.vdmde-dyn-rt'

  elif (env == 'cpp'):
    specDir = cmdline.LookUp('cpp-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-cg-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-cg-pp'
    else:
      dotVdm = '.vdmde-cg-rt'
  elif (env == 'java'):
    specDir = cmdline.LookUp('java-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-cg-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-cg-pp'
    else:
      dotVdm = '.vdmde-cg-rt'
  elif (env == 'java2vdm'):
    specDir = cmdline.LookUp('java2vdm-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-j2v-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-j2v-pp'
    else:
      dotVdm = '.vdmde-j2v-rt'
  elif (env == 'j2vtf'):
    specDir = cmdline.LookUp('j2vtf-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-j2vtf-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-j2vtf-pp'
    else:
      dotVdm = '.vdmde-j2vtf-rt'  
  elif (env == 'pog'):
    specDir = cmdline.LookUp('pog-spec-dir')
    if lang == 'sl':
      dotVdm = '.vdmde-pog-sl'
    elif lang == 'pp':
      dotVdm = '.vdmde-pog-pp'
    else:
      dotVdm = '.vdmde-pog-rt'
  else:
    report.Error("Internal error in CreateSpecFiles, unknow env: '" + env + "'")
    return false;

  # Windows needs a different dotVdm file since file paths are different
  if util.IsWindowsOS() and os.environ.get('OSTYPE') == 'win32':
    dotVdm = dotVdm + '-win'
  
  if lang == 'sl':
    action = 'SL'
  elif lang == 'pp':
    action = 'PP'
  else:
    action = 'RT'

  if (env == 'java2vdm'):
    action = 'dot'

  # For Windows, build a Makefile on the fly
  if util.IsWindowsOS() and os.environ.get('OSTYPE') == 'win32':
    util.BuildMakefile(specDir)
    (exitCode, stdout, stderr) = util.RunCommand("make " + action, 
                                                 0, 'Possible syntax error in input specification')
  #else:
  #  (exitCode, stdout, stderr) = util.RunCommand('cd ' + specDir + "; make -f Makefile " + action, 
  #                                               0, 'Possible syntax error in input specification')

    if exitCode != 0:
      return false

  ### Create the .vdmde file
  # For Windows, execute the Makefile built locally
  if util.IsWindowsOS() and os.environ.get('OSTYPE') == 'win32':
    (exitCode, stdout, stderr) = util.RunCommand("make " + dotVdm, 0)
  else:
    (exitCode, stdout, stderr) = util.RunCommand('cd ' + specDir + "; make -f Makefile " + dotVdm, 0)

  if exitCode != 0:
    return false

  ### Copying the file to .vdmde
  return util.SymLink(specDir+'/' + dotVdm, ".vdmde")
Пример #5
0
def executeSpec(lang):
    if not util.IsWindowsOS():
        ok = convert.SetupSpecification(lang, "java2vdm")
        if not ok:
            report.Error("ABORTING specification test for " + 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()

    # indicates if any spec test case produced an error.
    anyError = false

    # Initialize coverage file
    coverageFile = "coverage-java2vdm-" + lang + "-" + cmdline.StartDate()

    oneTestCase = cmdline.LookUp('java2vdm-test-case')

    if oneTestCase != "":
        testCasesDirectories.append(oneTestCase)
    else:
        AddTestDirectoriesFromHierarchy(cmdline.GetTestCases('java2vdm'), lang)

    while (true):
        cases = NextTestCasesDir(jobSize)

        if (cases == []):
            break

        startIndex = total

        endIndex = total + len(testCasesDirectories) - 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 case in cases:
            # prepare test cases.

            ok = PrepareSpecCaseDir(case, lang)
            anyError = not ok or anyError
            if ok:
                names.append(case)

            # 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)

        # Clean Up.
        for testName in names:
            ok = (okNames.count(testName) > 0)
            baseName = GetTestName(testName)
            if util.CleanFile(ok):
                util.DeleteFiles([
                    baseName + ".vdm", baseName + ".ast", baseName + ".arg",
                    baseName + ".arg.res", baseName + ".debug",
                    baseName + ".opt", baseName + ".res.exp",
                    baseName + ".arg.pt", "debug.arg", baseName + ".res"
                ])
                util.DeleteFiles(["vpp.arg"])
                anyError = anyError or not ok

    #clean directories
    filesToDelete = []
    FID = os.popen("find" + " -type f ")
    line = FID.readline()
    while (line != ''):
        if line[len(line) -
                4:].strip() == 'vpp' or line[len(line) -
                                             6:].strip() == 'class':
            filesToDelete.append(line[:-1])
        line = FID.readline()
    util.DeleteFiles(filesToDelete)

    for f in os.listdir(os.getcwd()):
        if os.path.isdir(f):
            os.system("rmdir " + f)

    #Clean up .vdmde and .vdmtest
    if util.CleanFile(not anyError):
        util.DeleteFiles([".vdmde", ".vdmtest", parseRes, "nuloptions"])

    if not util.IsWindowsOS():
        util.SymLink(coverageFile, "rtinfo.ast")
    return
Пример #6
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)