Esempio n. 1
0
def CreateArgFile(fullName,lang, modules):
  global srcext
  info = convert.ExtractArgFileInfo(fullName)
  if info == None:
    return None
  else:
    (modcls, op) = info

  if lang == 'sl':
    template = util.GetTemplate('arg-file-cpp-sl')
    str = ""
    for mod0 in modules:
      mod = string.replace(mod0, "_", "_u")
      str = str + "init_" + mod + "();"
    data = util.SubString('<<INIT>>', str, template)
    data = util.SubString('<<MOD>>', modcls, data)
    data = util.SubString('<<OP>>', op, data)
  else:
# Remove any package path if it exists (n/a for c++)
    match = re.match("^.*\.([^.]+)$", modcls, re.M)
    if match != None:
      modcls = match.group(1)
    template = util.GetTemplate('arg-file-cpp-pp')
    data = util.SubString('<<CLASS>>',modcls, template)
    data = util.SubString('<<OP>>', op, data)

  if data == None:
    return false
  return util.WriteFile("icode." + srcext, data)
Esempio n. 2
0
def CreateArgumentAst(fullName, lang):
    info = convert.ExtractArgFileInfo(fullName)
    if info == None:
        return None
    else:
        (modcls, op) = info

    if lang == 'sl':
        template = util.GetTemplate("arg-file-pog")
    else:
        template = util.GetTemplate("arg-file-pog")

    data = util.SubString('<<MODORCLASS>>', modcls, template)
    data = util.SubString('<<OPERATION>>', op, data)
    return data
Esempio n. 3
0
def CreateDebugFile(fileName, templateName, extra):
  base = util.ExtractName(fileName)
  astFile   = base + ".ast"
  debugFile = base + ".debug"  
  report.Progress(4, "Creating debug (" + debugFile +")")

  ast = util.ReadFile(astFile)
  if ast == None:
    return false

  template = util.GetTemplate(templateName)
  if template == None:
    return false
  
  data = util.SubString("<<AST>>", ast, template)
  for key in extra.keys():
    data = util.SubString(key, extra[key], data)

  ok = util.WriteFile(debugFile, data)
  if not ok:
    return false

  # Make a symlink from the debug file til debug.arg
  ok = util.SymLink(debugFile, "debug.arg")
  return ok
Esempio n. 4
0
def CreateArgumentAst(fullName, lang):
  info = convert.ExtractArgFileInfo(fullName)
  if info == None:
    return None
  else:
    (modcls, op) = info

  isStatic = false
  if modcls == None:
    isStatic = true
    (modcls, op) = op
  
  if lang == 'sl' or isStatic:
    template = util.GetTemplate("arg-file-ip-arguments-sl")
  elif lang == 'pp' or isStatic:
    template = util.GetTemplate("arg-file-ip-arguments-pp")
  else:
    template = util.GetTemplate("arg-file-ip-arguments-rt")

  data = util.SubString('<<MODORCLASS>>', modcls, template)
  data = util.SubString('<<OPERATION>>', op, data)
  return data
Esempio n. 5
0
def CreateArgFile(fullName, lang, modules):
    info = convert.ExtractArgFileInfo(fullName)
    if info == None:
        return None
    else:
        (modcls, op) = info

    if lang == 'sl':
        template = util.GetTemplate('arg-file-java-sl')
        str = ""
        for mod in modules:
            str = str + "init_" + mod + "();"
        data = util.SubString('<<INIT>>', str, template)
        data = util.SubString('<<MOD>>', modcls, data)
        data = util.SubString('<<OP>>', op, data)
    else:
        template = util.GetTemplate('arg-file-java-pp')
        data = util.SubString('<<CLASS>>', modcls, template)
        data = util.SubString('<<OP>>', op, data)

    if data == None:
        return false

    return util.WriteFile("TMAIN.java", data)
Esempio n. 6
0
def CreateArgFile(fileName, templateName, extra):
  argFile = util.ExtractName(fileName) + ".arg"  
  astFile = util.ExtractName(fileName) + ".ast"
  report.Progress(4, "Creating arg file (" + argFile +")")
  
  template = util.GetTemplate(templateName)
  if template == None:
    return false
  
  ast = util.ReadFile(astFile)
  if ast == None:
    return false

  data = util.SubString('<<AST>>', ast, template)
  for key in extra.keys():
    data = util.SubString(key, extra[key], data)

  ok = util.WriteFile(argFile, data)
  return ok
Esempio n. 7
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