-
Notifications
You must be signed in to change notification settings - Fork 383
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
Add functionality to validate analyzer and checker options #4204
Conversation
670041a
to
cdb5ec7
Compare
cdb5ec7
to
fadef54
Compare
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.
Please check the analyzer name as well, and clear up the wording in the error msg.
if 'analyzer_config' in args and isinstance(args.analyzer_config, | ||
list): |
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.
COuld decrease indentation here as well with an early return.
LOG.error(f"Invalid --analyzer-config parameter: " | ||
f"{analyzer_class.ANALYZER_NAME} has no " | ||
f"analyzer named {cfg.option}. Use the " | ||
f"'CodeChecker analyzers --analyzer-config " | ||
f"{analyzer_class.ANALYZER_NAME}' " | ||
f"command to check available analyzers.") |
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.
Wording is off here: under analyzer, we mean the actual plugins that CodeChecker implements around a static analyzer tool: clangsa, clang-tidy, cppcheck and gcc. While we should definitely check if the user gave a wrong analyzer name, but at this point you are checking the name of the config, not the analyzer. Your message states
$ CodeChecker check -b "clang++ -c test.cpp -o results/prune_paths_full -c --analyzer-config clangsa:hahaha=false --analyzers=clangsa
[ERROR 2024-04-09 11:21] - Invalid --analyzer-config parameter: clangsa has no analyzer named hahaha. Use the 'CodeChecker analyzers --analyzer-config clangsa' command to check available analyzers.
But should instead state:
$ CodeChecker check -b "clang++ -c test.cpp -o results/prune_paths_full -c --analyzer-config clangsa:hahaha=false --analyzers=clangsa
[ERROR 2024-04-09 11:21] - Invalid --analyzer-config parameter: clangsa has no config named hahaha. Use the 'CodeChecker analyzers --analyzer-config clangsa' command to check available configs.
@@ -797,6 +795,57 @@ def add_arguments_to_parser(parser): | |||
func=main, func_process_config_file=cmd_config.process_config_file) | |||
|
|||
|
|||
def validate_analyzer_parameter(args, analyzer): |
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.
Please don't take args as a parmeter.
"args", which contains everything you need to get CodeChecker going (user invocation, default values, etc). If you want to create a unit test for this function, it would look something like this:
args = {'analyzer_config' : ['clangsa:HAHAHA=true']}
self.assertFalse(validate_analyzer_parameter(args, 'clangsa'))
It is not impossible to conjure up an args
object to pass to this function for testing, but its fragile: if we ever need to read more values from args after a new feature or refactoring, all tests needs changing as well. Consider the following alterative:
# analyzer/tests/unit/test_checker_handling.py
self.assertFalse(validate_analyzer_parameter(["clangsa:HAHAHA=true"]))
This philosophy is one of the reasons behind that have soooo many function tests instead of unit tests. I may be painting a greater evil than what is actually present in the patch, but the idea stands.
Prefer having an easy-to-test boolean function
On another issue, its fine if you have a non-returning validator function, but it'd be nice for testing purposes and clarify if you had a boolean function as well for both clarity and testing pusposes.
I'd imagine the main function to look like this (which would be more in line with the existing input testing):
for analyzer_config in args.analyzer_configs:
if not is_valid_analyzer_config(analyzer_config):
LOG.error("SORT YOUR INPUT OUT!")
sys.exit(1);
for checker_config in args.checker_configs:
if not is_valid_checker_config(checker_config):
LOG.error("SORT YOUR INPUT OUT!")
sys.exit(1);
And everything else should happen behind the scenes.
fadef54
to
895a846
Compare
When specifying invalid checker and analyzer config, the CodeChecker analyze command used to give a warning but continued running. This functionality throws an error and prevents the analysis from running in this case.
895a846
to
1603968
Compare
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.
Analyzer value checking is still a little off. My other comments are just nitpicking.
Ensure that the analyzer_config parameter is set to a valid value | ||
by verifying if it belongs to the set of allowed values. | ||
""" | ||
analyzer = analyzer_conf.__getitem__(0).analyzer |
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.
Why didn't you use the bracket ([]
) operator? Also, you check all analyzer configs here, but only check the very first analyzer config for a valid analyzer field?
For this example, the second analyzer config this has an invalid analyzer field, but you miss it:
CodeChecker check -b "g++ test.cpp" --analyzer-config clangsa:prune-paths=false --analyzer-config:OOGABOOGA:no-false-positives=true
Co-authored-by: Kristóf Umann <dkszelethus@gmail.com>
Co-authored-by: Kristóf Umann <dkszelethus@gmail.com>
Co-authored-by: Kristóf Umann <dkszelethus@gmail.com>
Co-authored-by: Kristóf Umann <dkszelethus@gmail.com>
a529225
to
86e9191
Compare
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.
Almost there!
LOG.error(f"Invalid --analyzer-config parameter: {analyzer} is" | ||
f" not a supported analyzer. The supported analyzers are" | ||
f" {', '.join(a for a in supported_analyzers)}.") |
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.
Fun fact:
def func(a, b, c = 5): <--- these are parameters
pass
func("a", 3) <--- these are arguments
LOG.error(f"Invalid --analyzer-config parameter: {analyzer} is" | |
f" not a supported analyzer. The supported analyzers are" | |
f" {', '.join(a for a in supported_analyzers)}.") | |
LOG.error(f"Invalid argument to --analyzer-config: {analyzer} " | |
f"is not a supported analyzer. Supported analyzers are :" | |
f" {', '.join(a for a in supported_analyzers)}.") |
LOG.error(f"Invalid --analyzer-config parameter: " | ||
f"{analyzer_class.ANALYZER_NAME} has no config named " | ||
f"{cfg.option}. Use the 'CodeChecker analyzers " | ||
f"--analyzer-config {analyzer_class.ANALYZER_NAME}' " | ||
f"command to check available configs.") |
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.
Same here.
86e9191
to
4d70afc
Compare
|
||
if False in config_validator_res \ | ||
and 'no_missing_checker_error' not in args: | ||
sys.exit(1) |
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.
If the validation failed and this suppression flag isn't present, try to advertise it, somewhat like what I've done in #3866:
sys.exit(1) | |
LOG.info("Although it is not reccomended, if you want to " | |
"suppress errors relating to unknown " | |
"analyzer/checker configs, consider using the option " | |
"'--no-missing-checker-error'") | |
sys.exit(1) |
Also, please create tests for the interaction of the suppression flag and this validation checking. |
When specifying invalid checker and analyzer config, the CodeChecker analyze command used to give a warning but continued running. This functionality throws an error and prevents the analysis from running in this case. Co-authored-by: Kristóf Umann <dkszelethus@gmail.com>
4d70afc
to
4f23852
Compare
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.
LGTM, very well done!
When specifying invalid checker and analyzer config, the CodeChecker analyze command used to give a warning but continued running.
This functionality throws an error and prevents the analysis from running in this case.
CODECHKR-5784