Ejemplo n.º 1
0
  def _StartPywebsocketServer(self):
    """Starts the pywebsocket server."""
    print 'Starting pywebsocket server.'

    # Pywebsocket source directory.
    path_pyws_dir = os.path.join(pyauto_paths.GetThirdPartyDir(), 'pywebsocket',
                                 'src')

    # Pywebsocket standalone server.
    path_to_pywebsocket= os.path.join(path_pyws_dir, 'mod_pywebsocket',
                                      'standalone.py')

    # Path to the data handler to handle data received by the server.
    path_to_handler = os.path.join(pyauto_paths.GetSourceDir(), 'chrome',
                                   'test', 'functional')

    # The python interpreter binary.
    python_interp = sys.executable

    # The pywebsocket start command - we could add --log-level=debug for debug.
    # -p stands for port, -d stands for root_directory (where the data handlers
    # are).
    start_cmd = [python_interp, path_to_pywebsocket,
                 '-p', _PYWEBSOCKET_PORT_NUMBER,
                 '-d', path_to_handler,]
    env = os.environ
    # Set PYTHONPATH to include the pywebsocket base directory.
    env['PYTHONPATH'] = (path_pyws_dir + os.path.pathsep +
                         env.get('PYTHONPATH', ''))

    # Start the pywebsocket server. The server will not start instantly, so the
    # code opening websockets to it should take this into account.
    self._pywebsocket_server = subprocess.Popen(start_cmd, env=env)
    def _CompareVideos(self, width, height, captured_video_filename,
                       reference_video_filename, stats_filename):
        """Compares the captured video with the reference video.

    The barcode decoder decodes the captured video containing barcodes overlaid
    into every frame of the video (produced by rgba_to_i420_converter). It
    produces a set of PNG images and a stats file that describes the relation
    between the filenames and the (decoded) frame number of each frame.

    Args:
      width(int): The frames width of the video to be decoded.
      height(int): The frames height of the video to be decoded.
      captured_video_filename(string): The captured video file we want to
        extract frame images and decode frame numbers from.
      reference_video_filename(string): The reference video file we want to
        compare the captured video quality with.
      stats_filename(string): Filename for the output file containing
        data that shows the relation between each frame filename and the
        reference file's frame numbers.

    Returns:
      (string): The output of the script.

    Raises:
      FailedToRunToolException: If the script fails to run.
    """
        path_to_analyzer = os.path.join(self.BrowserPath(), 'frame_analyzer')
        path_to_analyzer = os.path.abspath(path_to_analyzer)
        path_to_analyzer = self.BinPathForPlatform(path_to_analyzer)

        path_to_compare_script = os.path.join(pyauto_paths.GetThirdPartyDir(),
                                              'webrtc', 'tools',
                                              'compare_videos.py')
        if not os.path.exists(path_to_compare_script):
            raise MissingRequiredToolException('Cannot find the script at %s' %
                                               path_to_compare_script)
        python_interp = sys.executable
        cmd = [
            python_interp,
            path_to_compare_script,
            '--ref_video=%s' % reference_video_filename,
            '--test_video=%s' % captured_video_filename,
            '--frame_analyzer=%s' % path_to_analyzer,
            '--yuv_frame_width=%d' % width,
            '--yuv_frame_height=%d' % height,
            '--stats_file=%s' % stats_filename,
        ]
        print 'Start command: ', ' '.join(cmd)

        compare_videos = subprocess.Popen(cmd,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
        output, error = compare_videos.communicate()
        if compare_videos.returncode != 0:
            raise FailedToRunToolException(
                'Failed to run compare videos script!')

        return output
Ejemplo n.º 3
0
  def _RunBarcodeDecoder(self, width, height, captured_video_filename,
                         stats_filename):
    """Runs the barcode decoder script.

    The barcode decoder decodes the captured video containing barcodes overlaid
    into every frame of the video (produced by rgba_to_i420_converter). It
    produces a set of PNG images and a stats file that describes the relation
    between the filenames and the (decoded) frame number of each frame.

    The script depends on an external executable which is a part of the Zxing
    barcode library, which must be located in the PATH when running this test.

    Args:
      width(int): The frames width of the video to be decoded.
      height(int): The frames height of the video to be decoded.
      captured_video_filename(string): The captured video file we want to
        extract frame images and decode frame numbers from.
      stats_filename(string): Filename for the output file containing
        data that shows the relation between each frame filename and the
        reference file's frame numbers.

    Returns:
      (bool): True if the decoding was successful, False otherwise.
    """
    path_to_decoder = os.path.join(pyauto_paths.GetThirdPartyDir(), 'webrtc',
                                   'tools', 'barcode_tools',
                                   'barcode_decoder.py')
    if not os.path.exists(path_to_decoder):
      raise MissingRequiredToolException(
          'Could not locate the barcode decoder script! The barcode decoder '
          'decodes the barcodes overlaid on top of every frame of the captured '
          'video.')
    python_interp = sys.executable
    start_cmd = [python_interp, path_to_decoder,
                 '--yuv_file=%s' % captured_video_filename,
                 '--yuv_frame_width=%d' % width,
                 '--yuv_frame_height=%d' % height,
                 '--stats_file=%s' % stats_filename]
    print 'Start command: ', ' '.join(start_cmd)

    barcode_decoder = subprocess.Popen(start_cmd, stdout=sys.stdout,
                                       stderr=sys.stderr)
    barcode_decoder.wait()
    return barcode_decoder.returncode == 0
Ejemplo n.º 4
0
  def RunAgain():
    """Run the script again with the correct version of python.

    Note, this function does not return, but exits with the return code of the
    child.
    """
    if sys.platform == 'cygwin' or sys.platform.startswith('win'):
      cmd = [os.path.join(pyauto_paths.GetThirdPartyDir(), 'python_26',
                          'python_slave.exe')]
    elif sys.platform.startswith('darwin'):
      # Arch runs the specified architecture of a universal binary. Run
      # the 32 bit one.
      cmd = ['arch', '-i386', 'python2.6']
    elif sys.platform.startswith('linux'):
      cmd = ['python2.6']

    cmd.extend(sys.argv)
    print 'Running:', ' '.join(cmd)
    proc = subprocess.Popen(cmd)
    proc.wait()
    sys.exit(proc.returncode)
Ejemplo n.º 5
0
    import sys
    import warnings
    # Ignore deprecation warnings, they make our output more cluttered.
    warnings.filterwarnings('ignore', category=DeprecationWarning)

    # Find the path to the pyproto and add it to sys.path.
    # Prepend it so that google.protobuf is loaded from here.
    for path in pyauto_paths.GetBuildDirs():
        p = os.path.join(path, 'pyproto')
        if os.path.isdir(p):
            sys.path = [
                p, os.path.join(p, 'chrome', 'browser', 'policy', 'proto')
            ] + sys.path
            break
    sys.path.append('/usr/local')  # to import autotest libs.
    sys.path.append(os.path.join(pyauto_paths.GetThirdPartyDir(), 'tlslite'))

    import chrome_device_policy_pb2 as dp
    import device_management_backend_pb2 as dm
    import tlslite.api
    from autotest.cros import constants
    from autotest.cros import cros_ui
elif pyauto.PyUITest.IsWin():
    import _winreg as winreg
elif pyauto.PyUITest.IsMac():
    import getpass
    import plistlib

# ASN.1 object identifier for PKCS#1/RSA.
PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01'