linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kunit: add --make_options
@ 2020-02-27  6:31 Greg Thelen
  2020-02-27 18:49 ` Brendan Higgins
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Greg Thelen @ 2020-02-27  6:31 UTC (permalink / raw)
  To: Brendan Higgins
  Cc: linux-kselftest, kunit-dev, linux-kernel, clang-built-linux, Greg Thelen

The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
optional --make_options flag to kunit.py allowing for the operator to
specify extra build options.

This allows use of the clang compiler for kunit:
  tools/testing/kunit/kunit.py run --defconfig \
    --make_options CC=clang --make_options HOSTCC=clang

Signed-off-by: Greg Thelen <gthelen@google.com>
---
 tools/testing/kunit/kunit.py        | 15 +++++++++++----
 tools/testing/kunit/kunit_kernel.py | 24 ++++++++++++++----------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index e59eb9e7f923..34a7ec8d9594 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -22,7 +22,9 @@ import kunit_parser
 
 KunitResult = namedtuple('KunitResult', ['status','result'])
 
-KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'defconfig'])
+KunitRequest = namedtuple('KunitRequest', ['raw_output', 'timeout', 'jobs',
+                                           'build_dir', 'defconfig',
+                                           'make_options'])
 
 class KunitStatus(Enum):
 	SUCCESS = auto()
@@ -38,7 +40,7 @@ def create_default_kunitconfig():
 def run_tests(linux: kunit_kernel.LinuxSourceTree,
 	      request: KunitRequest) -> KunitResult:
 	config_start = time.time()
-	success = linux.build_reconfig(request.build_dir)
+	success = linux.build_reconfig(request.build_dir, request.make_options)
 	config_end = time.time()
 	if not success:
 		return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel')
@@ -46,7 +48,7 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
 	kunit_parser.print_with_timestamp('Building KUnit Kernel ...')
 
 	build_start = time.time()
-	success = linux.build_um_kernel(request.jobs, request.build_dir)
+	success = linux.build_um_kernel(request.jobs, request.build_dir, request.make_options)
 	build_end = time.time()
 	if not success:
 		return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel')
@@ -111,6 +113,10 @@ def main(argv, linux=None):
 				help='Uses a default .kunitconfig.',
 				action='store_true')
 
+	run_parser.add_argument('--make_options',
+				help='X=Y make option, can be repeated.',
+				action='append')
+
 	cli_args = parser.parse_args(argv)
 
 	if cli_args.subcommand == 'run':
@@ -131,7 +137,8 @@ def main(argv, linux=None):
 				       cli_args.timeout,
 				       cli_args.jobs,
 				       cli_args.build_dir,
-				       cli_args.defconfig)
+				       cli_args.defconfig,
+				       cli_args.make_options)
 		result = run_tests(linux, request)
 		if result.status != KunitStatus.SUCCESS:
 			sys.exit(1)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index cc5d844ecca1..2b9b3fdbc13f 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -35,8 +35,10 @@ class LinuxSourceTreeOperations(object):
 		except subprocess.CalledProcessError as e:
 			raise ConfigError(e.output)
 
-	def make_olddefconfig(self, build_dir):
+	def make_olddefconfig(self, build_dir, make_options):
 		command = ['make', 'ARCH=um', 'olddefconfig']
+		if make_options:
+			command.extend(make_options)
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
@@ -46,8 +48,10 @@ class LinuxSourceTreeOperations(object):
 		except subprocess.CalledProcessError as e:
 			raise ConfigError(e.output)
 
-	def make(self, jobs, build_dir):
+	def make(self, jobs, build_dir, make_options):
 		command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
+		if make_options:
+			command.extend(make_options)
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
@@ -93,13 +97,13 @@ class LinuxSourceTree(object):
 			return False
 		return True
 
-	def build_config(self, build_dir):
+	def build_config(self, build_dir, make_options):
 		kconfig_path = get_kconfig_path(build_dir)
 		if build_dir and not os.path.exists(build_dir):
 			os.mkdir(build_dir)
 		self._kconfig.write_to_file(kconfig_path)
 		try:
-			self._ops.make_olddefconfig(build_dir)
+			self._ops.make_olddefconfig(build_dir, make_options)
 		except ConfigError as e:
 			logging.error(e)
 			return False
@@ -110,7 +114,7 @@ class LinuxSourceTree(object):
 			return False
 		return True
 
-	def build_reconfig(self, build_dir):
+	def build_reconfig(self, build_dir, make_options):
 		"""Creates a new .config if it is not a subset of the .kunitconfig."""
 		kconfig_path = get_kconfig_path(build_dir)
 		if os.path.exists(kconfig_path):
@@ -119,17 +123,17 @@ class LinuxSourceTree(object):
 			if not self._kconfig.is_subset_of(existing_kconfig):
 				print('Regenerating .config ...')
 				os.remove(kconfig_path)
-				return self.build_config(build_dir)
+				return self.build_config(build_dir, make_options)
 			else:
 				return True
 		else:
 			print('Generating .config ...')
-			return self.build_config(build_dir)
+			return self.build_config(build_dir, make_options)
 
-	def build_um_kernel(self, jobs, build_dir):
+	def build_um_kernel(self, jobs, build_dir, make_options):
 		try:
-			self._ops.make_olddefconfig(build_dir)
-			self._ops.make(jobs, build_dir)
+			self._ops.make_olddefconfig(build_dir, make_options)
+			self._ops.make(jobs, build_dir, make_options)
 		except (ConfigError, BuildError) as e:
 			logging.error(e)
 			return False
-- 
2.25.0.265.gbab2e86ba0-goog


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

* Re: [PATCH] kunit: add --make_options
  2020-02-27  6:31 [PATCH] kunit: add --make_options Greg Thelen
@ 2020-02-27 18:49 ` Brendan Higgins
  2020-02-27 18:54 ` David Gow
  2020-02-29  1:53 ` Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: Brendan Higgins @ 2020-02-27 18:49 UTC (permalink / raw)
  To: Greg Thelen
  Cc: open list:KERNEL SELFTEST FRAMEWORK, KUnit Development,
	Linux Kernel Mailing List, clang-built-linux

