コード例 #1
0
  def GenerateCoverageReportIfNeeded(self):
    """Uses the Emma to generate a coverage report and a html page."""
    if not self.coverage:
      return
    cmd = ['java', '-classpath', TestRunner._EMMA_JAR,
           'emma', 'report', '-r', 'html',
           '-in', TestRunner._COVERAGE_MERGED_FILENAME,
           '-in', TestRunner._COVERAGE_META_INFO_PATH]
    cmd_helper.RunCmd(cmd)
    new_dir = os.path.join(TestRunner._COVERAGE_WEB_ROOT_DIR,
                           time.strftime('Coverage_for_%Y_%m_%d_%a_%H:%M'))
    shutil.copytree('coverage', new_dir)

    latest_dir = os.path.join(TestRunner._COVERAGE_WEB_ROOT_DIR,
                              'Latest_Coverage_Run')
    if os.path.exists(latest_dir):
      shutil.rmtree(latest_dir)
    os.mkdir(latest_dir)
    webserver_new_index = os.path.join(new_dir, 'index.html')
    webserver_new_files = os.path.join(new_dir, '_files')
    webserver_latest_index = os.path.join(latest_dir, 'index.html')
    webserver_latest_files = os.path.join(latest_dir, '_files')
    # Setup new softlinks to last result.
    os.symlink(webserver_new_index, webserver_latest_index)
    os.symlink(webserver_new_files, webserver_latest_files)
    cmd_helper.RunCmd(['chmod', '755', '-R', latest_dir, new_dir])
コード例 #2
0
def _KillPendingServers():
    for retry in range(5):
        for server in ['lighttpd', 'web-page-replay']:
            pids = [p.pid for p in psutil.process_iter() if server in p.name]
            for pid in pids:
                try:
                    logging.warning('Killing %s %s', server, pid)
                    os.kill(pid, signal.SIGQUIT)
                except Exception as e:
                    logging.warning('Failed killing %s %s %s', server, pid, e)
    # Restart the adb server with taskset to set a single CPU affinity.
    cmd_helper.RunCmd(['adb', 'kill-server'])
    cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'start-server'])
    cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'root'])
    i = 1
    while not android_commands.GetAttachedDevices():
        time.sleep(i)
        i *= 2
        if i > 10:
            break
    # Reset the test port allocation. It's important to do it before starting
    # to dispatch any step.
    if not ports.ResetTestServerPortAllocation():
        raise Exception('Failed to reset test server port.')

    forwarder.Forwarder.UseMultiprocessing()
コード例 #3
0
  def testPushAndDeleteFiles_noSubDir(self):
    host_tmp_dir = tempfile.mkdtemp()
    (host_file_path1, file_name1) = self._MakeTempFileGivenDir(
        host_tmp_dir, _OLD_CONTENTS)
    (host_file_path2, file_name2) = self._MakeTempFileGivenDir(
        host_tmp_dir, _OLD_CONTENTS)

    device_file_path1 = "%s/%s" % (_DEVICE_DIR, file_name1)
    device_file_path2 = "%s/%s" % (_DEVICE_DIR, file_name2)
    self.adb.Push(host_file_path1, device_file_path1)
    self.adb.Push(host_file_path2, device_file_path2)

    with open(host_file_path1, 'w') as f:
      f.write(_NEW_CONTENTS)
    cmd_helper.RunCmd(['rm', host_file_path2])

    self.device.PushChangedFiles([(host_tmp_dir, _DEVICE_DIR)],
                                   delete_device_stale=True)
    result = self.device.RunShellCommand(['cat', device_file_path1],
                                         single_line=True)
    self.assertEqual(_NEW_CONTENTS, result)
    result = self.device.RunShellCommand(['ls', _DEVICE_DIR], single_line=True)
    self.assertEqual(file_name1, result)

    self.device.RunShellCommand(['rm', '-rf',  _DEVICE_DIR])
    cmd_helper.RunCmd(['rm', '-rf', host_tmp_dir])
