From c2708c86628c51ce1910a8493ef5b16adb723374 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 2 Jun 2016 23:32:35 +0000 Subject: [PATCH] [lit] Factor out a helper for shell command results. llvm-svn: 271608 --- llvm/utils/lit/lit/TestRunner.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 3f02420572a0..e4bc48daa7fd 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -110,6 +110,16 @@ class TimeoutHelper(object): self._procs = [] # Python2 doesn't have list.clear() self._doneKillPass = True +class ShellCommandResult(object): + """Captures the result of an individual command.""" + + def __init__(self, command, stdout, stderr, exitCode, timeoutReached): + self.command = command + self.stdout = stdout + self.stderr = stderr + self.exitCode = exitCode + self.timeoutReached = timeoutReached + def executeShCmd(cmd, shenv, results, timeout=0): """ Wrapper around _executeShCmd that handles @@ -377,7 +387,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): except: err = str(err) - results.append((cmd.commands[i], out, err, res, timeoutHelper.timeoutReached())) + results.append(ShellCommandResult( + cmd.commands[i], out, err, res, timeoutHelper.timeoutReached())) if cmd.pipe_err: # Python treats the exit code as a signed char. if exitCode is None: @@ -422,16 +433,19 @@ def executeScriptInternal(test, litConfig, tmpBase, commands, cwd): except InternalShellError: e = sys.exc_info()[1] exitCode = 127 - results.append((e.command, '', e.message, exitCode, False)) + results.append( + ShellCommandResult(e.command, '', e.message, exitCode, False)) out = err = '' - for i,(cmd, cmd_out, cmd_err, res, timeoutReached) in enumerate(results): - out += 'Command %d: %s\n' % (i, ' '.join('"%s"' % s for s in cmd.args)) - out += 'Command %d Result: %r\n' % (i, res) + for i,result in enumerate(results): + out += 'Command %d: %s\n' % (i, ' '.join('"%s"' % s + for s in result.command.args)) + out += 'Command %d Result: %r\n' % (i, result.exitCode) if litConfig.maxIndividualTestTime > 0: - out += 'Command %d Reached Timeout: %s\n\n' % (i, str(timeoutReached)) - out += 'Command %d Output:\n%s\n\n' % (i, cmd_out) - out += 'Command %d Stderr:\n%s\n\n' % (i, cmd_err) + out += 'Command %d Reached Timeout: %s\n\n' % ( + i, str(result.timeoutReached)) + out += 'Command %d Output:\n%s\n\n' % (i, result.stdout) + out += 'Command %d Stderr:\n%s\n\n' % (i, result.stderr) return out, err, exitCode, timeoutInfo