blob: 61e9ceb199ee4620c29c01ce93e1d9950322644a [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
Adrian Prantl748310b2018-08-23 17:19:08 +000012def getBuildDir(cmd):
13 found = False
14 for arg in cmd:
15 if found:
16 return arg
17 if arg == '--build-dir':
18 found = True
19 return None
Jonas Devlieghere1a928f32018-04-18 17:08:49 +000020
21class LLDBTest(TestFormat):
22 def __init__(self, dotest_cmd):
23 self.dotest_cmd = dotest_cmd
24
25 def getTestsInDirectory(self, testSuite, path_in_suite, litConfig,
26 localConfig):
27 source_path = testSuite.getSourcePath(path_in_suite)
28 for filename in os.listdir(source_path):
29 # Ignore dot files and excluded tests.
30 if (filename.startswith('.') or filename in localConfig.excludes):
31 continue
32
33 # Ignore files that don't start with 'Test'.
34 if not filename.startswith('Test'):
35 continue
36
37 filepath = os.path.join(source_path, filename)
38 if not os.path.isdir(filepath):
39 base, ext = os.path.splitext(filename)
40 if ext in localConfig.suffixes:
41 yield lit.Test.Test(testSuite, path_in_suite +
42 (filename, ), localConfig)
43
44 def execute(self, test, litConfig):
45 if litConfig.noExecute:
46 return lit.Test.PASS, ''
47
Michal Gorny6dde8362018-06-06 09:44:14 +000048 if test.config.lldb_disable_python:
49 return (lit.Test.UNSUPPORTED, 'Python module disabled')
50
Jonas Devlieghere1a928f32018-04-18 17:08:49 +000051 if test.config.unsupported:
52 return (lit.Test.UNSUPPORTED, 'Test is unsupported')
53
54 testPath, testFile = os.path.split(test.getSourcePath())
Adrian Prantl0e45df42018-08-20 22:00:32 +000055 # On Windows, the system does not always correctly interpret
56 # shebang lines. To make sure we can execute the tests, add
57 # python exe as the first parameter of the command.
Aaron Smithba48c9b2018-04-24 17:08:05 +000058 cmd = [sys.executable] + self.dotest_cmd + [testPath, '-p', testFile]
Jonas Devlieghere1a928f32018-04-18 17:08:49 +000059
Adrian Prantl748310b2018-08-23 17:19:08 +000060 # The macOS system integrity protection (SIP) doesn't allow injecting
61 # libraries into system binaries, but this can be worked around by
62 # copying the binary into a different location.
Adrian Prantl6c7f5882018-08-23 17:51:14 +000063 if 'DYLD_INSERT_LIBRARIES' in test.config.environment and \
Adrian Prantl748310b2018-08-23 17:19:08 +000064 sys.executable.startswith('/System/'):
65 builddir = getBuildDir(cmd)
66 assert(builddir)
67 copied_python = os.path.join(builddir, 'copied-system-python')
68 import shutil
69 shutil.copy(sys.executable, os.path.join(builddir, copied_python))
70 cmd[0] = copied_python
71
Jonas Devlieghere1a928f32018-04-18 17:08:49 +000072 try:
73 out, err, exitCode = lit.util.executeCommand(
74 cmd,
75 env=test.config.environment,
76 timeout=litConfig.maxIndividualTestTime)
77 except lit.util.ExecuteCommandTimeoutException:
78 return (lit.Test.TIMEOUT, 'Reached timeout of {} seconds'.format(
79 litConfig.maxIndividualTestTime))
80
81 if exitCode:
82 return lit.Test.FAIL, out + err
83
84 passing_test_line = 'RESULT: PASSED'
85 if passing_test_line not in out and passing_test_line not in err:
86 msg = ('Unable to find %r in dotest output:\n\n%s%s' %
87 (passing_test_line, out, err))
88 return lit.Test.UNRESOLVED, msg
89
90 return lit.Test.PASS, ''