On Wed, Feb 26, 2020 at 10:31 PM Greg Thelen <gthelen@google.com> wrote:
>
> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
> optional --make_options flag to kunit.py allowing for the operator to
> specify extra build options.
>
> This allows use of the clang compiler for kunit:
>   tools/testing/kunit/kunit.py run --defconfig \
>     --make_options CC=clang --make_options HOSTCC=clang
>
> Signed-off-by: Greg Thelen <gthelen@google.com>

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

Thanks! This is something we have been meaning to do for a while!

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

* Re: [PATCH] kunit: add --make_options
  2020-02-27  6:31 [PATCH] kunit: add --make_options Greg Thelen
  2020-02-27 18:49 ` Brendan Higgins
@ 2020-02-27 18:54 ` David Gow
  2020-02-29  1:53 ` Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: David Gow @ 2020-02-27 18:54 UTC (permalink / raw)
  To: Greg Thelen
  Cc: Brendan Higgins, open list:KERNEL SELFTEST FRAMEWORK,
	KUnit Development, Linux Kernel Mailing List, clang-built-linux

On Wed, Feb 26, 2020 at 10:31 PM 'Greg Thelen' via KUnit Development
<kunit-dev@googlegroups.com> wrote:
>
> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
> optional --make_options flag to kunit.py allowing for the operator to
> specify extra build options.
>
> This allows use of the clang compiler for kunit:
>   tools/testing/kunit/kunit.py run --defconfig \
>     --make_options CC=clang --make_options HOSTCC=clang
>
> Signed-off-by: Greg Thelen <gthelen@google.com>

Tested-by: David Gow <davidgow@google.com>

Nice! This worked for me with all of the options I tried (and it's
great to see KUnit working on clang builds!)

-- David

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

* Re: [PATCH] kunit: add --make_options
  2020-02-27  6:31 [PATCH] kunit: add --make_options Greg Thelen
  2020-02-27 18:49 ` Brendan Higgins
  2020-02-27 18:54 ` David Gow
@ 2020-02-29  1:53 ` Nathan Chancellor
  2020-03-13 20:24   ` shuah
  2 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2020-02-29  1:53 UTC (permalink / raw)
  To: Greg Thelen
  Cc: Brendan Higgins, linux-kselftest, kunit-dev, linux-kernel,
	clang-built-linux

On Wed, Feb 26, 2020 at 10:31:34PM -0800, 'Greg Thelen' via Clang Built Linux wrote:
> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
> optional --make_options flag to kunit.py allowing for the operator to
> specify extra build options.
> 
> This allows use of the clang compiler for kunit:
>   tools/testing/kunit/kunit.py run --defconfig \
>     --make_options CC=clang --make_options HOSTCC=clang
> 
> Signed-off-by: Greg Thelen <gthelen@google.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

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

* Re: [PATCH] kunit: add --make_options
  2020-02-29  1:53 ` Nathan Chancellor
