Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Logging enabled checkers at the beginning of analysis #2858

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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