Example #1
0
    def setUp(self):
        """Put data in the local ndb table the tests to query from and set
    bandit selection environment variable."""
        test_helpers.patch_environ(self)

        data = []

        strategy1 = data_types.FuzzStrategyProbability()
        strategy1.strategy_name = 'fork,corpus_subset,recommended_dict,'
        strategy1.probability = 0.33
        strategy1.engine = 'libFuzzer'
        data.append(strategy1)

        strategy2 = data_types.FuzzStrategyProbability()
        strategy2.strategy_name = ('random_max_len,corpus_mutations_ml_rnn,'
                                   'value_profile,recommended_dict,')
        strategy2.probability = 0.34
        strategy2.engine = 'libFuzzer'
        data.append(strategy2)

        strategy3 = data_types.FuzzStrategyProbability()
        strategy3.strategy_name = ('corpus_mutations_radamsa,'
                                   'random_max_len,corpus_subset,')
        strategy3.probability = 0.33
        strategy3.engine = 'libFuzzer'
        data.append(strategy3)
        ndb.put_multi(data)

        distribution = fuzz_task.get_strategy_distribution_from_ndb()

        environment.set_value('USE_BANDIT_STRATEGY_SELECTION', True)
        environment.set_value('STRATEGY_SELECTION_DISTRIBUTION', distribution)
def _query_and_upload_strategy_probabilities(engine):
    """Uploads queried data into datastore.

  Calls query functions and uploads query results
  to datastore to use as new probabilities. Probabilities
  are based on new_edges feature."""
    strategy_data = []
    data = _query_multi_armed_bandit_probabilities(engine)
    logs.log('Queried distribution for {}.'.format(engine.name))

    # TODO(mukundv): Update once we choose a temperature parameter for final
    # implementation.
    for row in data:
        curr_strategy = data_types.FuzzStrategyProbability()
        curr_strategy.strategy_name = str(row['strategy'])
        curr_strategy.probability = float(row['bandit_weight'])
        curr_strategy.engine = engine.name
        strategy_data.append(curr_strategy)

    query = data_types.FuzzStrategyProbability.query(
        data_types.FuzzStrategyProbability.engine == engine.name)
    ndb_utils.delete_multi(
        [entity.key for entity in ndb_utils.get_all_from_query(query)])
    ndb_utils.put_multi(strategy_data)
    logs.log('Uploaded queried distribution to ndb for {}'.format(engine.name))
    _store_probabilities_in_bigquery(engine, data)
    logs.log('Uploaded queried distribution to BigQuery for {}'.format(
        engine.name))
Example #3
0
    def setUp(self):
        """Put data in the local ndb table the tests to query from."""
        test_helpers.patch_environ(self)
        test_helpers.patch(self, [
            'clusterfuzz._internal.bot.fuzzers.engine_common.decide_with_probability'
        ])
        self.mock.decide_with_probability.return_value = True

        data = []

        strategy1 = data_types.FuzzStrategyProbability()
        strategy1.strategy_name = 'corpus_mutations_ml_rnn,corpus_subset,'
        strategy1.probability = 1
        strategy1.engine = 'afl'
        data.append(strategy1)
        ndb.put_multi(data)

        distribution = fuzz_task.get_strategy_distribution_from_ndb()

        environment.set_value('USE_BANDIT_STRATEGY_SELECTION', True)
        environment.set_value('STRATEGY_SELECTION_DISTRIBUTION', distribution)