kunit: run kunit_tool from any directory
PATCH 1/1 kunit: run kunit_tool from any directory
Implemented small fix so that the script changes work directories to the linux directory where 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.
--- tools/testing/kunit/kunit.py | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/testing/kunit/kunit.py +10 -0
@@ -35,6 +35,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()
@@ -114,6 +121,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)
Signature · 1 line
2.25.0.341.g760bfbb309-goog
Quoted 9 lines · Heidi Fahim
Implemented small fix so that the script changes work directories to the linux directory where
kunit.pyis 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]>
Thanks!
Quoted 35 lines
--- tools/testing/kunit/kunit.py | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/testing/kunit/kunit.py +10
-1@@ -35,6 +35,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()@@ -114,6 +121,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) --2.25.0.341.g760bfbb309-goog
Quoted 19 lines
-----Original Message-----
From: Brendan Higgins
Sent: Monday, February 10, 2020 5:32 PM
To: Heidi Fahim <[email protected]>; David Gow <[email protected]>; Daniel Latypov <[email protected]>
Cc: open list:KERNEL SELFTEST FRAMEWORK <[email protected]>; KUnit Development <[email protected]>; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH] kunit: runkunit_toolfrom any directoryQuoted 8 lines · Heidi Fahim
Implemented small fix so that the script changes work directories to the linux directory where
kunit.pyis 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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Heidi Fahim <[email protected]>Reviewed-by Brendan Higgins <[email protected]>
Sorry - I'm not a current kunit user, but does this mean that the kernel source has to be present in order to run the unit tests? That's problematical for embedded systems. Maybe that's outside the scope of what unit tests were envisioned for?
-- Tim
Quoted 17 lines · Tim
Quoted 17 lines
-----Original Message-----
From: Brendan Higgins
Sent: Monday, February 10, 2020 5:32 PM
To: Heidi Fahim <[email protected]>; David Gow <[email protected]>; Daniel Latypov <[email protected]>
Cc: open list:KERNEL SELFTEST FRAMEWORK <[email protected]>; KUnit Development <[email protected]>; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH] kunit: runkunit_toolfrom any directoryQuoted 8 lines · Heidi Fahim
Implemented small fix so that the script changes work directories to the linux directory where
kunit.pyis 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.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Heidi Fahim <[email protected]>Reviewed-by Brendan Higgins <[email protected]>Sorry - I'm not a current kunit user, but does this mean that the kernel source has to be present in order to run the unit tests? That's problematical for embedded systems. Maybe that's outside the scope of what unit tests were envisioned for?
No worries.
It is already the case that the kunit_tool assumes you have the source. It's purpose is to build tests, run them, and collect results. We are working on separating these functions, but right now given that the script assumes it will build the kernel for you, it is necessarily the case that you have source.
You can, nevertheless, build and run KUnit tests without the use of our scripts, which should work for most applications.
Quoted 3 lines · Heidi Fahim
Implemented small fix so that the script changes work directories to the
linux directory where
kunit.pyis run. This enables the user to run
s/linux directory where/root of the linux kernel source tree from which/
The existing wording implies that the cd is to .../tools/testing/kunit/
-Frank
Quoted 39 lines
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]>--- tools/testing/kunit/kunit.py | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/testing/kunit/kunit.py +10
-0@@ -35,6 +35,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()@@ -114,6 +121,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)