コード例 #1
0
ファイル: reproduce.py プロジェクト: itsHabib/clusterfuzz
def _reproduce_crash(testcase_url, build_directory):
    """Reproduce a crash."""
    _prepare_initial_environment(build_directory)

    # Validate the test case URL and fetch the tool's configuration.
    testcase_id = _get_testcase_id_from_url(testcase_url)
    configuration = config.ReproduceToolConfiguration(testcase_url)

    testcase = _get_testcase(testcase_id, configuration)
    testcase_path = _download_testcase(testcase_id, testcase, configuration)
    _update_environment_for_testcase(testcase, build_directory)

    # Validate that we're running on the right platform for this test case.
    platform = environment.platform().lower()
    if testcase.platform == 'android' and platform == 'linux':
        _prepare_environment_for_android()
    elif testcase.platform == 'android' and platform != 'linux':
        raise errors.ReproduceToolUnrecoverableError(
            'The ClusterFuzz environment only supports running Android test cases '
            'on Linux host machines. Unable to reproduce the test case on '
            '{current_platform}.'.format(current_platform=platform))
    elif testcase.platform != platform:
        raise errors.ReproduceToolUnrecoverableError(
            'The specified test case was discovered on {testcase_platform}. '
            'Unable to attempt to reproduce it on {current_platform}.'.format(
                testcase_platform=testcase.platform,
                current_platform=platform))

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

    return result
コード例 #2
0
    def test_failure(self):
        """Ensure that we raise an exception if the server encounters an error."""
        self.mock.request.return_value = (FakeResponse(403), '{"x": 1}')

        with self.assertRaises(errors.ReproduceToolUnrecoverableError):
            config.ReproduceToolConfiguration(
                'https://clusterfuzz/testcase-detail/1')
コード例 #3
0
    def test_https_server(self):
        """Ensure that we can get the configuration for an HTTPS server."""
        self.mock.request.return_value = (FakeResponse(200), '{"x": 1}')
        configuration = config.ReproduceToolConfiguration(
            'https://clusterfuzz/testcase-detail/1')

        self.assertEqual(configuration.get('x'), 1)
        self.mock.request.assert_called_once_with(
            'https://clusterfuzz/reproduce-tool/get-config', body={})
コード例 #4
0
def _reproduce_crash(testcase_url, build_directory, iterations, disable_xvfb):
    """Reproduce a crash."""
    _prepare_initial_environment(build_directory, iterations)

    # Validate the test case URL and fetch the tool's configuration.
    testcase_id = _get_testcase_id_from_url(testcase_url)
    configuration = config.ReproduceToolConfiguration(testcase_url)

    testcase = _get_testcase(testcase_id, configuration)

    # Ensure that we support this test case.
    if testcase.platform not in SUPPORTED_PLATFORMS:
        raise errors.ReproduceToolUnrecoverableError(
            'The reproduce tool is not yet supported on {platform}.'.format(
                platform=testcase.platform))

    testcase_path = _download_testcase(testcase_id, testcase, configuration)
    _update_environment_for_testcase(testcase, build_directory)

    # Validate that we're running on the right platform for this test case.
    platform = environment.platform().lower()
    if testcase.platform == 'android' and platform == 'linux':
        _prepare_environment_for_android()
    elif testcase.platform == 'android' and platform != 'linux':
        raise errors.ReproduceToolUnrecoverableError(
            'The ClusterFuzz environment only supports running Android test cases '
            'on Linux host machines. Unable to reproduce the test case on '
            '{current_platform}.'.format(current_platform=platform))
    elif testcase.platform != platform:
        raise errors.ReproduceToolUnrecoverableError(
            'The specified test case was discovered on {testcase_platform}. '
            'Unable to attempt to reproduce it on {current_platform}.'.format(
                testcase_platform=testcase.platform,
                current_platform=platform))

    x_processes = []
    if not disable_xvfb:
        _setup_x()
    timeout = environment.get_value('TEST_TIMEOUT')

    print('Running testcase...')
    result = testcase_manager.test_for_crash_with_retries(
        testcase, testcase_path, timeout)

    # Terminate Xvfb and blackbox.
    for process in x_processes:
        process.terminate()

    return result