コード例 #4
0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option('-s',
                      '--steps',
                      help='A JSON file containing all the steps to be '
                      'sharded.')
    parser.add_option('--flaky_steps',
                      help='A JSON file containing steps that are flaky and '
                      'will have its exit code ignored.')
    parser.add_option('-p',
                      '--print_results',
                      help='Only prints the results for the previously '
                      'executed step, do not run it again.')
    options, urls = parser.parse_args(argv)
    if options.print_results:
        return cmd_helper.RunCmd([
            'build/android/test_runner.py', 'perf', '--print-step',
            options.print_results
        ])
    flaky_options = []
    if options.flaky_steps:
        flaky_options = ['--flaky-steps', options.flaky_steps]
    return cmd_helper.RunCmd([
        'build/android/test_runner.py', 'perf', '-v', '--steps', options.steps
    ] + flaky_options)
コード例 #5
0
 def testRestartServerNotRunning(self):
     self.assertEqual(0,
                      cmd_helper.RunCmd(['pkill', 'adb']),
                      msg='Unable to kill adb during setup.')
     self.assertNotEqual(0,
                         cmd_helper.RunCmd(['pgrep', 'adb']),
                         msg='Unexpectedly found adb during setup.')
     device_utils.RestartServer()
     self.assertEqual(0, cmd_helper.RunCmd(['pgrep', 'adb']))
コード例 #6
0
  def testPushAndDeleteFiles_SubDir(self):
    host_tmp_dir = tempfile.mkdtemp()
    host_sub_dir1 = "%s/%s" % (host_tmp_dir, _SUB_DIR1)
    host_sub_dir2 = "%s/%s/%s" % (host_tmp_dir, _SUB_DIR, _SUB_DIR2)
    cmd_helper.RunCmd(['mkdir', '-p', host_sub_dir1])
    cmd_helper.RunCmd(['mkdir', '-p', host_sub_dir2])

    (host_file_path1, file_name1) = self._MakeTempFileGivenDir(
        host_tmp_dir, _OLD_CONTENTS)
    (host_file_path2, file_name2) = self._MakeTempFileGivenDir(
        host_tmp_dir, _OLD_CONTENTS)
    (host_file_path3, file_name3) = self._MakeTempFileGivenDir(
        host_sub_dir1, _OLD_CONTENTS)
    (host_file_path4, file_name4) = self._MakeTempFileGivenDir(
        host_sub_dir2, _OLD_CONTENTS)

    device_file_path1 = "%s/%s" % (_DEVICE_DIR, file_name1)
    device_file_path2 = "%s/%s" % (_DEVICE_DIR, file_name2)
    device_file_path3 = "%s/%s/%s" % (_DEVICE_DIR, _SUB_DIR1, file_name3)
    device_file_path4 = "%s/%s/%s/%s" % (_DEVICE_DIR, _SUB_DIR,
                                         _SUB_DIR2, file_name4)

    self.adb.Push(host_file_path1, device_file_path1)
    self.adb.Push(host_file_path2, device_file_path2)
    self.adb.Push(host_file_path3, device_file_path3)
    self.adb.Push(host_file_path4, device_file_path4)

    with open(host_file_path1, 'w') as f:
      f.write(_NEW_CONTENTS)
    cmd_helper.RunCmd(['rm', host_file_path2])
    cmd_helper.RunCmd(['rm', host_file_path4])

    self.device.PushChangedFiles([(host_tmp_dir, _DEVICE_DIR)],
                                   delete_device_stale=True)
    result = self.device.RunShellCommand(['cat', device_file_path1],
                                         single_line=True)
    self.assertEqual(_NEW_CONTENTS, result)

    result = self.device.RunShellCommand(['ls', _DEVICE_DIR])
    self.assertIn(file_name1, result)
    self.assertIn(_SUB_DIR1, result)
    self.assertIn(_SUB_DIR, result)
    self.assertEqual(3, len(result))

    result = self.device.RunShellCommand(['cat', device_file_path3],
                                      single_line=True)
    self.assertEqual(_OLD_CONTENTS, result)

    result = self.device.RunShellCommand(["ls", "%s/%s/%s"
                                          % (_DEVICE_DIR, _SUB_DIR, _SUB_DIR2)],
                                         single_line=True)
    self.assertEqual('', result)

    self.device.RunShellCommand(['rm', '-rf',  _DEVICE_DIR])
    cmd_helper.RunCmd(['rm', '-rf', host_tmp_dir])
コード例 #7
0
def GetARMv7Image():
  """Download and install the ARMv7 system image."""
  logging.info('Download ARMv7 system image directory into sdk directory.')
  try:
    cmd_helper.RunCmd(['curl', '-o', '/tmp/armv7_img.zip', ARMV7_IMG_URL])
    rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/armv7_img.zip', '-d', '/tmp/'])
    if rc:
      raise Exception('ERROR: Could not download/unzip image zip.')
    sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk',
                            'system-images', API_TARGET, 'armeabi-v7a')
    shutil.move('/tmp/armeabi-v7a', sys_imgs)
  finally:
    os.unlink('/tmp/armv7_img.zip')
コード例 #8
0
def GetX86Image():
  """Download x86 system image from Intel's website."""
  logging.info('Download x86 system image directory into sdk directory.')
  try:
    cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL])
    rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/'])
    if rc:
      raise Exception('ERROR: Could not download/unzip image zip.')
    sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk',
                            'system-images', API_TARGET, 'x86')
    shutil.move('/tmp/x86', sys_imgs)
  finally:
    os.unlink('/tmp/x86_img.zip')
コード例 #9
0
 def CreateCommandLineFileOnDevice(self, device, test_filter,
                                   test_arguments):
     tool_wrapper = self.tool.GetTestWrapper()
     sh_script_file = tempfile.NamedTemporaryFile()
     # We need to capture the exit status from the script since adb shell won't
     # propagate to us.
     sh_script_file.write(
         'cd %s\n'
         '%s'
         '%s LD_LIBRARY_PATH=%s/%s_deps %s/%s --gtest_filter=%s %s\n'
         'echo $? > %s' %
         (constants.TEST_EXECUTABLE_DIR,
          self._AddNativeCoverageExports(device), tool_wrapper,
          constants.TEST_EXECUTABLE_DIR, self.suite_name,
          constants.TEST_EXECUTABLE_DIR, self.suite_name, test_filter,
          test_arguments, TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
     sh_script_file.flush()
     cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
     device.PushChangedFiles([
         (sh_script_file.name,
          constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')
     ])
     logging.info('Conents of the test runner script: ')
     for line in open(sh_script_file.name).readlines():
         logging.info('  ' + line.rstrip())
コード例 #10
0
  def SaveCoverageData(self, test):
    """Saves the Emma coverage data before it's overwritten by the next test.

    Args:
      test: the test whose coverage data is collected.
    """
    if not self.coverage:
      return
    if not self.adb.Adb().Pull(TestRunner._COVERAGE_RESULT_PATH,
                               constants.CHROME_DIR):
      logging.error('ERROR: Unable to find file ' +
                    TestRunner._COVERAGE_RESULT_PATH +
                    ' on the device for test ' + test)
    pulled_coverage_file = os.path.join(constants.CHROME_DIR,
                                        TestRunner._COVERAGE_FILENAME)
    if os.path.exists(TestRunner._COVERAGE_MERGED_FILENAME):
      cmd = ['java', '-classpath', TestRunner._EMMA_JAR, 'emma', 'merge',
             '-in', pulled_coverage_file,
             '-in', TestRunner._COVERAGE_MERGED_FILENAME,
             '-out', TestRunner._COVERAGE_MERGED_FILENAME]
      cmd_helper.RunCmd(cmd)
    else:
      shutil.copy(pulled_coverage_file,
                  TestRunner._COVERAGE_MERGED_FILENAME)
    os.remove(pulled_coverage_file)
コード例 #11
0
    def StripAndCopyExecutable(self):
        """Strips and copies the executable to the device."""
        if self.tool.NeedsDebugInfo():
            target_name = self.test_suite
        else:
            target_name = self.test_suite + '_' + self.device + '_stripped'
            should_strip = True
            if os.path.isfile(target_name):
                logging.info('Found target file %s' % target_name)
                target_mtime = os.stat(target_name).st_mtime
                source_mtime = os.stat(self.test_suite).st_mtime
                if target_mtime > source_mtime:
                    logging.info(
                        'Target mtime (%d) is newer than source (%d), assuming '
                        'no change.' % (target_mtime, source_mtime))
                    should_strip = False

            if should_strip:
                logging.info(
                    'Did not find up-to-date stripped binary. Generating a '
                    'new one (%s).' % target_name)
                # Whenever we generate a stripped binary, copy to the symbols dir. If we
                # aren't stripping a new binary, assume it's there.
                if self.symbols_dir:
                    if not os.path.exists(self.symbols_dir):
                        os.makedirs(self.symbols_dir)
                    shutil.copy(self.test_suite, self.symbols_dir)
                strip = os.environ['STRIP']
                cmd_helper.RunCmd([strip, self.test_suite, '-o', target_name])
        test_binary = constants.TEST_EXECUTABLE_DIR + '/' + self.test_suite_basename
        self.adb.PushIfNeeded(target_name, test_binary)
コード例 #12
0
    def CreateTestRunnerScript(self, gtest_filter, test_arguments):
        """Creates a test runner script and pushes to the device.

    Args:
      gtest_filter: A gtest_filter flag.
      test_arguments: Additional arguments to pass to the test binary.
    """
        tool_wrapper = self.tool.GetTestWrapper()
        sh_script_file = tempfile.NamedTemporaryFile()
        # We need to capture the exit status from the script since adb shell won't
        # propagate to us.
        sh_script_file.write(
            'cd %s\n'
            '%s'
            '%s %s/%s --gtest_filter=%s %s\n'
            'echo $? > %s' %
            (constants.TEST_EXECUTABLE_DIR, self._AddNativeCoverageExports(),
             tool_wrapper, constants.TEST_EXECUTABLE_DIR,
             self.test_suite_basename, gtest_filter, test_arguments,
             TestPackageExecutable._TEST_RUNNER_RET_VAL_FILE))
        sh_script_file.flush()
        cmd_helper.RunCmd(['chmod', '+x', sh_script_file.name])
        self.adb.PushIfNeeded(
            sh_script_file.name,
            constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh')
        logging.info('Conents of the test runner script: ')
        for line in open(sh_script_file.name).readlines():
            logging.info('  ' + line.rstrip())
コード例 #13
0
  def testDeleteFiles(self):
    host_tmp_dir = tempfile.mkdtemp()
    (host_file_path, file_name) = self._MakeTempFileGivenDir(
        host_tmp_dir, _OLD_CONTENTS)

    device_file_path = "%s/%s" % (_DEVICE_DIR, file_name)
    self.adb.Push(host_file_path, device_file_path)

    cmd_helper.RunCmd(['rm', host_file_path])
    self.device.PushChangedFiles([(host_tmp_dir, _DEVICE_DIR)],
                                 delete_device_stale=True)
    result = self.device.RunShellCommand(['ls', _DEVICE_DIR], single_line=True)
    self.assertEqual('', result)

    cmd_helper.RunCmd(['rm', '-rf', host_tmp_dir])
    self.device.RunShellCommand(['rm', '-rf',  _DEVICE_DIR])
コード例 #14
0
def InstallKVM():
  """Installs KVM packages."""
  rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm'])
  if rc:
    logging.critical('ERROR: Did not install KVM. Make sure hardware '
                     'virtualization is enabled in BIOS (i.e. Intel VT-x or '
                     'AMD SVM).')
  # TODO(navabi): Use modprobe kvm-amd on AMD processors.
  rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel'])
  if rc:
    logging.critical('ERROR: Did not add KVM module to Linux Kernel. Make sure '
                     'hardware virtualization is enabled in BIOS.')
  # Now check to ensure KVM acceleration can be used.
  if not RunKvmOk():
    logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware '
                     'virtualization is enabled in BIOS (i.e. Intel VT-x or '
                     'AMD SVM).')
コード例 #15
0
def GetSDK():
    """Download the SDK and unzip it into EMULATOR_SDK_ROOT."""
    logging.info('Download Android SDK.')
    sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP)
    try:
        cmd_helper.RunCmd(['curl', '-o', '/tmp/sdk.zip', sdk_url])
        print 'curled unzipping...'
        rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/'])
        if rc:
            raise Exception('ERROR: could not download/unzip Android SDK.')
        # Get the name of the sub-directory that everything will be extracted to.
        dirname, _ = os.path.splitext(SDK_ZIP)
        zip_dir = '/tmp/%s' % dirname
        # Move the extracted directory to EMULATOR_SDK_ROOT
        shutil.move(zip_dir, constants.EMULATOR_SDK_ROOT)
    finally:
        os.unlink('/tmp/sdk.zip')
コード例 #16
0
 def testRestartServerAlreadyRunning(self):
     if cmd_helper.RunCmd(['pgrep', 'adb']) != 0:
         device_utils.RestartServer()
     code, original_pid = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb'])
     self.assertEqual(0, code)
     device_utils.RestartServer()
     code, new_pid = cmd_helper.GetCmdStatusAndOutput(['pgrep', 'adb'])
     self.assertEqual(0, code)
     self.assertNotEqual(original_pid, new_pid)
コード例 #17
0
def main(argv):
    option_parser = optparse.OptionParser()
    option_parser.add_option('--output', help='HTML output filename.')
    option_parser.add_option(
        '--coverage-dir',
        default=None,
        help=('Root of the directory in which to search for '
              'coverage data (.ec) files.'))
    option_parser.add_option(
        '--metadata-dir',
        default=None,
        help=('Root of the directory in which to search for '
              'coverage metadata (.em) files.'))
    option_parser.add_option(
        '--cleanup',
        action='store_true',
        help=('If set, removes coverage files generated at '
              'runtime.'))
    options, args = option_parser.parse_args()

    if not (options.coverage_dir and options.metadata_dir and options.output):
        option_parser.error('One or more mandatory options are missing.')

    coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec')
    metadata_files = _GetFilesWithExt(options.metadata_dir, 'em')
    print 'Found coverage files: %s' % str(coverage_files)
    print 'Found metadata files: %s' % str(metadata_files)

    sources = []
    for f in metadata_files:
        sources_file = os.path.splitext(f)[0] + '_sources.txt'
        with open(sources_file, 'r') as sf:
            sources.extend(json.load(sf))
    sources = [os.path.join(constants.DIR_SOURCE_ROOT, s) for s in sources]
    print 'Sources: %s' % sources

    input_args = []
    for f in coverage_files + metadata_files:
        input_args.append('-in')
        input_args.append(f)

    output_args = ['-Dreport.html.out.file', options.output]
    source_args = ['-sp', ','.join(sources)]

    exit_code = cmd_helper.RunCmd([
        'java', '-cp',
        os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'),
        'emma', 'report', '-r', 'html'
    ] + input_args + output_args + source_args)

    if options.cleanup:
        for f in coverage_files:
            os.remove(f)

    return exit_code
コード例 #18
0
  def testPushChangedFiles_noFileChange(self):
    (host_file_path, file_name) = self._MakeTempFile(_OLD_CONTENTS)
    device_file_path = "%s/%s" % (_DEVICE_DIR, file_name)
    self.adb.Push(host_file_path, device_file_path)
    self.device.PushChangedFiles([(host_file_path, device_file_path)])
    result = self.device.RunShellCommand(['cat', device_file_path],
                                         single_line=True)
    self.assertEqual(_OLD_CONTENTS, result)

    cmd_helper.RunCmd(['rm', host_file_path])
    self.device.RunShellCommand(['rm', '-rf',  _DEVICE_DIR])
コード例 #19
0
def CheckKVM():
    """Check if KVM is enabled.

  Returns:
    True if kvm-ok returns 0 (already enabled)
  """
    try:
        return not cmd_helper.RunCmd(['kvm-ok'])
    except OSError:
        logging.info('kvm-ok not installed')
        return False
コード例 #20
0
ファイル: emulator.py プロジェクト: xinchao1230/kalpa
 def _DeleteAVD(self):
   """Delete the AVD of this emulator."""
   avd_command = [
       self.android,
       '--silent',
       'delete',
       'avd',
       '--name', self.avd_name,
   ]
   logging.info('Delete AVD command: %s', ' '.join(avd_command))
   cmd_helper.RunCmd(avd_command)
コード例 #21
0
 def _CopyLibrary(self):
   """Copy the shlib into the apk source tree (if relevant)."""
   if self._native_library:
     destdir = os.path.join(self._output_directory, 'libs/' + self._target_abi)
     if not os.path.exists(destdir):
       os.makedirs(destdir)
     dest = os.path.join(destdir, os.path.basename(self._native_library))
     logging.info('strip %s --> %s', self._native_library, dest)
     cmd_helper.RunCmd(
         [self._strip_binary, '--strip-unneeded', self._native_library, '-o',
          dest])
コード例 #22
0
def _KillPendingServers():
  for retry in range(5):
    for server in ['lighttpd', 'web-page-replay']:
      pids = cmd_helper.GetCmdOutput(['pgrep', '-f', server])
      pids = [pid.strip() for pid in pids.split('\n') if pid.strip()]
      for pid in pids:
        try:
          logging.warning('Killing %s %s', server, pid)
          os.kill(int(pid), signal.SIGQUIT)
        except Exception as e:
          logging.warning('Failed killing %s %s %s', server, pid, e)
  # Restart the adb server with taskset to set a single CPU affinity.
  cmd_helper.RunCmd(['adb', 'kill-server'])
  cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'start-server'])
  cmd_helper.RunCmd(['taskset', '-c', '0', 'adb', 'root'])
  i = 1
  while not android_commands.GetAttachedDevices():
    time.sleep(i)
    i *= 2
    if i > 10:
      break
