From 491d05d4fa932b79e68e5ee9b90c880e7dcc7a2d Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Tue, 24 Apr 2018 18:58:59 +0200 Subject: [PATCH] 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). --- prism/etc/scripts/prism-auto | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/prism/etc/scripts/prism-auto b/prism/etc/scripts/prism-auto index 7d1bb620..5911c7d0 100755 --- a/prism/etc/scripts/prism-auto +++ b/prism/etc/scripts/prism-auto @@ -393,6 +393,7 @@ def printColoured(colour, msg): print('\033[' + str(testColours[colour]) + 'm' + msg + '\033[0m') else: print(msg) + sys.stdout.flush() # # Given a switch (-xyz or --xyz), expand to full-length form @@ -514,6 +515,7 @@ def runPrism(args, dir=""): print(' '.join(prismArgs)) return print(' '.join(prismArgs)) + sys.stdout.flush() if options.logDir: logFile = os.path.join(options.logDir, createLogFileName(args, dir)) #f = open(logFile, 'w') @@ -559,6 +561,7 @@ def runPrism(args, dir=""): # in verbose mode, also print the non-matching lines # rstrip to remove newline before printing print(line.rstrip()) + sys.stdout.flush() 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) # 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 def timeout(proc, flag): - printColoured('FAILURE', 'Timeout (' + str(options.timeout) + 's)') + printColoured('FAILURE', '\nTimeout (' + str(options.timeout) + 's)') flag.append(True) proc.kill() @@ -619,7 +622,8 @@ def printTestResult(msg): msg = str.rstrip(msg) countTestResult(msg) if not isColourEnabled(): - print(msg); + print(msg) + sys.stdout.flush() return # Coloured-coded... if 'Error:' in msg or 'FAIL' in msg: @@ -634,6 +638,7 @@ def printTestResult(msg): printColoured('UNSUPPORTED', msg) else: print(msg) + sys.stdout.flush() def incrementTestStat(stat): global testStats @@ -703,6 +708,7 @@ def verifyAndCleanupExports(outFiles, exportPrefix): msg = msg + "FAIL (" + os.path.basename(expFile) + " does not match)" print("To see difference, run:") print("diff " + outFile + " " + expFile) + sys.stdout.flush() result = False else: 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) def restartNailGunServer(): print("Stopping existing nailgun server, if it's running...") + sys.stdout.flush() subprocess.Popen([options.ngprism, "stop"]).wait() print("Starting nailgun server...") + sys.stdout.flush() os.system(options.prismExec + " -ng &") time.sleep(0.5)