@ 2020-03-13 20:24   ` shuah
  2020-03-14  6:24     ` Greg Thelen
  0 siblings, 1 reply; 7+ messages in thread
From: shuah @ 2020-03-13 20:24 UTC (permalink / raw)
  To: Nathan Chancellor, Greg Thelen
  Cc: Brendan Higgins, linux-kselftest, kunit-dev, linux-kernel,
	clang-built-linux, shuah

On 2/28/20 6:53 PM, Nathan Chancellor wrote:
> On Wed, Feb 26, 2020 at 10:31:34PM -0800, 'Greg Thelen' via Clang Built Linux wrote:
>> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
>> optional --make_options flag to kunit.py allowing for the operator to
>> specify extra build options.
>>
>> This allows use of the clang compiler for kunit:
>>    tools/testing/kunit/kunit.py run --defconfig \
>>      --make_options CC=clang --make_options HOSTCC=clang
>>
>> Signed-off-by: Greg Thelen <gthelen@google.com>
> 
> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
> 

Please rebase on Linux 5.6-rc5 and resend. I tried applying
on Linux 5.6-rc1 as well as 5.6-rc5 and both fail.

thanks,
-- Shuah

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

* Re: [PATCH] kunit: add --make_options
  2020-03-13 20:24   ` shuah
@ 2020-03-14  6:24     ` Greg Thelen
  2020-03-23 15:09       ` shuah
  0 siblings, 1 reply; 7+ messages in thread
From: Greg Thelen @ 2020-03-14  6:24 UTC (permalink / raw)
  To: shuah, Nathan Chancellor
  Cc: Brendan Higgins, linux-kselftest, kunit-dev, linux-kernel,
	clang-built-linux, shuah

shuah <shuah@kernel.org> wrote:

> On 2/28/20 6:53 PM, Nathan Chancellor wrote:
>> On Wed, Feb 26, 2020 at 10:31:34PM -0800, 'Greg Thelen' via Clang Built Linux wrote:
>>> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
>>> optional --make_options flag to kunit.py allowing for the operator to
>>> specify extra build options.
>>>
>>> This allows use of the clang compiler for kunit:
>>>    tools/testing/kunit/kunit.py run --defconfig \
>>>      --make_options CC=clang --make_options HOSTCC=clang
>>>
>>> Signed-off-by: Greg Thelen <gthelen@google.com>
>> 
>> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
>> 
>
> Please rebase on Linux 5.6-rc5 and resend. I tried applying
> on Linux 5.6-rc1 as well as 5.6-rc5 and both fail.
>
> thanks,
> -- Shuah

Rebased onto v5.6-rc5 below:

From 0517b2c8b481535fb52bd86e94be1fec9aaeead7 Mon Sep 17 00:00:00 2001
From: Greg Thelen <gthelen@google.com>
Date: Wed, 26 Feb 2020 22:31:34 -0800
Subject: [PATCH v2] kunit: add --make_options

The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
optional --make_options flag to kunit.py allowing for the operator to
specify extra build options.

This allows use of the clang compiler for kunit:
  tools/testing/kunit/kunit.py run --defconfig \
    --make_options CC=clang --make_options HOSTCC=clang

Signed-off-by: Greg Thelen <gthelen@google.com>
---
 tools/testing/kunit/kunit.py        | 15 +++++++++++----
 tools/testing/kunit/kunit_kernel.py | 24 ++++++++++++++----------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 180ad1e1b04f..1aa4d14dc28d 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -22,7 +22,9 @@ import kunit_parser
 
 KunitResult = namedtuple('KunitResult', ['status','result'])
 
-KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'defconfig'])
+KunitRequest = namedtuple('KunitRequest', ['raw_output', 'timeout', 'jobs',
+                                           'build_dir', 'defconfig',
+                                           'make_options'])
 
 KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
 
@@ -47,7 +49,7 @@ def get_kernel_root_path():
 def run_tests(linux: kunit_kernel.LinuxSourceTree,
 	      request: KunitRequest) -> KunitResult:
 	config_start = time.time()
-	success = linux.build_reconfig(request.build_dir)
+	success = linux.build_reconfig(request.build_dir, request.make_options)
 	config_end = time.time()
 	if not success:
 		return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel')
@@ -55,7 +57,7 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
 	kunit_parser.print_with_timestamp('Building KUnit Kernel ...')
 
 	build_start = time.time()
-	success = linux.build_um_kernel(request.jobs, request.build_dir)
+	success = linux.build_um_kernel(request.jobs, request.build_dir, request.make_options)
 	build_end = time.time()
 	if not success:
 		return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel')
@@ -120,6 +122,10 @@ def main(argv, linux=None):
 				help='Uses a default .kunitconfig.',
 				action='store_true')
 
+	run_parser.add_argument('--make_options',
+				help='X=Y make option, can be repeated.',
+				action='append')
+
 	cli_args = parser.parse_args(argv)
 
 	if cli_args.subcommand == 'run':
@@ -143,7 +149,8 @@ def main(argv, linux=None):
 				       cli_args.timeout,
 				       cli_args.jobs,
 				       cli_args.build_dir,
-				       cli_args.defconfig)
+				       cli_args.defconfig,
+				       cli_args.make_options)
 		result = run_tests(linux, request)
 		if result.status != KunitStatus.SUCCESS:
 			sys.exit(1)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index d99ae75ef72f..27758d6d115b 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -35,8 +35,10 @@ class LinuxSourceTreeOperations(object):
 		except subprocess.CalledProcessError as e:
 			raise ConfigError(e.output)
 
-	def make_olddefconfig(self, build_dir):
+	def make_olddefconfig(self, build_dir, make_options):
 		command = ['make', 'ARCH=um', 'olddefconfig']
+		if make_options:
+			command.extend(make_options)
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
@@ -46,8 +48,10 @@ class LinuxSourceTreeOperations(object):
 		except subprocess.CalledProcessError as e:
 			raise ConfigError(e.output)
 
-	def make(self, jobs, build_dir):
+	def make(self, jobs, build_dir, make_options):
 		command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
+		if make_options:
+			command.extend(make_options)
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
@@ -107,19 +111,19 @@ class LinuxSourceTree(object):
 			return False
 		return True
 
-	def build_config(self, build_dir):
+	def build_config(self, build_dir, make_options):
 		kconfig_path = get_kconfig_path(build_dir)
 		if build_dir and not os.path.exists(build_dir):
 			os.mkdir(build_dir)
 		self._kconfig.write_to_file(kconfig_path)
 		try:
-			self._ops.make_olddefconfig(build_dir)
+			self._ops.make_olddefconfig(build_dir, make_options)
 		except ConfigError as e:
 			logging.error(e)
 			return False
 		return self.validate_config(build_dir)
 
-	def build_reconfig(self, build_dir):
+	def build_reconfig(self, build_dir, make_options):
 		"""Creates a new .config if it is not a subset of the .kunitconfig."""
 		kconfig_path = get_kconfig_path(build_dir)
 		if os.path.exists(kconfig_path):
@@ -128,17 +132,17 @@ class LinuxSourceTree(object):
 			if not self._kconfig.is_subset_of(existing_kconfig):
 				print('Regenerating .config ...')
 				os.remove(kconfig_path)
-				return self.build_config(build_dir)
+				return self.build_config(build_dir, make_options)
 			else:
 				return True
 		else:
 			print('Generating .config ...')
-			return self.build_config(build_dir)
+			return self.build_config(build_dir, make_options)
 
-	def build_um_kernel(self, jobs, build_dir):
+	def build_um_kernel(self, jobs, build_dir, make_options):
 		try:
-			self._ops.make_olddefconfig(build_dir)
-			self._ops.make(jobs, build_dir)
+			self._ops.make_olddefconfig(build_dir, make_options)
+			self._ops.make(jobs, build_dir, make_options)
 		except (ConfigError, BuildError) as e:
 			logging.error(e)
 			return False
-- 
2.25.1.481.gfbce0eb801-goog


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

* Re: [PATCH] kunit: add --make_options
  2020-03-14  6:24     ` Greg Thelen
