def test_add_recommended_dictionary_with_merge(self): """Test dictionary processing when there is a local dictionary.""" dictionary_path = os.path.join(self.work_directory_path, 'dictionary_from_repository.dict') self.fs.create_file(dictionary_path, contents=self.dictionary_from_repository_data) dictionary_argument = '-dict=%s' % dictionary_path expected_arguments = [ '-max_len=80', '-rss_limit_mb=2048', '-timeout=25', dictionary_argument, '-artifact_prefix=/fake/', '-max_total_time=2950', '-print_final_stats=1', '/fake/inputs-disk/temp-1337/new', '/fake/corpus_basic' ] actual_arguments = copy.deepcopy(expected_arguments) # The function call below is expected to modify actual_arguments list. libfuzzer.add_recommended_dictionary(actual_arguments, self.fuzzer_name, self.fuzzer_path) # The dictionary argument is expected to be removed and added to the end. expected_arguments.remove(dictionary_argument) expected_arguments.append(dictionary_argument + '.merged') self.assertEqual(actual_arguments, expected_arguments) # The dictionary should content merged data. updated_dictionary_data = read_data_from_file(dictionary_path + '.merged') self.assert_compare_dictionaries(updated_dictionary_data, self.expected_merged_dictionary_data)
def test_download_recommended_dictionary_with_merge(self): """Test downloading of recommended dictionary.""" arguments = [ '-max_len=80', '-rss_limit_mb=2048', '-timeout=25', '-artifact_prefix=/fake/', '-max_total_time=2950', '-print_final_stats=1', '/fake/inputs-disk/temp-1337/new', '/fake/corpus_basic' ] libfuzzer.add_recommended_dictionary(arguments, self.fuzzer_name, self.fuzzer_path) self.assertIn( '/fake/fuzzers/inputs-disk/temp-1337/recommended_dictionary.dict', self.mock.download_recommended_dictionary_from_gcs.call_args[0])
def test_add_recommended_dictionary_no_merge(self): """Test dictionary processing when there is no local dictionary.""" arguments = [ '-max_len=80', '-rss_limit_mb=2048', '-timeout=25', '-artifact_prefix=/fake/', '-max_total_time=2950', '-print_final_stats=1', '/fake/inputs-disk/temp-1337/new', '/fake/corpus_basic' ] libfuzzer.add_recommended_dictionary(arguments, self.fuzzer_name, self.fuzzer_path) expected_dictionary_path = '%s.dict.merged' % self.fuzzer_path # Check '-dict' argument that should be added by # add_recommended_dictionary(). expected_dictionary_argument = '-dict=%s' % expected_dictionary_path self.assertTrue(expected_dictionary_argument in arguments) # Check the dictionary contents. dictionary_data = read_data_from_file(expected_dictionary_path) self.assert_compare_dictionaries( dictionary_data, self.expected_gcs_only_merged_dictionary_data)