Skip to content

Commit

Permalink
kunit: tool: fix running kunit_tool from outside kernel tree
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
bjh83 authored and shuahkh committed Aug 31, 2020
1 parent 9123e3a commit 5578d00
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tools/testing/kunit/kunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,13 @@ def main(argv, linux=None):

cli_args = parser.parse_args(argv)

if get_kernel_root_path():
os.chdir(get_kernel_root_path())

if cli_args.subcommand == 'run':
if not os.path.exists(cli_args.build_dir):
os.mkdir(cli_args.build_dir)
create_default_kunitconfig()

if not linux:
linux = kunit_kernel.LinuxSourceTree()
Expand All @@ -257,6 +261,7 @@ def main(argv, linux=None):
if cli_args.build_dir:
if not os.path.exists(cli_args.build_dir):
os.mkdir(cli_args.build_dir)
create_default_kunitconfig()

if not linux:
linux = kunit_kernel.LinuxSourceTree()
Expand All @@ -270,10 +275,6 @@ def main(argv, linux=None):
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
elif cli_args.subcommand == 'build':
if cli_args.build_dir:
if not os.path.exists(cli_args.build_dir):
os.mkdir(cli_args.build_dir)

if not linux:
linux = kunit_kernel.LinuxSourceTree()

Expand All @@ -288,10 +289,6 @@ def main(argv, linux=None):
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
elif cli_args.subcommand == 'exec':
if cli_args.build_dir:
if not os.path.exists(cli_args.build_dir):
os.mkdir(cli_args.build_dir)

if not linux:
linux = kunit_kernel.LinuxSourceTree()

Expand Down

0 comments on commit 5578d00

Please sign in to comment.