-
Notifications
You must be signed in to change notification settings - Fork 379
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
Handle ambigous profile/group parameters #4377
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
|
||
from abc import ABCMeta | ||
from enum import Enum | ||
from string import Template | ||
import collections | ||
import platform | ||
import sys | ||
import re | ||
|
||
from codechecker_analyzer import analyzer_context | ||
|
@@ -210,23 +212,40 @@ def initialize_checkers(self, | |
profiles = checker_labels.get_description('profile') | ||
guidelines = checker_labels.occurring_values('guideline') | ||
|
||
templ = Template("The ${entity} name '${identifier}' conflicts with a " | ||
"checker(-group) name. Please use -e ${entity}: to " | ||
"select checkers of a ${entity} or use -e group: " | ||
"to select checkers which have a name " | ||
"starting with '${identifier}'.") | ||
|
||
for identifier, enabled in cmdline_enable: | ||
if ':' in identifier: | ||
if "group:" in identifier: | ||
identifier = identifier.replace("group:", "") | ||
self.set_checker_enabled(identifier, enabled) | ||
|
||
elif ':' in identifier: | ||
for checker in checker_labels.checkers_by_labels([identifier]): | ||
self.set_checker_enabled(checker, enabled) | ||
|
||
elif identifier in profiles: | ||
if identifier in reserved_names: | ||
LOG.warning("Profile name '%s' conflicts with a " | ||
"checker(-group) name.", identifier) | ||
for checker in checker_labels.checkers_by_labels( | ||
[f'profile:{identifier}']): | ||
self.set_checker_enabled(checker, enabled) | ||
LOG.error(templ.substitute(entity="profile", | ||
identifier=identifier)) | ||
sys.exit(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is exit status 1 the proper exit code in case of configuration errors? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same applies 10 lines below |
||
else: | ||
for checker in checker_labels.checkers_by_labels( | ||
[f'profile:{identifier}']): | ||
self.set_checker_enabled(checker, enabled) | ||
|
||
elif identifier in guidelines: | ||
if identifier in reserved_names: | ||
LOG.warning("Guideline name '%s' conflicts with a " | ||
"checker(-group) name.", identifier) | ||
for checker in checker_labels.checkers_by_labels( | ||
[f'guideline:{identifier}']): | ||
self.set_checker_enabled(checker, enabled) | ||
LOG.error(templ.substitute(entity="guideline", | ||
identifier=identifier)) | ||
sys.exit(1) | ||
else: | ||
for checker in checker_labels.checkers_by_labels( | ||
[f'guideline:{identifier}']): | ||
self.set_checker_enabled(checker, enabled) | ||
|
||
else: | ||
self.set_checker_enabled(identifier, enabled) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ def available(ordered_checkers, available_checkers): | |
if checker_name.startswith('profile:') or \ | ||
checker_name.startswith('guideline:') or \ | ||
checker_name.startswith('severity:') or \ | ||
checker_name.startswith('sei-cert:'): | ||
checker_name.startswith('sei-cert:') or \ | ||
checker_name.startswith('group:'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you plan to introduce a new checker enable prefix, please add this to the documentation and help of CodeChecker analyze and CodeChecker check. |
||
continue | ||
|
||
name_match = False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,10 @@ def checkers_by_labels(self, labels): | |
if labels[0] == 'profile:security': | ||
return ['alpha.security'] | ||
|
||
if labels[0] == 'profile:sensitive': | ||
return ['alpha.core.BoolAssignment', | ||
'alpha.core.TestAfterDivZero'] | ||
|
||
if labels[0] == 'guideline:sei-cert': | ||
return ['alpha.core.CastSize', 'alpha.core.CastToStruct'] | ||
|
||
|
@@ -154,6 +158,10 @@ def f(checks, checkers): | |
'alpha.security.ArrayBound', | ||
'alpha.security.MallocOverflow'] | ||
|
||
sensitive_profile_alpha = [ | ||
'alpha.core.BoolAssignment', | ||
'alpha.core.TestAfterDivZero'] | ||
|
||
# "default" profile. | ||
default_profile = [ | ||
'security.FloatLoopCounter', | ||
|
@@ -175,6 +183,7 @@ def f(checks, checkers): | |
|
||
checkers = [] | ||
checkers.extend(map(add_description, security_profile_alpha)) | ||
checkers.extend(map(add_description, sensitive_profile_alpha)) | ||
checkers.extend(map(add_description, default_profile)) | ||
checkers.extend(map(add_description, cert_guideline)) | ||
checkers.extend(map(add_description, statisticsbased)) | ||
|
@@ -199,7 +208,7 @@ def f(checks, checkers): | |
|
||
# Enable alpha checkers explicitly. | ||
cfg_handler = ClangSA.construct_config_handler(args) | ||
cfg_handler.initialize_checkers(checkers, [('alpha', True)]) | ||
cfg_handler.initialize_checkers(checkers, [('group:alpha', True)]) | ||
self.assertTrue(all_with_status(CheckerState.ENABLED) | ||
(cfg_handler.checks(), security_profile_alpha)) | ||
self.assertTrue(all_with_status(CheckerState.ENABLED) | ||
|
@@ -216,10 +225,15 @@ def f(checks, checkers): | |
|
||
# Enable "security" profile checkers without "profile:" prefix. | ||
cfg_handler = ClangSA.construct_config_handler(args) | ||
cfg_handler.initialize_checkers(checkers, | ||
[('security', True)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you replacing the security prefix? enabling with sensitive? |
||
with self.assertRaises(SystemExit) as e: | ||
cfg_handler.initialize_checkers(checkers, [('security', True)]) | ||
self.assertEqual(e.exception.code, 1) | ||
|
||
# Enable "sensitive" profile checkers without "profile:" prefix. | ||
cfg_handler = ClangSA.construct_config_handler(args) | ||
cfg_handler.initialize_checkers(checkers, [('sensitive', True)]) | ||
self.assertTrue(all_with_status(CheckerState.ENABLED) | ||
(cfg_handler.checks(), security_profile_alpha)) | ||
(cfg_handler.checks(), sensitive_profile_alpha)) | ||
self.assertTrue(all_with_status(CheckerState.ENABLED) | ||
(cfg_handler.checks(), default_profile)) | ||
|
||
|
@@ -232,8 +246,7 @@ def f(checks, checkers): | |
|
||
# Enable "sei-cert" guideline checkers. | ||
cfg_handler = ClangSA.construct_config_handler(args) | ||
cfg_handler.initialize_checkers(checkers, | ||
[('sei-cert', True)]) | ||
cfg_handler.initialize_checkers(checkers, [('sei-cert', True)]) | ||
self.assertTrue(all_with_status(CheckerState.ENABLED) | ||
(cfg_handler.checks(), cert_guideline)) | ||
|
||
|
@@ -244,13 +257,6 @@ def f(checks, checkers): | |
self.assertTrue(all_with_status(CheckerState.DISABLED) | ||
(cfg_handler.checks(), cert_guideline)) | ||
|
||
# Disable "sei-cert" guideline checkers. | ||
cfg_handler = ClangSA.construct_config_handler(args) | ||
cfg_handler.initialize_checkers(checkers, | ||
[('sei-cert', False)]) | ||
self.assertTrue(all_with_status(CheckerState.DISABLED) | ||
(cfg_handler.checks(), cert_guideline)) | ||
|
||
cfg_handler = ClangSA.construct_config_handler(args) | ||
cfg_handler.initialize_checkers(checkers, | ||
[('default', False), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be very specific about what conflicts with what. So if you can provide an exact error message instead of
...with a checker(-group)...
then please be specific.