def Run(self):
        self._ParseArgs()
        if not os.path.isdir(self._outdir):
            os.makedirs(self._outdir)

        # Fetch chrome & pyauto binaries
        print 'Fetching'
        print self._chrome_zip_url
        print self._pyautolib_py_url
        print self._pyautolib_so_url
        chrome_zip = urllib.urlretrieve(self._chrome_zip_url)[0]
        pyautolib_py = urllib.urlretrieve(self._pyautolib_py_url)[0]
        pyautolib_so = urllib.urlretrieve(self._pyautolib_so_url)[0]
        chrome_unzip_dir = os.path.join(self._outdir, self._chrome_zip_name)
        if os.path.exists(chrome_unzip_dir):
            print 'Cleaning', chrome_unzip_dir
            pyauto_utils.RemovePath(chrome_unzip_dir)
        pyauto_utils.UnzipFilenameToDir(chrome_zip, self._outdir)

        # Copy over the binaries to outdir
        items_to_copy = {
            pyautolib_py:
            os.path.join(self._outdir, 'pyautolib.py'),
            pyautolib_so:
            os.path.join(
                self._outdir, {
                    'linux64': '_pyautolib.so',
                    'linux32': '_pyautolib.so',
                    'mac': '_pyautolib.so',
                    'win': '_pyautolib.pyd'
                }[self._options.platform])
        }
        unzip_dir_contents = glob.glob(os.path.join(chrome_unzip_dir, '*'))
        for item in unzip_dir_contents:
            name = os.path.basename(item)
            items_to_copy[item] = os.path.join(self._outdir, name)

        for src, dest in items_to_copy.iteritems():
            pyauto_utils.RemovePath(dest)
            print '%s ==> %s' % (os.path.basename(src), dest)
            shutil.move(src, dest)
        pyauto_utils.RemovePath(chrome_unzip_dir)

        # Final setup (if any)
        # Create symlink to .framework on Mac
        if self._options.platform == 'mac':
            mac_app_name = os.path.basename(
                [x for x in unzip_dir_contents if x.endswith('.app')][0])
            os.chdir(self._outdir)
            framework = glob.glob(
                os.path.join(mac_app_name, 'Contents', 'Versions', '*',
                             '*.framework'))[0]
            print framework
            dest = os.path.basename(framework)
            os.path.lexists(dest) and os.remove(dest)
            print 'Creating symlink "%s"' % dest
            os.symlink(framework, dest)

        print 'Prepared binaries in "%s"' % self._outdir
Exemple #2
0
def RemoveDownloadedTestFile(test, file_name):
    """Delete a file from the downloads directory.

  Arg:
    test: derived from pyauto.PyUITest - base class for UI test cases
    file_name: name of file to remove
  """
    downloaded_pkg = os.path.join(test.GetDownloadDirectory().value(),
                                  file_name)
    pyauto_utils.RemovePath(downloaded_pkg)
    pyauto_utils.RemovePath(downloaded_pkg + '.crdownload')
Exemple #3
0
    def SetUp(self, is_linux, revision, gsutil):
        """Sets up Deep Memory Profiler settings for a Chrome process.

    It sets environment variables and makes a working directory.
    """
        if not self._enabled:
            return

        if not is_linux:
            raise NotSupportedEnvironmentError(
                'Deep Memory Profiler is not supported in this environment (OS).'
            )

        self._revision = revision
        self._gsutil = gsutil

        # Remove old dumped files with keeping latest _SAVED_WORKDIRS workdirs.
        # It keeps the latest workdirs not to miss data by failure in uploading
        # and other operations.  Dumped files are no longer available if they are
        # removed.  Re-execution doesn't generate the same files.
        tempdir = tempfile.gettempdir()
        saved_workdirs = 0
        for filename in sorted(os.listdir(tempdir), reverse=True):
            if self._WORKDIR_PATTERN.match(filename):
                saved_workdirs += 1
                if saved_workdirs > self._SAVED_WORKDIRS:
                    fullpath = os.path.abspath(os.path.join(tempdir, filename))
                    logging.info('Removing an old workdir: %s' % fullpath)
                    pyauto_utils.RemovePath(fullpath)

        dir_prefix = 'endure.%s.' % datetime.today().strftime('%Y%m%d.%H%M%S')
        self._workdir = tempfile.mkdtemp(prefix=dir_prefix, dir=tempdir)
        os.environ['HEAPPROFILE'] = os.path.join(self._workdir, 'endure')
        os.environ['HEAP_PROFILE_MMAP'] = '1'
        os.environ['DEEP_HEAP_PROFILE'] = '1'
