Skip to content

Commit dde54b9

Browse files
Heidifahimshuahkh
authored andcommitted
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. Signed-off-by: Heidi Fahim <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Tested-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent e20d8e8 commit dde54b9

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tools/testing/kunit/kunit_kernel.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ def clean(self):
9393
return False
9494
return True
9595

96+
def validate_config(self, build_dir):
97+
kconfig_path = get_kconfig_path(build_dir)
98+
validated_kconfig = kunit_config.Kconfig()
99+
validated_kconfig.read_from_file(kconfig_path)
100+
if not self._kconfig.is_subset_of(validated_kconfig):
101+
invalid = self._kconfig.entries() - validated_kconfig.entries()
102+
message = 'Provided Kconfig is not contained in validated .config. Following fields found in kunitconfig, ' \
103+
'but not in .config: %s' % (
104+
', '.join([str(e) for e in invalid])
105+
)
106+
logging.error(message)
107+
return False
108+
return True
109+
96110
def build_config(self, build_dir):
97111
kconfig_path = get_kconfig_path(build_dir)
98112
if build_dir and not os.path.exists(build_dir):
@@ -103,12 +117,7 @@ def build_config(self, build_dir):
103117
except ConfigError as e:
104118
logging.error(e)
105119
return False
106-
validated_kconfig = kunit_config.Kconfig()
107-
validated_kconfig.read_from_file(kconfig_path)
108-
if not self._kconfig.is_subset_of(validated_kconfig):
109-
logging.error('Provided Kconfig is not contained in validated .config!')
110-
return False
111-
return True
120+
return self.validate_config(build_dir)
112121

113122
def build_reconfig(self, build_dir):
114123
"""Creates a new .config if it is not a subset of the .kunitconfig."""
@@ -133,12 +142,7 @@ def build_um_kernel(self, jobs, build_dir):
133142
except (ConfigError, BuildError) as e:
134143
logging.error(e)
135144
return False
136-
used_kconfig = kunit_config.Kconfig()
137-
used_kconfig.read_from_file(get_kconfig_path(build_dir))
138-
if not self._kconfig.is_subset_of(used_kconfig):
139-
logging.error('Provided Kconfig is not contained in final config!')
140-
return False
141-
return True
145+
return self.validate_config(build_dir)
142146

143147
def run_kernel(self, args=[], timeout=None, build_dir=''):
144148
args.extend(['mem=256M'])

0 commit comments

Comments
 (0)