コード例 #23
0
ファイル: findbugs.py プロジェクト: tnip/dartlang-sdk
def Run(exclude, classes_to_analyze, auxiliary_classes, output_file,
        findbug_args, jars):
    """Run FindBugs.

  Args:
    exclude: the exclude xml file, refer to FindBugs's -exclude command option.
    classes_to_analyze: the list of classes need to analyze, refer to FindBug's
                        -onlyAnalyze command line option.
    auxiliary_classes: the classes help to analyze, refer to FindBug's
                       -auxclasspath command line option.
    output_file: An optional path to dump XML results to.
    findbug_args: A list of addtional command line options to pass to Findbugs.
  """
    # TODO(jbudorick): Get this from the build system.
    system_classes = [
        os.path.join(constants.ANDROID_SDK_ROOT, 'platforms',
                     'android-%s' % constants.ANDROID_SDK_VERSION,
                     'android.jar')
    ]
    system_classes.extend(
        os.path.abspath(classes) for classes in auxiliary_classes or [])

    cmd = [
        'java', '-classpath',
        '%s:' % _FINDBUGS_JAR,
        '-Xmx%dm' % _FINDBUGS_MAX_HEAP,
        '-Dfindbugs.home="%s"' % _FINDBUGS_HOME, '-jar', _FINDBUGS_JAR,
        '-textui', '-sortByClass', '-pluginList', _FINDBUGS_PLUGIN_PATH,
        '-xml:withMessages'
    ]
    if system_classes:
        cmd.extend(['-auxclasspath', ':'.join(system_classes)])
    if classes_to_analyze:
        cmd.extend(['-onlyAnalyze', classes_to_analyze])
    if exclude:
        cmd.extend(['-exclude', os.path.abspath(exclude)])
    if output_file:
        cmd.extend(['-output', output_file])
    if findbug_args:
        cmd.extend(findbug_args)
    cmd.extend(os.path.abspath(j) for j in jars or [])

    if output_file:
        cmd_helper.RunCmd(cmd)
        results_doc = xml.dom.minidom.parse(output_file)
    else:
        raw_out = cmd_helper.GetCmdOutput(cmd)
        results_doc = xml.dom.minidom.parseString(raw_out)

    current_warnings_set = _ParseXmlResults(results_doc)

    return (' '.join(cmd), current_warnings_set)