Exemple #4
0
  def _tearDownWithSessionManagerStopped(self):
    """Resets the test environment after stopping the session manager."""
    assert self.IsChromeOS()
    logging.debug('Stopping session manager')
    cros_ui.stop(allow_fail=True)

    # Stop mock GAIA server.
    self._auth_server.stop()

    # Reenable TPM if present.
    if os.path.exists(TPM_SYSFS_PATH):
      self._Call('umount %s' % os.path.realpath(TPM_SYSFS_PATH))

    # Clear install attributes and restart cryptohomed to pick up the change.
    self._ClearInstallAttributesOnChromeOS()

    # Stop mock DNS server.
    self._dns_server.stop()

    # Stop mock DMServer.
    self.StopHTTPServer(self._http_server)

    # Clear the policy served.
    pyauto_utils.RemovePath(self._temp_data_dir)

    # Remove the device policy blob.
    self._RemoveIfExists(constants.OWNER_KEY_FILE)
    self._RemoveIfExists(constants.SIGNED_POLICY_FILE)

    # Remove any existing vaults.
    self.RemoveAllCryptohomeVaultsOnChromeOS()

    # Restart session manager and Chrome.
    self._StartSessionManagerAndChrome()
Exemple #5
0
 def tearDown(self):
   # Cleanup all files we created in the download dir
   download_dir = self.GetDownloadDirectory().value()
   if os.path.isdir(download_dir):
     for name in os.listdir(download_dir):
       if name not in self._existing_downloads:
         self._files_to_remove.append(os.path.join(download_dir, name))
   pyauto.PyUITest.tearDown(self)
   # Delete all paths marked for deletion after browser shutdown.
   for item in self._files_to_remove:
     pyauto_utils.RemovePath(item)
Exemple #6
0
 def _DownloadStress(self):
     """Run all the Download stress test."""
     org_download_dir = self.GetDownloadDirectory().value()
     new_dl_dir = os.path.join(org_download_dir, 'My+Downloads Folder')
     os.path.exists(new_dl_dir) and shutil.rmtree(new_dl_dir)
     os.makedirs(new_dl_dir)
     self.SetPrefs(pyauto.kDownloadDefaultDirectory, new_dl_dir)
     self._OpenAndCloseMultipleTabsWithDownloads()
     self._OpenAndCloseMultipleWindowsWithDownloads()
     self._OpenAndCloseMultipleTabsWithMultipleDownloads()
     self._OpenAndCloseMultipleWindowsWithMultipleDownloads()
     pyauto_utils.RemovePath(new_dl_dir)  # cleanup
     self.SetPrefs(pyauto.kDownloadDefaultDirectory, org_download_dir)
Exemple #7
0
  def tearDown(self):
    """Cleans up the files created by setUp and policies added in tests."""
    # Clear the policies.
    self.SetPolicies()

    if self.IsChromeOS():
      pyauto.PyUITest.Logout(self)

    pyauto.PyUITest.tearDown(self)

    if self.IsChromeOS():
      self.StopHTTPServer(self._http_server)
      pyauto_utils.RemovePath(self._temp_data_dir)
Exemple #8
0
  def TearDown(self):
    """Tear down Deep Memory Profiler settings for the Chrome process.

    It removes the environment variables and the temporary directory.
    Call it after Chrome finishes.  Chrome may dump last files at the end.
    """
    if not self._enabled:
      return

    del os.environ['DEEP_HEAP_PROFILE']
    del os.environ['HEAP_PROFILE_MMAP']
    del os.environ['HEAPPROFILE']
    if not self._save and self._tempdir:
      pyauto_utils.RemovePath(self._tempdir)
Exemple #9
0
  def _RemoveDownloadedTestFile(self):
    """Delete downloaded files and dirs from downloads directory."""
    if self._extracted_sdk_path and os.path.exists(self._extracted_sdk_path):
      self._CloseHTTPServer()

      def _RemoveFile():
        shutil.rmtree(self._extracted_sdk_path, ignore_errors=True)
        return os.path.exists(self._extracted_sdk_path)

      success = self.WaitUntil(_RemoveFile, retry_sleep=2,
                               expect_retval=False)
      self.assertTrue(success,
                      msg='Cannot remove %s' % self._extracted_sdk_path)

    if self._temp_dir:
      pyauto_utils.RemovePath(self._temp_dir)
Exemple #10
0
    def tearDown(self):
        """Cleans up the policies and related files created in tests."""
        if self.IsChromeOS():
            # On ChromeOS, clearing device policy logs out the current user so that
            # no policy is in force. User policy is then permanently cleared at the
            # end of the method after stopping the TestServer.
            self.SetDevicePolicy()
        else:
            # On other platforms, there is only user policy to clear.
            self.SetUserPolicy()

        pyauto.PyUITest.tearDown(self)

        if self.IsChromeOS():
            self.StopHTTPServer(self._http_server)
            pyauto_utils.RemovePath(self._temp_data_dir)
            self.RemoveAllCryptohomeVaultsOnChromeOS()
Exemple #11
0
        def _CleanupAdditionalFilesInDir(directory, orig_files):
            """Removes the additional files in the specified directory.

      This function will remove all files from |directory| that are not
      specified in |orig_files|.

      Args:
        directory: A string directory path.
        orig_files: A list of strings representing the original set of files in
                    the specified directory.
      """
            downloads_to_remove = []
            if os.path.isdir(directory):
                downloads_to_remove = [
                    os.path.join(directory, name)
                    for name in os.listdir(directory) if name not in orig_files
                ]
            for file_name in downloads_to_remove:
                pyauto_utils.RemovePath(file_name)
