From 6538406b78e03f70e085d70c73f034bf3bb2de94 Mon Sep 17 00:00:00 2001 From: bruntib Date: Thu, 21 Nov 2024 14:59:17 +0100 Subject: [PATCH] [feat] Unique reports by different annotations Two report should also be considered different if they differ only in their annotations. --- .../report/hash.py | 4 ++ .../dynamic_results/test_dynamic_results.py | 17 +++++-- ...idy_0212cbc2c7194b7a5d431a18ff51bb1c.plist | 48 +++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/tools/report-converter/codechecker_report_converter/report/hash.py b/tools/report-converter/codechecker_report_converter/report/hash.py index a5f4854f03..7d0ee24772 100644 --- a/tools/report-converter/codechecker_report_converter/report/hash.py +++ b/tools/report-converter/codechecker_report_converter/report/hash.py @@ -198,6 +198,10 @@ def get_report_path_hash(report: Report) -> str: col = str(event.column) report_path_hash += f"{line}|{col}|{event.message}|{event.file.path}" + if report.annotations: + for k, v in report.annotations.items(): + report_path_hash += f"|{k}|{v}" + report_path_hash += report.checker_name if report.report_hash: report_path_hash += report.report_hash diff --git a/web/tests/functional/dynamic_results/test_dynamic_results.py b/web/tests/functional/dynamic_results/test_dynamic_results.py index d3b7e3bafc..2611155b14 100644 --- a/web/tests/functional/dynamic_results/test_dynamic_results.py +++ b/web/tests/functional/dynamic_results/test_dynamic_results.py @@ -102,7 +102,7 @@ def test_sort_by_timestamp(self): results = self._cc_client.getRunResults( None, 500, 0, None, ReportFilter(), None, False) - self.assertEqual(len(results), 4) + self.assertEqual(len(results), 5) sort_timestamp = SortMode(SortType.TIMESTAMP, Order.ASC) @@ -147,7 +147,7 @@ def test_filter_by_attribute(self): results = self._cc_client.getRunResults( None, 500, 0, None, testcase_filter, None, False) - self.assertEqual(len(results), 3) + self.assertEqual(len(results), 4) self.assertTrue(all(map( lambda report: report.annotations['testcase'].startswith('TC-'), @@ -160,7 +160,7 @@ def test_count_by_attribute(self): num = self._cc_client.getRunResultCount( None, ReportFilter(), None) - self.assertEqual(num, 4) + self.assertEqual(num, 5) testcase_filter = ReportFilter(annotations=[Pair( first='testcase', @@ -170,3 +170,14 @@ def test_count_by_attribute(self): None, testcase_filter, None) self.assertEqual(num, 2) + + def test_unique_path_hash(self): + """Test that the unique path hash is calculated when two reports differ + only in their annotations.""" + results = self._cc_client.getRunResults( + None, 500, 0, None, ReportFilter(), None, False) + + # The main.c_lang-tidy.plist test file contains two + # bugprone-sizeof-expression reports that differ in their annotations. + # They should be considered as different reports. + self.assertEqual(len(results), 5) diff --git a/web/tests/projects/dynamic/main.c_clang-tidy_0212cbc2c7194b7a5d431a18ff51bb1c.plist b/web/tests/projects/dynamic/main.c_clang-tidy_0212cbc2c7194b7a5d431a18ff51bb1c.plist index 6565e6a0d2..20ec7d713f 100644 --- a/web/tests/projects/dynamic/main.c_clang-tidy_0212cbc2c7194b7a5d431a18ff51bb1c.plist +++ b/web/tests/projects/dynamic/main.c_clang-tidy_0212cbc2c7194b7a5d431a18ff51bb1c.plist @@ -52,6 +52,54 @@ + + category + bugprone + check_name + bugprone-sizeof-expression + description + suspicious usage of 'sizeof(K)'; did you mean 'K'? + issue_hash_content_of_line_in_context + 34f8bd4635566816af99c68456d2efc0 + report-annotation + + timestamp + 2001-02-02 09:01 + testcase + TS-2 + testcase + TC-2 + + location + + col + 3 + file + 0 + line + 7 + + path + + + depth + 0 + kind + event + location + + col + 3 + file + 0 + line + 7 + + message + suspicious usage of 'sizeof(K)'; did you mean 'K'? + + + category clang