diff mbox series

[v1,1/3] kunit: Do not pollute source directory with generated files (.kunitconfig)

Message ID 20201015152348.65147-1-andriy.shevchenko@linux.intel.com
State Accepted
Commit fcdb0bc08ced274078f371e1e0fe6421a97fa9f2
Headers show
Series [v1,1/3] kunit: Do not pollute source directory with generated files (.kunitconfig) | expand

Commit Message

Andy Shevchenko Oct. 15, 2020, 3:23 p.m. UTC
When --build_dir is provided use it and do not pollute source directory
which even can be mounted over network or read-only.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 tools/testing/kunit/kunit.py        | 25 ++++++++++++-------------
 tools/testing/kunit/kunit_kernel.py | 24 +++++++++++++++++++-----
 2 files changed, 31 insertions(+), 18 deletions(-)

Comments

Brendan Higgins Oct. 23, 2020, 8:37 p.m. UTC | #1
On Thu, Oct 15, 2020 at 8:23 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> When --build_dir is provided use it and do not pollute source directory
> which even can be mounted over network or read-only.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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

One minor nit below:

> ---
>  tools/testing/kunit/kunit.py        | 25 ++++++++++++-------------
>  tools/testing/kunit/kunit_kernel.py | 24 +++++++++++++++++++-----
>  2 files changed, 31 insertions(+), 18 deletions(-)
>
> diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
> index ebf5f5763dee..1907bf9aacac 100755
> --- a/tools/testing/kunit/kunit.py
> +++ b/tools/testing/kunit/kunit.py
> @@ -11,7 +11,6 @@ import argparse
>  import sys
>  import os
>  import time
> -import shutil
>
>  from collections import namedtuple
>  from enum import Enum, auto
> @@ -44,11 +43,6 @@ class KunitStatus(Enum):
>         BUILD_FAILURE = auto()
>         TEST_FAILURE = auto()
>
> -def create_default_kunitconfig():
> -       if not os.path.exists(kunit_kernel.kunitconfig_path):
> -               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')
> @@ -61,7 +55,6 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
>         kunit_parser.print_with_timestamp('Configuring KUnit Kernel ...')
>
>         config_start = time.time()
> -       create_default_kunitconfig()
>         success = linux.build_reconfig(request.build_dir, request.make_options)
>         config_end = time.time()
>         if not success:
> @@ -262,12 +255,12 @@ def main(argv, linux=None):
>                 if not os.path.exists(cli_args.build_dir):
>                         os.mkdir(cli_args.build_dir)
>
> -               if not os.path.exists(kunit_kernel.kunitconfig_path):
> -                       create_default_kunitconfig()
> -
>                 if not linux:
>                         linux = kunit_kernel.LinuxSourceTree()
>
> +               linux.create_unitconfig(cli_args.build_dir)
> +               linux.read_unitconfig(cli_args.build_dir)
> +
>                 request = KunitRequest(cli_args.raw_output,
>                                        cli_args.timeout,
>                                        cli_args.jobs,
> @@ -283,12 +276,12 @@ def main(argv, linux=None):
>                                 not os.path.exists(cli_args.build_dir)):
>                         os.mkdir(cli_args.build_dir)
>
> -               if not os.path.exists(kunit_kernel.kunitconfig_path):
> -                       create_default_kunitconfig()
> -
>                 if not linux:
>                         linux = kunit_kernel.LinuxSourceTree()
>
> +               linux.create_unitconfig(cli_args.build_dir)
> +               linux.read_unitconfig(cli_args.build_dir)
> +
>                 request = KunitConfigRequest(cli_args.build_dir,
>                                              cli_args.make_options)
>                 result = config_tests(linux, request)
> @@ -301,6 +294,9 @@ def main(argv, linux=None):
>                 if not linux:
>                         linux = kunit_kernel.LinuxSourceTree()
>
> +               linux.create_unitconfig(cli_args.build_dir)
> +               linux.read_unitconfig(cli_args.build_dir)
> +
>                 request = KunitBuildRequest(cli_args.jobs,
>                                             cli_args.build_dir,
>                                             cli_args.alltests,
> @@ -315,6 +311,9 @@ def main(argv, linux=None):
>                 if not linux:
>                         linux = kunit_kernel.LinuxSourceTree()
>
> +               linux.create_unitconfig(cli_args.build_dir)
> +               linux.read_unitconfig(cli_args.build_dir)
> +
>                 exec_request = KunitExecRequest(cli_args.timeout,
>                                                 cli_args.build_dir,
>                                                 cli_args.alltests)
> diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
> index b557b1e93f98..412dc5e3102b 100644
> --- a/tools/testing/kunit/kunit_kernel.py
> +++ b/tools/testing/kunit/kunit_kernel.py
> @@ -6,10 +6,10 @@
>  # Author: Felix Guo <felixguoxiuping@gmail.com>
>  # Author: Brendan Higgins <brendanhiggins@google.com>
>
> -
>  import logging
>  import subprocess
>  import os
> +import shutil
>  import signal
>
>  from contextlib import ExitStack
> @@ -18,7 +18,8 @@ import kunit_config
>  import kunit_parser
>
>  KCONFIG_PATH = '.config'
> -kunitconfig_path = '.kunitconfig'
> +KUNITCONFIG_PATH = '.kunitconfig'
> +DEFAULT_KUNITCONFIG_PATH = 'arch/um/configs/kunit_defconfig'
>  BROKEN_ALLCONFIG_PATH = 'tools/testing/kunit/configs/broken_on_uml.config'
>
>  class ConfigError(Exception):
> @@ -99,19 +100,22 @@ class LinuxSourceTreeOperations(object):
>                                                    stderr=subprocess.STDOUT)
>                         process.wait(timeout)
>
> -
>  def get_kconfig_path(build_dir):
>         kconfig_path = KCONFIG_PATH
>         if build_dir:
>                 kconfig_path = os.path.join(build_dir, KCONFIG_PATH)
>         return kconfig_path
>
> +def get_kunitconfig_path(build_dir):
> +       kunitconfig_path = KUNITCONFIG_PATH
> +       if build_dir:
> +               kunitconfig_path = os.path.join(build_dir, KUNITCONFIG_PATH)
> +       return kunitconfig_path
> +
>  class LinuxSourceTree(object):
>         """Represents a Linux kernel source tree with KUnit tests."""
>
>         def __init__(self):
> -               self._kconfig = kunit_config.Kconfig()
> -               self._kconfig.read_from_file(kunitconfig_path)
>                 self._ops = LinuxSourceTreeOperations()
>                 signal.signal(signal.SIGINT, self.signal_handler)
>
> @@ -123,6 +127,16 @@ class LinuxSourceTree(object):
>                         return False
>                 return True
>
> +       def create_unitconfig(self, build_dir, defconfig=DEFAULT_KUNITCONFIG_PATH):

