blob: 4c3f01b803a59bcf2ff90f9a88f2a8669bb9a544 [file] [log] [blame]
Jonas Devlieghere1a928f32018-04-18 17:08:49 +00001from __future__ import absolute_import
2import os
3
4import subprocess
5import sys
6
7import lit.Test
8import lit.TestRunner
9import lit.util
10from lit.formats.base import TestFormat
11
12
13class LLDBTest(TestFormat):
14 def __init__(self, dotest_cmd):
15 self.dotest_cmd = dotest_cmd
16
17 def getTestsInDirectory(self, testSuite, path_in_suite, litConfig,
18 localConfig):
19 source_path = testSuite.getSourcePath(path_in_suite)
20 for filename in os.listdir(source_path):
21 # Ignore dot files and excluded tests.
22 if (filename.startswith('.') or filename in localConfig.excludes):
23 continue
24
25 # Ignore files that don't start with 'Test'.
26 if not filename.startswith('Test'):
27 continue
28
29 filepath = os.path.join(source_path, filename)
30 if not os.path.isdir(filepath):
31 base, ext = os.path.splitext(filename)
32 if ext in localConfig.suffixes:
33 yield lit.Test.Test(testSuite, path_in_suite +
34 (filename, ), localConfig)
35
36 def execute(self, test, litConfig):
37 if litConfig.noExecute:
38 return lit.Test.PASS, ''
39
40 if test.config.unsupported:
41 return (lit.Test.UNSUPPORTED, 'Test is unsupported')
42
43 testPath, testFile = os.path.split(test.getSourcePath())
Aaron Smithba48c9b2018-04-24 17:08:05 +000044 # On Windows, the system does not always correctly interpret shebang lines.
45 # To make sure we can execute the tests, add python exe as the first parameter
46 # of the command.
47 cmd = [sys.executable] + self.dotest_cmd + [testPath, '-p', testFile]
Jonas Devlieghere1a928f32018-04-18 17:08:49 +000048
49 try:
50 out, err, exitCode = lit.util.executeCommand(
51 cmd,
52 env=test.config.environment,
53 timeout=litConfig.maxIndividualTestTime)
54 except lit.util.ExecuteCommandTimeoutException:
55 return (lit.Test.TIMEOUT, 'Reached timeout of {} seconds'.format(
56 litConfig.maxIndividualTestTime))
57
58 if exitCode:
59 return lit.Test.FAIL, out + err
60
61 passing_test_line = 'RESULT: PASSED'
62 if passing_test_line not in out and passing_test_line not in err:
63 msg = ('Unable to find %r in dotest output:\n\n%s%s' %
64 (passing_test_line, out, err))
65 return lit.Test.UNRESOLVED, msg
66
67 return lit.Test.PASS, ''