2018-04-19 01:08:49 +08:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import os
|
2020-04-14 23:41:50 +08:00
|
|
|
import tempfile
|
2018-04-19 01:08:49 +08:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-05-08 07:07:32 +08:00
|
|
|
import platform
|
2018-04-19 01:08:49 +08:00
|
|
|
|
|
|
|
import lit.Test
|
|
|
|
import lit.TestRunner
|
|
|
|
import lit.util
|
|
|
|
from lit.formats.base import TestFormat
|
|
|
|
|
2018-08-28 07:06:37 +08:00
|
|
|
|
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, ''
|
|
|
|
|
2020-08-29 09:05:01 +08:00
|
|
|
if not getattr(test.config, 'lldb_enable_python', False):
|
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())
|
2020-05-07 05:33:34 +08:00
|
|
|
|
|
|
|
# The Python used to run lit can be different from the Python LLDB was
|
|
|
|
# build with.
|
|
|
|
executable = test.config.python_executable
|
|
|
|
|
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.
|
2020-05-07 05:33:34 +08:00
|
|
|
cmd = [executable] + self.dotest_cmd + [testPath, '-p', testFile]
|
2018-04-19 01:08:49 +08:00
|
|
|
|
2020-04-14 23:41:50 +08:00
|
|
|
if 'lldb-repro-capture' in test.config.available_features or \
|
|
|
|
'lldb-repro-replay' in test.config.available_features:
|
2020-06-12 10:29:26 +08:00
|
|
|
reproducer_path = os.path.join(
|
|
|
|
test.config.lldb_reproducer_directory, testFile)
|
2020-04-14 23:41:50 +08:00
|
|
|
if 'lldb-repro-capture' in test.config.available_features:
|
|
|
|
cmd.extend(['--capture-path', reproducer_path])
|
|
|
|
else:
|
|
|
|
cmd.extend(['--replay-path', reproducer_path])
|
|
|
|
|
2020-01-25 08:11:18 +08:00
|
|
|
timeoutInfo = None
|
2018-04-19 01:08:49 +08:00
|
|
|
try:
|
|
|
|
out, err, exitCode = lit.util.executeCommand(
|
|
|
|
cmd,
|
|
|
|
env=test.config.environment,
|
|
|
|
timeout=litConfig.maxIndividualTestTime)
|
2020-01-31 13:23:58 +08:00
|
|
|
except lit.util.ExecuteCommandTimeoutException as e:
|
|
|
|
out = e.out
|
|
|
|
err = e.err
|
|
|
|
exitCode = e.exitCode
|
2020-01-25 08:11:18 +08:00
|
|
|
timeoutInfo = 'Reached timeout of {} seconds'.format(
|
|
|
|
litConfig.maxIndividualTestTime)
|
|
|
|
|
2020-04-21 23:25:44 +08:00
|
|
|
if sys.version_info.major == 2:
|
[lldb/test] Fix for flakiness in TestNSDictionarySynthetic
Summary:
TestNSDictionarySynthetic sets up an NSURL which does not initialize its
_baseURL member. When the test runs and we print out the NSURL, we print
out some garbage memory pointed-to by the _baseURL member, like:
```
_baseURL = 0x0800010020004029 @"d��qX"
```
and this can cause a python unicode decoding error like:
```
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position
10309: invalid start byte
```
There's a discrepancy here because lldb's StringPrinter facility tries
to only print out "printable" sequences (see: isprint32()), whereas python
rejects the StringPrinter output as invalid utf8. For the specific error
seen above, lldb's `isprint32(0xa0) = true`, even though 0xa0 is not
really "printable" in the usual sense.
The problem is that lldb and python disagree on what exactly is
"printable". Both have dismayingly hand-rolled utf8 validation code
(c.f. _Py_DecodeUTF8Ex), and I can't really tell which one is more
correct.
I tried replacing lldb's isprint32() with a call to libc's iswprint():
this satisfied python, but broke emoji printing :|.
Now, I believe that lldb (and python too) ought to just call into some
battle-tested utf library, and that we shouldn't aim for compatibility
with python's strict unicode decoding mode until then.
FWIW I ran this test under an ASanified lldb hundreds of times but
didn't turn up any other issues.
rdar://62941711
Reviewers: JDevlieghere, jingham, shafik
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D79645
2020-05-07 07:08:19 +08:00
|
|
|
# In Python 2, string objects can contain Unicode characters. Use
|
|
|
|
# the non-strict 'replace' decoding mode. We cannot use the strict
|
|
|
|
# mode right now because lldb's StringPrinter facility and the
|
|
|
|
# Python utf8 decoder have different interpretations of which
|
|
|
|
# characters are "printable". This leads to Python utf8 decoding
|
|
|
|
# exceptions even though lldb is behaving as expected.
|
|
|
|
out = out.decode('utf-8', 'replace')
|
|
|
|
err = err.decode('utf-8', 'replace')
|
2020-04-21 23:25:44 +08:00
|
|
|
|
2020-01-25 08:11:18 +08:00
|
|
|
output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % (
|
|
|
|
' '.join(cmd), exitCode)
|
|
|
|
if timeoutInfo is not None:
|
|
|
|
output += """Timeout: %s\n""" % (timeoutInfo,)
|
|
|
|
output += "\n"
|
|
|
|
|
|
|
|
if out:
|
|
|
|
output += """Command Output (stdout):\n--\n%s\n--\n""" % (out,)
|
|
|
|
if err:
|
|
|
|
output += """Command Output (stderr):\n--\n%s\n--\n""" % (err,)
|
|
|
|
|
|
|
|
if timeoutInfo:
|
|
|
|
return lit.Test.TIMEOUT, output
|
2018-04-19 01:08:49 +08:00
|
|
|
|
|
|
|
if exitCode:
|
2018-12-21 04:44:23 +08:00
|
|
|
if 'XPASS:' in out or 'XPASS:' in err:
|
2020-01-25 08:11:18 +08:00
|
|
|
return lit.Test.XPASS, output
|
2018-12-18 05:40:37 +08:00
|
|
|
|
2020-02-25 15:20:41 +08:00
|
|
|
# Otherwise this is just a failure.
|
|
|
|
return lit.Test.FAIL, output
|
|
|
|
|
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:
|
2020-01-25 08:11:18 +08:00
|
|
|
return lit.Test.UNSUPPORTED, output
|
2019-09-26 03:31:54 +08:00
|
|
|
|
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:
|
2020-01-25 08:11:18 +08:00
|
|
|
return lit.Test.UNRESOLVED, output
|
2018-04-19 01:08:49 +08:00
|
|
|
|
2020-01-25 08:11:18 +08:00
|
|
|
return lit.Test.PASS, output
|