Exemple #12
0
    def tearDown(self):
        logging.info('Terminating connection to remote inspector...')
        self._remote_inspector_client.Stop()
        logging.info('Connection to remote inspector terminated.')
        if self._deep_memory_profile:
            # TODO(dmikurube): Stop to set HEAP_PROFILE_TIME_INTERVAL in setUp when
            # PyAuto supports to dump renderer heap profile.
            del os.environ['HEAP_PROFILE_TIME_INTERVAL']
            del os.environ['DEEP_HEAP_PROFILE']
            del os.environ['HEAP_PROFILE_MMAP']
            del os.environ['HEAPPROFILE']

        # Must be done at end of this function except for post-cleaning after
        # Chrome finishes.
        perf.BasePerfTest.tearDown(self)

        # Remove the temporary directory after Chrome finishes in tearDown.
        if (self._deep_memory_profile and not self._deep_memory_profile_save
                and self._deep_tempdir):
            pyauto_utils.RemovePath(self._deep_tempdir)
Exemple #13
0
  def Run(self):
    self._ParseArgs()
    if not os.path.isdir(self._outdir):
      os.makedirs(self._outdir)
    get_it2me = self._DoesURLExist(self._it2me_zip_url)

    # Fetch chrome & pyauto binaries
    print 'Fetching'
    print self._chrome_zip_url
    if get_it2me:
      print self._it2me_zip_url
    else:
      print 'Warning: %s does not exist.' % self._it2me_zip_url
    print self._pyautolib_py_url
    print self._pyautolib_so_url
    print self._chromedriver_url
    chrome_zip = urllib.urlretrieve(self._chrome_zip_url)[0]
    if get_it2me:
      it2me_zip = urllib.urlretrieve(self._it2me_zip_url)[0]
    pyautolib_py = urllib.urlretrieve(self._pyautolib_py_url)[0]
    pyautolib_so = urllib.urlretrieve(self._pyautolib_so_url)[0]
    chromedriver = urllib.urlretrieve(self._chromedriver_url)[0]
    chrome_unzip_dir = os.path.join(self._outdir, self._chrome_zip_name)
    if os.path.exists(chrome_unzip_dir):
      print 'Cleaning', chrome_unzip_dir
      pyauto_utils.RemovePath(chrome_unzip_dir)
    pyauto_utils.UnzipFilenameToDir(chrome_zip, self._outdir)
    if get_it2me:
      pyauto_utils.UnzipFilenameToDir(it2me_zip, self._outdir)
      shutil.move(self._outdir + '/remoting-it2me',
                  self._outdir + '/remoting/it2me.webapp')

    # Copy over the binaries to outdir
    items_to_copy = {
      pyautolib_py: os.path.join(self._outdir, 'pyautolib.py'),
      pyautolib_so: os.path.join(self._outdir, self._pyautolib_so_name),
      chromedriver: os.path.join(self._outdir, self._chromedriver_name)
    }
    unzip_dir_contents = glob.glob(os.path.join(chrome_unzip_dir, '*'))
    for item in unzip_dir_contents:
      name = os.path.basename(item)
      items_to_copy[item] = os.path.join(self._outdir, name)

    for src, dest in items_to_copy.iteritems():
      pyauto_utils.RemovePath(dest)
      print '%s ==> %s' % (os.path.basename(src), dest)
      shutil.move(src, dest)
    pyauto_utils.RemovePath(chrome_unzip_dir)

    # Final setup (if any)
    # Set executable bit on chromedriver binary.
    if not self._options.platform == 'win':
      os.chmod(items_to_copy[chromedriver], 0700)

    # Create symlink to .framework on Mac
    if self._options.platform == 'mac':
      mac_app_name = os.path.basename([x for x in unzip_dir_contents
                                       if x.endswith('.app')][0])
      os.chdir(self._outdir)
      framework = glob.glob(os.path.join(
          mac_app_name, 'Contents', 'Versions', '*', '*.framework'))[0]
      print framework
      dest = os.path.basename(framework)
      os.path.lexists(dest) and os.remove(dest)
      print 'Creating symlink "%s"' % dest
      os.symlink(framework, dest)

    print 'Prepared binaries in "%s"' % self._outdir
Exemple #14
0
 def tearDown(self):
   super(DevToolsInstrumentedObjectsCheck, self).tearDown()
   del os.environ['HEAPPROFILE']
   if self._tempdir:
     pyauto_utils.RemovePath(self._tempdir)
Exemple #15
0
 def tearDown(self):
     """Performs necessary cleanup work after running each test in this class."""
     BasePerfTest.tearDown(self)
     self._test_server.ShutDown()
     pyauto_utils.RemovePath(self._temp_dir)