Skip to content
Permalink
Browse files

Merge pull request #12946 from milljm/no-trimmed-on-error-12937

Only trim output during print operations
  • Loading branch information...
aeslaughter committed Feb 21, 2019
2 parents 715a6fd + ecd06ec commit 08ce4a1b6c5c7e99b0b5af49e1175ae98d42a9bc
@@ -449,7 +449,7 @@ def printOutput(self, job):
# Print what ever status the tester has at the time
if self.options.verbose or (tester.isFail() and not self.options.quiet):
output = 'Working Directory: ' + tester.getTestDir() + '\nRunning command: ' + tester.getCommand(self.options) + '\n'
output += job.getOutput()
output += util.trimOutput(job, self.options)
output = output.replace('\r', '\n') # replace the carriage returns with newlines
lines = output.split('\n')

@@ -817,6 +817,7 @@ def parseCLArgs(self, argv):
outputgroup.add_argument("--yaml", action="store_true", dest="yaml", help="Dump the parameters for the testers in Yaml Format")
outputgroup.add_argument("--dump", action="store_true", dest="dump", help="Dump the parameters for the testers in GetPot Format")
outputgroup.add_argument("--no-trimmed-output", action="store_true", dest="no_trimmed_output", help="Do not trim the output")
outputgroup.add_argument("--no-trimmed-output-on-error", action="store_true", dest="no_trimmed_output_on_error", help="Do not trim output for tests which cause an error")

queuegroup = parser.add_argument_group('Queue Options', 'Options controlling which queue manager to use')
queuegroup.add_argument('--pbs', nargs=1, action='store', metavar='session_name', help='Launch tests using PBS as your scheduler. You must supply a name to identify this session with')
@@ -315,7 +315,7 @@ def runCommand(self, cmd, cwd, timer, options):
self.errfile.flush()

# store the contents of output, and close the file
self.joined_out = util.readOutput(self.outfile, self.errfile, options, max_size=self.specs['max_buffer_size'])
self.joined_out = util.readOutput(self.outfile, self.errfile)
self.outfile.close()
self.errfile.close()

@@ -7,6 +7,7 @@
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html

import subprocess
from TestHarnessTestCase import TestHarnessTestCase

class TestHarnessTester(TestHarnessTestCase):
@@ -23,3 +24,14 @@ def testNoTrimOutput(self):
"""
output = self.runTests('--no-color', '-i', 'always_ok', '-v')
self.assertNotIn('Output trimmed', output)

def testNoTrimmedOutputOnError(self):
"""
Verify trimming does not take place with a failed test using
appropriate arguments
"""
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.runTests('--no-color', '-i', 'no_trim_on_error', '--no-trimmed-output-on-error', '-v')

e = cm.exception
self.assertNotIn('Output trimmed', e.output)
@@ -717,38 +717,39 @@ def getOutputFromFiles(tester, options):
for file_path in output_files:
with open(file_path, 'r') as f:
file_output += "#"*80 + "\nOutput from " + file_path \
+ "\n" + "#"*80 + "\n" + readOutput(f, None, options, max_size=tester.specs['max_buffer_size'])
+ "\n" + "#"*80 + "\n" + readOutput(f, None)
return file_output

# This function reads output from the file (i.e. the test output)
# but trims it down to the specified size. It'll save the first two thirds
# of the requested size and the last third trimming from the middle
def readOutput(f, e, options, max_size=None):
if max_size is None:
max_size = 100000

first_part = int(max_size*(2.0/3.0))
second_part = int(max_size*(1.0/3.0))
# Read stdout and stderr file objects, append error and return the string
def readOutput(stdout, stderr):
output = ''
if stdout:
stdout.seek(0)
output += stdout.read()
if stderr:
stderr.seek(0)
output += stderr.read()
return output

f.seek(0)
if e:
e.seek(0)
if options.no_trimmed_output or max_size == -1:
output += f.read()
if e:
output += e.read()

# Trimming routines for job output
def trimOutput(job, options):
output = job.getOutput()
tester = job.getTester()
if ((tester.isFail() and options.no_trimmed_output_on_error)
or (tester.specs.isValid('max_buffer_size') and tester.specs['max_buffer_size'] == -1)
or options.no_trimmed_output):
return output
elif tester.specs.isValid('max_buffer_size'):
max_size = tester.specs['max_buffer_size']
else:
output = f.read(first_part) # Limit the output to 1MB
if len(output) == first_part: # This means we didn't read the whole file yet
output += "\n" + "#"*80 + "\n\nOutput trimmed\n\n" + "#"*80 + "\n"
f.seek(-second_part, 2) # Skip the middle part of the file
max_size = 100000

if (f.tell() <= first_part): # Don't re-read some of what you've already read
f.seek(first_part+1, 0)
if len(output) <= max_size:
return output

output += f.read() # Now read the rest
if e:
output += e.read() # Do not trim errors
return output
first_part = int(max_size*(2.0/3.0))
second_part = int(max_size*(1.0/3.0))
return "%s\n%s\n\nOutput trimmed\n\n%s\n%s" % (output[:first_part],
"#"*80,
"#"*80,
output[-second_part:])
@@ -0,0 +1,50 @@
[Mesh]
type = GeneratedMesh
dim = 1
nx = 2
[]

[Variables]
[./u]
[../]
[]

[Kernels]
[./diff]
type = CoefDiffusion
variable = u
coef = 0.01
[../]
[./time]
type = TimeDerivative
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Executioner]
type = Transient
num_steps = 500
dt = 0.01
solve_type = PJFNK
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]
@@ -0,0 +1,7 @@
[Tests]
[./output_not_trimmed_on_error]
type = RunApp
input = 500_num_steps.i
expect_out = "Not going to find this text"
[../]
[]

0 comments on commit 08ce4a1

Please sign in to comment.
You can’t perform that action at this time.