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

Exclude Polyspace defects with status "Not a Defect" or "Justified"; Add substitution of env variables for min/max possible for Robot and Polyspace #143

Merged
merged 24 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2369e6f
Exclude defect when the status is "Not a defect" or "Justified"
JokeWaumans Jul 25, 2024
f3ddb51
Indent .format
JokeWaumans Jul 25, 2024
5668a5d
Fix column number
JokeWaumans Jul 25, 2024
e248258
Fix typo; col is used instead of column
JokeWaumans Jul 25, 2024
10b1b16
Change some status to "Justified" or "Not a defect"; 5 less defects i…
JokeWaumans Jul 25, 2024
f03cfb1
Change test code quality to use the right column numbers
JokeWaumans Jul 25, 2024
ada326c
Add explanation about the excluded statuses in readme
JokeWaumans Jul 25, 2024
c13c003
Delete default status "No Action Planned" from the excluded statuses
JokeWaumans Jul 25, 2024
0b4eb2a
Make substitution of environment variables possible for min and max o…
JokeWaumans Jul 25, 2024
deecdd1
Fix over-indented
JokeWaumans Jul 25, 2024
dc0ca29
Fix bullet list
JokeWaumans Jul 25, 2024
7b57dc7
Update README.rst typo correction
pietvr Jul 25, 2024
b86dbb6
Rephrase
JokeWaumans Jul 25, 2024
bd2ee46
Rephrase README
JokeWaumans Jul 25, 2024
6e8cb8d
Revert "Fix over-indented"
JasperCraeghs Jul 25, 2024
ff64d74
Revert "Make substitution of environment variables possible for min a…
JasperCraeghs Jul 25, 2024
59b1209
Revert "Revert "Make substitution of environment variables possible f…
JasperCraeghs Jul 25, 2024
4923b47
Revert implementation part of 0b4eb2a649dc84a2dd2b6dd2b6b61f2482ce8b48
JasperCraeghs Jul 25, 2024
364686b
Update test suite after 4923b47e5ea7ac5c9e54863dbdf8259d299b43d5
JasperCraeghs Jul 25, 2024
47c1f70
Improve readability of error msg
JasperCraeghs Jul 25, 2024
5b79619
Substitute envvars in WarningsChecker.substitute_envvar
JasperCraeghs Jul 25, 2024
feb0553
Merge branch 'filter-poly-defects' of https://github.com/melexis/warn…
JasperCraeghs Jul 25, 2024
1911694
Remove redundant newline
JasperCraeghs Jul 25, 2024
cd52002
Delete minimum and maximum of docstring
JokeWaumans Jul 25, 2024
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
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ For example, "run-time check" is the family of Code Prover and "defect" is the f
The value of that key is a list, which contains the name of the column to check as a key and
the value of that column to check together with ``min`` and ``max`` values.

Note that all defects with one of the following statuses are excluded from the warnings and code quality report:
JokeWaumans marked this conversation as resolved.
Show resolved Hide resolved

- Justified
- Not a Defect
JasperCraeghs marked this conversation as resolved.
Show resolved Hide resolved

These statuses are used when you do not plan to fix your code in response to a result.
The status "No Action Planned" is not listed because this is a default status if you do not explicitly specify
a status in you annotation.
More info can be found `on this help page`_.

.. _`on this help page`: https://nl.mathworks.com/help/polyspace_access/ug/fix-or-comment-polyspace-results-web-browser.html

Example Checks
^^^^^^^^^^^^^^

Expand Down
41 changes: 30 additions & 11 deletions src/mlx/warnings/polyspace_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ def return_check_limits(self):
count += checker.return_check_limits()
return count

def config_parser(self, config, name):
''' Parsing configuration dict extracted by previously opened JSON or YAML file

Args:
config (dict): Content of configuration file
'''
try:
from .warnings import substitute_envvar

substitute_envvar(config, {'min', 'max'})
print("Config parsing for {name} completed".format(name=name))
except KeyError as err:
print("Incomplete config. Missing: {key}".format(key=err))

