kunit: test: Improve error messages for kunit_tool when kunitconfig is invalid
PATCH 1/1 kunit: test: Improve error messages for kunit_tool when kunitconfig is invalid
Previous error message for invalid kunitconfig was vague. Added to it so that it lists invalid fields and prompts for them to be removed. Added validate_config function returning whether or not this kconfig is valid.
--- tools/testing/kunit/kunit_kernel.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit_kernel.py +15 -12
@@ -93,6 +93,19 @@ class LinuxSourceTree(object): return False return True + def validate_config(self, build_dir): + kconfig_path = get_kconfig_path(build_dir) + validated_kconfig = kunit_config.Kconfig() + validated_kconfig.read_from_file(kconfig_path) + if not self._kconfig.is_subset_of(validated_kconfig): + invalid = self._kconfig.entries() - validated_kconfig.entries() + message = 'Provided Kconfig is not contained in validated .config. Invalid fields found in kunitconfig: %s' % ( + ', '.join([str(e) for e in invalid]) + ) + logging.error(message) + return False + return True + def build_config(self, build_dir): kconfig_path = get_kconfig_path(build_dir) if build_dir and not os.path.exists(build_dir):
@@ -103,12 +116,7 @@ class LinuxSourceTree(object): except ConfigError as e: logging.error(e) return False - validated_kconfig = kunit_config.Kconfig() - validated_kconfig.read_from_file(kconfig_path) - if not self._kconfig.is_subset_of(validated_kconfig): - logging.error('Provided Kconfig is not contained in validated .config!') - return False - return True + return self.validate_config(build_dir) def build_reconfig(self, build_dir): """Creates a new .config if it is not a subset of the kunitconfig."""
@@ -133,12 +141,7 @@ class LinuxSourceTree(object): except (ConfigError, BuildError) as e: logging.error(e) return False - used_kconfig = kunit_config.Kconfig() - used_kconfig.read_from_file(get_kconfig_path(build_dir)) - if not self._kconfig.is_subset_of(used_kconfig): - logging.error('Provided Kconfig is not contained in final config!') - return False - return True + return self.validate_config(build_dir) def run_kernel(self, args=[], timeout=None, build_dir=None): args.extend(['mem=256M'])
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
+David Gow
Quoted 6 lines · Heidi Fahim' via KUnit Development
Previous error message for invalid kunitconfig was vague. Added to it so that it lists invalid fields and prompts for them to be removed. Added
validate_configfunction returning whether or not this kconfig is valid.Signed-off-by Heidi Fahim <[email protected]>
Looks good to me other than one minor nit below.
Quoted 9 lines
--- tools/testing/kunit/kunit_kernel.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)tools/testing/kunit/kunit_kernel.py +0
-0
tools/testing/kunit/kunit_kernel.py class LinuxSourceTree(object): · line 102
Quoted 10 lines
tools/testing/kunit/kunit_kernel.py +7
-0@@ -93,6 +93,19 @@ class LinuxSourceTree(object): return False return True + def validate_config(self, build_dir): + kconfig_path = get_kconfig_path(build_dir) + validated_kconfig = kunit_config.Kconfig() + validated_kconfig.read_from_file(kconfig_path) + if not self._kconfig.is_subset_of(validated_kconfig): + invalid = self._kconfig.entries() - validated_kconfig.entries() + message = 'Provided Kconfig is not contained in validated .config. Invalid fields found in kunitconfig: %s' % (
nit: Rather than "Invalid fields found in kunitconfig", how about something like "Following fields found in kunitconfig, but not .config:"?
tools/testing/kunit/kunit_kernel.py class LinuxSourceTree(object): · line 111
Quoted 9 lines
tools/testing/kunit/kunit_kernel.py +6
-0+ ', '.join([str(e) for e in invalid]) + ) + logging.error(message) + return False + return True + def build_config(self, build_dir): kconfig_path = get_kconfig_path(build_dir) if build_dir and not os.path.exists(build_dir):
Thanks for the patch!
PATCH v2 1/1 kunit: test: Improve error messages for kunit_tool when kunitconfig is invalid
In reply to Heidi FahimPrevious error message for invalid kunitconfig was vague. Added to it so that it lists invalid fields and prompts for them to be removed. Added validate_config function returning whether or not this kconfig is valid.
---
Addressed Brendan's nit for error message
tools/testing/kunit/kunit_kernel.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
tools/testing/kunit/kunit_kernel.py +16 -12
@@ -93,6 +93,20 @@ class LinuxSourceTree(object): return False return True + def validate_config(self, build_dir): + kconfig_path = get_kconfig_path(build_dir) + validated_kconfig = kunit_config.Kconfig() + validated_kconfig.read_from_file(kconfig_path) + if not self._kconfig.is_subset_of(validated_kconfig): + invalid = self._kconfig.entries() - validated_kconfig.entries() + message = 'Provided Kconfig is not contained in validated .config. Following fields found in kunitconfig, ' \ + 'but not in .config: %s' % ( + ', '.join([str(e) for e in invalid]) + ) + logging.error(message) + return False + return True + def build_config(self, build_dir): kconfig_path = get_kconfig_path(build_dir) if build_dir and not os.path.exists(build_dir):
@@ -103,12 +117,7 @@ class LinuxSourceTree(object): except ConfigError as e: logging.error(e) return False - validated_kconfig = kunit_config.Kconfig() - validated_kconfig.read_from_file(kconfig_path) - if not self._kconfig.is_subset_of(validated_kconfig): - logging.error('Provided Kconfig is not contained in validated .config!') - return False - return True + return self.validate_config(build_dir) def build_reconfig(self, build_dir): """Creates a new .config if it is not a subset of the kunitconfig."""
@@ -133,12 +142,7 @@ class LinuxSourceTree(object): except (ConfigError, BuildError) as e: logging.error(e) return False - used_kconfig = kunit_config.Kconfig() - used_kconfig.read_from_file(get_kconfig_path(build_dir)) - if not self._kconfig.is_subset_of(used_kconfig): - logging.error('Provided Kconfig is not contained in final config!') - return False - return True + return self.validate_config(build_dir) def run_kernel(self, args=[], timeout=None, build_dir=None): args.extend(['mem=256M'])
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog