示例#1
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
示例#2
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
示例#3
0
def RunTestCase(name, lang, type, coverageFile):

    stdout = None
    stderr = None

    baseName = util.ExtractName(name)
    report.setTestCaseName(name)
    ok = true

    #run the test cases
    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.")

    # See if a result file was created
    if ok:
        if not os.path.exists(baseName + ".arg.res"):
            report.Error("No result file generated for test case " + name,
                         "Maybe it failed before")
            ok = false

    if ok:
        resFile = resfile.FindResFile(name)
        ok = (resFile != None)
    if ok:
        ok = resfile.CompareResult(name, baseName + ".arg.res", resFile, None)

    return ok
示例#4
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()
示例#5
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
示例#6
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()
示例#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
示例#8
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
示例#9
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 from javacg-code and java2vdm.
    StartCollectionOfTests()

    AddTestsFromHierarchy(cmdline.GetTestCases('java2vdm'), lang)

    while (testCases != []):
        test = testCases[0]
        report.setTestCaseName(test)
        if (total % jobSize) == 1:
            report.Progress(
                2, "Handling test cases " + str(total) + "..." +
                str(total + jobSize - 1))
        ok = RunImplTestCase(test, lang)
        total = total + 1

        GetNextTest()

    return
示例#10
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
示例#11
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
示例#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)
示例#13
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
示例#14
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
示例#15
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
示例#16
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
示例#17
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
示例#18
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)
示例#19
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
示例#20
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"])
示例#21
0
def executeSpec(lang, posdef):
    ok = convert.SetupSpecification(lang, 'tc')
    if not ok:
        report.Error("ABORTING specification test for '" + langi + "'")
        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('tc', lang, 'spec')

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

    # Initialize coverage file
    coverageFile = "coverage-tc-" + lang + "-" + posdef + "-" + 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, posdef)
            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 = RunSpecTestCases(names, lang, posdef, 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"
                ])
            anyError = anyError and ok

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