linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kunit: tool: print out stderr from make (like build warnings)
@ 2020-10-29 22:09 Daniel Latypov
  2020-10-30  2:36 ` David Gow
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Latypov @ 2020-10-29 22:09 UTC (permalink / raw)
  To: brendanhiggins
  Cc: davidgow, linux-kernel, linux-kselftest, skhan, Daniel Latypov

Currently the tool redirects make stdout + stderr, and only shows them
if the make command fails.
This means build warnings aren't shown to the user.

This change prints the contents of stderr even if make succeeds, under
the assumption these are only build warnings or other messages the user
likely wants to see.

We drop stdout from the raised exception since we can no longer easily
collate stdout and stderr and just showing the stderr seems fine.

Example with a warning:

[14:56:35] Building KUnit Kernel ...
../lib/kunit/kunit-test.c: In function ‘kunit_test_successful_try’:
../lib/kunit/kunit-test.c:19:6: warning: unused variable ‘unused’ [-Wunused-variable]
   19 |  int unused;
      |      ^~~~~~

[14:56:40] Starting KUnit Kernel ...

Note the stderr has a trailing \n, and since we use print, we add
another, but it helps separate make and kunit.py output.

Example with a build error:

[15:02:45] Building KUnit Kernel ...
ERROR:root:../lib/kunit/kunit-test.c: In function ‘kunit_test_successful_try’:
../lib/kunit/kunit-test.c:19:2: error: unknown type name ‘invalid_type’
   19 |  invalid_type *test = data;
      |  ^~~~~~~~~~~~
...

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

diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index b557b1e93f98..326e82746d41 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -82,11 +82,16 @@ class LinuxSourceTreeOperations(object):
 		if build_dir:
 			command += ['O=' + build_dir]
 		try:
-			subprocess.check_output(command, stderr=subprocess.STDOUT)
+			proc = subprocess.Popen(command,
+						stderr=subprocess.PIPE,
+						stdout=subprocess.DEVNULL)
 		except OSError as e:
-			raise BuildError('Could not call execute make: ' + str(e))
-		except subprocess.CalledProcessError as e:
-			raise BuildError(e.output.decode())
+			raise BuildError('Could not call make command: ' + str(e))
+		_, stderr = proc.communicate()
+		if proc.returncode != 0:
+			raise BuildError(stderr.decode())
+		if stderr:  # likely only due to build warnings
+			print(stderr.decode())
 
 	def linux_bin(self, params, timeout, build_dir, outfile):
 		"""Runs the Linux UML binary. Must be named 'linux'."""

base-commit: 07e0887302450a62f51dba72df6afb5fabb23d1c
-- 
2.29.1.341.ge80a0c044ae-goog


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

* Re: [PATCH] kunit: tool: print out stderr from make (like build warnings)
  2020-10-29 22:09 [PATCH] kunit: tool: print out stderr from make (like build warnings) Daniel Latypov
@ 2020-10-30  2:36 ` David Gow
  0 siblings, 0 replies; 2+ messages in thread
From: David Gow @ 2020-10-30  2:36 UTC (permalink / raw)
  To: Daniel Latypov
  Cc: Brendan Higgins, Linux Kernel Mailing List,
	open list:KERNEL SELFTEST FRAMEWORK, Shuah Khan

On Fri, Oct 30, 2020 at 6:10 AM Daniel Latypov <dlatypov@google.com> wrote:
>
> Currently the tool redirects make stdout + stderr, and only shows them
> if the make command fails.
> This means build warnings aren't shown to the user.
>
> This change prints the contents of stderr even if make succeeds, under
> the assumption these are only build warnings or other messages the user
> likely wants to see.
>
> We drop stdout from the raised exception since we can no longer easily
> collate stdout and stderr and just showing the stderr seems fine.
>
> Example with a warning:
>
> [14:56:35] Building KUnit Kernel ...
> ../lib/kunit/kunit-test.c: In function ‘kunit_test_successful_try’:
> ../lib/kunit/kunit-test.c:19:6: warning: unused variable ‘unused’ [-Wunused-variable]
>    19 |  int unused;
>       |      ^~~~~~
>
> [14:56:40] Starting KUnit Kernel ...
>
> Note the stderr has a trailing \n, and since we use print, we add
> another, but it helps separate make and kunit.py output.
>
> Example with a build error:
>
> [15:02:45] Building KUnit Kernel ...
> ERROR:root:../lib/kunit/kunit-test.c: In function ‘kunit_test_successful_try’:
> ../lib/kunit/kunit-test.c:19:2: error: unknown type name ‘invalid_type’
>    19 |  invalid_type *test = data;
>       |  ^~~~~~~~~~~~
> ...
>
> Signed-off-by: Daniel Latypov <dlatypov@google.com>
> ---

Thanks a lot -- this was really bugging me, and works great.

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

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

end of thread, other threads:[~2020-10-30  2:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 22:09 [PATCH] kunit: tool: print out stderr from make (like build warnings) Daniel Latypov
2020-10-30  2:36 ` David Gow

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).