def test_empty_weights(self): """Ensure that we select with even weights if none are specified.""" fuzzer_selection.select_fuzz_target(['target_0', 'target_1'], {}) expected_target_0 = fuzzer_selection.WeightedTarget('target_0', 1.0) expected_target_1 = fuzzer_selection.WeightedTarget('target_1', 1.0) self.mock.random_weighted_choice.assert_called_once_with( [expected_target_0, expected_target_1])
def test_weights_for_some_targets(self): """Ensure that we use weights we applicable, and defaults where not.""" fuzzer_selection.select_fuzz_target( ['weighted_0', 'weighted_1', 'unweighted_0'], { 'weighted_0': 2.0, 'weighted_1': 0.5 }) expected_weighted_0 = fuzzer_selection.WeightedTarget( 'weighted_0', 2.0) expected_weighted_1 = fuzzer_selection.WeightedTarget( 'weighted_1', 0.5) expected_unweighted_0 = fuzzer_selection.WeightedTarget( 'unweighted_0', 1.0) self.mock.random_weighted_choice.assert_called_once_with( [expected_weighted_0, expected_weighted_1, expected_unweighted_0])
def _set_random_fuzz_target_for_fuzzing_if_needed(fuzz_targets, target_weights): """Sets a random fuzz target for fuzzing.""" if not environment.is_engine_fuzzer_job(): return # TODO(ochang): Untie this dependency on knowledge of the current task. task_name = environment.get_value('TASK_NAME') if task_name != 'fuzz': return fuzz_targets = list(fuzz_targets) if not fuzz_targets: logs.log_error('No fuzz targets found. Unable to pick random one.') return fuzz_target = fuzzer_selection.select_fuzz_target(fuzz_targets, target_weights) environment.set_value('FUZZ_TARGET', fuzz_target) logs.log('Picked fuzz target %s for fuzzing.' % fuzz_target)