Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
def PrepareSpecCase(name, lang):

    report.Progress(3, "Preparing " + name)
    report.setTestCaseName(name)

    parser = cmdline.LookUpWildCard('j2vtf', lang, 'spec', 'parser')
    ok = convert.VDM2AST(name, parser, false)

    if ok:
        ok = convert.CreateOptionsFile(name)

    if ok:
        extra = GetIdSet()
        ok = convert.CreateDebugFile(name, "debug-file-j2vtf", extra)

    if ok:
        ok = convert.CreateArgFile(name, "arg-file-j2vtf", extra)

    util.DeleteFiles([".vdmtest"])

    if ok:
        ok = convert.AppendToDotVdmtest(name)

    # Clean up if preparation failed
    if not ok and util.CleanFile(ok):
        baseName = util.ExtractName(name)
        util.DeleteFiles([
            baseName + ".arg", baseName + ".ast", baseName + ".debug",
            "debug.arg"
        ])

    return ok
Beispiel #4
0
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
Beispiel #5
0
def CodeGenerateImpl(fullName, lang, modules):
    global srcext
    localName = util.ExtractName(fullName) + ".vdm"

    # Clean out the files we expect as output from the code generation.
    for mod0 in modules:
        mod = mod0.replace("_", "_u")
        util.DeleteFiles([
            mod + "." + srcext, mod + ".h", mod + "_anonym." + srcext,
            mod + "_anonym.h", mod + "_userdef.h"
        ])

    # Run the code generation
    interpreter = cmdline.LookUpWildCard('cpp', lang, 'impl', 'code-generator')

    cmd = interpreter + " -c -P " + localName
    (exitCode, dummy1, dummy2) = util.RunCommand(
        cmd, 0,
        "Problem code generating specification, maybe syntax or type error in test case"
    )
    ok = (exitCode == 0)

    if ok:
        ok = VerifyPresenceOfGeneratedFiles(fullName, modules)

    return ok
Beispiel #6
0
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()
Beispiel #7
0
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
Beispiel #8
0
def PrepareSpecCase(fullName, lang):
  report.Progress(3, "preparing " + fullName)
  report.setTestCaseName(fullName)

  ok = convert.ConvertLanguage(lang, fullName)

  if ok:
    parser = cmdline.LookUpWildCard('cpp', lang, 'spec', 'parser')
    ok = convert.VDM2AST(fullName, parser, true)

  if ok:
    ok = convert.CreateOptionsFile(fullName)

  if ok:
    convert.CreateDebugFile(fullName, "debug-file-cpp", {'<<CGKIND>>' : '<CPP>'} )

  if ok:
    ok = convert.CreateArgFile(fullName, "arg-file-cpp",  {'<<CGKIND>>' : '<CPP>'} )

  if ok:
    ok = convert.AppendToDotVdmtest(fullName)

  # Clean up if test case failed
  if not ok and util.CleanFile(ok):
    baseName = util.ExtractName(fullName)
    util.DeleteFiles([baseName+".vdm", baseName+".ast", baseName+".arg", baseName+".debug", "debug.arg"])
        
  return ok
Beispiel #9
0
def CodeGenerateImpl(fullName, lang, modules):
    localName = util.ExtractName(fullName) + ".vdm"

    # Clean out the files we expect as output from the code generation.
    for mod in modules:
        util.DeleteFiles([mod + ".java", "external_" + mod + ".java"])

    exitCode0 = os.system("rm -f ./quotes/* ./*.class")

    CopyFilesForMerging(fullName, modules)

    # Run the code generation
    interpreter = cmdline.LookUpWildCard('java', lang, 'impl',
                                         'code-generator')

    options = convert.ParseOptionsFile(fullName)

    cmd = interpreter + options + " -j -e -P " + localName
    #cmd = interpreter + options + " -j -e -P -L " + localName
    (exitCode, dummy1, dummy2) = util.RunCommand(
        cmd, 0, "Problem code generating specification, " +
        "maybe syntax or type error in test case")
    ok = (exitCode == 0)

    if ok:
        ok = VerifyPresenceOfGeneratedFiles(fullName, modules)

    return ok
