예제 #1
0
  def open_llvm_symbolizer(self):
    if not os.path.exists(self.symbolizer_path):
      return None

    # Setup symbolizer command line.
    cmd = [
        self.symbolizer_path,
        '--default-arch=%s' % self.default_arch, '--demangle=true',
        '--functions=linkage',
        '--inlining=%s' % stack_inlining, '--use-symbol-table=true'
    ]
    if self.system == 'darwin':
      for hint in self.dsym_hints:
        cmd.append('--dsym-hint=%s' % hint)

    # Set LD_LIBRARY_PATH to use the right libstdc++.
    env_copy = environment.copy()
    env_copy['LD_LIBRARY_PATH'] = os.path.dirname(self.symbolizer_path)

    # FIXME: Since we are not using process_handler.run_process here, we can run
    # into issues with unicode environment variable and values. Add this
    # explicit hack to convert these into strings.
    env_copy = {str(key): str(value) for key, value in six.iteritems(env_copy)}

    # Run the symbolizer.
    pipe = subprocess.Popen(
        cmd, env=env_copy, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

    global pipes
    pipes.append(pipe)

    return pipe
예제 #2
0
 def test_selection_for_android_apk(self):
     """Ensure that flags are added for the Android APK format."""
     self.mock.random.return_value = 0.3
     environment.set_value('APP_NAME', 'App_1.apk')
     env_copy = environment.copy()
     trial_selector = trials.Trials()
     trial_selector.setup_additional_args_for_app(env_copy)
     self.assertEqual(env_copy.get('APP_ARGS'), '-x --a1')
     self.assertEqual(env_copy.get('TRIAL_APP_ARGS'), '--a1')
예제 #3
0
 def test_selection_for_windows_executable(self):
     """Ensure that flags are added when the app name ends in ".exe"."""
     self.mock.random.return_value = 0.3
     environment.set_value('APP_NAME', 'app_1.exe')
     env_copy = environment.copy()
     trial_selector = trials.Trials()
     trial_selector.setup_additional_args_for_app(env_copy)
     self.assertEqual(env_copy.get('APP_ARGS'), '-x --a1')
     self.assertEqual(env_copy.get('TRIAL_APP_ARGS'), '--a1')
예제 #4
0
 def test_multiple_trial_selection(self):
     """Ensure that we can suggest the second trial in a batch of multiple."""
     self.mock.random.return_value = 0.1
     environment.set_value('APP_NAME', 'app_3')
     env_copy = environment.copy()
     trial_selector = trials.Trials()
     trial_selector.setup_additional_args_for_app(env_copy)
     self.assertEqual(env_copy.get('APP_ARGS'), '-x --c1 --c2 --c3')
     self.assertEqual(env_copy.get('TRIAL_APP_ARGS'), '--c1 --c2 --c3')
예제 #5
0
 def test_trial_not_selected(self):
     """Ensure no additional flags if a trial was not selected."""
     self.mock.random.return_value = 0.5
     environment.set_value('APP_NAME', 'app_2')
     env_copy = environment.copy()
     trial_selector = trials.Trials()
     trial_selector.setup_additional_args_for_app(env_copy)
     self.assertEqual(env_copy.get('APP_ARGS'), '-x')
     self.assertIsNone(env_copy.get('TRIAL_APP_ARGS'))
예제 #6
0
 def test_trial_selected_one_option(self):
     """Ensure that the expected flags are added if a trial is selected."""
     self.mock.random.return_value = 0.3
     environment.set_value('APP_NAME', 'app_1')
     env_copy = environment.copy()
     trial_selector = trials.Trials()
     trial_selector.setup_additional_args_for_app(env_copy)
     self.assertEqual(env_copy.get('APP_ARGS'), '-x --a1')
     self.assertEqual(env_copy.get('TRIAL_APP_ARGS'), '--a1')
예제 #7
0
 def test_no_effect_on_no_match(self):
     """Ensure that no additional flags are added if a binary has no trials."""
     self.mock.random.return_value = 0.0
     environment.set_value('APP_NAME', 'app_0')
     env_copy = environment.copy()
     trial_selector = trials.Trials()
     trial_selector.setup_additional_args_for_app(env_copy)
     self.assertEqual(env_copy.get('APP_ARGS'), '-x')
     self.assertIsNone(env_copy.get('TRIAL_APP_ARGS'))
예제 #8
0
def store_testcase_dependencies_from_bundled_testcase_archive(
    metadata, testcase, testcase_file_path):
  """Store testcase dependencies from a bundled testcase archive
  (with multiple testcases)."""
  # Nothing to do if this is not a bundled testcase archive with
  # multiple testcase.
  if not metadata.bundled:
    return 1

  # Cleanup, before re-running the app to get resource list.
  process_handler.terminate_stale_application_instances()
  shell.clear_temp_directory()

  # Increase the test timeout to warmup timeout. This is needed
  # since we use warmup timeout in test_for_crash_with_retries.
  warmup_timeout = environment.get_value('WARMUP_TIMEOUT')
  environment.set_value('TEST_TIMEOUT', warmup_timeout)

  env_copy = environment.copy()
  crash_queue = process_handler.get_queue()
  thread_index = 0
  thread = process_handler.get_process()(
      target=testcase_manager.run_testcase_and_return_result_in_queue,
      args=(crash_queue, thread_index, testcase_file_path, testcase.gestures,
            env_copy))
  thread.start()
  thread.join(warmup_timeout)

  if thread.is_alive():
    try:
      thread.terminate()
    except:
      logs.log_error('Process termination failed or was not needed.')

  # We should be able to reproduce this reproducible crash. If not,
  # something wrong happened and we would just try to redo task.
  if not crash_queue.empty():
    crash = crash_queue.get()
    fuzzed_key, archived, absolute_path, archive_filename = (
        setup.archive_testcase_and_dependencies_in_gcs(crash.resource_list,
                                                       testcase_file_path))

    if archived:
      testcase.archive_state = data_types.ArchiveStatus.FUZZED
    else:
      testcase.archive_state = 0

    testcase.fuzzed_keys = fuzzed_key
    metadata.blobstore_key = fuzzed_key
    testcase.absolute_path = absolute_path

    if archive_filename:
      testcase.archive_filename = archive_filename
      metadata.filename = os.path.basename(archive_filename)
    else:
      metadata.filename = os.path.basename(testcase_file_path)

    metadata.bundled = False
    metadata.put()
  else:
    logs.log_error('Could not get crash data from queue. Retrying task.')
    tasks.add_task('analyze', testcase.key.id(), testcase.job_type)
    return None

  return 1