From 0b0a1262f2b401ea16b7d0b36d8254c500cb9d8e Mon Sep 17 00:00:00 2001 From: Joan Sala Date: Thu, 20 Sep 2018 22:37:58 +0200 Subject: [PATCH] testbench: fix incompatibility of one omprog test with Python3 Python3 writes to stderr immediately, and this caused the captured output to differ with respect to Python2. Simplified the test to do a single write to stderr. Also a cast to int was needed when calculating 'numRepeats'. closes #3030 --- tests/omprog-output-capture-mt.sh | 2 +- .../testsuites/omprog-output-capture-mt-bin.py | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/omprog-output-capture-mt.sh b/tests/omprog-output-capture-mt.sh index 50f5c6354..080fabd2a 100755 --- a/tests/omprog-output-capture-mt.sh +++ b/tests/omprog-output-capture-mt.sh @@ -24,7 +24,7 @@ else LINE_LENGTH=511 # 512 minus 1 byte (for the newline char) fi -export command_line="/usr/bin/stdbuf -oL -eL $srcdir/testsuites/omprog-output-capture-mt-bin.py $LINE_LENGTH" +export command_line="/usr/bin/stdbuf -oL $srcdir/testsuites/omprog-output-capture-mt-bin.py $LINE_LENGTH" check_command_available stdbuf generate_conf diff --git a/tests/testsuites/omprog-output-capture-mt-bin.py b/tests/testsuites/omprog-output-capture-mt-bin.py index 6c81da24b..03097f37b 100755 --- a/tests/testsuites/omprog-output-capture-mt-bin.py +++ b/tests/testsuites/omprog-output-capture-mt-bin.py @@ -10,7 +10,7 @@ logLine = sys.stdin.readline() while logLine: logLine = logLine.strip() - numRepeats = lineLength / len(logLine) + numRepeats = int(lineLength / len(logLine)) lineToStdout = (linePrefix + "[stdout] " + logLine*numRepeats)[:lineLength] lineToStderr = (linePrefix + "[stderr] " + logLine*numRepeats)[:lineLength] @@ -22,16 +22,13 @@ # size of the block buffer is generally greater than PIPE_BUF). sys.stdout.write(lineToStdout + "\n") - # Write to stderr using two writes. Since stderr is unbuffered, each write will be written - # immediately to the pipe, and this will cause intermingled lines in the output file. - # However, we avoid this by executing this script with 'stdbuf -eL', which forces line - # buffering for stderr. We could alternatively do a single write. - sys.stderr.write(lineToStderr) - sys.stderr.write("\n") + # Write to stderr using a single write. Since stderr is unbuffered, each write will be + # written immediately (and atomically) to the pipe. + sys.stderr.write(lineToStderr + "\n") - # Note: In future versions of Python3, stderr will possibly be line buffered (see - # https://bugs.python.org/issue13601). - # Note: When writing to stderr using the Python logging module, it seems that line + # Note (FTR): In future versions of Python3, stderr will possibly be line buffered (see + # https://bugs.python.org/issue13601). The previous write will also be atomic in this case. + # Note (FTR): When writing to stderr using the Python logging module, it seems that line # buffering is also used (although this could depend on the Python version). logLine = sys.stdin.readline()