mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kunit: tool: fix display of make errors
@ 2020-09-30 18:31 Daniel Latypov
  2020-09-30 20:00 ` Brendan Higgins
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Latypov @ 2020-09-30 18:31 UTC (permalink / raw)
  To: Brendan Higgins, David Gow, Shuah Khan
  Cc: kunit-dev, linux-kselftest, linux-kernel, Daniel Latypov

CalledProcessError stores the output of the failed process as `bytes`,
not a `str`.

So when we log it on build error, the make output is all crammed into
one line with "\n" instead of actually printing new lines.

After this change, we get readable output with new lines, e.g.
>   CC      lib/kunit/kunit-example-test.o
> In file included from ../lib/kunit/test.c:9:
> ../include/kunit/test.h:22:1: error: unknown type name ‘invalid_type_that_causes_compile’
>    22 | invalid_type_that_causes_compile errors;
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> make[3]: *** [../scripts/Makefile.build:283: lib/kunit/test.o] Error 1

Secondly, trying to concat exceptions to strings will fail with
> TypeError: can only concatenate str (not "OSError") to str
so fix this with an explicit cast to str.

Signed-off-by: Daniel Latypov <dlatypov@google.com>
---
 tools/testing/kunit/kunit_kernel.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index e20e2056cb38..0e19089f62f0 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -36,9 +36,9 @@ class LinuxSourceTreeOperations(object):
 		try:
 			subprocess.check_output(['make', 'mrproper'], stderr=subprocess.STDOUT)
 		except OSError as e:
-			raise ConfigError('Could not call make command: ' + e)
+			raise ConfigError('Could not call make command: ' + str(e))
 		except subprocess.CalledProcessError as e:
-			raise ConfigError(e.output)
+			raise ConfigError(e.output.decode())
 
 	def make_olddefconfig(self, build_dir, make_options):
 		command = ['make', 'ARCH=um', 'olddefconfig']
@@ -49,9 +49,9 @@ class LinuxSourceTreeOperations(object):
 		try:
 			subprocess.check_output(command, stderr=subprocess.STDOUT)
 		except OSError as e:
-			raise ConfigError('Could not call make command: ' + e)
+			raise ConfigError('Could not call make command: ' + str(e))
 		except subprocess.CalledProcessError as e:
-			raise ConfigError(e.output)
+			raise ConfigError(e.output.decode())
 
 	def make_allyesconfig(self):
 		kunit_parser.print_with_timestamp(
@@ -79,9 +79,9 @@ class LinuxSourceTreeOperations(object):
 		try:
 			subprocess.check_output(command, stderr=subprocess.STDOUT)
 		except OSError as e:
-			raise BuildError('Could not call execute make: ' + e)
+			raise BuildError('Could not call execute make: ' + str(e))
 		except subprocess.CalledProcessError as e:
-			raise BuildError(e.output)
+			raise BuildError(e.output.decode())
 
 	def linux_bin(self, params, timeout, build_dir, outfile):
 		"""Runs the Linux UML binary. Must be named 'linux'."""

base-commit: ccc1d052eff9f3cfe59d201263903fe1d46c79a5
-- 
2.28.0.709.gb0816b6eb0-goog


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

* Re: [PATCH] kunit: tool: fix display of make errors
  2020-09-30 18:31 [PATCH] kunit: tool: fix display of make errors Daniel Latypov
@ 2020-09-30 20:00 ` Brendan Higgins
  0 siblings, 0 replies; 2+ messages in thread
From: Brendan Higgins @ 2020-09-30 20:00 UTC (permalink / raw)
  To: Daniel Latypov
  Cc: David Gow, Shuah Khan, KUnit Development,
	open list:KERNEL SELFTEST FRAMEWORK, Linux Kernel Mailing List

On Wed, Sep 30, 2020 at 11:32 AM Daniel Latypov <dlatypov@google.com> wrote:
>
> CalledProcessError stores the output of the failed process as `bytes`,
> not a `str`.
>
> So when we log it on build error, the make output is all crammed into
> one line with "\n" instead of actually printing new lines.
>
> After this change, we get readable output with new lines, e.g.
> >   CC      lib/kunit/kunit-example-test.o
> > In file included from ../lib/kunit/test.c:9:
> > ../include/kunit/test.h:22:1: error: unknown type name ‘invalid_type_that_causes_compile’
> >    22 | invalid_type_that_causes_compile errors;
> >       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > make[3]: *** [../scripts/Makefile.build:283: lib/kunit/test.o] Error 1
>
> Secondly, trying to concat exceptions to strings will fail with
> > TypeError: can only concatenate str (not "OSError") to str
> so fix this with an explicit cast to str.
>
> Signed-off-by: Daniel Latypov <dlatypov@google.com>

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

Cheers!

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

end of thread, other threads:[~2020-09-30 20:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 18:31 [PATCH] kunit: tool: fix display of make errors Daniel Latypov
2020-09-30 20:00 ` Brendan Higgins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®