Debian Codegraph @

llvm-project/llvm/utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest.py

raw
1 #!/usr/bin/env python
2
3 import os
4 import sys
5
6 if len(sys.argv) == 3 and sys.argv[1] == "--gtest_list_tests":
7 if sys.argv[2] != '--gtest_filter=-*DISABLED_*':
8 raise ValueError("unexpected argument: %s" % (sys.argv[2]))
9 print("""\
10 T.
11 QuickSubTest
12 InfiniteLoopSubTest
13 """)
14 sys.exit(0)
15 elif len(sys.argv) != 1:
16 # sharding and json output are specified using environment variables
17 raise ValueError("unexpected argument: %r" % (' '.join(sys.argv[1:])))
18
19 for e in ['GTEST_TOTAL_SHARDS', 'GTEST_SHARD_INDEX', 'GTEST_OUTPUT', 'GTEST_FILTER']:
20 if e not in os.environ:
21 raise ValueError("missing environment variables: " + e)
22
23 if not os.environ['GTEST_OUTPUT'].startswith('json:'):
24 raise ValueError("must emit json output: " + os.environ['GTEST_OUTPUT'])
25
26 output = """\
27 {
28 "testsuites": [
29 {
30 "name": "T",
31 "testsuite": [
32 {
33 "name": "QuickSubTest",
34 "result": "COMPLETED",
35 "time": "2s"
36 }
37 ]
38 }
39 ]
40 }"""
41
42 dummy_output = """\
43 {
44 "testsuites": [
45 ]
46 }"""
47
48 json_filename = os.environ['GTEST_OUTPUT'].split(':', 1)[1]
49
50 if os.environ['GTEST_SHARD_INDEX'] == '0':
51 test_name = os.environ['GTEST_FILTER']
52 if test_name == 'QuickSubTest':
53 with open(json_filename, 'w', encoding='utf-8') as f:
54 f.write(output)
55 exit_code = 0
56 elif test_name == 'InfiniteLoopSubTest':
57 while True:
58 pass
59 else:
60 raise SystemExit("error: invalid test name: %r" % (test_name,))
61 else:
62 with open(json_filename, 'w', encoding='utf-8') as f:
63 f.write(dummy_output)
64 exit_code = 0
65
66 sys.exit(exit_code)