@ 2020-03-23 15:09       ` shuah
  0 siblings, 0 replies; 7+ messages in thread
From: shuah @ 2020-03-23 15:09 UTC (permalink / raw)
  To: Greg Thelen, Nathan Chancellor
  Cc: Brendan Higgins, linux-kselftest, kunit-dev, linux-kernel,
	clang-built-linux, shuah

On 3/14/20 12:24 AM, Greg Thelen wrote:
> shuah <shuah@kernel.org> wrote:
> 
>> On 2/28/20 6:53 PM, Nathan Chancellor wrote:
>>> On Wed, Feb 26, 2020 at 10:31:34PM -0800, 'Greg Thelen' via Clang Built Linux wrote:
>>>> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
>>>> optional --make_options flag to kunit.py allowing for the operator to
>>>> specify extra build options.
>>>>
>>>> This allows use of the clang compiler for kunit:
>>>>     tools/testing/kunit/kunit.py run --defconfig \
>>>>       --make_options CC=clang --make_options HOSTCC=clang
>>>>
>>>> Signed-off-by: Greg Thelen <gthelen@google.com>
>>>
>>> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
>>>
>>
>> Please rebase on Linux 5.6-rc5 and resend. I tried applying
>> on Linux 5.6-rc1 as well as 5.6-rc5 and both fail.
>>
>> thanks,
>> -- Shuah
> 
> Rebased onto v5.6-rc5 below:
> 
>>From 0517b2c8b481535fb52bd86e94be1fec9aaeead7 Mon Sep 17 00:00:00 2001
> From: Greg Thelen <gthelen@google.com>
> Date: Wed, 26 Feb 2020 22:31:34 -0800
> Subject: [PATCH v2] kunit: add --make_options
> 
> The kunit.py utility builds an ARCH=um kernel and then runs it.  Add
> optional --make_options flag to kunit.py allowing for the operator to
> specify extra build options.
> 
> This allows use of the clang compiler for kunit:
>    tools/testing/kunit/kunit.py run --defconfig \
>      --make_options CC=clang --make_options HOSTCC=clang
> 
> Signed-off-by: Greg Thelen <gthelen@google.com>

I can't apply this one.

Please send a proper patch with either REBASE tag or v2.

thanks,
-- Shuah

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

end of thread, other threads:[~2020-03-23 15:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27  6:31 [PATCH] kunit: add --make_options Greg Thelen
2020-02-27 18:49 ` Brendan Higgins
2020-02-27 18:54 ` David Gow
2020-02-29  1:53 ` Nathan Chancellor
2020-03-13 20:24   ` shuah
2020-03-14  6:24     ` Greg Thelen
2020-03-23 15:09       ` 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).