summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Traut <manut@linutronix.de>2017-12-13 08:02:24 +0100
committerManuel Traut <manut@linutronix.de>2017-12-14 09:35:30 +0100
commitd31866270135b3360efddfb6e6d0a36096c57f42 (patch)
tree92eae1b933d84ea5f54b39403feb15ff79dbf767
parent572e2642b5cc0f6e51d0b64e59bfc8081aa2ab11 (diff)
print stdout/stderr during runtime
If pyjustest is used with a test command, that prints an input request to stdout and afterwards waits for the input, it waits forever. The reason for this is, that stdout and stderr is printed only after the test command was executed completely. Instead of printing stdout and stderr after execution of the test-command print it as it occurs. This also provides meaningful timestamps if run in a timestamp wrapped environment like jenkins. Signed-off-by: Manuel Traut <manut@linutronix.de> Reviewed-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
-rwxr-xr-xpyjutest41
1 files changed, 31 insertions, 10 deletions
diff --git a/pyjutest b/pyjutest
index 96766cb..ee04fdd 100755
--- a/pyjutest
+++ b/pyjutest
@@ -14,6 +14,7 @@ from subprocess import Popen, PIPE, STDOUT
from optparse import OptionParser
import os
+import select
import sys
import time
@@ -48,12 +49,39 @@ else:
start = time.time()
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
-out,err = p.communicate()
+fds = [ p.stdout, p.stderr ]
+
+out = ""
+err = ""
+
+while True:
+ readable, writable, exceptional = select.select(fds, [], [])
+ done = 0
+
+ if p.stderr in readable:
+ l = p.stderr.readline().decode('utf-8')
+ if len(l):
+ print(l[:-1], file=sys.stderr)
+ sys.stderr.flush()
+ err += l
+ else:
+ done = 1
+
+ if p.stdout in readable:
+ l = p.stdout.readline().decode('utf-8')
+ if len(l):
+ print(l[:-1])
+ sys.stdout.flush()
+ out += l
+ else:
+ if done:
+ break
+
+p.wait()
duration = time.time() - start
-tc = TestCase(opt.uname, opt.uclass, duration, out[:-1].decode('utf-8'),
- err[:-1].decode('utf-8'))
+tc = TestCase(opt.uname, opt.uclass, duration, out, err)
if p.returncode:
tc.add_failure_info(err, "return: %d" % p.returncode)
@@ -65,10 +93,3 @@ with open('pyjutest.dat', 'wb') as dat:
with open('pyjutest.xml', 'w') as xml:
TestSuite.to_file(xml, tss, prettyprint=True)
-
-print("%s STDOUT:" % opt.uname)
-for l in out.decode().split("\n"):
- print(l)
-print("%s STDERR:" % opt.uname)
-for l in err.decode().split("\n"):
- print(l, file=sys.stderr)