files.new_contents: # Copyright (c) 2013 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """
  Cocotb is a coroutine, cosimulation framework for writing testbenches in Python.
  
  See https://docs.cocotb.org for full documentation
  """
  import os
  import sys
  import logging
  import threading
  import random
  import time
  import warnings
  
  import cocotb.handle
  import cocotb.log
  from cocotb.scheduler import Scheduler
  from cocotb.regression import RegressionManager
  
  
  # Things we want in the cocotb namespace
  from cocotb.decorators import test, coroutine, hook, function, external  # noqa: F401
  
  # Singleton scheduler instance
  # NB this cheekily ensures a singleton since we're replacing the reference
  # so that cocotb.scheduler gives you the singleton instance and not the
  # scheduler package
  
  from ._version import __version__
  
  # GPI logging instance
  if "COCOTB_SIM" in os.environ:
  
      # sys.path normally includes "" (the current directory), but does not appear to when python is embedded.
      # Add it back because users expect to be able to import files in their test directory.
      # TODO: move this to gpi_embed.cpp
      sys.path.insert(0, "")
  
      def _reopen_stream_with_buffering(stream_name):
          try:
              if not getattr(sys, stream_name).isatty():
                  setattr(sys, stream_name, os.fdopen(getattr(sys, stream_name).fileno(), 'w', 1))
                  return True
              return False
          except Exception as e:
              return e
  
      # If stdout/stderr are not TTYs, Python may not have opened them with line
      # buffering. In that case, try to reopen them with line buffering
      # explicitly enabled. This ensures that prints such as stack traces always
      # appear. Continue silently if this fails.
      _stdout_buffer_result = _reopen_stream_with_buffering('stdout')
      _stderr_buffer_result = _reopen_stream_with_buffering('stderr')
  
      # Don't set the logging up until we've attempted to fix the standard IO,
      # otherwise it will end up connected to the unfixed IO.
      cocotb.log.default_config()
      log = logging.getLogger(__name__)
  
      # we can't log these things until the logging is set up!
      if _stderr_buffer_result is True:
          log.debug("Reopened stderr with line buffering")
      if _stdout_buffer_result is True:
          log.debug("Reopened stdout with line buffering")
      if isinstance(_stdout_buffer_result, Exception) or isinstance(_stderr_buffer_result, Exception):
          if isinstance(_stdout_buffer_result, Exception):
              log.warning("Failed to ensure
  
  [... the rest is omitted ...]
files.new_path: cocotb/__init__.py
files.old_contents: # Copyright (c) 2013 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """
  Cocotb is a coroutine, cosimulation framework for writing testbenches in Python.
  
  See https://docs.cocotb.org for full documentation
  """
  import os
  import sys
  import logging
  import threading
  import random
  import time
  import warnings
  
  import cocotb.handle
  import cocotb.log
  from cocotb.scheduler import Scheduler
  from cocotb.regression import RegressionManager
  
  
  # Things we want in the cocotb namespace
  from cocotb.decorators import test, coroutine, hook, function, external  # noqa: F401
  
  # Singleton scheduler instance
  # NB this cheekily ensures a singleton since we're replacing the reference
  # so that cocotb.scheduler gives you the singleton instance and not the
  # scheduler package
  
  from ._version import __version__
  
  # GPI logging instance
  if "COCOTB_SIM" in os.environ:
  
      # sys.path normally includes "" (the current directory), but does not appear to when python is embedded.
      # Add it back because users expect to be able to import files in their test directory.
      # TODO: move this to gpi_embed.cpp
      sys.path.insert(0, "")
  
      def _reopen_stream_with_buffering(stream_name):
          try:
              if not getattr(sys, stream_name).isatty():
                  setattr(sys, stream_name, os.fdopen(getattr(sys, stream_name).fileno(), 'w', 1))
                  return True
              return False
          except Exception as e:
              return e
  
      # If stdout/stderr are not TTYs, Python may not have opened them with line
      # buffering. In that case, try to reopen them with line buffering
      # explicitly enabled. This ensures that prints such as stack traces always
      # appear. Continue silently if this fails.
      _stdout_buffer_result = _reopen_stream_with_buffering('stdout')
      _stderr_buffer_result = _reopen_stream_with_buffering('stderr')
  
      # Don't set the logging up until we've attempted to fix the standard IO,
      # otherwise it will end up connected to the unfixed IO.
      cocotb.log.default_config()
      log = logging.getLogger(__name__)
  
      # we can't log these things until the logging is set up!
      if _stderr_buffer_result is True:
          log.debug("Reopened stderr with line buffering")
      if _stdout_buffer_result is True:
          log.debug("Reopened stdout with line buffering")
      if isinstance(_stdout_buffer_result, Exception) or isinstance(_stderr_buffer_result, Exception):
          if isinstance(_stdout_buffer_result, Exception):
              log.warning("Failed to ensure
  
  [... the rest is omitted ...]
files.old_path: cocotb/__init__.py
files.new_contents: # Copyright (c) 2013, 2018 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """All things relating to regression capabilities."""
  
  import time
  import inspect
  from itertools import product
  import sys
  import os
  import traceback
  import pdb
  from typing import Any, Optional, Tuple, Iterable
  
  import cocotb
  import cocotb.ANSI as ANSI
  from cocotb.log import SimLog
  from cocotb.result import TestSuccess, SimFailure
  from cocotb.utils import get_sim_time, remove_traceback_frames, want_color_output
  from cocotb.xunit_reporter import XUnitReporter
  from cocotb.decorators import test as Test, hook as Hook, RunningTask
  from cocotb.outcomes import Outcome, Error
  from cocotb.handle import SimHandle
  
  if "COCOTB_PDB_ON_EXCEPTION" in os.environ:
      _pdb_on_exception = True
  else:
      _pdb_on_exception = False
  
  if "COCOTB_SIM" in os.environ:
      from cocotb import simulator
  else:
      simulator = None
  
  # Optional support for coverage collection of testbench files
  coverage = None
  if "COVERAGE" in os.environ:
      try:
          import coverage
      except ImportError as e:
          msg = ("Coverage collection requested but coverage module not available"
                 "\n"
                 "Import error was: %s\n" % repr(e))
          sys.stderr.write(msg)
  
  
  def _my_import(name: str) -> Any:
      mod = __import__(name)
      components = name.split('.')
      for comp in components[1:]:
          mod = getattr(mod, comp)
      return mod
  
  
  _logger = SimLog(__name__)
  
  
  class RegressionManager:
      """Encapsulates all regression capability into a single place"""
  
      def __init__(self, dut: SimHandle, tests: Iterable[Test], hooks: Iterable[Hook]):
          """
          Args:
              dut (SimHandle): The root handle to pass into test functions.
              tests (Iterable[Test]): tests to run
              hooks (Iterable[Hook]): hooks to tun
          """
          self._dut = dut
          self._test_task = None
          self._cov = None
          self.log = _logger
          self.start_time = time.time()
          self.test_results = []
          self.count = 0
          self.skipped = 0
          self.failures = 0
  
          # Setup XUnit
          ###################
  
          results_filename = os.getenv('COCOTB_RESULTS_FILE', "results.xml")
          suite_name = os.getenv('RESULT_TESTSUITE', "all")
          package_name = os.getenv('RESULT_TEST
  
  [... the rest is omitted ...]
files.new_path: cocotb/regression.py
files.old_contents: # Copyright (c) 2013, 2018 Potential Ventures Ltd
  # Copyright (c) 2013 SolarFlare Communications Inc
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions are met:
  #     * Redistributions of source code must retain the above copyright
  #       notice, this list of conditions and the following disclaimer.
  #     * Redistributions in binary form must reproduce the above copyright
  #       notice, this list of conditions and the following disclaimer in the
  #       documentation and/or other materials provided with the distribution.
  #     * Neither the name of Potential Ventures Ltd,
  #       SolarFlare Communications Inc nor the
  #       names of its contributors may be used to endorse or promote products
  #       derived from this software without specific prior written permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  # DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  """All things relating to regression capabilities."""
  
  import time
  import inspect
  from itertools import product
  import sys
  import os
  import traceback
  import pdb
  from typing import Any, Optional, Tuple, Iterable
  
  import cocotb
  import cocotb.ANSI as ANSI
  from cocotb.log import SimLog
  from cocotb.result import TestSuccess, SimFailure
  from cocotb.utils import get_sim_time, remove_traceback_frames, want_color_output
  from cocotb.xunit_reporter import XUnitReporter
  from cocotb.decorators import test as Test, hook as Hook, RunningTask
  from cocotb.outcomes import Outcome, Error
  from cocotb.handle import SimHandle
  
  if "COCOTB_PDB_ON_EXCEPTION" in os.environ:
      _pdb_on_exception = True
  else:
      _pdb_on_exception = False
  
  if "COCOTB_SIM" in os.environ:
      from cocotb import simulator
  else:
      simulator = None
  
  # Optional support for coverage collection of testbench files
  coverage = None
  if "COVERAGE" in os.environ:
      try:
          import coverage
      except ImportError as e:
          msg = ("Coverage collection requested but coverage module not available"
                 "\n"
                 "Import error was: %s\n" % repr(e))
          sys.stderr.write(msg)
  
  
  def _my_import(name: str) -> Any:
      mod = __import__(name)
      components = name.split('.')
      for comp in components[1:]:
          mod = getattr(mod, comp)
      return mod
  
  
  class RegressionManager:
      """Encapsulates all regression capability into a single place"""
  
      def __init__(self, dut: SimHandle):
          """
          Args:
              dut (SimHandle): The root handle to pass into test functions.
          """
          self._dut = dut
          self._test_task = None
          self._cov = None
          self.log = SimLog("cocotb.regression")
          self.start_time = time.time()
          self.test_results = []
          self.count = 0
          self.skipped = 0
          self.failures = 0
  
          # Setup XUnit
          ###################
  
          results_filename = os.getenv('COCOTB_RESULTS_FILE', "results.xml")
          suite_name = os.getenv('RESULT_TESTSUITE', "all")
          package_name = os.getenv('RESULT_TESTPACKAGE', "all")
  
          self.xunit = XUnitReporter(filename=results_filename)
  
          self.xunit.add_testsuite(name=suite_name, package=package_name)
  
          self
  
  [... the rest is omitted ...]
files.old_path: cocotb/regression.py