-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[unittest] Add option to allow disabling sharding in unittest #67063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
llvm/utils/lit/tests/Inputs/googletest-no-sharding/DummySubDir/OneTest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
|
||
if len(sys.argv) == 3 and sys.argv[1] == "--gtest_list_tests": | ||
if sys.argv[2] != "--gtest_filter=-*DISABLED_*": | ||
raise ValueError(f"unexpected argument: {sys.argv[2]}") | ||
print( | ||
"""\ | ||
FirstTest. | ||
subTestA | ||
subTestB | ||
subTestC | ||
subTestD | ||
ParameterizedTest/0. | ||
subTest | ||
ParameterizedTest/1. | ||
subTest""" | ||
) | ||
sys.exit(0) | ||
elif len(sys.argv) != 1: | ||
# sharding and json output are specified using environment variables | ||
raise ValueError(f"unexpected argument: {' '.join(sys.argv[1:])!r}") | ||
|
||
for e in ["GTEST_OUTPUT"]: | ||
if e not in os.environ: | ||
raise ValueError(f"missing environment variables: {e}") | ||
|
||
if not os.environ["GTEST_OUTPUT"].startswith("json:"): | ||
raise ValueError(f"must emit json output: {os.environ['GTEST_OUTPUT']}") | ||
|
||
output = """\ | ||
{ | ||
"random_seed": 123, | ||
"testsuites": [ | ||
{ | ||
"name": "FirstTest", | ||
"testsuite": [ | ||
{ | ||
"name": "subTestA", | ||
"result": "COMPLETED", | ||
"time": "0.001s" | ||
}, | ||
{ | ||
"name": "subTestB", | ||
"result": "COMPLETED", | ||
"time": "0.001s", | ||
"failures": [ | ||
{ | ||
"failure": "I am subTest B, I FAIL\\nAnd I have two lines of output", | ||
"type": "" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "subTestC", | ||
"result": "SKIPPED", | ||
"time": "0.001s" | ||
}, | ||
{ | ||
"name": "subTestD", | ||
"result": "UNRESOLVED", | ||
"time": "0.001s" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "ParameterizedTest/0", | ||
"testsuite": [ | ||
{ | ||
"name": "subTest", | ||
"result": "COMPLETED", | ||
"time": "0.001s" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "ParameterizedTest/1", | ||
"testsuite": [ | ||
{ | ||
"name": "subTest", | ||
"result": "COMPLETED", | ||
"time": "0.001s" | ||
} | ||
] | ||
} | ||
] | ||
}""" | ||
|
||
dummy_output = """\ | ||
{ | ||
"testsuites": [ | ||
] | ||
}""" | ||
|
||
json_filename = os.environ["GTEST_OUTPUT"].split(":", 1)[1] | ||
with open(json_filename, "w", encoding="utf-8") as f: | ||
print("[ RUN ] FirstTest.subTestB", flush=True) | ||
print("I am subTest B output", file=sys.stderr, flush=True) | ||
print("[ FAILED ] FirstTest.subTestB (8 ms)", flush=True) | ||
f.write(output) | ||
exit_code = 1 | ||
|
||
sys.exit(exit_code) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import lit.formats | ||
|
||
config.name = "googletest-no-sharding" | ||
config.test_format = lit.formats.GoogleTest("DummySubDir", "Test") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Check the various features of the GoogleTest format. | ||
|
||
# RUN: not %{lit} -v --disable-gtest-sharding --order=random %{inputs}/googletest-no-sharding > %t.out | ||
# FIXME: Temporarily dump test output so we can debug failing tests on | ||
# buildbots. | ||
# RUN: cat %t.out | ||
# RUN: FileCheck < %t.out %s | ||
# | ||
# END. | ||
|
||
# CHECK: -- Testing: | ||
# CHECK: FAIL: googletest-no-sharding :: [[PATH:[Dd]ummy[Ss]ub[Dd]ir/]][[FILE:OneTest\.py]] | ||
# CHECK: *** TEST 'googletest-no-sharding :: [[PATH]][[FILE]]' FAILED *** | ||
# CHECK-NEXT: Script(shard): | ||
# CHECK-NEXT: -- | ||
# CHECK-NEXT: GTEST_OUTPUT=json:{{[^[:space:]]*}} GTEST_SHUFFLE=1 GTEST_RANDOM_SEED=123 {{.*}}[[FILE]] | ||
# CHECK-NEXT: -- | ||
# CHECK-EMPTY: | ||
# CHECK-NEXT: Script: | ||
# CHECK-NEXT: -- | ||
# CHECK-NEXT: [[FILE]] --gtest_filter=FirstTest.subTestB | ||
# CHECK-NEXT: -- | ||
# CHECK-NEXT: I am subTest B output | ||
# CHECK-EMPTY: | ||
# CHECK-NEXT: I am subTest B, I FAIL | ||
# CHECK-NEXT: And I have two lines of output | ||
# CHECK-EMPTY: | ||
# CHECK: Script: | ||
# CHECK-NEXT: -- | ||
# CHECK-NEXT: [[FILE]] --gtest_filter=FirstTest.subTestD | ||
# CHECK-NEXT: -- | ||
# CHECK-NEXT: unresolved test result | ||
# CHECK: *** | ||
# CHECK: *** | ||
# CHECK: Unresolved Tests (1): | ||
# CHECK-NEXT: googletest-no-sharding :: FirstTest/subTestD | ||
# CHECK: *** | ||
# CHECK-NEXT: Failed Tests (1): | ||
# CHECK-NEXT: googletest-no-sharding :: FirstTest/subTestB | ||
# CHECK: Skipped{{ *}}: 1 | ||
# CHECK: Passed{{ *}}: 3 | ||
# CHECK: Unresolved{{ *}}: 1 | ||
# CHECK: Failed{{ *}}: 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable name is inconsistent with Python style which uses
snake_case
. I'd suggest calling it simplygtest_sharding
and have a pair of arguments--gtest-sharding
and--no-gtest-sharding
to control whether sharding is enabled or disabled, with default beingTrue
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like my comment wasn't addressed, it'd be great to address this in a follow up change.