Browse Source

prism-auto: flush() to align script with prism output when used with pipes

In non-test mode, PRISM and prism-auto both write to stdout, without
prism-auto seeing/processing the output of PRISM. If the output of
prism-auto is piped to another program or to a file, the prism-auto
output is buffered. Then, the output by prism-auto (e.g., printing the
command lines) is not properly synchronized with the output of the
PRISM instances.

So, we flush stdout at appropriate locations.

Additionally, on timeout we prepend a '\n' to ensure that the timeout
message starts at a new line (in particular for the common case of a
timeout during explicit model building, where there is no newline from
PRISM until the model is fully built).
master
Joachim Klein 8 years ago
parent
commit
491d05d4fa
  1. 12
      prism/etc/scripts/prism-auto

12
prism/etc/scripts/prism-auto

@ -393,6 +393,7 @@ def printColoured(colour, msg):
print('\033[' + str(testColours[colour]) + 'm' + msg + '\033[0m') print('\033[' + str(testColours[colour]) + 'm' + msg + '\033[0m')
else: else:
print(msg) print(msg)
sys.stdout.flush()
# #
# Given a switch (-xyz or --xyz), expand to full-length form # Given a switch (-xyz or --xyz), expand to full-length form
@ -514,6 +515,7 @@ def runPrism(args, dir=""):
print(' '.join(prismArgs)) print(' '.join(prismArgs))
return return
print(' '.join(prismArgs)) print(' '.join(prismArgs))
sys.stdout.flush()
if options.logDir: if options.logDir:
logFile = os.path.join(options.logDir, createLogFileName(args, dir)) logFile = os.path.join(options.logDir, createLogFileName(args, dir))
#f = open(logFile, 'w') #f = open(logFile, 'w')
@ -559,6 +561,7 @@ def runPrism(args, dir=""):
# in verbose mode, also print the non-matching lines # in verbose mode, also print the non-matching lines
# rstrip to remove newline before printing # rstrip to remove newline before printing
print(line.rstrip()) print(line.rstrip())
sys.stdout.flush()
if options.test and not options.verboseTest and exitCode != 0: if options.test and not options.verboseTest and exitCode != 0:
# failure, we don't want to cleanup the log (if it was a temporary file) # failure, we don't want to cleanup the log (if it was a temporary file)
# so that the user can inspect it # so that the user can inspect it
@ -576,7 +579,7 @@ def runPrism(args, dir=""):
# call-back function for expiration of the execute timer thread # call-back function for expiration of the execute timer thread
def timeout(proc, flag): def timeout(proc, flag):
printColoured('FAILURE', 'Timeout (' + str(options.timeout) + 's)')
printColoured('FAILURE', '\nTimeout (' + str(options.timeout) + 's)')
flag.append(True) flag.append(True)
proc.kill() proc.kill()
@ -619,7 +622,8 @@ def printTestResult(msg):
msg = str.rstrip(msg) msg = str.rstrip(msg)
countTestResult(msg) countTestResult(msg)
if not isColourEnabled(): if not isColourEnabled():
print(msg);
print(msg)
sys.stdout.flush()
return return
# Coloured-coded... # Coloured-coded...
if 'Error:' in msg or 'FAIL' in msg: if 'Error:' in msg or 'FAIL' in msg:
@ -634,6 +638,7 @@ def printTestResult(msg):
printColoured('UNSUPPORTED', msg) printColoured('UNSUPPORTED', msg)
else: else:
print(msg) print(msg)
sys.stdout.flush()
def incrementTestStat(stat): def incrementTestStat(stat):
global testStats global testStats
@ -703,6 +708,7 @@ def verifyAndCleanupExports(outFiles, exportPrefix):
msg = msg + "FAIL (" + os.path.basename(expFile) + " does not match)" msg = msg + "FAIL (" + os.path.basename(expFile) + " does not match)"
print("To see difference, run:") print("To see difference, run:")
print("diff " + outFile + " " + expFile) print("diff " + outFile + " " + expFile)
sys.stdout.flush()
result = False result = False
else: else:
if options.noExportTests: if options.noExportTests:
@ -927,8 +933,10 @@ def benchmarkPropListFile(propListFile):
# We first try to stop an existing server (which should fail quickly if there is none running) # We first try to stop an existing server (which should fail quickly if there is none running)
def restartNailGunServer(): def restartNailGunServer():
print("Stopping existing nailgun server, if it's running...") print("Stopping existing nailgun server, if it's running...")
sys.stdout.flush()
subprocess.Popen([options.ngprism, "stop"]).wait() subprocess.Popen([options.ngprism, "stop"]).wait()
print("Starting nailgun server...") print("Starting nailgun server...")
sys.stdout.flush()
os.system(options.prismExec + " -ng &") os.system(options.prismExec + " -ng &")
time.sleep(0.5) time.sleep(0.5)

Loading…
Cancel
Save