All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] test-runner: fix duplicate process output
@ 2021-03-02 16:30 James Prestwood
  2021-03-02 16:38 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: James Prestwood @ 2021-03-02 16:30 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2518 bytes --]

Process output was being duplicated when -v was used. This was
due to both stderr and stdout being appended to the write_fd list
as well as stderr being set to stdout in the Popen call.

To fix this only stdout should be appended to the write_fd list,
but then there comes a problem with closing the streams. stdout
cannot be closed, so instead it is special cased. A new
verbose boolean was added to Process which, if True, will
cause any output to be written to stdout explicitly.
---
 tools/test-runner | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

v2:
 * Added check for self.verbose so long running
   processes get an IO watch and can actually
   print to the console with -v.

diff --git a/tools/test-runner b/tools/test-runner
index eab0f0ab..a0c4022e 100755
--- a/tools/test-runner
+++ b/tools/test-runner
@@ -174,6 +174,7 @@ class Process:
 		self.write_fds = []
 		self.io_watch = None
 		self.cleanup = cleanup
+		self.verbose = False
 
 		if not namespace:
 			self.output_name = '/tmp/%s-out' % self.name
@@ -195,8 +196,7 @@ class Process:
 		if ctx:
 			# Verbose requested, add stdout/stderr to write FD list
 			if self.name in ctx.args.verbose:
-				self.write_fds.append(sys.__stdout__)
-				self.write_fds.append(sys.__stderr__)
+				self.verbose = True
 
 			# Add output file to FD list
 			if outfile:
@@ -230,11 +230,11 @@ class Process:
 			# the process is being waited for, the log/outfile bits
 			# will be handled after the process exists.
 			#
-			if self.write_fds != [] and not wait and not check:
+			if self.write_fds != [] and not wait and not check or self.verbose:
 				self.io_watch = GLib.io_add_watch(self.stdout, GLib.IO_IN,
 								self.io_callback)
 
-		self.pid = subprocess.Popen(self.args, stdout=self.stdout, stderr=subprocess.STDOUT,
+		self.pid = subprocess.Popen(self.args, stdout=self.stdout, stderr=self.stdout,
 						env=env, cwd=os.getcwd())
 
 		print("Starting process {}".format(self.pid.args))
@@ -261,6 +261,9 @@ class Process:
 
 			self.write_fds = []
 
+		if self.verbose:
+			sys.__stdout__.write(self.out)
+
 		print("%s returned %d" % (args[0], self.ret))
 		if check and self.ret != 0:
 			raise subprocess.CalledProcessError(returncode=self.ret, cmd=self.args)
@@ -284,6 +287,9 @@ class Process:
 		for f in self.write_fds:
 			f.write(data)
 
+		if self.verbose:
+			sys.__stdout__.write(data)
+
 		return True
 
 	def __del__(self):
-- 
2.26.2

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

* Re: [PATCH v2] test-runner: fix duplicate process output
  2021-03-02 16:30 [PATCH v2] test-runner: fix duplicate process output James Prestwood
@ 2021-03-02 16:38 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-03-02 16:38 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

Hi James,

On 3/2/21 10:30 AM, James Prestwood wrote:
> Process output was being duplicated when -v was used. This was
> due to both stderr and stdout being appended to the write_fd list
> as well as stderr being set to stdout in the Popen call.
> 
> To fix this only stdout should be appended to the write_fd list,
> but then there comes a problem with closing the streams. stdout
> cannot be closed, so instead it is special cased. A new
> verbose boolean was added to Process which, if True, will
> cause any output to be written to stdout explicitly.
> ---
>   tools/test-runner | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
> 
> v2:
>   * Added check for self.verbose so long running
>     processes get an IO watch and can actually
>     print to the console with -v.
> 

Applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2021-03-02 16:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 16:30 [PATCH v2] test-runner: fix duplicate process output James Prestwood
2021-03-02 16:38 ` Denis Kenzior

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.