コード例 #24
0
 def RunTest(self, _test):
   """Runs junit tests from |self._test_suite|."""
   command = ['java',
              '-jar', os.path.join(constants.GetOutDirectory(), 'lib.java',
                                   '%s.jar' % self._test_suite)]
   if self._test_filter:
     command.extend(['-gtest-filter', self._test_filter])
   if self._package_filter:
     command.extend(['-package-filter', self._package_filter])
   if self._runner_filter:
     command.extend(['-runner-filter', self._runner_filter])
   if self._sdk_version:
     command.extend(['-sdk-version', self._sdk_version])
   return cmd_helper.RunCmd(command)
コード例 #25
0
def DeleteAllTempAVDs():
    """Delete all temporary AVDs which are created for tests.

  If the test exits abnormally and some temporary AVDs created when testing may
  be left in the system. Clean these AVDs.
  """
    avds = android_commands.GetAVDs()
    if not avds:
        return
    for avd_name in avds:
        if 'run_tests_avd' in avd_name:
            cmd = ['android', '-s', 'delete', 'avd', '--name', avd_name]
            cmd_helper.RunCmd(cmd)
            logging.info('Delete AVD %s' % avd_name)
コード例 #26
0
ファイル: debug_info.py プロジェクト: dreamii/libjingle-linux
  def ZipAndCleanResults(dest_dir, dump_file_name):
    """A helper method to zip all debug information results into a dump file.

    Args:
      dest_dir: Dir path in where we put the dump file.
      dump_file_name: Desired name of the dump file. This method makes sure
                      '.zip' will be added as ext name.
    """
    if not dest_dir or not dump_file_name:
      return
    cmd_helper.RunCmd(['mkdir', '-p', dest_dir])
    log_basename = os.path.basename(dump_file_name)
    log_zip_file = os.path.join(dest_dir,
                                os.path.splitext(log_basename)[0] + '.zip')
    logging.info('Zipping debug dumps into %s ...', log_zip_file)
    # Add new dumps into the zip file. The zip may exist already if previous
    # gtest also dumps the debug information. It's OK since we clean up the old
    # dumps in each build step.
    log_src_dir = os.path.join(tempfile.gettempdir(), 'gtest_debug_info')
    cmd_helper.RunCmd(['zip', '-q', '-r', log_zip_file, log_src_dir])
    assert os.path.exists(log_zip_file)
    assert os.path.exists(log_src_dir)
    shutil.rmtree(log_src_dir)
