Skip to content

Commit be886ba

Browse files
Heidifahimshuahkh
authored andcommitted
kunit: run kunit_tool from any directory
Implemented small fix so that the script changes work directories to the root of the linux kernel source tree from which kunit.py is run. This enables the user to run kunit from any working directory. Originally considered using os.path.join but this is more error prone as we would have to find all file path usages and modify them accordingly. Using os.chdir ensures that the entire script is run within /linux. Signed-off-by: Heidi Fahim <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent dde54b9 commit be886ba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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)

0 commit comments

Comments
 (0)