diff --git a/tools/compare_cts_reports/aggregate_cts_reports.py b/tools/compare_cts_reports/aggregate_cts_reports.py index 2dc7331a7..ae49f1730 100755 --- a/tools/compare_cts_reports/aggregate_cts_reports.py +++ b/tools/compare_cts_reports/aggregate_cts_reports.py @@ -72,7 +72,7 @@ def aggregate_cts_reports(report_files): def main(): parser = argparse.ArgumentParser() - parser.add_argument('--report-files', required=True, nargs='+', + parser.add_argument('-r', '--report', required=True, nargs='+', help=('Path to cts report(s), where a cts report could ' 'be a zip archive or a xml file.')) parser.add_argument('-d', '--output-dir', required=True, @@ -80,7 +80,7 @@ def main(): args = parser.parse_args() - report_files = args.report_files + report_files = args.report output_dir = args.output_dir if not os.path.exists(output_dir): diff --git a/tools/compare_cts_reports/compare_cts_reports.py b/tools/compare_cts_reports/compare_cts_reports.py index 21705ce80..006f63638 100755 --- a/tools/compare_cts_reports/compare_cts_reports.py +++ b/tools/compare_cts_reports/compare_cts_reports.py @@ -47,10 +47,7 @@ import tempfile import aggregate_cts_reports import parse_cts_report - - -TESTED_ITEMS = 'tested_items' -PASS_RATE = 'pass_rate' +import constant def one_way_compare(reports, diff_csv): @@ -113,7 +110,7 @@ def two_way_compare(reports, diff_csv): result = report.get_test_status(module_name, abi, class_name, test_name) if test_name not in tests: - tests[test_name] = [parse_cts_report.NO_DATA, parse_cts_report.NO_DATA] + tests[test_name] = [constant.NO_DATA, constant.NO_DATA] tests[test_name][i] = result @@ -163,10 +160,10 @@ def gen_summary_row(reports, module_with_abi, item): summary = module_summary[abi] if abi in module_summary else None if not summary: - row.append(0.0 if item == PASS_RATE else 0) - elif item == TESTED_ITEMS: + row.append(0.0 if item == constant.PASS_RATE else 0) + elif item == constant.TESTED_ITEMS: row.append(summary.tested_items) - elif item == PASS_RATE: + elif item == constant.PASS_RATE: row.append(summary.pass_rate) elif item in parse_cts_report.CtsReport.STATUS_ORDER: row.append(summary.counter[item]) @@ -215,7 +212,10 @@ def n_way_compare(reports, diff_csv): module_names, key=lambda module_name: modules_min_rate[module_name] ) - items = parse_cts_report.CtsReport.STATUS_ORDER + [TESTED_ITEMS, PASS_RATE] + items = parse_cts_report.CtsReport.STATUS_ORDER + [ + constant.TESTED_ITEMS, + constant.PASS_RATE, + ] with open(diff_csv, 'w') as diff_csvfile: diff_writer = csv.writer(diff_csvfile) @@ -238,7 +238,7 @@ def load_parsed_report(report_dir): for f in [info_path, result_path]: if not os.path.exists(f): - raise FileNotFoundError(f'file {f} doesn\'t exist.') + raise FileNotFoundError(f"file {f} doesn't exist.") with open(info_path, 'r') as info_jsonfile: info = json.load(info_jsonfile) @@ -254,11 +254,11 @@ def load_parsed_report(report_dir): def main(): parser = argparse.ArgumentParser() - parser.add_argument('--reports', '-r', nargs='+', + parser.add_argument('-r', '--report', nargs='+', dest='cts_reports', action='append', help=('Path to cts reports. Each flag -r is followed by ' 'a group of files to be aggregated as one report.')) - parser.add_argument('--folder', '-f', + parser.add_argument('-f', '--folder', dest='cts_reports', action='append', help=('Path to folder that stores intermediate files ' 'of parsed reports.')) diff --git a/tools/compare_cts_reports/constant.py b/tools/compare_cts_reports/constant.py new file mode 100755 index 000000000..c409e909a --- /dev/null +++ b/tools/compare_cts_reports/constant.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 +# +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +"""Constants for development/tools/compare_cts_reports/.""" + + +VERSION = '1.0' + +NO_DATA = 'null' +TESTED_ITEMS = 'tested_items' +PASS_RATE = 'pass_rate' diff --git a/tools/compare_cts_reports/parse_cts_report.py b/tools/compare_cts_reports/parse_cts_report.py index b176dadaf..bdf786c3e 100755 --- a/tools/compare_cts_reports/parse_cts_report.py +++ b/tools/compare_cts_reports/parse_cts_report.py @@ -28,14 +28,12 @@ import shutil import tempfile import xml.etree.ElementTree as ET import zipfile +import constant # TODO(b/293809772): Logging. -NO_DATA = 'null' - - class CtsReport: """Class to record the test result of a cts report.""" @@ -57,7 +55,7 @@ class CtsReport: @staticmethod def is_fail(status): - if status == NO_DATA: + if status == constant.NO_DATA: return False else: return CtsReport.STATUS_ORDER.index(status) >= CtsReport.FAIL_INDEX @@ -84,19 +82,20 @@ class CtsReport: """Get test status from the CtsReport object.""" if module_name not in self.result_tree: - return NO_DATA + return constant.NO_DATA abis = self.result_tree[module_name] if abi not in abis: - return NO_DATA + return constant.NO_DATA test_classes = abis[abi] if class_name not in test_classes: - return NO_DATA + return constant.NO_DATA + tests = test_classes[class_name] if test_name not in tests: - return NO_DATA + return constant.NO_DATA return tests[test_name] @@ -111,7 +110,7 @@ class CtsReport: test_classes = abis.setdefault(abi, {}) tests = test_classes.setdefault(class_name, {}) - if previous == NO_DATA: + if previous == constant.NO_DATA: tests[test_name] = test_status module_summary = self.module_summaries.setdefault(module_name, {}) @@ -290,7 +289,10 @@ def get_test_info_xml(test_result_path): tree = ET.parse(test_result_path) root = tree.getroot() - test_info = {'source_path': test_result_path} + test_info = { + 'tool_version': constant.VERSION, + 'source_path': test_result_path, + } for attrib_path in ATTRS_TO_SHOW: tags, attr_name = parse_attrib_path(attrib_path) @@ -359,7 +361,8 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument( - '--report-file', + '-r', + '--report', required=True, help=( 'Path to a cts report, where a cts report could ' @@ -375,7 +378,7 @@ def main(): args = parser.parse_args() - report_file = args.report_file + report_file = args.report output_dir = args.output_dir if not os.path.exists(output_dir):