Ejemplo n.º 1
0
def execution_monitor(file_path, pragma_dictionary):
  """
  <Purpose>
    Executes a unit test written with a source contained in file_path. If the source
    contains any pragmas (#pragma out, #pragma repy, #pragma err), the unit testing
    framework creates the report differently. If there is a repy pragma, the test
    executes in repy, not python. If there is an out or err pragma, the unit testing
    framework will include that there was to be output in the report.

  <Arguments>
    file_path: file to be executed under the framework
    pragma_dictionary: dictionary of pragmas within this test file

  <Exceptions>
    None

  <Side Effects>
    None

  <Returns>
    A report containing information about any unexpected output:
    { Pragma Type : (Produced, Expected), ... }
  """

  # Status report.
  report = { }

  executable = sys.executable
  popen_args = [ executable ]

  if pragma_dictionary.has_key(REPY_PRAGMA):
    repy = 'repy.py'
    default_restriction = 'restrictions.default'

    # Did the user specify a non-default restrictions file?
    repyArgs = pragma_dictionary[REPY_PRAGMA]
    if not repyArgs:
      repyArgs = default_restriction

    popen_args.append(repy)

    # For tests requiring repy arguments besides restrictions.default
    # the user must specify them after the pragma
    arguments = repyArgs.split(" ")
    for element in arguments:
      popen_args.append(element)

  popen_args.append(file_path)

  # Execute the program.
  (out, error) = utfutil.execute(popen_args)

  report = {}

  verify_results(OUT_PRAGMA, pragma_dictionary, out, report)
  verify_results(ERROR_PRAGMA, pragma_dictionary, error, report)


  return report
Ejemplo n.º 2
0
def execution_monitor(file_path, pragma_dictionary, security_layers):
    """
  <Purpose>
    Executes a unit test written with a source contained in file_path. If the source
    contains any pragmas (#pragma out, #pragma repy, #pragma err), the unit testing
    framework creates the report differently. If there is a repy pragma, the test
    executes in repy, not python. If there is an out or err pragma, the unit testing
    framework will include that there was to be output in the report.
 
  <Arguments>
    file_path: file to be executed under the framework.
    
    pragma_dictionary: dictionary of pragmas within this test file.
    
    security_layers: A list of security layers to use. If no security are 
      selected, this should have a value of None.
      
  <Exceptions>
    None

  <Side Effects>
    None

  <Returns>
    A report containing information about any unexpected output:
    { Pragma Type : (Produced, Expected), ... }
  """

    # Status report.
    report = {}

    popen_args = []
    popen_args.append(sys.executable)

    if pragma_dictionary.has_key(REPY_PRAGMA):
        restrictions = 'restrictions.default'
        otherargs = []

        repyArgs = pragma_dictionary[REPY_PRAGMA]

        # Did the user specify a non-default restrictions file?
        if repyArgs:
            arguments = repyArgs.split(" ")

            # The first argument is the restrictions file
            restrictions = arguments[0]
            # The remaining arguments are the program's arguments
            otherargs = arguments[1:]

        popen_args.append('repy.py')
        popen_args.append(restrictions)
        if security_layers:
            popen_args.append('encasementlib.r2py')
            popen_args.extend(security_layers)

        # Add in dylink for import purposes.
        # MMM: We cannot unfortunately add in dylink blindly,
        # otherwise it breaks some tests. We need to re-evaluate
        # and figure out another way of adding dylink to only specific
        # tests.
        # popen_args.append('dylink.r2py')

        # Do allow other args to Repy (#1373)
        popen_args.extend(otherargs)

    popen_args.append(file_path)

    # Execute the program.
    (out, error) = utfutil.execute(popen_args)

    report = {}

    verify_results(OUT_PRAGMA, pragma_dictionary, out, report)
    verify_results(ERROR_PRAGMA, pragma_dictionary, error, report)

    return report
Ejemplo n.º 3
0
def execution_monitor(file_path, pragma_dictionary):
  """
  <Purpose>
    Executes a unit test written with a source contained in file_path. If the source
    contains any pragmas (#pragma out, #pragma repy, #pragma err), the unit testing
    framework creates the report differently. If there is a repy pragma, the test
    executes in repy, not python. If there is an out or err pragma, the unit testing
    framework will include that there was to be output in the report.
 
  <Arguments>
    file_path: file to be executed under the framework
    pragma_dictionary: dictionary of pragmas within this test file

  <Exceptions>
    None

  <Side Effects>
    None

  <Returns>
    A report containing information about any unexpected output:
    { Pragma Type : (Produced, Expected), ... }
  """

  # Status report.
  report = { }

  executable = 'python'
  popen_args = [ executable ]

  if pragma_dictionary.has_key(REPY_PRAGMA):
    repy = 'repy.py'
    default_restriction = 'restrictions.default'
    
    # Did the user specify a non-default restrictions file?
    repyArgs = pragma_dictionary[REPY_PRAGMA]
    if not repyArgs: 
      repyArgs = default_restriction
   
    popen_args.append(repy)

    # For tests requiring repy arguments besides restrictions.default
    # the user must specify them after the pragma
    arguments = repyArgs.split(" ")
    for element in arguments:
      popen_args.append(element)
  
  popen_args.append(file_path)

  # Execute the program.
  (out, error) = utfutil.execute(popen_args)
  
  # Is this executable suppose to produce any output on standard out?
  if pragma_dictionary.has_key(OUT_PRAGMA):
    expected_out = pragma_dictionary[OUT_PRAGMA]
    
    if not expected_out and not out: # pragma out
      report[OUT_PRAGMA] = (None, expected_out)
    elif not expected_out in out: # pragma out [ARGUMENT]
      report[OUT_PRAGMA] = (out, expected_out)
    
  elif out: # If not, make sure the standard out is empty.
    report[ERROR_PRAGMA] = (out, None)


  # Is this executable suppose to produce any output on standard error?
  if pragma_dictionary.has_key(ERROR_PRAGMA):
    expected_error = pragma_dictionary[ERROR_PRAGMA]
    
    if not expected_error and not  error: # pragma error
      report[ERROR_PRAGMA] = (None, expected_error)
    elif not expected_error in error: # pragma error [ARGUMENT]
      report[ERROR_PRAGMA] = (error, expected_error)
      
  elif error: # If not, make sure the standard error is empty.
    report[ERROR_PRAGMA] = (error, None)


  return report