def parse_config(self, config):
"""Parsing configuration dict extracted by previously opened JSON or yaml/yml file

Expand Down Expand Up @@ -145,6 +159,7 @@ def parse_config(self, config):
column_name = key.lower()
check_value = value.lower()
checker = PolyspaceFamilyChecker(family_value, column_name, check_value, verbose=self.verbose)
self.config_parser(check, f"{family_value} ({column_name}:{check_value})")
checker.parse_config(check)
checker.cq_findings = self.cq_findings # share object with sub-checkers
self.checkers.append(checker)
Expand Down Expand Up @@ -243,7 +258,7 @@ def add_code_quality_finding(self, row):
if "line" in row:
finding["location"]["positions"]["begin"]["line"] = row["line"]
if "col" in row:
finding["location"]["positions"]["begin"]["column"] = row["line"]
finding["location"]["positions"]["begin"]["column"] = row["col"]
finding["description"] = description
exclude = ("new", "status", "severity", "comment", "key")
row_without_key = [value for key, value in row.items() if key not in exclude]
Expand All @@ -258,13 +273,17 @@ def check(self, content):
content (dict): The row of the TSV file
'''
if content[self.column_name].lower() == self.check_value:
tab_sep_string = "\t".join(content.values())
if not self._is_excluded(tab_sep_string):
self.count = self.count + 1
self.counted_warnings.append('family: {} -> {}: {}'.format(
self.family_value,
self.column_name,
self.check_value
))
if self.cq_enabled and content["color"].lower() != "green":
self.add_code_quality_finding(content)
if content["status"].lower() in ["not a defect", "justified"]:
self.print_when_verbose("Excluded row {!r} because the status is 'Not a defect' or 'Justified'"
.format(content))
else:
tab_sep_string = "\t".join(content.values())
if not self._is_excluded(tab_sep_string):
self.count = self.count + 1
self.counted_warnings.append('family: {} -> {}: {}'.format(
self.family_value,
self.column_name,
self.check_value
))
if self.cq_enabled and content["color"].lower() != "green":
self.add_code_quality_finding(content)
15 changes: 15 additions & 0 deletions src/mlx/warnings/robot_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,27 @@ def return_check_limits(self):
count += checker.return_check_limits()
return count

def config_parser(self, config, name):
''' Parsing configuration dict extracted by previously opened JSON or YAML file

Args:
config (dict): Content of configuration file
'''
try:
from .warnings import substitute_envvar

substitute_envvar(config, {'min', 'max'})
print("Config parsing for suite {name!r} completed".format(name=name))
except KeyError as err:
print("Incomplete config. Missing: {key}".format(key=err))

def parse_config(self, config):
self.checkers = []
check_suite_name = config.get('check_suite_names', True)
for suite_config in config['suites']:
checker = RobotSuiteChecker(suite_config['name'], check_suite_name=check_suite_name,
verbose=self.verbose)
self.config_parser(suite_config, suite_config['name'])
checker.parse_config(suite_config)
self.checkers.append(checker)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_in/config_example_polyspace_exclude.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"run-time check": [
{
"color": "red",
"min": 0,
"max": 0
"min": "$MIN_POLY_WARNINGS",
"max": "${MAX_POLY_WARNINGS}"
},
{
"color": "orange",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_in/config_example_robot.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
},
{
"name": "b4d su1te name",
"min": 0,
"max": 0
"min": "$MIN_ROBOT_WARNINGS",
"max": "${MAX_ROBOT_WARNINGS}"
}
]
},
Expand Down
12 changes: 6 additions & 6 deletions tests/test_in/polyspace.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ ID Family Group Color New Check Information Function File Status Severity Commen
22036 Run-time Check Numerical Green no Overflow dummy_function() dummy_file_name.c Unreviewed Unset C4992326D32B4698C491 6 4
22065 Run-time Check Data flow Green no Non-initialized local variable dummy_function() dummy_file_name.c Unreviewed Unset C49953E693A45698C489 5 5
22035 Run-time Check Data flow Green no Non-initialized local variable dummy_function() dummy_file_name.c Unreviewed Unset C499232693A45698C491 5 6
21989 Run-time Check Numerical Green no Overflow dummy_function() dummy_file_name.c Unreviewed Unset C4997327D32B4698C881 6 7
21989 Run-time Check Numerical Green no Overflow dummy_function() dummy_file_name.c Not a defect Unset C4997327D32B4698C881 6 7
19928 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 62C8B1F4CA9126336A 6 8
19962 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 62D8A9F4CA91263472 7 9
19962 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Not a defect Unset 62D8A9F4CA91263472 7 9
19526 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C899F4CA9126316A 7 10
19424 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.h Unreviewed Unset 62E489F4CA91263262 6 11
19429 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.h Unreviewed Unset 62E4A1F4CA91263162 6 2
19429 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.h Justified Unset 62E4A1F4CA91263162 6 2
19442 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.h Unreviewed Unset 62C091F4CA91263170 7 3
19450 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.h Unreviewed Unset 62C091F4CA91263170 7 3
19450 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.h Justified Unset 62C091F4CA91263170 7 3
19375 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C089F4CA9126326C 8 4
19378 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C091F4CA9126316E 8 5
19377 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C091F4CA9126336A 7 6
19357 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8A9F4CA91263368 7 7
19352 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8A9F4CA91263760 8 8
19351 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8A9F4CA91263862 8 9
19351 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Justified Unset 66C8A9F4CA91263862 8 9
19355 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8A9F4CA91263962 9 10
19354 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset CC9153E995234C62C091 9 11
19358 Run-time Check Numerical Orange no Overflow Origin: Path related issue dummy_function() dummy_file_name.c Unreviewed Unset CC9153E995234C62C0C1 8 3
19360 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8B1F4CA91263262 8 4
19349 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8C1F4CA91263262 9 5
19345 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8C1F4CA91263470 9 6
19344 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66C8C1F4CA91263572 10 7
19339 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66CC91F4CA91263464 10 8
19339 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Not a defect Unset 66CC91F4CA91263464 10 8
19338 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66CC91F4CA91263468 9 9
19336 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset 66CC91F4CA91263970 9 10
19335 Run-time Check Numerical Orange no Overflow dummy_function() dummy_file_name.c Unreviewed Unset CC9923E995234C62C0C9 10 11
Expand Down
Loading
Loading