[PATCH] D123797: [lit] Keep stdout/stderr when using GoogleTest

Sam Elliott via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 08:18:04 PDT 2022


lenary created this revision.
lenary added reviewers: tmatheson, simon_tatham.
Herald added a subscriber: delcypher.
Herald added a project: All.
lenary requested review of this revision.
Herald added a project: LLVM.

When debugging issues with GoogleTest sharding, it is very useful to see
the stdout/stderr from the whole shard as part of the test failure
output.

This change ensures that the stream output and error code is kept and
logged in the case of any failures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123797

Files:
  llvm/utils/lit/lit/formats/googletest.py


Index: llvm/utils/lit/lit/formats/googletest.py
===================================================================
--- llvm/utils/lit/lit/formats/googletest.py
+++ llvm/utils/lit/lit/formats/googletest.py
@@ -133,17 +133,19 @@
         shard_header = get_shard_header(shard_env)
 
         try:
-            _, _, exitCode = lit.util.executeCommand(
+            out, err, exitCode = lit.util.executeCommand(
                 cmd, env=test.config.environment,
                 timeout=litConfig.maxIndividualTestTime)
-        except lit.util.ExecuteCommandTimeoutException:
-            return (lit.Test.TIMEOUT, f'{shard_header}Reached timeout of '
-                    f'{litConfig.maxIndividualTestTime} seconds')
+        except lit.util.ExecuteCommandTimeoutException as e:
+            stream_msg = f"\n{e.out}\n--\n{e.err}\n--\nexit: {e.exitCode}\n--\n"
+            return (lit.Test.TIMEOUT, f'{shard_header}{stream_msg}Reached '
+                    f'timeout of {litConfig.maxIndividualTestTime} seconds')
 
+        stream_msg = f"\n{out}\n--\n{err}\n--\nexit: {exitCode}\n--\n"
         if not os.path.exists(test.gtest_json_file):
             errmsg = f"shard JSON output does not exist: %s" % (
                 test.gtest_json_file)
-            return lit.Test.FAIL, shard_header + errmsg
+            return lit.Test.FAIL, shard_header + stream_msg + errmsg
 
         if exitCode == 0:
             return lit.Test.PASS, ''
@@ -153,7 +155,7 @@
 
             if use_shuffle:
                 shard_env['GTEST_RANDOM_SEED'] = str(jf['random_seed'])
-            output = get_shard_header(shard_env) + '\n'
+            output = get_shard_header(shard_env) + stream_msg + '\n'
 
             for testcase in jf['testsuites']:
                 for testinfo in testcase['testsuite']:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123797.422872.patch
Type: text/x-patch
Size: 1801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220414/ffd90d86/attachment.bin>


More information about the llvm-commits mailing list