def test_get_benchmark_cov_dict(): """Tests that get_benchmark_cov_dict() returns correct dictionary.""" coverage_dict = create_coverage_data() benchmark = 'libpng-1.2.56' benchmark_cov_dict = coverage_data_utils.get_benchmark_cov_dict( coverage_dict, benchmark) expected_cov_dict = { "afl": {(0, 0, 3, 3), (0, 0, 2, 2), (0, 0, 1, 1)}, "libfuzzer": {(0, 0, 4, 4), (0, 0, 3, 3), (0, 0, 2, 3), (0, 0, 1, 1)} } assert expected_cov_dict == benchmark_cov_dict
def test_get_pairwise_unique_coverage_table(): """Tests that get_pairwise_unique_coverage_table() gives the correct dataframe.""" coverage_dict = create_coverage_data() benchmark_coverage_dict = coverage_data_utils.get_benchmark_cov_dict( coverage_dict, 'libpng-1.2.56') fuzzers = ['libfuzzer', 'afl'] table = coverage_data_utils.get_pairwise_unique_coverage_table( benchmark_coverage_dict, fuzzers) expected_table = pd.DataFrame([[0, 1], [2, 0]], index=fuzzers, columns=fuzzers) pd_test.assert_frame_equal(table, expected_table)
def test_get_unique_region_dict(): """Tests get_unique_region_dict() function.""" coverage_dict = create_coverage_data() benchmark_coverage_dict = coverage_data_utils.get_benchmark_cov_dict( coverage_dict, 'libpng-1.2.56') unique_region_dict = coverage_data_utils.get_unique_region_dict( benchmark_coverage_dict) expected_dict = { (0, 0, 2, 2): ['afl'], (0, 0, 2, 3): ['libfuzzer'], (0, 0, 4, 4): ['libfuzzer'] } assert expected_dict == unique_region_dict
def test_get_unique_region_cov_df(): """Tests get_unique_region_cov_df() function.""" coverage_dict = create_coverage_data() benchmark_coverage_dict = coverage_data_utils.get_benchmark_cov_dict( coverage_dict, 'libpng-1.2.56') unique_region_dict = coverage_data_utils.get_unique_region_dict( benchmark_coverage_dict) fuzzer_names = ['afl', 'libfuzzer'] unique_region_df = coverage_data_utils.get_unique_region_cov_df( unique_region_dict, fuzzer_names) unique_region_df = unique_region_df.sort_values(by=['fuzzer']).reset_index( drop=True) expected_df = pd.DataFrame([{ 'fuzzer': 'afl', 'unique_regions_covered': 1 }, { 'fuzzer': 'libfuzzer', 'unique_regions_covered': 2 }]) assert unique_region_df.equals(expected_df)
def _benchmark_coverage_dict(self): """Covered regions of each fuzzer on this benchmark.""" return coverage_data_utils.get_benchmark_cov_dict( self._coverage_dict, self.name)