[PATCH] D133542: [llvm][lit] Respect GTEST_TOTAL_SHARDS and GTEST_SHARD_INDEX env vars

Joe Loser via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 17:04:17 PDT 2022


jloser created this revision.
jloser added reviewers: ychen, yln, rnk, abrachet, fhahn.
Herald added subscribers: arphaman, delcypher.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There are a variety of issues with using GTest sharding by default for users of
`lit` using the Google Test formatter as mentioned in
https://github.com/llvm/llvm-project/issues/56492 and
https://github.com/llvm/llvm-project/issues/56491.

Currently, there is no way for users to explicitly control the sharding
behavior, even with the environment variables that GTest provides. This patch
teaches the `googletest` formatter to actually respect `GTEST_TOTAL_SHARDS`
and `GTEST_SHARD_INDEX` environment variables if they are set.

In practice, we could go one step further and not do any of the post-processing
of the JSON files if `GTEST_TOTAL_SHARDS` is `1` for example, but that it left
as a follow-up if desired.  There may be preferred alternative approaches to
disabling sharding entirely through another mechanism, such as a lit config
variable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133542

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
@@ -112,8 +112,8 @@
         shard_env = {
             'GTEST_OUTPUT': 'json:' + test.gtest_json_file,
             'GTEST_SHUFFLE': '1' if use_shuffle else '0',
-            'GTEST_TOTAL_SHARDS': total_shards,
-            'GTEST_SHARD_INDEX': shard_idx
+            'GTEST_TOTAL_SHARDS': os.getenv("GTEST_TOTAL_SHARDS", total_shards),
+            'GTEST_SHARD_INDEX': os.getenv("GTEST_SHARD_INDEX", shard_idx)
         }
         test.config.environment.update(shard_env)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133542.458920.patch
Type: text/x-patch
Size: 684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220909/6d886e3e/attachment-0001.bin>


More information about the llvm-commits mailing list