Skip to content

Commit

Permalink
Merge pull request Ericsson#4113 from bruntib/ignore_status
Browse files Browse the repository at this point in the history
[cfg] Add a config file to change review statuses
  • Loading branch information
dkrupp authored Dec 8, 2023
2 parents c422f91 + d885936 commit 23148e8
Show file tree
Hide file tree
Showing 20 changed files with 775 additions and 104 deletions.
28 changes: 18 additions & 10 deletions analyzer/codechecker_analyzer/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import psutil

from codechecker_common.logger import get_logger
from codechecker_common.review_status_handler import ReviewStatusHandler

from codechecker_statistics_collector.collectors.special_return_value import \
SpecialReturnValueCollector
Expand Down Expand Up @@ -217,8 +218,11 @@ def prepare_check(action, analyzer_config, output_dir,
return source_analyzer, rh


def handle_success(rh, result_file, result_base, skip_handlers,
capture_analysis_output, success_dir):
def handle_success(
rh, result_file, result_base, skip_handlers,
rs_handler: ReviewStatusHandler,
capture_analysis_output, success_dir
):
"""
Result postprocessing is required if the analysis was
successful (mainly clang tidy output conversion is done).
Expand All @@ -229,7 +233,7 @@ def handle_success(rh, result_file, result_base, skip_handlers,
save_output(os.path.join(success_dir, result_base),
rh.analyzer_stdout, rh.analyzer_stderr)

rh.postprocess_result(skip_handlers)
rh.postprocess_result(skip_handlers, rs_handler)

# Generated reports will be handled separately at store.

Expand Down Expand Up @@ -316,7 +320,8 @@ def handle_reproducer(source_analyzer, rh, zip_file, actions_map):


def handle_failure(
source_analyzer, rh, zip_file, result_base, actions_map, skip_handlers
source_analyzer, rh, zip_file, result_base, actions_map, skip_handlers,
rs_handler: ReviewStatusHandler
):
"""
If the analysis fails a debug zip is packed together which contains
Expand All @@ -331,7 +336,7 @@ def handle_failure(
checks = source_analyzer.config_handler.checks()
state = checks.get('clang-diagnostic-error', (CheckerState.enabled, ''))[0]
if state == CheckerState.enabled:
rh.postprocess_result(skip_handlers)
rh.postprocess_result(skip_handlers, rs_handler)

# Remove files that successfully analyzed earlier on.
plist_file = result_base + ".plist"
Expand Down Expand Up @@ -485,7 +490,7 @@ def check(check_data):
skiplist handler is None if no skip file was configured.
"""
actions_map, action, analyzer_config, \
output_dir, skip_handlers, quiet_output_on_stdout, \
output_dir, skip_handlers, rs_handler, quiet_output_on_stdout, \
capture_analysis_output, generate_reproducer, analysis_timeout, \
ctu_reanalyze_on_failure, \
output_dirs, statistics_data = check_data
Expand Down Expand Up @@ -603,12 +608,13 @@ def handle_analysis_result(success, zip_file=zip_file):

if success:
handle_success(rh, result_file, result_base,
skip_handlers, capture_analysis_output,
success_dir)
skip_handlers, rs_handler,
capture_analysis_output, success_dir)
elif not generate_reproducer:
handle_failure(source_analyzer, rh,
os.path.join(failed_dir, zip_file),
result_base, actions_map, skip_handlers)
result_base, actions_map, skip_handlers,
rs_handler)

if rh.analyzer_returncode == 0:
handle_analysis_result(success=True)
Expand Down Expand Up @@ -716,7 +722,8 @@ def skip_cpp(compile_actions, skip_handlers):


def start_workers(actions_map, actions, analyzer_config_map,
jobs, output_path, skip_handlers, metadata_tool,
jobs, output_path, skip_handlers,
rs_handler: ReviewStatusHandler, metadata_tool,
quiet_analyze, capture_analysis_output, generate_reproducer,
timeout, ctu_reanalyze_on_failure, statistics_data, manager,
compile_cmd_count):
Expand Down Expand Up @@ -783,6 +790,7 @@ def signal_handler(signum, frame):
analyzer_config_map.get(build_action.analyzer_type),
output_path,
skip_handlers,
rs_handler,
quiet_analyze,
capture_analysis_output,
generate_reproducer,
Expand Down
6 changes: 4 additions & 2 deletions analyzer/codechecker_analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from multiprocess.managers import SyncManager

from codechecker_common.logger import get_logger
from codechecker_common.review_status_handler import ReviewStatusHandler

from . import analyzer_context, analysis_manager, pre_analysis_manager, \
checkers
Expand Down Expand Up @@ -129,8 +130,8 @@ def __has_enabled_checker(ch: AnalyzerConfigHandler):
for _, (state, _) in ch.checks().items())


def perform_analysis(args, skip_handlers, actions, metadata_tool,
compile_cmd_count):
def perform_analysis(args, skip_handlers, rs_handler: ReviewStatusHandler,
actions, metadata_tool, compile_cmd_count):
"""
Perform static analysis via the given (or if not, all) analyzers,
in the given analysis context for the supplied build actions.
Expand Down Expand Up @@ -313,6 +314,7 @@ def perform_analysis(args, skip_handlers, actions, metadata_tool,
config_map, args.jobs,
args.output_path,
skip_handlers,
rs_handler,
metadata_tool,
'quiet' in args,
'capture_analysis_output' in args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from codechecker_report_converter.report.hash import get_report_hash, HashType
from codechecker_common.logger import get_logger
from codechecker_common.skiplist_handler import SkipListHandlers
from codechecker_common.review_status_handler import ReviewStatusHandler

from ..result_handler_base import ResultHandler

Expand All @@ -34,7 +35,11 @@ def __init__(self, *args, **kwargs):

super(ClangSAResultHandler, self).__init__(*args, **kwargs)

def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
def postprocess_result(
self,
skip_handlers: Optional[SkipListHandlers],
rs_handler: Optional[ReviewStatusHandler]
):
"""
Generate analyzer result output file which can be parsed and stored
into the database.
Expand All @@ -55,6 +60,10 @@ def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
for report in reports:
report.report_hash = get_report_hash(report, hash_type)

if rs_handler:
reports = [r for r in reports
if not rs_handler.should_ignore(r)]

report_file.create(
self.analyzer_result_file, reports, self.checker_labels,
self.analyzer_info)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from codechecker_common.logger import get_logger
from codechecker_common.skiplist_handler import SkipListHandlers
from codechecker_common.review_status_handler import ReviewStatusHandler

from ..result_handler_base import ResultHandler

Expand All @@ -36,7 +37,11 @@ def __init__(self, *args, **kwargs):

super(ClangTidyResultHandler, self).__init__(*args, **kwargs)

def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
def postprocess_result(
self,
skip_handlers: Optional[SkipListHandlers],
rs_handler: Optional[ReviewStatusHandler]
):
"""
Generate analyzer result output file which can be parsed and stored
into the database.
Expand All @@ -62,6 +67,9 @@ def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
for report in reports:
report.report_hash = get_report_hash(report, hash_type)

if rs_handler:
reports = [r for r in reports if not rs_handler.should_ignore(r)]

report_file.create(
self.analyzer_result_file, reports, self.checker_labels,
self.analyzer_info)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from codechecker_common.logger import get_logger
from codechecker_common.skiplist_handler import SkipListHandlers
from codechecker_common.review_status_handler import ReviewStatusHandler

from ..result_handler_base import ResultHandler

Expand All @@ -35,7 +36,11 @@ def __init__(self, *args, **kwargs):

super(CppcheckResultHandler, self).__init__(*args, **kwargs)

def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
def postprocess_result(
self,
skip_handlers: Optional[SkipListHandlers],
rs_handler: Optional[ReviewStatusHandler]
):
"""
Generate analyzer result output file which can be parsed and stored
into the database.
Expand All @@ -47,6 +52,7 @@ def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
source_dir_path=self.source_dir_path)

reports = [r for r in reports if not r.skip(skip_handlers)]

for report in reports:
# TODO check if prefix cascading still occurs.
if not report.checker_name.startswith("cppcheck-"):
Expand All @@ -72,6 +78,9 @@ def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
if bpe != report.bug_path_events[-1]:
report.bug_path_events.append(bpe)

if rs_handler:
reports = [r for r in reports if not rs_handler.should_ignore(r)]

report_file.create(
self.analyzer_result_file, reports, self.checker_labels,
self.analyzer_info)
10 changes: 9 additions & 1 deletion analyzer/codechecker_analyzer/analyzers/gcc/result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from codechecker_common.logger import get_logger
from codechecker_common.skiplist_handler import SkipListHandlers
from codechecker_common.review_status_handler import ReviewStatusHandler

from ..result_handler_base import ResultHandler

Expand Down Expand Up @@ -53,7 +54,11 @@ def __init__(self, *args, **kwargs):

super(GccResultHandler, self).__init__(*args, **kwargs)

def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
def postprocess_result(
self,
skip_handlers: Optional[SkipListHandlers],
rs_handler: Optional[ReviewStatusHandler]
):
"""
Generate analyzer result output file which can be parsed and stored
into the database.
Expand Down Expand Up @@ -107,6 +112,9 @@ def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
for report in reports:
report.report_hash = get_report_hash(report, hash_type)

if rs_handler:
reports = [r for r in reports if not rs_handler.should_ignore(r)]

report_file.create(
self.analyzer_result_file, reports, self.checker_labels,
self.analyzer_info)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from codechecker_analyzer import analyzer_context
from codechecker_common.logger import get_logger
from codechecker_common.skiplist_handler import SkipListHandlers
from codechecker_common.review_status_handler import ReviewStatusHandler


LOG = get_logger('analyzer')
Expand Down Expand Up @@ -181,7 +182,13 @@ def clean_results(self):
# There might be no result file if analysis failed.
LOG.debug(oserr)

def postprocess_result(self, skip_handlers: Optional[SkipListHandlers]):
# TODO: If the parameters are not optional then we can get rid of some
# extra checks.
def postprocess_result(
self,
skip_handlers: Optional[SkipListHandlers],
rs_handler: Optional[ReviewStatusHandler]
):
"""
Postprocess result if needed.
Should be called after the analyses finished.
Expand Down
16 changes: 12 additions & 4 deletions analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
analyzer_config, checker_config
from codechecker_analyzer.buildlog import log_parser

from codechecker_common import arg, logger, cmd_config
from codechecker_common import arg, logger, cmd_config, review_status_handler
from codechecker_common.skiplist_handler import SkipListHandler, \
SkipListHandlers
from codechecker_common.util import load_json
Expand Down Expand Up @@ -877,7 +877,7 @@ def __update_review_status_config(args):
if 'review_status_config' in args:
LOG.debug("Copying review status config file %s to %s",
args.review_status_config, rs_config_to_send)
shutil.copyfile(args.review_status_config, rs_config_to_send)
os.symlink(args.review_status_config, rs_config_to_send)


def __cleanup_metadata(metadata_prev, metadata):
Expand Down Expand Up @@ -984,6 +984,14 @@ def main(args):

# Process the skip list if present.
skip_handlers = __get_skip_handlers(args, compile_commands)
rs_handler = review_status_handler.ReviewStatusHandler(args.output_path)

try:
if 'review_status_config' in args:
rs_handler.set_review_status_config(args.review_status_config)
except ValueError as ex:
LOG.error(ex)
sys.exit(1)

ctu_or_stats_enabled = False
# Skip list is applied only in pre-analysis
Expand Down Expand Up @@ -1121,8 +1129,8 @@ def main(args):
LOG.debug_analyzer("Compile commands forwarded for analysis: %d",
compile_cmd_count.analyze)

analyzer.perform_analysis(args, skip_handlers, actions, metadata_tool,
compile_cmd_count)
analyzer.perform_analysis(args, skip_handlers, rs_handler, actions,
metadata_tool, compile_cmd_count)

__update_skip_file(args)
__update_review_status_config(args)
Expand Down
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def get_output_file_path(default_file_name: str) -> Optional[str]:

for dir_path, file_paths in report_file.analyzer_result_files(args.input):
review_status_cfg = os.path.join(dir_path, 'review_status.yaml')
if os.path.isfile(review_status_cfg):
if os.path.lexists(review_status_cfg):
try:
review_status_handler.set_review_status_config(
review_status_cfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ nofail:
$(CXX) -w nofail.cpp -o /dev/null
simple1:
$(CXX) -w simple1.cpp -o /dev/null
dir_simple1:
$(CXX) -w test_dir/simple1.cpp -o /dev/null
simple2:
$(CXX) -w simple2.cpp -o /dev/null
tidy_check:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$version: 1
rules:
- filters:
checker_name: core.DivideZero
actions:
review_status: false_positive
reason: Division by zero in test files is automatically intentional.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$version: 1
rules:
- filters:
filepath: "*/test_dir/*"
actions:
review_status: false_positive
reason: Division by zero in test files is automatically intentional.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$version: 1
rules:
- filters:
report_hash: 8459557f082fb0cc2d6150da71a7bcd3
actions:
review_status: false_positive
reason: Division by zero in test files is automatically intentional.
Loading

0 comments on commit 23148e8

Please sign in to comment.