Skip to content

Commit

Permalink
Merge pull request #2858 from bruntib/enabled_checkers
Browse files Browse the repository at this point in the history
[cmd] Logging enabled checkers at the beginning of analysis
  • Loading branch information
csordasmarton authored Aug 31, 2020
2 parents b16365c + 1f4e1ea commit 1577240
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
7 changes: 7 additions & 0 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""


from collections import defaultdict
from multiprocessing.managers import SyncManager
import os
import shlex
Expand Down Expand Up @@ -240,6 +241,8 @@ def perform_analysis(args, skip_handler, context, actions, metadata_tool,
check_env = env.extend(context.path_env_extra,
context.ld_lib_path_extra)

enabled_checkers = defaultdict(list)

# Save some metadata information.
for analyzer in analyzers:
metadata_info = {
Expand All @@ -254,12 +257,16 @@ def perform_analysis(args, skip_handler, context, actions, metadata_tool,
state, _ = data
metadata_info['checkers'].update({
check: state == CheckerState.enabled})
enabled_checkers[analyzer].append(check)

version = config_map[analyzer].get_version(check_env)
metadata_info['analyzer_statistics']['version'] = version

metadata_tool['analyzers'][analyzer] = metadata_info

LOG.info("Enabled checkers:\n%s", '\n'.join(
k + ': ' + ', '.join(v) for k, v in enabled_checkers.items()))

if 'makefile' in args and args.makefile:
statistics_data = __get_statistics_data(args)

Expand Down
16 changes: 12 additions & 4 deletions analyzer/tests/functional/analyze/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ def test_analyzer_and_checker_config(self):
errors="ignore")
out, _ = process.communicate()

self.assertEqual(out.count('hicpp-use-nullptr'), 1)
# First it's printed as the member of enabled checkers at the beginning
# of the output. Second it is printed as a found report.
self.assertEqual(out.count('hicpp-use-nullptr'), 2)

analyze_cmd = [self._codechecker_cmd, "check", "-l", build_json,
"--analyzers", "clang-tidy", "-o", self.report_dir,
Expand All @@ -909,7 +911,9 @@ def test_analyzer_and_checker_config(self):
errors="ignore")
out, _ = process.communicate()

self.assertEqual(out.count('hicpp-use-nullptr'), 2)
# First it's printed as the member of enabled checkers at the beginning
# of the output. Second and third it is printed as a found report.
self.assertEqual(out.count('hicpp-use-nullptr'), 3)

analyze_cmd = [self._codechecker_cmd, "check", "-l", build_json,
"--analyzers", "clangsa", "-o", self.report_dir,
Expand All @@ -927,7 +931,9 @@ def test_analyzer_and_checker_config(self):
errors="ignore")
out, _ = process.communicate()

self.assertEqual(out.count('UninitializedObject'), 1)
# First it's printed as the member of enabled checkers at the beginning
# of the output. Second it is printed as a found report.
self.assertEqual(out.count('UninitializedObject'), 2)

analyze_cmd = [self._codechecker_cmd, "check", "-l", build_json,
"--analyzers", "clangsa", "-o", self.report_dir,
Expand All @@ -947,7 +953,9 @@ def test_analyzer_and_checker_config(self):
errors="ignore")
out, _ = process.communicate()

self.assertEqual(out.count('UninitializedObject'), 0)
# It is printed as the member of enabled checkers, but it gives no
# report.
self.assertEqual(out.count('UninitializedObject'), 1)

def test_invalid_compilation_database(self):
""" Warn in case of an invalid enabled checker. """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ def check_one_file(self, path, mode):
post_processed_output = []
skip_prefixes = ["[] - Analysis length:",
"[] - Previous analysis results",
"[] - Skipping input file"]
"[] - Skipping input file",
# Enabled checkers are listed in the beginning of
# analysis.
"[] - Enabled checkers:",
"clang-tidy:",
"clangsa:"]
for line in output:
# replace timestamps
line = re.sub(r'\[\w+ \d{4}-\d{2}-\d{2} \d{2}:\d{2}\]',
Expand Down

0 comments on commit 1577240

Please sign in to comment.