mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-30 22:05:27 +00:00
Bugfix aa-decode test: Get stderr correctly, don't ignore stderr contents
Defining 'stderr = subprocess.STDOUT' as a default value for function did not work and the 'stderr' was always empty, thus also 'outerr' was always empty and not standard error contents was ever considered in any way. Best in fact was to remove excess function arguments as they were not even used and replace it with a simpler and less error prone structure. Even after reading 'stderr' correctly it did not help much as all tests used 'assertIn' which ignored excess output. Better replace the normal output with the error output if there ever was something, since stderr is most likely a serious thing and tests should stop on it.
This commit is contained in:
@@ -28,23 +28,33 @@ def subprocess_setup():
|
|||||||
# non-Python subprocesses expect.
|
# non-Python subprocesses expect.
|
||||||
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||||
|
|
||||||
def cmd(command, input = None, stderr = subprocess.STDOUT, stdout = subprocess.PIPE, stdin = None, timeout = None):
|
# Define only arguments that are actually ever used: command and stdin
|
||||||
|
def cmd(command, stdin=None):
|
||||||
'''Try to execute given command (array) and return its stdout, or return
|
'''Try to execute given command (array) and return its stdout, or return
|
||||||
a textual error if it failed.'''
|
a textual error if it failed.'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sp = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True, preexec_fn=subprocess_setup)
|
sp = subprocess.Popen(
|
||||||
|
command,
|
||||||
|
stdin=stdin,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
close_fds=True,
|
||||||
|
preexec_fn=subprocess_setup
|
||||||
|
)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
return [127, str(e)]
|
return [127, str(e)]
|
||||||
|
|
||||||
out, outerr = sp.communicate(input)
|
stdout, stderr = sp.communicate(input)
|
||||||
# Handle redirection of stdout
|
|
||||||
if out == None:
|
# If there was some error output, show that instead of stdout to ensure
|
||||||
out = b''
|
# test fails and does not mask potentially major warnings and errors.
|
||||||
# Handle redirection of stderr
|
if stderr:
|
||||||
if outerr == None:
|
out = stderr
|
||||||
outerr = b''
|
else:
|
||||||
return [sp.returncode, out.decode('utf-8') + outerr.decode('utf-8')]
|
out = stdout
|
||||||
|
|
||||||
|
return [sp.returncode, out.decode('utf-8')]
|
||||||
|
|
||||||
|
|
||||||
def mkstemp_fill(contents, suffix='', prefix='tst-aadecode-', dir=None):
|
def mkstemp_fill(contents, suffix='', prefix='tst-aadecode-', dir=None):
|
||||||
|
Reference in New Issue
Block a user