All of lore.kernel.org
 help / color / mirror / Atom feed
From: SeongJae Park <sjpark@amazon.com>
To: <brendanhiggins@google.com>
Cc: SeongJae Park <sjpark@amazon.de>, <skhan@linuxfoundation.org>,
	<linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2 1/2] kunit: tool: Respect '.kunitconfig' in 'build_dir'
Date: Thu, 22 Oct 2020 09:40:10 +0200	[thread overview]
Message-ID: <20201022074011.1990-2-sjpark@amazon.com> (raw)
In-Reply-To: <20201022074011.1990-1-sjpark@amazon.com>

From: SeongJae Park <sjpark@amazon.de>

Commit d43c7fb05765 ("kunit: tool: fix improper treatment of file
location") removed 'kunit_kernel.kunitconfig_path' modification for the
'--build_dir' argument.  As a result, running kunit with '--build_dir'
failed with below error message:

    Traceback (most recent call last):
      File "./tools/testing/kunit/kunit.py", line 325, in <module>
        main(sys.argv[1:])
      File "./tools/testing/kunit/kunit.py", line 245, in main
        linux = kunit_kernel.LinuxSourceTree()
      File "/home/sjpark/linux/tools/testing/kunit/kunit_kernel.py", line 109, in __init__
        self._kconfig.read_from_file(kunitconfig_path)
      File "/home/sjpark/linux/tools/testing/kunit/kunit_config.py", line 88, in read_from_file
        with open(path, 'r') as f:
    FileNotFoundError: [Errno 2] No such file or directory: '.kunitconfig'

The error removed after commit 82206a0c06cc ("kunit: tool: handle when
.kunit exists but .kunitconfig does not").  However, it was not the
intention of the commit.  It hides the error by ignoring the
'.kunitconfig' in the '--build_dir'.

This commit makes the tool to respect '.kunitconfig' in '--build_dir'
again, while respecting the constantness of
'kunit_kernel.kunitconfig_path', as modifying the variable makes the
'kunit_tool_test.py' fails

Fixes: d43c7fb05765 ("kunit: tool: fix improper treatment of file location")
Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
 tools/testing/kunit/kunit.py        | 26 ++++++++++++++------------
 tools/testing/kunit/kunit_kernel.py |  4 ++--
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index ebf5f5763dee..8bee2a5fee27 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -44,10 +44,10 @@ 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 create_default_kunitconfig(build_dir=''):
+	kunitconfig = os.path.join(build_dir, kunit_kernel.kunitconfig_path)
+	if not os.path.exists(kunitconfig):
+		shutil.copyfile('arch/um/configs/kunit_defconfig', kunitconfig)
 
 def get_kernel_root_path():
 	parts = sys.argv[0] if not __file__ else __file__
@@ -61,7 +61,7 @@ def config_tests(linux: kunit_kernel.LinuxSourceTree,
 	kunit_parser.print_with_timestamp('Configuring KUnit Kernel ...')
 
 	config_start = time.time()
-	create_default_kunitconfig()
+	create_default_kunitconfig(request.build_dir)
 	success = linux.build_reconfig(request.build_dir, request.make_options)
 	config_end = time.time()
 	if not success:
@@ -258,15 +258,17 @@ def main(argv, linux=None):
 	if get_kernel_root_path():
 		os.chdir(get_kernel_root_path())
 
+	kunitconfig_path = os.path.join(cli_args.build_dir,
+			kunit_kernel.kunitconfig_path)
 	if cli_args.subcommand == 'run':
 		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 os.path.exists(kunitconfig_path):
+			create_default_kunitconfig(cli_args.build_dir)
 
 		if not linux:
-			linux = kunit_kernel.LinuxSourceTree()
+			linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir)
 
 		request = KunitRequest(cli_args.raw_output,
 				       cli_args.timeout,
@@ -284,10 +286,10 @@ def main(argv, linux=None):
 			os.mkdir(cli_args.build_dir)
 
 		if not os.path.exists(kunit_kernel.kunitconfig_path):
-			create_default_kunitconfig()
+			create_default_kunitconfig(cli_args.build_dir)
 
 		if not linux:
-			linux = kunit_kernel.LinuxSourceTree()
+			linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir)
 
 		request = KunitConfigRequest(cli_args.build_dir,
 					     cli_args.make_options)
@@ -299,7 +301,7 @@ def main(argv, linux=None):
 			sys.exit(1)
 	elif cli_args.subcommand == 'build':
 		if not linux:
-			linux = kunit_kernel.LinuxSourceTree()
+			linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir)
 
 		request = KunitBuildRequest(cli_args.jobs,
 					    cli_args.build_dir,
@@ -313,7 +315,7 @@ def main(argv, linux=None):
 			sys.exit(1)
 	elif cli_args.subcommand == 'exec':
 		if not linux:
-			linux = kunit_kernel.LinuxSourceTree()
+			linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir)
 
 		exec_request = KunitExecRequest(cli_args.timeout,
 						cli_args.build_dir,
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index b557b1e93f98..7dd4268665a8 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -109,9 +109,9 @@ def get_kconfig_path(build_dir):
 class LinuxSourceTree(object):
 	"""Represents a Linux kernel source tree with KUnit tests."""
 
-	def __init__(self):
+	def __init__(self, build_dir):
 		self._kconfig = kunit_config.Kconfig()
-		self._kconfig.read_from_file(kunitconfig_path)
+		self._kconfig.read_from_file(os.path.join(build_dir, kunitconfig_path))
 		self._ops = LinuxSourceTreeOperations()
 		signal.signal(signal.SIGINT, self.signal_handler)
 
-- 
2.17.1


  reply	other threads:[~2020-10-22  7:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22  7:40 [PATCH v2 0/2] kunit: tool: Respect '.kunitconfig' in '--build_dir' SeongJae Park
2020-10-22  7:40 ` SeongJae Park [this message]
2020-10-22  7:40 ` [PATCH v2 2/2] kunit: tool: Mark 'kunittest_config' as constant again SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201022074011.1990-2-sjpark@amazon.com \
    --to=sjpark@amazon.com \
    --cc=brendanhiggins@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=sjpark@amazon.de \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.