[libcxx-commits] [libcxx] b408bbb - [libc++] Avoid conflating stderr and stdout in the DSL
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 11 14:07:06 PDT 2021
Author: Louis Dionne
Date: 2021-08-11T17:06:56-04:00
New Revision: b408bbbf5b8932574661398d1ea7fd484d233778
URL: https://github.com/llvm/llvm-project/commit/b408bbbf5b8932574661398d1ea7fd484d233778
DIFF: https://github.com/llvm/llvm-project/commit/b408bbbf5b8932574661398d1ea7fd484d233778.diff
LOG: [libc++] Avoid conflating stderr and stdout in the DSL
This is a workaround until https://reviews.llvm.org/D81892 is merged
and the internal Lit shell stops conflating error output with normal
output. Without this, any program that writes to stderr will trip up
the programOutput function, because it will pick up the '# command stderr:'
string and think it's part of the command's stdout.
rdar://81056048
Differential Revision: https://reviews.llvm.org/D107912
Added:
Modified:
libcxx/test/libcxx/selftest/dsl/dsl.sh.py
libcxx/utils/libcxx/test/dsl.py
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
index 1901ddb9964d0..220bb4f9813bd 100644
--- a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
+++ b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
@@ -196,6 +196,7 @@ def test_caching_is_not_too_aggressive(self):
#include <cstdio>
int main(int, char**) {
std::printf("MACRO=%u\\n", MACRO);
+ return 0;
}
"""
compileFlagsIndex = findIndex(self.config.substitutions, lambda x: x[0] == '%{compile_flags}')
@@ -209,6 +210,19 @@ def test_caching_is_not_too_aggressive(self):
output2 = dsl.programOutput(self.config, source)
self.assertEqual(output2, "MACRO=2\n")
+ def test_program_stderr_is_not_conflated_with_stdout(self):
+ # Run a program that produces stdout output and stderr output too, making
+ # sure the stderr output does not pollute the stdout output.
+ source = """
+ #include <cstdio>
+ int main(int, char**) {
+ std::fprintf(stdout, "STDOUT-OUTPUT");
+ std::fprintf(stderr, "STDERR-OUTPUT");
+ return 0;
+ }
+ """
+ self.assertEqual(dsl.programOutput(self.config, source), "STDOUT-OUTPUT")
+
class TestHasLocale(SetupConfigs):
"""
diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index 3f2b5b7b33ecf..7476978ebbbd4 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -64,9 +64,20 @@ def _executeScriptInternal(test, commands):
if not os.path.exists(d):
os.makedirs(d)
res = lit.TestRunner.executeScriptInternal(test, litConfig, tmpBase, parsedCommands, execDir)
- if isinstance(res, lit.Test.Result):
- res = ('', '', 127, None)
- return res
+ if isinstance(res, lit.Test.Result): # Handle failure to parse the Lit test
+ res = ('', res.output, 127, None)
+ (out, err, exitCode, timeoutInfo) = res
+
+ # TODO: As a temporary workaround until https://reviews.llvm.org/D81892 lands, manually
+ # split any stderr output that is included in stdout. It shouldn't be there, but
+ # the Lit internal shell conflates stderr and stdout.
+ conflatedErrorOutput = re.search("(# command stderr:.+$)", out, flags=re.DOTALL)
+ if conflatedErrorOutput:
+ conflatedErrorOutput = conflatedErrorOutput.group(0)
+ out = out[:-len(conflatedErrorOutput)]
+ err += conflatedErrorOutput
+
+ return (out, err, exitCode, timeoutInfo)
def _makeConfigTest(config, testPrefix=''):
sourceRoot = os.path.join(config.test_exec_root, '__config_src__')
@@ -122,7 +133,7 @@ def programOutput(config, program, args=None, testPrefix=''):
if exitCode != 0:
return None
- actualOut = re.search("command output:\n(.+)\n$", out, flags=re.DOTALL)
+ actualOut = re.search("# command output:\n(.+)\n$", out, flags=re.DOTALL)
actualOut = actualOut.group(1) if actualOut else ""
return actualOut
More information about the libcxx-commits
mailing list