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)
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)
def _do_builds(args, config, credentials, build_type, projects): """Does |build_type| test builds of |projects|.""" build_ids = {} for project_name in projects: logging.info('Getting steps for: "%s".', project_name) try: project_yaml, dockerfile_contents = ( build_project.get_project_data(project_name)) except FileNotFoundError: logging.error('Couldn\'t get project data. Skipping %s.', project_name) continue build_project.set_yaml_defaults(project_yaml) print(project_yaml['sanitizers'], args.sanitizers) project_yaml_sanitizers = build_project.get_sanitizer_strings( project_yaml['sanitizers']) + ['coverage', 'introspector'] project_yaml['sanitizers'] = list( set(project_yaml_sanitizers).intersection(set(args.sanitizers))) project_yaml['fuzzing_engines'] = list( set(project_yaml['fuzzing_engines']).intersection( set(args.fuzzing_engines))) if not project_yaml['sanitizers'] or not project_yaml[ 'fuzzing_engines']: logging.info('Nothing to build for this project: %s.', project_name) continue steps = build_type.get_build_steps_func(project_name, project_yaml, dockerfile_contents, IMAGE_PROJECT, BASE_IMAGES_PROJECT, config) if not steps: logging.error('No steps. Skipping %s.', project_name) continue try: build_ids[project_name] = (build_project.run_build( project_name, steps, credentials, build_type.type_name, extra_tags=['trial-build'])) except Exception: # pylint: disable=broad-except # Handle flake. print('Failed to start build', project_name) return build_ids
def _do_builds(args, config, credentials, build_type, projects): """Does |build_type| test builds of |projects|.""" build_ids = {} for project_name in projects: logging.info('Getting steps for: "%s".', project_name) try: project_yaml, dockerfile_contents = ( build_project.get_project_data(project_name)) except FileNotFoundError: logging.error('Couldn\'t get project data. Skipping %s.', project_name) continue project_yaml['sanitizers'] = list( set(project_yaml['sanitizers']).intersection(set(args.sanitizers))) project_yaml['fuzzing_engines'] = list( set(project_yaml['fuzzing_engines']).intersection( set(args.fuzzing_engines))) if not project_yaml['sanitizers'] or not project_yaml[ 'fuzzing_engines']: logging.info('Nothing to build for this project: %s.', project_name) continue steps = build_type.get_build_steps_func(project_name, project_yaml, dockerfile_contents, IMAGE_PROJECT, BASE_IMAGES_PROJECT, config) if not steps: logging.error('No steps. Skipping %s.', project_name) continue build_ids[project_name] = (build_project.run_build( project_name, steps, credentials, build_type.type_name, extra_tags=['trial-build'])) return build_ids