Jonas Devlieghere | 1a928f3 | 2018-04-18 17:08:49 +0000 | [diff] [blame] | 1 | from __future__ import absolute_import |
| 2 | import os |
| 3 | |
| 4 | import subprocess |
| 5 | import sys |
| 6 | |
| 7 | import lit.Test |
| 8 | import lit.TestRunner |
| 9 | import lit.util |
| 10 | from lit.formats.base import TestFormat |
| 11 | |
| 12 | |
| 13 | class 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 Smith | ba48c9b | 2018-04-24 17:08:05 +0000 | [diff] [blame] | 44 | # 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 Devlieghere | 1a928f3 | 2018-04-18 17:08:49 +0000 | [diff] [blame] | 48 | |
| 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, '' |