Beispiel #1
0
  def test_get_coverage_build_steps(self, mocked_url, mocked_corpora_steps,
                                    mocked_time):
    """Test for get_build_steps."""
    del mocked_url, mocked_corpora_steps, mocked_time
    datetime.datetime = test_utils.SpoofedDatetime
    project_yaml_contents = ('language: c++\n'
                             'sanitizers:\n'
                             '  - address\n'
                             'architectures:\n'
                             '  - x86_64\n')
    dockerfile_contents = 'test line'
    image_project = 'oss-fuzz'
    base_images_project = 'oss-fuzz-base'

    expected_build_steps_file_path = test_utils.get_test_data_file_path(
        'expected_coverage_build_steps.json')
    with open(expected_build_steps_file_path) as expected_build_steps_file:
      expected_coverage_build_steps = json.load(expected_build_steps_file)

    with ndb.Client().context():
      Project(name='test-project',
              project_yaml_contents=project_yaml_contents,
              dockerfile_contents=dockerfile_contents).put()

    dockerfile_lines = dockerfile_contents.split('\n')
    build_steps = get_build_steps('test-project', project_yaml_contents,
                                  dockerfile_lines, image_project,
                                  base_images_project)
    self.assertEqual(build_steps, expected_coverage_build_steps)
    def test_get_coverage_build_steps(self, mock_url, mock_corpora_steps,
                                      mock_get_datetime_now):
        """Test for get_build_steps."""
        del mock_url, mock_corpora_steps, mock_get_datetime_now
        project_yaml_contents = ('language: c++\n'
                                 'sanitizers:\n'
                                 '  - address\n'
                                 'architectures:\n'
                                 '  - x86_64\n')
        self.fs.create_dir(test_utils.PROJECT_DIR)
        test_utils.create_project_data(test_utils.PROJECT,
                                       project_yaml_contents)

        expected_build_steps_file_path = test_utils.get_test_data_file_path(
            'expected_coverage_build_steps.json')
        self.fs.add_real_file(expected_build_steps_file_path)
        with open(expected_build_steps_file_path) as expected_build_steps_file:
            expected_coverage_build_steps = json.load(
                expected_build_steps_file)

        config = build_project.Config(False, False, None, False)
        project_yaml, dockerfile = build_project.get_project_data(
            test_utils.PROJECT)
        build_steps = build_and_run_coverage.get_build_steps(
            test_utils.PROJECT, project_yaml, dockerfile,
            test_utils.IMAGE_PROJECT, test_utils.BASE_IMAGES_PROJECT, config)
        self.assertEqual(build_steps, expected_coverage_build_steps)
Beispiel #3
0
    def test_get_build_steps(self, mock_url, mock_get_datetime_now):
        """Test for get_build_steps."""
        del mock_url, mock_get_datetime_now
        project_yaml_contents = (
            'language: c++\n'
            'sanitizers:\n'
            '  - address\n'
            '  - memory\n'
            '  - undefined\n'
            'architectures:\n'
            '  - x86_64\n'
            '  - i386\n'
            'main_repo: https://github.com/google/oss-fuzz.git\n')
        self.fs.create_dir(test_utils.PROJECT_DIR)
        test_utils.create_project_data(test_utils.PROJECT,
                                       project_yaml_contents)

        expected_build_steps_file_path = test_utils.get_test_data_file_path(
            'expected_build_steps.json')
        self.fs.add_real_file(expected_build_steps_file_path)
        with open(expected_build_steps_file_path) as expected_build_steps_file:
            expected_build_steps = json.load(expected_build_steps_file)

        config = build_project.Config(False, False, None, False, True)
        project_yaml, dockerfile = build_project.get_project_data(
            test_utils.PROJECT)
        build_steps = build_project.get_build_steps(
            test_utils.PROJECT, project_yaml, dockerfile,
            test_utils.IMAGE_PROJECT, test_utils.BASE_IMAGES_PROJECT, config)
        self.assertEqual(build_steps, expected_build_steps)
Beispiel #4
0
 def test_build_steps_correct(self, mock_gcb_build_and_push_images,
                              mock_run_build, mock_get_application_default,
                              mock_wait_on_builds):
     """Tests that the correct build steps for building a project are passed to
 GCB."""
     del mock_gcb_build_and_push_images
     del mock_get_application_default
     del mock_wait_on_builds
     self.maxDiff = None  # pylint: disable=invalid-name
     build_id = 1
     mock_run_build.return_value = build_id
     branch_name = 'mybranch'
     project = 'skcms'
     args = [
         '--sanitizers', 'address', 'undefined', '--fuzzing-engines', 'afl',
         'libfuzzer', '--branch', branch_name, '--force-build', project
     ]
     self.assertTrue(trial_build.trial_build_main(args))
     expected_build_steps_path = test_utils.get_test_data_file_path(
         'expected_trial_build_steps.json')
     with open(expected_build_steps_path, 'r') as file_handle:
         expected_build_steps = json.load(file_handle)
     self.assertEqual(mock_run_build.call_args_list[0][0][1],
                      expected_build_steps)