nit: I think this should be create_kunitconfig() since everything else
refers to it as kunitconfig.

> +               kunitconfig_path = get_kunitconfig_path(build_dir)
> +               if not os.path.exists(kunitconfig_path):
> +                       shutil.copyfile(defconfig, kunitconfig_path)
> +
> +       def read_unitconfig(self, build_dir):

nit: Same as above: s/read_unitconfig/read_kunitconfig/.

> +               kunitconfig_path = get_kunitconfig_path(build_dir)
> +               self._kconfig = kunit_config.Kconfig()
> +               self._kconfig.read_from_file(kunitconfig_path)
> +
>         def validate_config(self, build_dir):
>                 kconfig_path = get_kconfig_path(build_dir)
>                 validated_kconfig = kunit_config.Kconfig()
> --
> 2.28.0
Brendan Higgins Oct. 23, 2020, 8:39 p.m. UTC | #2
On Thu, Oct 15, 2020 at 8:23 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>

> When --build_dir is provided use it and do not pollute source directory

> which even can be mounted over network or read-only.

>

> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


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

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


Thanks!
Brendan Higgins Oct. 23, 2020, 8:41 p.m. UTC | #3
On Thu, Oct 15, 2020 at 8:23 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Helper allows to derive file names depending on --build_dir argument.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

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

Greatly appreciated!
diff mbox series

Patch

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index ebf5f5763dee..1907bf9aacac 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -11,7 +11,6 @@  import argparse
 import sys
 import os
 import time
-import shutil
 
 from collections import namedtuple
 from enum import Enum, auto
@@ -44,11 +43,6 @@  class KunitStatus(Enum):
 	BUILD_FAILURE = auto()
 	TEST_FAILURE = auto()
 
