def _GetChecksumGcnoDict(self, cov_zip): """Generates a dictionary from gcno checksum to GCNOParser object. Processes the gcnodir files in the zip file to produce a mapping from gcno checksum to the GCNOParser object wrapping the gcno content. Args: cov_zip: the zip file containing gcnodir files from the device build Returns: the dictionary of gcno checksums to GCNOParser objects """ checksum_gcno_dict = dict() fnames = cov_zip.namelist() instrumented_modules = [ f for f in fnames if f.endswith(COVERAGE_SUFFIX) ] for instrumented_module in instrumented_modules: # Read the gcnodir file archive = archive_parser.Archive( cov_zip.open(instrumented_module).read()) try: archive.Parse() except ValueError: logging.error("Archive could not be parsed: %s", name) continue for gcno_file_path in archive.files: file_name_path = gcno_file_path.rsplit(".", 1)[0] file_name = os.path.basename(file_name_path) gcno_stream = io.BytesIO(archive.files[gcno_file_path]) gcno_file_parser = gcno_parser.GCNOParser(gcno_stream) checksum_gcno_dict[ gcno_file_parser.checksum] = gcno_file_parser return checksum_gcno_dict
def _GetChecksumGcnoDict(self, cov_zip): """Generates a dictionary from gcno checksum to GCNOParser object. Processes the gcnodir files in the zip file to produce a mapping from gcno checksum to the GCNOParser object wrapping the gcno content. Note there might be multiple gcno files corresponds to the same checksum. Args: cov_zip: the zip file containing gcnodir files from the device build Returns: the dictionary of gcno checksums to GCNOParser objects """ checksum_gcno_dict = dict() fnames = cov_zip.namelist() instrumented_modules = [ f for f in fnames if f.endswith(COVERAGE_SUFFIX) ] for instrumented_module in instrumented_modules: # Read the gcnodir file archive = archive_parser.Archive( cov_zip.open(instrumented_module).read()) try: archive.Parse() except ValueError: logging.error("Archive could not be parsed: %s", name) continue for gcno_file_path in archive.files: gcno_stream = io.BytesIO(archive.files[gcno_file_path]) gcno_file_parser = gcno_parser.GCNOParser(gcno_stream) if gcno_file_parser.checksum in checksum_gcno_dict: checksum_gcno_dict[gcno_file_parser.checksum].append( gcno_file_parser) else: checksum_gcno_dict[gcno_file_parser.checksum] = [ gcno_file_parser ] return checksum_gcno_dict
def _ManualProcess(self, cov_zip, revision_dict, gcda_dict, isGlobal): """Process coverage data and appends coverage reports to the report message. Opens the gcno files in the cov_zip for the specified modules and matches gcno/gcda files. Then, coverage vectors are generated for each set of matching gcno/gcda files and appended as a CoverageReportMessage to the provided report message. Unlike AutoProcess, coverage information is only processed for the modules explicitly defined in 'modules'. Args: cov_zip: the ZipFile object containing the gcno coverage artifacts. revision_dict: the dictionary from project name to project version. gcda_dict: the dictionary of gcda basenames to gcda content (binary string) isGlobal: boolean, True if the coverage data is for the entire test, False if only for the current test case. """ output_coverage_report = getattr( self, keys.ConfigKeys.IKEY_OUTPUT_COVERAGE_REPORT, True) modules = getattr(self, keys.ConfigKeys.IKEY_MODULES, None) covered_modules = set(cov_zip.namelist()) for module in modules: if MODULE_NAME not in module or GIT_PROJECT not in module: logging.error( "Coverage module must specify name and git project: %s", module) continue project = module[GIT_PROJECT] if PATH not in project or NAME not in project: logging.error("Project name and path not specified: %s", project) continue name = str(module[MODULE_NAME]) + COVERAGE_SUFFIX git_project = str(project[NAME]) git_project_path = str(project[PATH]) if name not in covered_modules: logging.error("No coverage information for module %s", name) continue if git_project not in revision_dict: logging.error( "Git project not present in device revision dict: %s", git_project) continue revision = str(revision_dict[git_project]) archive = archive_parser.Archive(cov_zip.open(name).read()) try: archive.Parse() except ValueError: logging.error("Archive could not be parsed: %s", name) continue for gcno_file_path in archive.files: file_name_path = gcno_file_path.rsplit(".", 1)[0] file_name = os.path.basename(file_name_path) gcno_content = archive.files[gcno_file_path] gcno_stream = io.BytesIO(gcno_content) try: gcno_summary = gcno_parser.GCNOParser(gcno_stream).Parse() except FileFormatError: logging.error("Error parsing gcno file %s", gcno_file_path) continue src_file_path = None # Match gcno file with gcda file gcda_name = file_name + GCDA_SUFFIX if gcda_name not in gcda_dict: logging.error("No gcda file found %s.", gcda_name) continue src_file_path = self._ExtractSourceName( gcno_summary, file_name) if not src_file_path: logging.error("No source file found for %s.", gcno_file_path) continue # Process and merge gcno/gcda data gcda_content = gcda_dict[gcda_name] gcda_stream = io.BytesIO(gcda_content) try: gcda_parser.GCDAParser(gcda_stream).Parse(gcno_summary) except FileFormatError: logging.error("Error parsing gcda file %s", gcda_content) continue if self.web and self.web.enabled: coverage_vec = coverage_report.GenerateLineCoverageVector( src_file_path, gcno_summary) total_count, covered_count = coverage_report.GetCoverageStats( coverage_vec) self.web.AddCoverageReport(coverage_vec, src_file_path, git_project, git_project_path, revision, covered_count, total_count, isGlobal) if output_coverage_report: self._OutputCoverageReport(isGlobal)