Skip to content

Commit 5578d00

Browse files
bjh83shuahkh
authored andcommitted
kunit: tool: fix running kunit_tool from outside kernel tree
Currently kunit_tool does not work correctly when executed from a path outside of the kernel tree, so make sure that the current working directory is correct and the kunit_dir is properly initialized before running. Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 9123e3a commit 5578d00

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

tools/testing/kunit/kunit.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,13 @@ def main(argv, linux=None):
237237

238238
cli_args = parser.parse_args(argv)
239239

240+
if get_kernel_root_path():
241+
os.chdir(get_kernel_root_path())
242+
240243
if cli_args.subcommand == 'run':
241244
if not os.path.exists(cli_args.build_dir):
242245
os.mkdir(cli_args.build_dir)
246+
create_default_kunitconfig()
243247

244248
if not linux:
245249
linux = kunit_kernel.LinuxSourceTree()
@@ -257,6 +261,7 @@ def main(argv, linux=None):
257261
if cli_args.build_dir:
258262
if not os.path.exists(cli_args.build_dir):
259263
os.mkdir(cli_args.build_dir)
264+
create_default_kunitconfig()
260265

261266
if not linux:
262267
linux = kunit_kernel.LinuxSourceTree()
@@ -270,10 +275,6 @@ def main(argv, linux=None):
270275
if result.status != KunitStatus.SUCCESS:
271276
sys.exit(1)
272277
elif cli_args.subcommand == 'build':
273-
if cli_args.build_dir:
274-
if not os.path.exists(cli_args.build_dir):
275-
os.mkdir(cli_args.build_dir)
276-
277278
if not linux:
278279
linux = kunit_kernel.LinuxSourceTree()
279280

@@ -288,10 +289,6 @@ def main(argv, linux=None):
288289
if result.status != KunitStatus.SUCCESS:
289290
sys.exit(1)
290291
elif cli_args.subcommand == 'exec':
291-
if cli_args.build_dir:
292-
if not os.path.exists(cli_args.build_dir):
293-
os.mkdir(cli_args.build_dir)
294-
295292
if not linux:
296293
linux = kunit_kernel.LinuxSourceTree()
297294

0 commit comments

Comments
 (0)