コード例 #27
0
def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL):
  """Download x86 system image from Intel's website.

  Args:
    api_level: the Android API level to download for.
  """
  logging.info('Download x86 system image directory into sdk directory.')
  # TODO(andrewhayden): Use python tempfile lib instead
  temp_file = '/tmp/x86_img_android-%d.zip' % api_level
  if api_level not in X86_IMG_URLS:
    raise Exception('ERROR: no URL known for x86 image for android-%s' %
                    api_level)
  try:
    cmd_helper.RunCmd(['curl', '-o', temp_file, X86_IMG_URLS[api_level]])
    rc = cmd_helper.RunCmd(['unzip', '-o', temp_file, '-d', '/tmp/'])
    if rc:
      raise Exception('ERROR: Could not download/unzip image zip.')
    api_target = 'android-%d' % api_level
    sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk',
                            'system-images', api_target, 'x86')
    logging.info('Deploying system image to %s' % sys_imgs)
    shutil.move('/tmp/x86', sys_imgs)
  finally:
    os.unlink(temp_file)
コード例 #28
0
def RunKvmOk():
  """Run kvm-ok as root to check that KVM is properly enabled after installation
     of the required packages.

  Returns:
    True iff KVM is enabled (/dev/kvm exists). On failure, returns False
    but also print detailed information explaining why KVM isn't enabled
    (e.g. CPU doesn't support it, or BIOS disabled it).
  """
  try:
    # Note: kvm-ok is in /usr/sbin, so always use 'sudo' to run it.
    return not cmd_helper.RunCmd(['sudo', 'kvm-ok'])
  except OSError:
    logging.info('kvm-ok not installed')
    return False