Beispiel #10
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
Beispiel #11
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 #12
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 #13
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
Beispiel #14
0
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
Beispiel #15
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)
Beispiel #16
0
def CompileJavaFiles(fullName, lang, type, modules):
    baseName = util.ExtractName(fullName)

    # Find the compiler to use
    compiler = os.path.expandvars(
        cmdline.LookUpWildCard('java', lang, type, 'compiler'))

    # figure out the names of all the Java files
    javaFiles = "TMAIN.java"

    for mod in modules:
        if os.path.exists(mod + ".java"):
            javaFiles = javaFiles + " " + mod + ".java"
        else:
            package = convert.GetModCls()
            packageStrings = package.split('.')
            packageDir = util.join(packageStrings, '/')
            if os.path.exists(packageDir +
                              ".java") and not packageDir in modules:
                print("-------> here")
                javaFiles = javaFiles + " " + packageDir + ".java"

        if os.path.exists("external_" + mod + ".java"):
            javaFiles = javaFiles + " external_" + mod + ".java"

    # Find the flags for the compiler
    flags = os.path.expandvars(
        os.path.expanduser(cmdline.LookUpWildCard('java', lang, type,
                                                  'cflags')))

    # First delete the binary.
    util.DeleteFiles(["TMAIN.class"])

    # build the command and execute it.
    cmd = compiler + " -d . " + flags + " " + javaFiles

    (exitCode, dummy1,
     dummy2) = util.RunCommand(cmd, 0, "Problem when compiling generated code")
    ok = (exitCode == 0)

    if ok:
        if not os.path.exists("TMAIN.class"):
            report.Error(
                "TMAIN.class was not created as a result of compiling the generated Java files"
            )
            return false

    return ok
Beispiel #17
0
def PrepareSpecCase(fullName, lang, dtc):
    report.Progress(3, "preparing " + fullName)
    report.setTestCaseName(fullName)

    ok = convert.ConvertLanguage(lang, fullName)

    if ok:
        parser = cmdline.LookUpWildCard('ip', lang, 'spec', 'parser', dtc)
        ok = convert.VDM2AST(fullName, parser, false)

    if ok:
        ok = convert.CreateOptionsFile(fullName)

    argStr = CreateArgumentAst(fullName, lang)
    if argStr == None:
        ok = false

    if dtc == 'dtcon':
        dtcbool = 'true'
    else:
        dtcbool = 'false'

    if ok:
        convert.CreateDebugFile(fullName, "debug-file-ip", {
            '<<ARG>>': argStr,
            '<<DTC>>': dtcbool
        })

    if ok:
        ok = convert.CreateArgFile(fullName, "arg-file-ip", {
            '<<ARG>>': argStr,
            '<<DTC>>': dtcbool
        })

    if ok:
        ok = convert.AppendToDotVdmtest(fullName)

    # Clean up if test case failed
    if not ok and util.CleanFile(ok):
        baseName = util.ExtractName(fullName)
        util.DeleteFiles([
            baseName + ".vdm", baseName + ".ast", baseName + ".arg",
            baseName + ".debug"
        ])

    return ok
Beispiel #18
0
def PrepareSpecCase(name, lang, posdef):
    report.Progress(3, "preparing " + name)
    report.setTestCaseName(name)

    ok = convert.ConvertLanguage(lang, name)

    if ok:
        parser = cmdline.LookUpWildCard('tc', lang, 'spec', 'parser', posdef)
        ok = convert.VDM2AST(name, parser, false)

    if ok:
        ok = convert.CreateOptionsFile(name)

    if posdef == 'pos':
        posdefStr = '<POS>'
    else:
        posdefStr = '<DEF>'

    if ok:
        convert.CreateDebugFile(name, "debug-file-tc",
                                {'<<POSDEF>>': posdefStr})

    if ok:
        ok = convert.CreateArgFile(name, "arg-file-tc",
                                   {'<<POSDEF>>': posdefStr})

    if ok:
        ok = convert.AppendToDotVdmtest(name)

    # Clean up if test case failed
    if not ok and util.CleanFile(ok):
        baseName = util.ExtractName(name)
        util.DeleteFiles([
            baseName + ".vdm", baseName + ".ast", baseName + ".arg",
            baseName + ".debug"
        ])

    return ok
Beispiel #19
0
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
Beispiel #20
0
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"])
Beispiel #21
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
Beispiel #22
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
Beispiel #23
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
Beispiel #24
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)
Beispiel #25
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
Beispiel #26
0
                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"
            except CORBA.UserException:
                result = result + "CORBA.UserException: in " + baseName + ".api, line " + ` line ` + "\n"
            except CORBA.SystemException, e:
                print e
                result = result + "CORBA.SystemException: in " + baseName + ".api, line " + ` line ` + "\n"
            except Exception, e:
                print "Python exception"
                print e.args
                result = result + "Python exception in " + baseName + ".api, line " + ` line ` + "\n"
            except:
                result = result + "Unknown exception in " + baseName + ".api, line " + ` 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
Beispiel #27
0
def RemoveTestFiles(fullName, extensions):
    bn = util.ExtractName(fullName)
    files = []
    for ext in extensions:
        files.append(bn + ext)
    util.DeleteFiles(files)
Beispiel #28
0
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"])