Exemplo n.º 1
0
def _reproduce_crash(testcase_id, build_dir):
    """Reproduce a crash."""
    testcase = _get_testcase(testcase_id)
    testcase_path = _download_testcase(testcase_id)
    _prepare_environment(testcase, build_dir)

    timeout = environment.get_value('TEST_TIMEOUT')
    result = testcase_manager.test_for_crash_with_retries(
        testcase, testcase_path, timeout)

    # Clean up the temporary root directory created in prepare environment.
    shell.remove_directory(environment.get_value('ROOT_DIR'))

    return result
Exemplo n.º 2
0
def _update_environment_for_job(testcase, build_directory):
  commands.update_environment_for_job(testcase.job_definition)
  environment.set_value('JOB_NAME', testcase.job_type)

  # Update APP_PATH now that we know the application name.
  app_path = os.path.join(build_directory, environment.get_value('APP_NAME'))
  environment.set_value('APP_PATH', app_path)
Exemplo n.º 3
0
def _prepare_environment(testcase, build_directory):
    """Prepare environment variables based on the test case and build path."""
    # Create a temporary directory to use as ROOT_DIR with a copy of the default
    # bot and configuration directories nested under it.
    root_dir = environment.get_value('ROOT_DIR')
    temp_root_dir = tempfile.mkdtemp()
    environment.set_value('ROOT_DIR', temp_root_dir)

    _copy_root_subdirectory(root_dir, temp_root_dir, 'bot')
    _copy_root_subdirectory(root_dir, temp_root_dir, 'configs')
    _copy_root_subdirectory(root_dir, temp_root_dir, 'resources')

    environment.set_value('CONFIG_DIR_OVERRIDE',
                          os.path.join(temp_root_dir, 'configs', 'test'))

    environment.set_bot_environment()
    commands.update_environment_for_job(testcase.job_definition)

    # Overrides that should not be set to the default values.
    environment.set_value('APP_DIR', build_directory)
    environment.set_value('BUILDS_DIR', build_directory)
    app_path = os.path.join(build_directory, environment.get_value('APP_NAME'))
    environment.set_value('APP_PATH', app_path)
Exemplo n.º 4
0
def _prepare_initial_environment(build_directory):
    """Prepare common environment variables that don't depend on the job."""
    # Create a temporary directory to use as ROOT_DIR with a copy of the default
    # bot and configuration directories nested under it.
    root_dir = environment.get_value('ROOT_DIR')
    temp_root_dir = tempfile.mkdtemp()
    environment.set_value('ROOT_DIR', temp_root_dir)

    _copy_root_subdirectory(root_dir, temp_root_dir, 'bot')
    _copy_root_subdirectory(root_dir, temp_root_dir, 'configs')
    _copy_root_subdirectory(root_dir, temp_root_dir, 'resources')

    environment.set_value('CONFIG_DIR_OVERRIDE',
                          os.path.join(temp_root_dir, 'configs', 'test'))

    environment.set_bot_environment()

    # Overrides that should not be set to the default values.
    environment.set_value('APP_DIR', build_directory)
    environment.set_value('BUILDS_DIR', build_directory)
Exemplo n.º 5
0
def _download_testcase(testcase_id, testcase):
  """Download the test case and return its path."""
  response, content = _http_request(
      TESTCASE_DOWNLOAD_URL.format(testcase_id=testcase_id), method=_GET_METHOD)
  bot_absolute_filename = response['x-goog-meta-filename']

  # Create a temporary directory where we can store the test case.
  testcase_directory = os.path.join(
      environment.get_value('ROOT_DIR'), 'current-testcase')
  shell.create_directory(testcase_directory)
  testcase_path = os.path.join(testcase_directory,
                               os.path.basename(bot_absolute_filename))

  utils.write_data_to_file(content, testcase_path)

  # Unpack the test case if it's archived.
  # TODO(mbarbella): Rewrite setup.unpack_testcase and share this code.
  if testcase.minimized_keys and testcase.minimized_keys != 'NA':
    mask = data_types.ArchiveStatus.MINIMIZED
  else:
    mask = data_types.ArchiveStatus.FUZZED

  if testcase.archive_state & mask:
    archive.unpack(testcase_path, testcase_directory)
    file_list = archive.get_file_list(testcase_path)

    testcase_path = None
    for file_name in file_list:
      if testcase.absolute_path.endswith(file_name):
        testcase_path = os.path.join(testcase_directory, file_name)
        break

    if not testcase_path:
      raise Exception('Test case file was not found in archive.\n'
                      'Original filename: {absolute_path}.\n'
                      'Archive contents: {file_list}'.format(
                          absolute_path=testcase.absolute_path,
                          file_list=file_list))

  return testcase_path