コード例 #29
0
ファイル: emulator.py プロジェクト: xinchao1230/kalpa
def _KillAllEmulators():
  """Kill all running emulators that look like ones we started.

  There are odd 'sticky' cases where there can be no emulator process
  running but a device slot is taken.  A little bot trouble and and
  we're out of room forever.
  """
  emulators = android_commands.GetAttachedDevices(hardware=False)
  if not emulators:
    return
  for emu_name in emulators:
    cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill'])
  logging.info('Emulator killing is async; give a few seconds for all to die.')
  for i in range(5):
    if not android_commands.GetAttachedDevices(hardware=False):
      return
    time.sleep(1)
コード例 #30
0
ファイル: isolator.py プロジェクト: TobbyT/mojo-apps
    def Remap(self,
              isolate_abs_path,
              isolated_abs_path,
              path_variables=None,
              config_variables=None):
        """Remaps data dependencies into |self._isolate_deps_dir|.

    Args:
      isolate_abs_path: The absolute path to the .isolate file, which specifies
        data dependencies in the source tree.
      isolated_abs_path: The absolute path to the .isolated file, which is
        generated by isolate.py and specifies data dependencies in
        |self._isolate_deps_dir| and their digests.
      path_variables: A dict containing everything that should be passed
        as a |--path-variable| to the isolate script. Defaults to the return
        value of |DefaultPathVariables()|.
      config_variables: A dict containing everything that should be passed
        as a |--config-variable| to the isolate script. Defaults to the return
        value of |DefaultConfigVariables()|.
    Raises:
      Exception if the isolate command fails for some reason.
    """
        if not path_variables:
            path_variables = DefaultPathVariables()
        if not config_variables:
            config_variables = DefaultConfigVariables()

        isolate_cmd = [
            sys.executable,
            _ISOLATE_SCRIPT,
            'remap',
            '--isolate',
            isolate_abs_path,
            '--isolated',
            isolated_abs_path,
            '--outdir',
            self._isolate_deps_dir,
        ]
        for k, v in path_variables.iteritems():
            isolate_cmd.extend(['--path-variable', k, v])
        for k, v in config_variables.iteritems():
            isolate_cmd.extend(['--config-variable', k, v])

        if cmd_helper.RunCmd(isolate_cmd):
            raise Exception('isolate command failed: %s' %
                            ' '.join(isolate_cmd))