def get_current_coverage(self) -> int: """Get the current number of lines covered.""" if not os.path.exists(self.cov_summary_file): self.logger.warning('No coverage summary json file found.') return 0 try: coverage_info = coverage_utils.get_coverage_infomation( self.cov_summary_file) coverage_data = coverage_info["data"][0] summary_data = coverage_data["totals"] regions_coverage_data = summary_data["regions"] regions_covered = regions_coverage_data["covered"] return regions_covered except Exception: # pylint: disable=broad-except self.logger.error( 'Coverage summary json file defective or missing.') return 0
def extract_segments_and_functions_from_summary_json( # pylint: disable=too-many-locals summary_json_file, benchmark, fuzzer, trial_id, time): """Return a trial-specific data frame container with segment and function coverage information given a trial-specific coverage summary json file.""" trial_specific_coverage_data = DetailedCoverageData() try: coverage_info = coverage_utils.get_coverage_infomation( summary_json_file) # Extract coverage information for functions. for function_data in coverage_info['data'][0]['functions']: trial_specific_coverage_data.add_function_entry( benchmark, fuzzer, trial_id, function_data['name'], function_data['count'], time) # Extract coverage information for segments. for file in coverage_info['data'][0]['files']: for segment in file['segments']: if segment[2] != 0: # Segment hits. trial_specific_coverage_data.add_segment_entry( benchmark, fuzzer, trial_id, file['filename'], segment[0], # Segment line. segment[1], # Segment column. time) except (ValueError, KeyError, IndexError): coverage_utils.logger.error( 'Failed when extracting trial-specific segment and function ' 'information from coverage summary.') trial_specific_coverage_data.generate_data_frames_after_adding_all_entries( ) return trial_specific_coverage_data