def test_strategy_specified(self): """Test weight is returned when strategy is defined in |FUZZING_STRATEGIES|.""" environment.set_value('FUZZING_STRATEGIES', '{"strategy_1": 0.5, "strategy_3": 1.0}') self.assertEqual(0.5, engine_common.get_strategy_probability('strategy_1', 0.33)) self.assertEqual(1.0, engine_common.get_strategy_probability('strategy_3', 0.33))
def test_strategy_not_specified(self): """Test 0.0 weight is return when strategy is not defined in |FUZZING_STRATEGIES|.""" environment.set_value("FUZZING_STRATEGIES", '{"strategy_1": 0.5, "strategy_3": 0.3}') self.assertEqual( 0.0, engine_common.get_strategy_probability("strategy_2", 0.33))
def do_mutator_plugin(): """Return whether or not to use a mutator_plugin.""" # TODO(metzman): Support Windows. if environment.platform() == 'WINDOWS': return False return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.MUTATOR_PLUGIN_STRATEGY, default=MUTATOR_PLUGIN_PROBABILITY))
def choose_generator(strategy_pool): """Chooses whether to use radamsa, ml rnn, or no generator and updates the strategy pool.""" radamsa_prob = engine_common.get_strategy_probability( strategy.CORPUS_MUTATION_RADAMSA_STRATEGY.name, default=strategy.CORPUS_MUTATION_RADAMSA_STRATEGY.probability) ml_rnn_prob = engine_common.get_strategy_probability( strategy.CORPUS_MUTATION_ML_RNN_STRATEGY.name, default=strategy.CORPUS_MUTATION_ML_RNN_STRATEGY.probability) if engine_common.decide_with_probability(radamsa_prob + ml_rnn_prob): if engine_common.decide_with_probability( radamsa_prob / (radamsa_prob + ml_rnn_prob)): strategy_pool.add_strategy(strategy.CORPUS_MUTATION_RADAMSA_STRATEGY) else: strategy_pool.add_strategy(strategy.CORPUS_MUTATION_ML_RNN_STRATEGY)
def do_fork(): """Return whether or not to do fork mode.""" # TODO(metzman): Find a workaround for Windows command line limit before # re-enabling this. if environment.platform() == 'WINDOWS': return False return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.FORK_STRATEGY, default=FORK_PROBABILITY))
def do_fork(): """Return whether or not to do fork mode.""" # TODO(crbug.com/920355): Reenable this when fork mode works with ChromeOS's # MSAN. job_name = environment.get_value('JOB_NAME') memory_tool = environment.get_memory_tool_name(job_name) if memory_tool == 'MSAN' and environment.is_chromeos_system_job(): return False return engine_common.decide_with_probability( engine_common.get_strategy_probability(strategy.FORK_STRATEGY, default=FORK_PROBABILITY))
def do_fork(): """Return whether or not to do fork mode.""" # TODO(metzman): Find a workaround for Windows command line limit before # re-enabling this. if environment.platform() == 'WINDOWS': return False # TODO(crbug.com/920355): Reenable this when fork mode works with ChromeOS's # MSAN. job_name = environment.get_value('JOB_NAME') memory_tool = environment.get_memory_tool_name(job_name) if memory_tool == 'MSAN' and environment.is_chromeos_system_job(): return False return engine_common.decide_with_probability( engine_common.get_strategy_probability(strategy.FORK_STRATEGY, default=FORK_PROBABILITY))
def do_value_profile(): """Return whether or not to do value profile.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.VALUE_PROFILE_STRATEGY, default=VALUE_PROFILE_PROBABILITY))
def do_recommended_dictionary(): """Retrn whether or not to use the recommended dictionary.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.RECOMMENDED_DICTIONARY_STRATEGY, default=RECOMMENDED_DICTIONARY_PROBABILITY))
def do_ml_rnn_generator(): """Return whether or not to do additional mutations.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.CORPUS_MUTATION_ML_RNN_STRATEGY, default=CORPUS_MUTATION_ML_RNN_PROBABILITY))
def do_radamsa_generator(): """Return whether or not to do radamsa mutations.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.CORPUS_MUTATION_RADAMSA_STRATEGY, default=CORPUS_MUTATION_RADAMSA_PROBABILITY))
def do_random_max_length(): """Return whether or not to do value profile.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability( strategy.RANDOM_MAX_LENGTH_STRATEGY, default=RANDOM_MAX_LENGTH_PROBABILITY))
def do_strategy(strategy_tuple): """Return whether or not to use a given strategy.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability(strategy_tuple.name, strategy_tuple.probability))
def test_env_var_not_dict(self): """Test default probability is returned when |FUZZING_STRATEGIES| is not a dict.""" environment.set_value('FUZZING_STRATEGIES', 'bad') self.assertEqual(0.33, engine_common.get_strategy_probability('foo', 0.33))
def test_default_probability(self): """Test default probability is returned when |FUZZING_STRATEGIES| is not set.""" self.assertEqual(0.33, engine_common.get_strategy_probability('foo', 0.33))
def do_fork(): """Return whether or not to do fork mode.""" return engine_common.decide_with_probability( engine_common.get_strategy_probability(strategy.FORK_STRATEGY, default=FORK_PROBABILITY))