llvm.org GIT mirror llvm / 2c42071
[lit] Port googletest lit tests to Windows Summary: The technique of directly calling subprocess.Popen on a python script doesn't work on Windows. The executable path of the command must refer to a valid win32 executable. Instead, rename all the python scripts masquerading as gtest executables to have .py extensions, so we can easily detect then and call the python executable for them. Do this on Linux as well as Windows for consistency. The test suite directory names also come out in lower-case on Windows. We can consider removing that in a later patch. This change just updates the FileCheck lines to match on Windows. Fixes PR33933 Reviewers: modocache, mgorny Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35909 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309347 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 years ago
10 changed file(s) with 143 addition(s) and 135 deletion(s). Raw diff Collapse all Expand all
1212 class GoogleTest(TestFormat):
1313 def __init__(self, test_sub_dirs, test_suffix):
1414 self.test_sub_dirs = os.path.normcase(str(test_sub_dirs)).split(';')
15 self.test_suffix = str(test_suffix)
1615
1716 # On Windows, assume tests will also end in '.exe'.
17 exe_suffix = str(test_suffix)
1818 if kIsWindows:
19 self.test_suffix += '.exe'
19 exe_suffix += '.exe'
20
21 # Also check for .py files for testing purposes.
22 self.test_suffixes = {exe_suffix, test_suffix + '.py'}
2023
2124 def getGTestTests(self, path, litConfig, localConfig):
2225 """getGTestTests(path) - [name]
2831 litConfig: LitConfig instance
2932 localConfig: TestingConfig instance"""
3033
34 list_test_cmd = self.maybeAddPythonToCmd([path, '--gtest_list_tests'])
35
3136 try:
32 output = subprocess.check_output([path, '--gtest_list_tests'],
37 output = subprocess.check_output(list_test_cmd,
3338 env=localConfig.environment)
3439 except subprocess.CalledProcessError as exc:
3540 litConfig.warning(
8186 if not os.path.isdir(dir_path):
8287 continue
8388 for fn in lit.util.listdir_files(dir_path,
84 suffixes={self.test_suffix}):
89 suffixes=self.test_suffixes):
8590 # Discover the tests in this executable.
8691 execpath = os.path.join(source_path, subdir, fn)
8792 testnames = self.getGTestTests(execpath, litConfig, localConfig)
99104 testName = namePrefix + '/' + testName
100105
101106 cmd = [testPath, '--gtest_filter=' + testName]
107 cmd = self.maybeAddPythonToCmd(cmd)
102108 if litConfig.useValgrind:
103109 cmd = litConfig.valgrindArgs + cmd
104110
125131 return lit.Test.UNRESOLVED, msg
126132
127133 return lit.Test.PASS,''
134
135 def maybeAddPythonToCmd(self, cmd):
136 """Insert the python exe into the command if cmd[0] ends in .py
137
138 We cannot rely on the system to interpret shebang lines for us on
139 Windows, so add the python executable to the command if this is a .py
140 script.
141 """
142 if cmd[0].endswith('.py'):
143 return [sys.executable] + cmd
144 return cmd
+0
-36
utils/lit/tests/Inputs/googletest-format/DummySubDir/OneTest less more
None #!/usr/bin/env python
1
2 import sys
3
4 if len(sys.argv) != 2:
5 raise ValueError("unexpected number of args")
6
7 if sys.argv[1] == "--gtest_list_tests":
8 print("""\
9 FirstTest.
10 subTestA
11 subTestB
12 ParameterizedTest/0.
13 subTest
14 ParameterizedTest/1.
15 subTest""")
16 sys.exit(0)
17 elif not sys.argv[1].startswith("--gtest_filter="):
18 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
19
20 test_name = sys.argv[1].split('=',1)[1]
21 if test_name == 'FirstTest.subTestA':
22 print('I am subTest A, I PASS')
23 print('[ PASSED ] 1 test.')
24 sys.exit(0)
25 elif test_name == 'FirstTest.subTestB':
26 print('I am subTest B, I FAIL')
27 print('And I have two lines of output')
28 sys.exit(1)
29 elif test_name in ('ParameterizedTest/0.subTest',
30 'ParameterizedTest/1.subTest'):
31 print('I am a parameterized test, I also PASS')
32 print('[ PASSED ] 1 test.')
33 sys.exit(0)
34 else:
35 raise SystemExit("error: invalid test name: %r" % (test_name,))
0 #!/usr/bin/env python
1
2 import sys
3
4 if len(sys.argv) != 2:
5 raise ValueError("unexpected number of args")
6
7 if sys.argv[1] == "--gtest_list_tests":
8 print("""\
9 FirstTest.
10 subTestA
11 subTestB
12 ParameterizedTest/0.
13 subTest
14 ParameterizedTest/1.
15 subTest""")
16 sys.exit(0)
17 elif not sys.argv[1].startswith("--gtest_filter="):
18 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
19
20 test_name = sys.argv[1].split('=',1)[1]
21 if test_name == 'FirstTest.subTestA':
22 print('I am subTest A, I PASS')
23 print('[ PASSED ] 1 test.')
24 sys.exit(0)
25 elif test_name == 'FirstTest.subTestB':
26 print('I am subTest B, I FAIL')
27 print('And I have two lines of output')
28 sys.exit(1)
29 elif test_name in ('ParameterizedTest/0.subTest',
30 'ParameterizedTest/1.subTest'):
31 print('I am a parameterized test, I also PASS')
32 print('[ PASSED ] 1 test.')
33 sys.exit(0)
34 else:
35 raise SystemExit("error: invalid test name: %r" % (test_name,))
+0
-35
utils/lit/tests/Inputs/googletest-timeout/DummySubDir/OneTest less more
None #!/usr/bin/env python
1
2 import sys
3 import time
4
5 if len(sys.argv) != 2:
6 raise ValueError("unexpected number of args")
7
8 if sys.argv[1] == "--gtest_list_tests":
9 print("""\
10 FirstTest.
11 subTestA
12 subTestB
13 subTestC
14 """)
15 sys.exit(0)
16 elif not sys.argv[1].startswith("--gtest_filter="):
17 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
18
19 test_name = sys.argv[1].split('=',1)[1]
20 if test_name == 'FirstTest.subTestA':
21 print('I am subTest A, I PASS')
22 print('[ PASSED ] 1 test.')
23 sys.exit(0)
24 elif test_name == 'FirstTest.subTestB':
25 print('I am subTest B, I am slow')
26 time.sleep(6)
27 print('[ PASSED ] 1 test.')
28 sys.exit(0)
29 elif test_name == 'FirstTest.subTestC':
30 print('I am subTest C, I will hang')
31 while True:
32 pass
33 else:
34 raise SystemExit("error: invalid test name: %r" % (test_name,))
0 #!/usr/bin/env python
1
2 import sys
3 import time
4
5 if len(sys.argv) != 2:
6 raise ValueError("unexpected number of args")
7
8 if sys.argv[1] == "--gtest_list_tests":
9 print("""\
10 FirstTest.
11 subTestA
12 subTestB
13 subTestC
14 """)
15 sys.exit(0)
16 elif not sys.argv[1].startswith("--gtest_filter="):
17 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
18
19 test_name = sys.argv[1].split('=',1)[1]
20 if test_name == 'FirstTest.subTestA':
21 print('I am subTest A, I PASS')
22 print('[ PASSED ] 1 test.')
23 sys.exit(0)
24 elif test_name == 'FirstTest.subTestB':
25 print('I am subTest B, I am slow')
26 time.sleep(6)
27 print('[ PASSED ] 1 test.')
28 sys.exit(0)
29 elif test_name == 'FirstTest.subTestC':
30 print('I am subTest C, I will hang')
31 while True:
32 pass
33 else:
34 raise SystemExit("error: invalid test name: %r" % (test_name,))
+0
-38
utils/lit/tests/Inputs/googletest-upstream-format/DummySubDir/OneTest less more
None #!/usr/bin/env python
1
2 import sys
3
4 if len(sys.argv) != 2:
5 raise ValueError("unexpected number of args")
6
7 if sys.argv[1] == "--gtest_list_tests":
8 print("""\
9 Running main() from gtest_main.cc
10 FirstTest.
11 subTestA
12 subTestB
13 ParameterizedTest/0.
14 subTest
15 ParameterizedTest/1.
16 subTest""")
17 sys.exit(0)
18 elif not sys.argv[1].startswith("--gtest_filter="):
19 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
20
21 test_name = sys.argv[1].split('=',1)[1]
22 print('Running main() from gtest_main.cc')
23 if test_name == 'FirstTest.subTestA':
24 print('I am subTest A, I PASS')
25 print('[ PASSED ] 1 test.')
26 sys.exit(0)
27 elif test_name == 'FirstTest.subTestB':
28 print('I am subTest B, I FAIL')
29 print('And I have two lines of output')
30 sys.exit(1)
31 elif test_name in ('ParameterizedTest/0.subTest',
32 'ParameterizedTest/1.subTest'):
33 print('I am a parameterized test, I also PASS')
34 print('[ PASSED ] 1 test.')
35 sys.exit(0)
36 else:
37 raise SystemExit("error: invalid test name: %r" % (test_name,))
0 #!/usr/bin/env python
1
2 import sys
3
4 if len(sys.argv) != 2:
5 raise ValueError("unexpected number of args")
6
7 if sys.argv[1] == "--gtest_list_tests":
8 print("""\
9 Running main() from gtest_main.cc
10 FirstTest.
11 subTestA
12 subTestB
13 ParameterizedTest/0.
14 subTest
15 ParameterizedTest/1.
16 subTest""")
17 sys.exit(0)
18 elif not sys.argv[1].startswith("--gtest_filter="):
19 raise ValueError("unexpected argument: %r" % (sys.argv[1]))
20
21 test_name = sys.argv[1].split('=',1)[1]
22 print('Running main() from gtest_main.cc')
23 if test_name == 'FirstTest.subTestA':
24 print('I am subTest A, I PASS')
25 print('[ PASSED ] 1 test.')
26 sys.exit(0)
27 elif test_name == 'FirstTest.subTestB':
28 print('I am subTest B, I FAIL')
29 print('And I have two lines of output')
30 sys.exit(1)
31 elif test_name in ('ParameterizedTest/0.subTest',
32 'ParameterizedTest/1.subTest'):
33 print('I am a parameterized test, I also PASS')
34 print('[ PASSED ] 1 test.')
35 sys.exit(0)
36 else:
37 raise SystemExit("error: invalid test name: %r" % (test_name,))
0 # Check the various features of the GoogleTest format.
1 #
2 # PR33933
3 # XFAIL: windows
41 #
52 # RUN: not %{lit} -j 1 -v %{inputs}/googletest-format > %t.out
63 # RUN: FileCheck < %t.out %s
85 # END.
96
107 # CHECK: -- Testing:
11 # CHECK: PASS: googletest-format :: DummySubDir/OneTest/FirstTest.subTestA
12 # CHECK: FAIL: googletest-format :: DummySubDir/OneTest/FirstTest.subTestB
13 # CHECK-NEXT: *** TEST 'googletest-format :: DummySubDir/OneTest/FirstTest.subTestB' FAILED ***
8 # CHECK: PASS: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestA
9 # CHECK: FAIL: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB
10 # CHECK-NEXT: *** TEST 'googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB' FAILED ***
1411 # CHECK-NEXT: I am subTest B, I FAIL
1512 # CHECK-NEXT: And I have two lines of output
1613 # CHECK: ***
17 # CHECK: PASS: googletest-format :: DummySubDir/OneTest/ParameterizedTest/0.subTest
18 # CHECK: PASS: googletest-format :: DummySubDir/OneTest/ParameterizedTest/1.subTest
14 # CHECK: PASS: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/0.subTest
15 # CHECK: PASS: googletest-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/1.subTest
1916 # CHECK: Failing Tests (1)
2017 # CHECK: Expected Passes : 3
2118 # CHECK: Unexpected Failures: 1
0 # REQUIRES: python-psutil
1
2 # PR33934
3 # XFAIL: windows
41
52 # Check that the per test timeout is enforced when running GTest tests.
63 #
1512 # RUN: FileCheck < %t.cfgset.out %s
1613
1714 # CHECK: -- Testing:
18 # CHECK: PASS: googletest-timeout :: DummySubDir/OneTest/FirstTest.subTestA
19 # CHECK: TIMEOUT: googletest-timeout :: DummySubDir/OneTest/FirstTest.subTestB
20 # CHECK: TIMEOUT: googletest-timeout :: DummySubDir/OneTest/FirstTest.subTestC
15 # CHECK: PASS: googletest-timeout :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestA
16 # CHECK: TIMEOUT: googletest-timeout :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB
17 # CHECK: TIMEOUT: googletest-timeout :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestC
2118 # CHECK: Expected Passes : 1
2219 # CHECK: Individual Timeouts: 2
2320
0 # Check the various features of the GoogleTest format.
1 #
2 # PR33935
3 # XFAIL: windows
41 #
52 # RUN: not %{lit} -j 1 -v %{inputs}/googletest-upstream-format > %t.out
63 # RUN: FileCheck < %t.out %s
85 # END.
96
107 # CHECK: -- Testing:
11 # CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestA
12 # CHECK: FAIL: googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestB
13 # CHECK-NEXT: *** TEST 'googletest-upstream-format :: DummySubDir/OneTest/FirstTest.subTestB' FAILED ***
8 # CHECK: PASS: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestA
9 # CHECK: FAIL: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB
10 # CHECK-NEXT: *** TEST 'googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/FirstTest.subTestB' FAILED ***
1411 # CHECK-NEXT: Running main() from gtest_main.cc
1512 # CHECK-NEXT: I am subTest B, I FAIL
1613 # CHECK-NEXT: And I have two lines of output
1714 # CHECK: ***
18 # CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/ParameterizedTest/0.subTest
19 # CHECK: PASS: googletest-upstream-format :: DummySubDir/OneTest/ParameterizedTest/1.subTest
15 # CHECK: PASS: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/0.subTest
16 # CHECK: PASS: googletest-upstream-format :: {{[Dd]ummy[Ss]ub[Dd]ir}}/OneTest.py/ParameterizedTest/1.subTest
2017 # CHECK: Failing Tests (1)
2118 # CHECK: Expected Passes : 3
2219 # CHECK: Unexpected Failures: 1