Skip to content

Commit

Permalink
kunit: run kunit_tool from any directory
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Heidifahim authored and shuahkh committed Feb 19, 2020
1 parent dde54b9 commit be886ba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/testing/kunit/kunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

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

KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]

class KunitStatus(Enum):
SUCCESS = auto()
CONFIG_FAILURE = auto()
Expand All @@ -35,6 +37,13 @@ def create_default_kunitconfig():
shutil.copyfile('arch/um/configs/kunit_defconfig',
kunit_kernel.kunitconfig_path)

def get_kernel_root_path():
parts = sys.argv[0] if not __file__ else __file__
parts = os.path.realpath(parts).split('tools/testing/kunit')
if len(parts) != 2:
sys.exit(1)
return parts[0]

def run_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitRequest) -> KunitResult:
config_start = time.time()
Expand Down Expand Up @@ -114,6 +123,9 @@ def main(argv, linux=None):
cli_args = parser.parse_args(argv)

if cli_args.subcommand == 'run':
if get_kernel_root_path():
os.chdir(get_kernel_root_path())

if cli_args.build_dir:
if not os.path.exists(cli_args.build_dir):
os.mkdir(cli_args.build_dir)
Expand Down

0 comments on commit be886ba

Please sign in to comment.