Skip to content

Commit b98cce1

Browse files
committed
Merge tag 'linux-kselftest-kunit-5.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kunit fixes from Shuah Khan: "This Kselftest kunit update consists of fixes to documentation and the run-time tool from Brendan Higgins and Heidi Fahim" * tag 'linux-kselftest-kunit-5.6-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: run kunit_tool from any directory kunit: test: Improve error messages for kunit_tool when kunitconfig is invalid Documentation: kunit: fixed sphinx error in code block
2 parents 2fcc741 + be886ba commit b98cce1

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

Documentation/dev-tools/kunit/usage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ options to your ``.config``:
551551
Once the kernel is built and installed, a simple
552552

553553
.. code-block:: bash
554+
554555
modprobe example-test
555556
556557
...will run the tests.

tools/testing/kunit/kunit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'defconfig'])
2626

27+
KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
28+
2729
class KunitStatus(Enum):
2830
SUCCESS = auto()
2931
CONFIG_FAILURE = auto()
@@ -35,6 +37,13 @@ def create_default_kunitconfig():
3537
shutil.copyfile('arch/um/configs/kunit_defconfig',
3638
kunit_kernel.kunitconfig_path)
3739

40+
def get_kernel_root_path():
41+
parts = sys.argv[0] if not __file__ else __file__
42+
parts = os.path.realpath(parts).split('tools/testing/kunit')
43+
if len(parts) != 2:
44+
sys.exit(1)
45+
return parts[0]
46+
3847
def run_tests(linux: kunit_kernel.LinuxSourceTree,
3948
request: KunitRequest) -> KunitResult:
4049
config_start = time.time()
@@ -114,6 +123,9 @@ def main(argv, linux=None):
114123
cli_args = parser.parse_args(argv)
115124

116125
if cli_args.subcommand == 'run':
126+
if get_kernel_root_path():
127+
os.chdir(get_kernel_root_path())
128+
117129
if cli_args.build_dir:
118130
if not os.path.exists(cli_args.build_dir):
119131
os.mkdir(cli_args.build_dir)

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)