diff --git a/avocado/test.py b/avocado/test.py index ae325d72edb15bf8a8854e79fba2f626fe67c6cc..3a7708e8151414d72139f15dff8580f90c282c7b 100644 --- a/avocado/test.py +++ b/avocado/test.py @@ -569,8 +569,7 @@ class DropinTest(Test): Run the executable, and log its detailed execution. """ try: - result = process.run(self.path, verbose=True, - record_stream_files=True) + result = process.run(self.path, verbose=True) self._log_detailed_cmd_info(result) except exceptions.CmdError, details: self._log_detailed_cmd_info(details.result) diff --git a/avocado/utils/build.py b/avocado/utils/build.py index 592f135cd8b0a9138f273225d3bdb928a925716e..2c09a868a78305334d8b40b5363959a138833135 100644 --- a/avocado/utils/build.py +++ b/avocado/utils/build.py @@ -16,13 +16,25 @@ import os import process -def make(path, make='make', env='', extra_args='', ignore_status=False): +def make(path, make='make', env='', extra_args='', ignore_status=False, allow_output_check='none'): """ Run make, adding MAKEOPTS to the list of options. :param env: environment variables to be set before calling make (e.g.: CFLAGS). :param extra: extra command line arguments to pass to make. + :param allow_output_check: Whether to log the command stream outputs + (stdout and stderr) of the make process in + the test stream files. Valid values: 'stdout', + for allowing only standard output, 'stderr', + to allow only standard error, 'all', + to allow both standard output and error, + and 'none', to allow none to be + recorded (default). The default here is + 'none', because usually we don't want + to use the compilation output as a reference + in tests. + :type allow_output_check: str """ cwd = os.getcwd() os.chdir(path) @@ -34,6 +46,6 @@ def make(path, make='make', env='', extra_args='', ignore_status=False): cmd += ' %s' % makeopts if extra_args: cmd += ' %s' % extra_args - make_process = process.system(cmd, ignore_status=ignore_status) + make_process = process.system(cmd, ignore_status=ignore_status, allow_output_check=allow_output_check) os.chdir(cwd) return make_process diff --git a/avocado/utils/process.py b/avocado/utils/process.py index 3ec2b5ae7d8b87f0719d639b6ca84d84b398ac6a..162dcdb7bddf151987ff439b76a04c62e6cf52bc 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -222,7 +222,7 @@ class SubProcess(object): Run a subprocess in the background, collecting stdout/stderr streams. """ - def __init__(self, cmd, verbose=True, record_stream_files=False): + def __init__(self, cmd, verbose=True, allow_output_check='all'): """ Creates the subprocess object, stdout/err, reader threads and locks. @@ -230,11 +230,15 @@ class SubProcess(object): :type cmd: str :param verbose: Whether to log the command run and stdout/stderr. :type verbose: bool - :param record_stream_files: Whether to log the command stream outputs - (stdout and stderr) in the - test stream files (stdout.actual and - stderr.actual). - :type record_stream_files: bool + :param allow_output_check: Whether to log the command stream outputs + (stdout and stderr) in the test stream + files. Valid values: 'stdout', for + allowing only standard output, 'stderr', + to allow only standard error, 'all', + to allow both standard output and error + (default), and 'none', to allow + none to be recorded. + :type allow_output_check: str """ self.cmd = cmd self.verbose = verbose @@ -244,7 +248,7 @@ class SubProcess(object): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - self.record_stream_files = record_stream_files + self.allow_output_check = allow_output_check self.start_time = time.time() self.result = CmdResult(cmd) self.stdout_file = StringIO.StringIO() @@ -284,12 +288,18 @@ class SubProcess(object): stream_prefix = "%s" if input_pipe == self.sp.stdout: prefix = '[stdout] %s' - stream_logger = stdout_log + if self.allow_output_check in ['none', 'stderr']: + stream_logger = None + else: + stream_logger = stdout_log output_file = self.stdout_file lock = self.stdout_lock elif input_pipe == self.sp.stderr: prefix = '[stderr] %s' - stream_logger = stderr_log + if self.allow_output_check in ['none', 'stdout']: + stream_logger = None + else: + stream_logger = stderr_log output_file = self.stderr_file lock = self.stderr_lock @@ -308,7 +318,7 @@ class SubProcess(object): if tmp.endswith('\n'): for l in bfr.splitlines(): log.debug(prefix, l) - if self.record_stream_files: + if stream_logger is not None: stream_logger.debug(stream_prefix, l) bfr = '' finally: @@ -706,8 +716,7 @@ def get_sub_process_klass(cmd): return SubProcess -def run(cmd, timeout=None, verbose=True, ignore_status=False, - record_stream_files=False): +def run(cmd, timeout=None, verbose=True, ignore_status=False, allow_output_check='all'): """ Run a subprocess, returning a CmdResult object. @@ -723,18 +732,22 @@ def run(cmd, timeout=None, verbose=True, ignore_status=False, :param ignore_status: Whether to raise an exception when command returns =! 0 (False), or not (True). :type ignore_status: bool - :param record_stream_files: Whether to log the command stream outputs - (stdout and stderr) in the - test stream files (stdout.actual and - stderr.actual). - :type record_stream_files: bool + :param allow_output_check: Whether to log the command stream outputs + (stdout and stderr) in the test stream + files. Valid values: 'stdout', for + allowing only standard output, 'stderr', + to allow only standard error, 'all', + to allow both standard output and error + (default), and 'none', to allow + none to be recorded. + :type allow_output_check: str :return: An :class:`avocado.utils.process.CmdResult` object. :raise: :class:`avocado.core.exceptions.CmdError`, if ``ignore_status=False``. """ klass = get_sub_process_klass(cmd) sp = klass(cmd=cmd, verbose=verbose, - record_stream_files=record_stream_files) + allow_output_check=allow_output_check) cmd_result = sp.run(timeout=timeout) fail_condition = cmd_result.exit_status != 0 or cmd_result.interrupted if fail_condition and not ignore_status: @@ -743,7 +756,7 @@ def run(cmd, timeout=None, verbose=True, ignore_status=False, def system(cmd, timeout=None, verbose=True, ignore_status=False, - record_stream_files=False): + allow_output_check='all'): """ Run a subprocess, returning its exit code. @@ -759,23 +772,25 @@ def system(cmd, timeout=None, verbose=True, ignore_status=False, :param ignore_status: Whether to raise an exception when command returns =! 0 (False), or not (True). :type ignore_status: bool - :param record_stream_files: Whether to log the command stream outputs - (stdout and stderr) in the - test stream files (stdout.actual and - stderr.actual). - :type record_stream_files: bool + :param allow_output_check: Whether to log the command stream outputs + (stdout and stderr) in the test stream + files. Valid values: 'stdout', for + allowing only standard output, 'stderr', + to allow only standard error, 'all', + to allow both standard output and error + (default), and 'none', to allow + none to be recorded. + :type allow_output_check: str :return: Exit code. :rtype: int :raise: :class:`avocado.core.exceptions.CmdError`, if ``ignore_status=False``. """ - cmd_result = run(cmd=cmd, timeout=timeout, verbose=verbose, - ignore_status=ignore_status, - record_stream_files=record_stream_files) + cmd_result = run(cmd=cmd, timeout=timeout, verbose=verbose, ignore_status=ignore_status, + allow_output_check=allow_output_check) return cmd_result.exit_status -def system_output(cmd, timeout=None, verbose=True, ignore_status=False, - record_stream_files=False): +def system_output(cmd, timeout=None, verbose=True, ignore_status=False, allow_output_check='all'): """ Run a subprocess, returning its output. @@ -790,16 +805,19 @@ def system_output(cmd, timeout=None, verbose=True, ignore_status=False, :type verbose: bool :param ignore_status: Whether to raise an exception when command returns =! 0 (False), or not (True). - :param record_stream_files: Whether to log the command stream outputs - (stdout and stderr) in the - test stream files (stdout.actual and - stderr.actual). - :type record_stream_files: bool + :param allow_output_check: Whether to log the command stream outputs + (stdout and stderr) in the test stream + files. Valid values: 'stdout', for + allowing only standard output, 'stderr', + to allow only standard error, 'all', + to allow both standard output and error + (default), and 'none', to allow + none to be recorded. + :type allow_output_check: str :return: Command output. :rtype: str :raise: :class:`avocado.core.exceptions.CmdError`, if ``ignore_status=False``. """ - cmd_result = run(cmd=cmd, timeout=timeout, verbose=verbose, - ignore_status=ignore_status, - record_stream_files=record_stream_files) + cmd_result = run(cmd=cmd, timeout=timeout, verbose=verbose, ignore_status=ignore_status, + allow_output_check=allow_output_check) return cmd_result.stdout diff --git a/examples/tests/synctest.py b/examples/tests/synctest.py index 595733a78ec52e44727afe393d767b9493ea26bb..0fce0779759b5c3e5cd79449ee01aa884cd4f324 100755 --- a/examples/tests/synctest.py +++ b/examples/tests/synctest.py @@ -42,9 +42,7 @@ class synctest(test.Test): archive.extract(tarball_path, self.srcdir) self.srcdir = os.path.join(self.srcdir, 'synctest') if self.params.debug_symbols: - build.make(self.srcdir, - env='CFLAGS="-g -O0"', - extra_args='synctest') + build.make(self.srcdir, env='CFLAGS="-g -O0"', extra_args='synctest') else: build.make(self.srcdir) @@ -56,7 +54,7 @@ class synctest(test.Test): path = os.path.join(os.getcwd(), 'synctest') cmd = ('%s %s %s' % (path, self.params.sync_length, self.params.sync_loop)) - process.system(cmd, record_stream_files=True) + process.system(cmd) os.chdir(self.cwd)