Skip to content

Commit 3908814

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: print out stderr from make (like build warnings)
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> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 873ddeb commit 3908814

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

tools/testing/kunit/kunit_kernel.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ def make(self, jobs, build_dir, make_options):
8484
if build_dir:
8585
command += ['O=' + build_dir]
8686
try:
87-
subprocess.check_output(command, stderr=subprocess.STDOUT)
87+
proc = subprocess.Popen(command,
88+
stderr=subprocess.PIPE,
89+
stdout=subprocess.DEVNULL)
8890
except OSError as e:
89-
raise BuildError('Could not call execute make: ' + str(e))
90-
except subprocess.CalledProcessError as e:
91-
raise BuildError(e.output.decode())
91+
raise BuildError('Could not call make command: ' + str(e))
92+
_, stderr = proc.communicate()
93+
if proc.returncode != 0:
94+
raise BuildError(stderr.decode())
95+
if stderr: # likely only due to build warnings
96+
print(stderr.decode())
9297

9398
def linux_bin(self, params, timeout, build_dir):
9499
"""Runs the Linux UML binary. Must be named 'linux'."""

0 commit comments

Comments
 (0)