Ejemplo n.º 4
0
def execution_monitor(file_path, pragma_dictionary, security_layers):
  """
  <Purpose>
    Executes a unit test written with a source contained in file_path. If the source
    contains any pragmas (#pragma out, #pragma repy, #pragma err), the unit testing
    framework creates the report differently. If there is a repy pragma, the test
    executes in repy, not python. If there is an out or err pragma, the unit testing
    framework will include that there was to be output in the report.
 
  <Arguments>
    file_path: file to be executed under the framework.
    
    pragma_dictionary: dictionary of pragmas within this test file.
    
    security_layers: A list of security layers to use. If no security are 
      selected, this should have a value of None.
      
  <Exceptions>
    None

  <Side Effects>
    None

  <Returns>
    A report containing information about any unexpected output:
    { Pragma Type : (Produced, Expected), ... }
  """

  # Status report.
  report = { }

  popen_args = []
  popen_args.append(sys.executable)
  
  if pragma_dictionary.has_key(REPY_PRAGMA):
    restrictions = 'restrictions.default'
    otherargs = []
    
    repyArgs = pragma_dictionary[REPY_PRAGMA]
    
    # Did the user specify a non-default restrictions file?
    if repyArgs: 
      arguments = repyArgs.split(" ")
      
      # The first argument is the restrictions file
      restrictions = arguments[0]
      # The remaining arguments are the program's arguments
      otherargs = arguments[1:]
   
    popen_args.append('repy.py')
    popen_args.append(restrictions)
    if security_layers:
      popen_args.append('encasementlib.r2py')
      popen_args.extend(security_layers)
    
    # Do allow other args to Repy (#1373)
    popen_args.extend(otherargs)

  popen_args.append(file_path)

  # Execute the program.
  (out, error) = utfutil.execute(popen_args)


  report = {}

  verify_results(OUT_PRAGMA, pragma_dictionary, out, report)
  verify_results(ERROR_PRAGMA, pragma_dictionary, error, report)


  return report
Ejemplo n.º 5
0
def execution_monitor(file_path, pragma_dictionary):
    """
  <Purpose>
    Executes a unit test written with a source contained in file_path. If the source
    contains any pragmas (#pragma out, #pragma repy, #pragma err), the unit testing
    framework creates the report differently. If there is a repy pragma, the test
    executes in repy, not python. If there is an out or err pragma, the unit testing
    framework will include that there was to be output in the report.
 
  <Arguments>
    file_path: file to be executed under the framework
    pragma_dictionary: dictionary of pragmas within this test file

  <Exceptions>
    None

  <Side Effects>
    None

  <Returns>
    A report containing information about any unexpected output:
    { Pragma Type : (Produced, Expected), ... }
  """

    # Status report.
    report = {}

    executable = 'python'
    popen_args = [executable]

    if pragma_dictionary.has_key(REPY_PRAGMA):
        repy = 'repy.py'
        default_restriction = 'restrictions.default'

        # Did the user specify a non-default restrictions file?
        repyArgs = pragma_dictionary[REPY_PRAGMA]
        if not repyArgs:
            repyArgs = default_restriction

        popen_args.append(repy)

        # For tests requiring repy arguments besides restrictions.default
        # the user must specify them after the pragma
        arguments = repyArgs.split(" ")
        for element in arguments:
            popen_args.append(element)

    popen_args.append(file_path)

    # Execute the program.
    (out, error) = utfutil.execute(popen_args)

    # Is this executable suppose to produce any output on standard out?
    if pragma_dictionary.has_key(OUT_PRAGMA):
        expected_out = pragma_dictionary[OUT_PRAGMA]

        if not expected_out and not out:  # pragma out
            report[OUT_PRAGMA] = (None, expected_out)
        elif not expected_out in out:  # pragma out [ARGUMENT]
            report[OUT_PRAGMA] = (out, expected_out)

    elif out:  # If not, make sure the standard out is empty.
        report[ERROR_PRAGMA] = (out, None)

    # Is this executable suppose to produce any output on standard error?
    if pragma_dictionary.has_key(ERROR_PRAGMA):
        expected_error = pragma_dictionary[ERROR_PRAGMA]

        if not expected_error and not error:  # pragma error
            report[ERROR_PRAGMA] = (None, expected_error)
        elif not expected_error in error:  # pragma error [ARGUMENT]
            report[ERROR_PRAGMA] = (error, expected_error)

    elif error:  # If not, make sure the standard error is empty.
        report[ERROR_PRAGMA] = (error, None)

    return report