-def create_default_kunitconfig():
-	if not os.path.exists(kunit_kernel.kunitconfig_path):
-		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')
@@ -61,7 +55,6 @@  def config_tests(linux: kunit_kernel.LinuxSourceTree,
 	kunit_parser.print_with_timestamp('Configuring KUnit Kernel ...')
 
 	config_start = time.time()
-	create_default_kunitconfig()
 	success = linux.build_reconfig(request.build_dir, request.make_options)
 	config_end = time.time()
 	if not success:
@@ -262,12 +255,12 @@  def main(argv, linux=None):
 		if not os.path.exists(cli_args.build_dir):
 			os.mkdir(cli_args.build_dir)
 
-		if not os.path.exists(kunit_kernel.kunitconfig_path):
-			create_default_kunitconfig()
-
 		if not linux:
 			linux = kunit_kernel.LinuxSourceTree()
 
+		linux.create_unitconfig(cli_args.build_dir)
+		linux.read_unitconfig(cli_args.build_dir)
+
 		request = KunitRequest(cli_args.raw_output,
 				       cli_args.timeout,
 				       cli_args.jobs,
@@ -283,12 +276,12 @@  def main(argv, linux=None):
 				not os.path.exists(cli_args.build_dir)):
 			os.mkdir(cli_args.build_dir)
 
-		if not os.path.exists(kunit_kernel.kunitconfig_path):
-			create_default_kunitconfig()
-
 		if not linux:
 			linux = kunit_kernel.LinuxSourceTree()
 
+		linux.create_unitconfig(cli_args.build_dir)
+		linux.read_unitconfig(cli_args.build_dir)
+
 		request = KunitConfigRequest(cli_args.build_dir,
 					     cli_args.make_options)
 		result = config_tests(linux, request)
@@ -301,6 +294,9 @@  def main(argv, linux=None):
 		if not linux:
 			linux = kunit_kernel.LinuxSourceTree()
 
+		linux.create_unitconfig(cli_args.build_dir)
+		linux.read_unitconfig(cli_args.build_dir)
+
 		request = KunitBuildRequest(cli_args.jobs,
 					    cli_args.build_dir,
 					    cli_args.alltests,
@@ -315,6 +311,9 @@  def main(argv, linux=None):
 		if not linux:
 			linux = kunit_kernel.LinuxSourceTree()
 
+		linux.create_unitconfig(cli_args.build_dir)
+		linux.read_unitconfig(cli_args.build_dir)
+
 		exec_request = KunitExecRequest(cli_args.timeout,
 						cli_args.build_dir,
 						cli_args.alltests)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index b557b1e93f98..412dc5e3102b 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -6,10 +6,10 @@ 
 # Author: Felix Guo <felixguoxiuping@gmail.com>
 # Author: Brendan Higgins <brendanhiggins@google.com>
 
-
 import logging
 import subprocess
 import os
+import shutil
 import signal
 
 from contextlib import ExitStack
@@ -18,7 +18,8 @@  import kunit_config
 import kunit_parser
 
 KCONFIG_PATH = '.config'
-kunitconfig_path = '.kunitconfig'
+KUNITCONFIG_PATH = '.kunitconfig'
+DEFAULT_KUNITCONFIG_PATH = 'arch/um/configs/kunit_defconfig'
 BROKEN_ALLCONFIG_PATH = 'tools/testing/kunit/configs/broken_on_uml.config'
 
 class ConfigError(Exception):
@@ -99,19 +100,22 @@  class LinuxSourceTreeOperations(object):
 						   stderr=subprocess.STDOUT)
 			process.wait(timeout)
 
-
 def get_kconfig_path(build_dir):
 	kconfig_path = KCONFIG_PATH
 	if build_dir:
 		kconfig_path = os.path.join(build_dir, KCONFIG_PATH)
 	return kconfig_path
 
+def get_kunitconfig_path(build_dir):
+	kunitconfig_path = KUNITCONFIG_PATH
+	if build_dir:
+		kunitconfig_path = os.path.join(build_dir, KUNITCONFIG_PATH)
+	return kunitconfig_path
+
 class LinuxSourceTree(object):
 	"""Represents a Linux kernel source tree with KUnit tests."""
 
 	def __init__(self):
-		self._kconfig = kunit_config.Kconfig()
-		self._kconfig.read_from_file(kunitconfig_path)
 		self._ops = LinuxSourceTreeOperations()
 		signal.signal(signal.SIGINT, self.signal_handler)
 
@@ -123,6 +127,16 @@  class LinuxSourceTree(object):
 			return False
 		return True
 
+	def create_unitconfig(self, build_dir, defconfig=DEFAULT_KUNITCONFIG_PATH):
+		kunitconfig_path = get_kunitconfig_path(build_dir)
+		if not os.path.exists(kunitconfig_path):
+			shutil.copyfile(defconfig, kunitconfig_path)
+
+	def read_unitconfig(self, build_dir):
+		kunitconfig_path = get_kunitconfig_path(build_dir)
+		self._kconfig = kunit_config.Kconfig()
+		self._kconfig.read_from_file(kunitconfig_path)
+
 	def validate_config(self, build_dir):
 		kconfig_path = get_kconfig_path(build_dir)
 		validated_kconfig = kunit_config.Kconfig()