コード例 #5
0
ファイル: reproduce.py プロジェクト: satoshi-n/clusterfuzz
def _reproduce_crash(testcase_url, build_directory):
  """Reproduce a crash."""
  _prepare_initial_environment(build_directory)

  # Validate the test case URL and fetch the tool's configuration.
  testcase_id = _get_testcase_id_from_url(testcase_url)
  configuration = config.ReproduceToolConfiguration(testcase_url)

  testcase = _get_testcase(testcase_id, configuration)
  testcase_path = _download_testcase(testcase_id, testcase, configuration)
  _update_environment_for_testcase(testcase, build_directory)

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

  return result
コード例 #6
0
def _reproduce_crash(
    testcase_url,
    build_directory,
    iterations,
    disable_xvfb,
    verbose,
    disable_android_setup,
):
    """Reproduce a crash."""
    _prepare_initial_environment(build_directory, iterations, verbose)

    # Validate the test case URL and fetch the tool's configuration.
    testcase_id = _get_testcase_id_from_url(testcase_url)
    configuration = config.ReproduceToolConfiguration(testcase_url)

    testcase = _get_testcase(testcase_id, configuration)

    # For new user uploads, we'll fail without the metadata set by analyze task.
    if not testcase.platform:
        raise errors.ReproduceToolUnrecoverableError(
            "This test case has not yet been processed. Please try again later."
        )

    # Ensure that we support this test case's platform.
    if testcase.platform not in SUPPORTED_PLATFORMS:
        raise errors.ReproduceToolUnrecoverableError(
            "The reproduce tool is not yet supported on {platform}.".format(
                platform=testcase.platform))

    # Print warnings for this test case.
    if testcase.one_time_crasher_flag:
        print("Warning: this test case was a one-time crash. It may not be "
              "reproducible.")
    if testcase.flaky_stack:
        print("Warning: this test case is known to crash with different stack "
              "traces.")

    testcase_path = _download_testcase(testcase_id, testcase, configuration)
    _update_environment_for_testcase(testcase, build_directory)

    # Validate that we're running on the right platform for this test case.
    platform = environment.platform().lower()
    if testcase.platform == "android" and platform == "linux":
        android.prepare_environment(disable_android_setup)
    elif testcase.platform == "android" and platform != "linux":
        raise errors.ReproduceToolUnrecoverableError(
            "The ClusterFuzz environment only supports running Android test cases "
            "on Linux host machines. Unable to reproduce the test case on "
            "{current_platform}.".format(current_platform=platform))
    elif testcase.platform != platform:
        raise errors.ReproduceToolUnrecoverableError(
            "The specified test case was discovered on {testcase_platform}. "
            "Unable to attempt to reproduce it on {current_platform}.".format(
                testcase_platform=testcase.platform,
                current_platform=platform))

    x_processes = []
    if not disable_xvfb:
        _setup_x()
    timeout = environment.get_value("TEST_TIMEOUT")

    print("Running testcase...")
    try:
        result = testcase_manager.test_for_crash_with_retries(testcase,
                                                              testcase_path,
                                                              timeout,
                                                              crash_retries=1)

        # If we can't reproduce the crash, prompt the user to try again.
        if not result.is_crash():
            _print_stacktrace(result)
            result = None
            use_default_retries = prompts.get_boolean(
                "Failed to find the desired crash on first run. Re-run "
                "{crash_retries} times?".format(
                    crash_retries=environment.get_value("CRASH_RETRIES")))
            if use_default_retries:
                print(
                    "Attempting to reproduce test case. This may take a while..."
                )
                result = testcase_manager.test_for_crash_with_retries(
                    testcase, testcase_path, timeout)

    except KeyboardInterrupt:
        print("Aborting...")
        result = None

    # Terminate Xvfb and blackbox.
    for process in x_processes:
        process.terminate()

    return result