def _build(config_file: str, config_name: str, substitutions: Dict[str, str] = None, timeout_seconds: int = GCB_BUILD_TIMEOUT) -> Tuple[int, str]: """Build each of |args| on gcb.""" config_arg = '--config=%s' % config_file machine_type_arg = '--machine-type=%s' % GCB_MACHINE_TYPE # Use "s" suffix to denote seconds. timeout_arg = '--timeout=%ds' % timeout_seconds command = [ 'gcloud', 'builds', 'submit', str(utils.ROOT_DIR), config_arg, timeout_arg, machine_type_arg, ] if substitutions is None: substitutions = {} assert '_REPO' not in substitutions substitutions['_REPO'] = experiment_utils.get_base_docker_tag() assert '_EXPERIMENT' not in substitutions substitutions['_EXPERIMENT'] = experiment_utils.get_experiment_name() substitutions = [ '%s=%s' % (key, value) for key, value in substitutions.items() ] substitutions = ','.join(substitutions) command.append('--substitutions=%s' % substitutions) # Don't write to stdout to make concurrent building faster. Otherwise # writing becomes the bottleneck. result = new_process.execute(command, write_to_stdout=False, kill_children=True, timeout=timeout_seconds) build_utils.store_build_logs(config_name, result) return result
def output_report(web_bucket, in_progress=False): """Generate the HTML report and write it to |web_bucket|.""" experiment_name = experiment_utils.get_experiment_name() reports_dir = get_reports_dir() try: logger.debug('Generating report.') filesystem.recreate_directory(reports_dir) generate_report.generate_report([experiment_name], str(reports_dir), in_progress=in_progress) gsutil.rsync(str(reports_dir), web_bucket, gsutil_options=[ '-h', 'Cache-Control:public,max-age=0,no-transform' ]) logger.debug('Done generating report.') except Exception: # pylint: disable=broad-except logger.error('Error generating HTML report.')
def output_report(experiment_config: dict, in_progress=False, coverage_report=False): """Generate the HTML report and write it to |web_bucket|.""" experiment_name = experiment_utils.get_experiment_name() web_filestore_path = posixpath.join(experiment_config['report_filestore'], experiment_name) reports_dir = get_reports_dir() core_fuzzers = yaml_utils.read(CORE_FUZZERS_YAML)['fuzzers'] fuzzers = sorted(set(experiment_config['fuzzers']).union(set(core_fuzzers))) # Don't merge with nonprivate experiments until the very end as doing it # while the experiment is in progress will produce unusable realtime # results. merge_with_nonprivate = (not in_progress and experiment_config.get( 'merge_with_nonprivate', False)) try: logger.debug('Generating report.') filesystem.recreate_directory(reports_dir) generate_report.generate_report( [experiment_name], str(reports_dir), report_name=experiment_name, fuzzers=fuzzers, in_progress=in_progress, merge_with_clobber_nonprivate=merge_with_nonprivate, coverage_report=coverage_report) filestore_utils.rsync( str(reports_dir), web_filestore_path, delete=False, # Don't remove existing coverage jsons. gsutil_options=[ '-h', 'Cache-Control:public,max-age=0,no-transform' ]) logger.debug('Done generating report.') except data_utils.EmptyDataError: logs.warning('No snapshot data.') except Exception: # pylint: disable=broad-except logger.error('Error generating HTML report.')
def main(): """Do the experiment and report results.""" logs.initialize(default_extras={ 'component': 'dispatcher', }) try: dispatcher_main() except Exception as error: logs.error('Error conducting experiment.') raise error if experiment_utils.is_local_experiment(): return 0 experiment_config_file_path = _get_config_file_path() if stop_experiment.stop_experiment(experiment_utils.get_experiment_name(), experiment_config_file_path): return 0 return 1
def build_images_for_trials(fuzzers: List[str], benchmarks: List[str], num_trials: int) -> List[models.Trial]: """Builds the images needed to run |experiment| and returns a list of trials that can be run for experiment. This is the number of trials specified in experiment times each pair of fuzzer+benchmark that builds successfully.""" # This call will raise an exception if the images can't be built which will # halt the experiment. builder.build_base_images() # Only build fuzzers for benchmarks whose measurers built successfully. benchmarks = builder.build_all_measurers(benchmarks) build_successes = builder.build_all_fuzzer_benchmarks(fuzzers, benchmarks) experiment_name = experiment_utils.get_experiment_name() trials = [] for fuzzer, benchmark in build_successes: fuzzer_benchmark_trials = [ models.Trial(fuzzer=fuzzer, experiment=experiment_name, benchmark=benchmark) for _ in range(num_trials) ] trials.extend(fuzzer_benchmark_trials) return trials
def coverage_steps(benchmark): """Returns GCB run steps for coverage builds.""" coverage_binaries_dir = exp_path.filestore( build_utils.get_coverage_binaries_dir()) steps = [{ 'name': DOCKER_IMAGE, 'args': [ 'run', '-v', '/workspace/out:/host-out', posixpath.join(get_docker_registry(), 'builders', 'coverage', benchmark) + ':' + experiment_utils.get_experiment_name(), '/bin/bash', '-c', 'cd /out; tar -czvf /host-out/coverage-build-' + benchmark + '.tar.gz * /src /work' ] }] step = {'name': 'gcr.io/cloud-builders/gsutil'} step['args'] = [ '-m', 'cp', '/workspace/out/coverage-build-' + benchmark + '.tar.gz', coverage_binaries_dir + '/' ] steps.append(step) return steps
def get_experiment_tag_for_image(image_specs, tag_by_experiment=True): """Returns the registry with the experiment tag for given image.""" tag = posixpath.join(get_docker_registry(), image_specs['tag']) if tag_by_experiment: tag += ':' + experiment_utils.get_experiment_name() return tag
def initialize_queue(redis_host): """Returns a redis-backed rq queue.""" queue_name = experiment_utils.get_experiment_name() redis_connection = redis.Redis(host=redis_host) queue = rq.Queue(queue_name, connection=redis_connection) return queue