2018-04-19 01:08:49 +08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import os
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import lit.Test
|
|
|
|
import lit.TestRunner
|
|
|
|
import lit.util
|
|
|
|
from lit.formats.base import TestFormat
|
|
|
|
|
2018-08-24 01:19:08 +08:00
|
|
|
def getBuildDir(cmd):
|
|
|
|
found = False
|
|
|
|
for arg in cmd:
|
|
|
|
if found:
|
|
|
|
return arg
|
|
|
|
if arg == '--build-dir':
|
|
|
|
found = True
|
|
|
|
return None
|
2018-04-19 01:08:49 +08:00
|
|
|
|
2018-08-28 07:06:37 +08:00
|
|
|
def mkdir_p(path):
|
|
|
|
import errno
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
raise OSError(errno.ENOTDIR, "%s is not a directory"%path)
|
|
|
|
|
2018-04-19 01:08:49 +08:00
|
|
|
class LLDBTest(TestFormat):
|
|
|
|
def __init__(self, dotest_cmd):
|
|
|
|
self.dotest_cmd = dotest_cmd
|
|
|
|
|
|
|
|
def getTestsInDirectory(self, testSuite, path_in_suite, litConfig,
|
|
|
|
localConfig):
|
|
|
|
source_path = testSuite.getSourcePath(path_in_suite)
|
|
|
|
for filename in os.listdir(source_path):
|
|
|
|
# Ignore dot files and excluded tests.
|
|
|
|
if (filename.startswith('.') or filename in localConfig.excludes):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Ignore files that don't start with 'Test'.
|
|
|
|
if not filename.startswith('Test'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
filepath = os.path.join(source_path, filename)
|
|
|
|
if not os.path.isdir(filepath):
|
|
|
|
base, ext = os.path.splitext(filename)
|
|
|
|
if ext in localConfig.suffixes:
|
|
|
|
yield lit.Test.Test(testSuite, path_in_suite +
|
|
|
|
(filename, ), localConfig)
|
|
|
|
|
|
|
|
def execute(self, test, litConfig):
|
|
|
|
if litConfig.noExecute:
|
|
|
|
return lit.Test.PASS, ''
|
|
|
|
|
2019-12-14 02:37:33 +08:00
|
|
|
if not test.config.lldb_enable_python:
|
2018-06-06 17:44:14 +08:00
|
|
|
return (lit.Test.UNSUPPORTED, 'Python module disabled')
|
|
|
|
|
2018-04-19 01:08:49 +08:00
|
|
|
if test.config.unsupported:
|
|
|
|
return (lit.Test.UNSUPPORTED, 'Test is unsupported')
|
|
|
|
|
|
|
|
testPath, testFile = os.path.split(test.getSourcePath())
|
2018-08-21 06:00:32 +08:00
|
|
|
# On Windows, the system does not always correctly interpret
|
|
|
|
# shebang lines. To make sure we can execute the tests, add
|
|
|
|
# python exe as the first parameter of the command.
|
[lit, lldbsuite] Update the lldbsuite to correctly run tests on windows and windows server
Summary:
The new script to run the lldbtests as part of lit invokes each test by calling dotest.py, however, we cannot rely on the system to always correctly interpret the script as python causing the tests to be unresolved on windows (at least). To fix this, we need to make sure that the first parameter in the command line is the python executable itself.
In Makefile.rules, there are a number of windows specific definitions that rely on the HOST_OS being set as Windows_NT but the logic detecting the OS currently does not detect server versions of windows correctly. This change updates the logic to detect windows server as well.
Reviewers: asmith, labath, JDevlieghere, zturner
Reviewed By: JDevlieghere, zturner
Subscribers: zturner, llvm-commits
Differential Revision: https://reviews.llvm.org/D46020
llvm-svn: 330740
2018-04-25 01:08:05 +08:00
|
|
|
cmd = [sys.executable] + self.dotest_cmd + [testPath, '-p', testFile]
|
2018-04-19 01:08:49 +08:00
|
|
|
|
2018-08-24 01:19:08 +08:00
|
|
|
# The macOS system integrity protection (SIP) doesn't allow injecting
|
|
|
|
# libraries into system binaries, but this can be worked around by
|
|
|
|
# copying the binary into a different location.
|
2018-08-24 01:51:14 +08:00
|
|
|
if 'DYLD_INSERT_LIBRARIES' in test.config.environment and \
|
2018-08-31 14:01:02 +08:00
|
|
|
(sys.executable.startswith('/System/') or \
|
2019-11-09 01:06:39 +08:00
|
|
|
sys.executable.startswith('/usr/bin/')):
|
2018-08-24 01:19:08 +08:00
|
|
|
builddir = getBuildDir(cmd)
|
2018-08-28 07:06:37 +08:00
|
|
|
mkdir_p(builddir)
|
2018-08-24 01:19:08 +08:00
|
|
|
copied_python = os.path.join(builddir, 'copied-system-python')
|
2018-08-28 07:06:38 +08:00
|
|
|
if not os.path.isfile(copied_python):
|
|
|
|
import shutil, subprocess
|
|
|
|
python = subprocess.check_output([
|
2019-11-09 01:19:54 +08:00
|
|
|
sys.executable,
|
|
|
|
'-c',
|
|
|
|
'import sys; print(sys.executable)'
|
|
|
|
]).decode('utf-8').strip()
|
2018-08-28 07:06:38 +08:00
|
|
|
shutil.copy(python, copied_python)
|
2018-08-24 01:19:08 +08:00
|
|
|
cmd[0] = copied_python
|
|
|
|
|
2018-04-19 01:08:49 +08:00
|
|
|
try:
|
|
|
|
out, err, exitCode = lit.util.executeCommand(
|
|
|
|
cmd,
|
|
|
|
env=test.config.environment,
|
|
|
|
timeout=litConfig.maxIndividualTestTime)
|
|
|
|
except lit.util.ExecuteCommandTimeoutException:
|
|
|
|
return (lit.Test.TIMEOUT, 'Reached timeout of {} seconds'.format(
|
|
|
|
litConfig.maxIndividualTestTime))
|
|
|
|
|
|
|
|
if exitCode:
|
2019-01-18 07:30:06 +08:00
|
|
|
# Match FAIL but not XFAIL.
|
|
|
|
for line in out.splitlines() + err.splitlines():
|
|
|
|
if line.startswith('FAIL:'):
|
|
|
|
return lit.Test.FAIL, out + err
|
|
|
|
|
2018-12-21 04:44:23 +08:00
|
|
|
if 'XPASS:' in out or 'XPASS:' in err:
|
|
|
|
return lit.Test.XPASS, out + err
|
2018-12-18 05:40:37 +08:00
|
|
|
|
2019-09-26 03:31:54 +08:00
|
|
|
has_unsupported_tests = 'UNSUPPORTED:' in out or 'UNSUPPORTED:' in err
|
|
|
|
has_passing_tests = 'PASS:' in out or 'PASS:' in err
|
|
|
|
if has_unsupported_tests and not has_passing_tests:
|
|
|
|
return lit.Test.UNSUPPORTED, out + err
|
|
|
|
|
2018-04-19 01:08:49 +08:00
|
|
|
passing_test_line = 'RESULT: PASSED'
|
|
|
|
if passing_test_line not in out and passing_test_line not in err:
|
2019-08-30 06:02:28 +08:00
|
|
|
msg = ('Unable to find %r in dotest output (exit code %d):\n\n%s%s'
|
|
|
|
% (passing_test_line, exitCode, out, err))
|
2018-04-19 01:08:49 +08:00
|
|
|
return lit.Test.UNRESOLVED, msg
|
|
|
|
|
|
|
|
return lit.Test.PASS, ''
|