linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] kunit: run kunit_tool from any directory
@ 2020-02-18 22:19 Heidi Fahim
  2020-02-19 22:18 ` shuah
  0 siblings, 1 reply; 3+ messages in thread
From: Heidi Fahim @ 2020-02-18 22:19 UTC (permalink / raw)
  To: brendanhiggins, linux-kselftest, kunit-dev, linux-kernel
  Cc: frowand.list, Heidi Fahim

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 <heidifahim@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
---
 tools/testing/kunit/kunit.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 3f552e847a14..060d960a7029 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -26,6 +26,8 @@ KunitResult = namedtuple('KunitResult', ['status','result'])
 KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs',
 					'build_dir', 'defconfig', 'json'])
 
+KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
+
 class KunitStatus(Enum):
 	SUCCESS = auto()
 	CONFIG_FAILURE = auto()
@@ -37,6 +39,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()
@@ -130,6 +139,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.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] kunit: run kunit_tool from any directory
  2020-02-18 22:19 [PATCH v2] kunit: run kunit_tool from any directory Heidi Fahim
@ 2020-02-19 22:18 ` shuah
       [not found]   ` <CAMVcs3uRj2uhFJXA+GEZmNjvNFF+3ODNmAON++scx26tnVhScA@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: shuah @ 2020-02-19 22:18 UTC (permalink / raw)
  To: Heidi Fahim, brendanhiggins, linux-kselftest, kunit-dev, linux-kernel
  Cc: frowand.list, shuah

Hi Heidi,

On 2/18/20 3:19 PM, Heidi Fahim wrote:
> 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 <heidifahim@google.com>
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

Thanks for  the patch. In the future please include changes from v1
to v2.

I am assuming this v2 addresses Frank's comments.

> ---
>   tools/testing/kunit/kunit.py | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
> index 3f552e847a14..060d960a7029 100755
> --- a/tools/testing/kunit/kunit.py
> +++ b/tools/testing/kunit/kunit.py
> @@ -26,6 +26,8 @@ KunitResult = namedtuple('KunitResult', ['status','result'])
>   KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs',
>   					'build_dir', 'defconfig', 'json'])
>   
> +KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
> +
>   class KunitStatus(Enum):
>   	SUCCESS = auto()
>   	CONFIG_FAILURE = auto()
> @@ -37,6 +39,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()
> @@ -130,6 +139,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)
> 

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] kunit: run kunit_tool from any directory
       [not found]   ` <CAMVcs3uRj2uhFJXA+GEZmNjvNFF+3ODNmAON++scx26tnVhScA@mail.gmail.com>
@ 2020-02-19 22:41     ` shuah
  0 siblings, 0 replies; 3+ messages in thread
From: shuah @ 2020-02-19 22:41 UTC (permalink / raw)
  To: Heidi Fahim
  Cc: Brendan Higgins, linux-kselftest, kunit-dev, linux-kernel,
	frowand.list, shuah

On 2/19/20 3:38 PM, Heidi Fahim wrote:
> On Wed, Feb 19, 2020 at 2:18 PM shuah <shuah@kernel.org 
> <mailto:shuah@kernel.org>> wrote:
> 
>     Hi Heidi,
> 
>     On 2/18/20 3:19 PM, Heidi Fahim wrote:
>      > 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 <heidifahim@google.com
>     <mailto:heidifahim@google.com>>
>      > Reviewed-by: Brendan Higgins <brendanhiggins@google.com
>     <mailto:brendanhiggins@google.com>>
> 
>     Thanks for  the patch. In the future please include changes from v1
>     to v2.
> 
>     I am assuming this v2 addresses Frank's comments.
> 
> 
> Sorry about that! Yes the only change here was in the commit message 
> addressing Frank's comment.
> 

Great. I will pull this in for 5.6-rc4.

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-19 22:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-18 22:19 [PATCH v2] kunit: run kunit_tool from any directory Heidi Fahim
2020-02-19 22:18 ` shuah
     [not found]   ` <CAMVcs3uRj2uhFJXA+GEZmNjvNFF+3ODNmAON++scx26tnVhScA@mail.gmail.com>
2020-02-19 22:41     ` shuah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).