Linux-kselftest Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] kunit: run kunit_tool from any directory
@ 2020-02-11  0:25 Heidi Fahim
  2020-02-11  0:31 ` Brendan Higgins
  0 siblings, 1 reply; 4+ messages in thread
From: Heidi Fahim @ 2020-02-11  0:25 UTC (permalink / raw)
  To: brendanhiggins, linux-kselftest, kunit-dev, linux-kernel; +Cc: Heidi Fahim

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.

Signed-off-by: Heidi Fahim <heidifahim@google.com>
---
 tools/testing/kunit/kunit.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index e59eb9e7f923..3cc7be7b28a0 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -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


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

* Re: [PATCH] kunit: run kunit_tool from any directory
  2020-02-11  0:25 [PATCH] kunit: run kunit_tool from any directory Heidi Fahim
@ 2020-02-11  0:31 ` Brendan Higgins
  2020-02-11 18:26   ` Bird, Tim
  0 siblings, 1 reply; 4+ messages in thread
From: Brendan Higgins @ 2020-02-11  0:31 UTC (permalink / raw)
  To: Heidi Fahim, David Gow, Daniel Latypov
  Cc: open list:KERNEL SELFTEST FRAMEWORK, KUnit Development,
	Linux Kernel Mailing List

On Mon, Feb 10, 2020 at 4:26 PM Heidi Fahim <heidifahim@google.com> wrote:
>
> 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.
>
> Signed-off-by: Heidi Fahim <heidifahim@google.com>

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

Thanks!

> ---
>  tools/testing/kunit/kunit.py | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
> index e59eb9e7f923..3cc7be7b28a0 100755
> --- a/tools/testing/kunit/kunit.py
> +++ b/tools/testing/kunit/kunit.py
> @@ -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
>

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

* RE: [PATCH] kunit: run kunit_tool from any directory
  2020-02-11  0:31 ` Brendan Higgins
@ 2020-02-11 18:26   ` Bird, Tim
  2020-02-11 18:48     ` Brendan Higgins
  0 siblings, 1 reply; 4+ messages in thread
From: Bird, Tim @ 2020-02-11 18:26 UTC (permalink / raw)
  To: Brendan Higgins, Heidi Fahim, David Gow, Daniel Latypov
  Cc: open list:KERNEL SELFTEST FRAMEWORK, KUnit Development,
	Linux Kernel Mailing List



> -----Original Message-----
> From: Brendan Higgins
> Sent: Monday, February 10, 2020 5:32 PM
> To: Heidi Fahim <heidifahim@google.com>; David Gow <davidgow@google.com>; Daniel Latypov <dlatypov@google.com>
> Cc: open list:KERNEL SELFTEST FRAMEWORK <linux-kselftest@vger.kernel.org>; KUnit Development <kunit-dev@googlegroups.com>; Linux
> Kernel Mailing List <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH] kunit: run kunit_tool from any directory
> 
> On Mon, Feb 10, 2020 at 4:26 PM Heidi Fahim <heidifahim@google.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Heidi Fahim <heidifahim@google.com>
> 
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
> 
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


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

* Re: [PATCH] kunit: run kunit_tool from any directory
  2020-02-11 18:26   ` Bird, Tim
@ 2020-02-11 18:48     ` Brendan Higgins
  0 siblings, 0 replies; 4+ messages in thread
From: Brendan Higgins @ 2020-02-11 18:48 UTC (permalink / raw)
  To: Bird, Tim
  Cc: Heidi Fahim, David Gow, Daniel Latypov,
	open list:KERNEL SELFTEST FRAMEWORK, KUnit Development,
	Linux Kernel Mailing List

On Tue, Feb 11, 2020 at 10:26 AM Bird, Tim <Tim.Bird@sony.com> wrote:
> > -----Original Message-----
> > From: Brendan Higgins
> > Sent: Monday, February 10, 2020 5:32 PM
> > To: Heidi Fahim <heidifahim@google.com>; David Gow <davidgow@google.com>; Daniel Latypov <dlatypov@google.com>
> > Cc: open list:KERNEL SELFTEST FRAMEWORK <linux-kselftest@vger.kernel.org>; KUnit Development <kunit-dev@googlegroups.com>; Linux
> > Kernel Mailing List <linux-kernel@vger.kernel.org>
> > Subject: Re: [PATCH] kunit: run kunit_tool from any directory
> >
> > On Mon, Feb 10, 2020 at 4:26 PM Heidi Fahim <heidifahim@google.com> wrote:
> > >
> > > 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.
> > >
> > > Signed-off-by: Heidi Fahim <heidifahim@google.com>
> >
> > Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
> >
> 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.

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11  0:25 [PATCH] kunit: run kunit_tool from any directory Heidi Fahim
2020-02-11  0:31 ` Brendan Higgins
2020-02-11 18:26   ` Bird, Tim
2020-02-11 18:48     ` Brendan Higgins

Linux-kselftest Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kselftest/0 linux-kselftest/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kselftest linux-kselftest/ https://lore.kernel.org/linux-kselftest \
		linux-kselftest@vger.kernel.org
	public-inbox-index linux-kselftest

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kselftest


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git