Skip to content

Commit

Permalink
[lit, python3] Update lit error logging to work correctly in python3 …
Browse files Browse the repository at this point in the history
…and other test fixes

Summary:
In Python2 'unicode' is a distinct type from 'str', but in Python3 'unicode' does not exist and instead all 'str' objects are Unicode string. This change updates the logic in the test logging for lit to correctly process each of the types, and more importantly, to not just fail in Python3.

This change also reverses the use of quotes in several of the cfg files. By using '""' we are guaranteeing that the resulting path will work correctly on Windows while "''" only works correctly sometimes. This also fixes one of the failing tests.

Reviewers: asmith, zturner

Subscribers: stella.stamenova, delcypher, llvm-commits

Differential Revision: https://reviews.llvm.org/D50397

llvm-svn: 339179
  • Loading branch information
sstamenova committed Aug 7, 2018
1 parent 65bd2f6 commit 8efc95a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
11 changes: 8 additions & 3 deletions llvm/utils/lit/lit/Test.py
Expand Up @@ -378,10 +378,15 @@ def writeJUnitXML(self, fil):
fil.write(testcase_xml)
if self.result.code.isFailure:
fil.write(">\n\t<failure ><![CDATA[")
if type(self.result.output) == unicode:
encoded_output = self.result.output.encode("utf-8", 'ignore')
else:
# In Python2, 'str' and 'unicode' are distinct types, but in Python3, the type 'unicode' does not exist
# and instead 'bytes' is distinct
# in Python3, there's no unicode
if isinstance(self.result.output, str):
encoded_output = self.result.output
elif isinstance(self.result.output, bytes):
encoded_output = self.result.output.decode("utf-8", 'ignore')
else:
encoded_output = self.result.output.encode("utf-8", 'ignore')
# In the unlikely case that the output contains the CDATA terminator
# we wrap it by creating a new CDATA block
fil.write(encoded_output.replace("]]>", "]]]]><![CDATA[>"))
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/lit/lit/llvm/config.py
Expand Up @@ -299,7 +299,7 @@ def use_default_substitutions(self):
'count'), verbatim=True, unresolved='fatal'),
ToolSubst(r'\| \bnot\b', command=FindTool('not'), verbatim=True, unresolved='fatal')]

self.config.substitutions.append(('%python', "'%s'" % (sys.executable)))
self.config.substitutions.append(('%python', '"%s"' % (sys.executable)))

self.add_tool_substitutions(
tool_patterns, [self.config.llvm_tools_dir])
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/lit/tests/Inputs/shtest-env/lit.cfg
Expand Up @@ -6,4 +6,4 @@ config.test_source_root = None
config.test_exec_root = None
config.environment['FOO'] = '1'
config.environment['BAR'] = '2'
config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))
config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))
2 changes: 1 addition & 1 deletion llvm/utils/lit/tests/Inputs/shtest-shell/lit.cfg
Expand Up @@ -4,4 +4,4 @@ config.suffixes = ['.txt']
config.test_format = lit.formats.ShTest()
config.test_source_root = None
config.test_exec_root = None
config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))
config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))
2 changes: 1 addition & 1 deletion llvm/utils/lit/tests/Inputs/shtest-timeout/lit.cfg
Expand Up @@ -29,4 +29,4 @@ config.test_exec_root = config.test_source_root
config.target_triple = '(unused)'
src_root = os.path.join(config.test_source_root, '..')
config.environment['PYTHONPATH'] = src_root
config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))
config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))
2 changes: 1 addition & 1 deletion llvm/utils/lit/tests/lit.cfg
Expand Up @@ -40,7 +40,7 @@ config.substitutions.append(('%{inputs}', os.path.join(
src_root, 'tests', 'Inputs')))
config.substitutions.append(('%{lit}', "%%{python} %s" % (
os.path.join(lit_path, 'lit.py'),)))
config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))
config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))


# Enable coverage.py reporting, assuming the coverage module has been installed
Expand Down
3 changes: 0 additions & 3 deletions llvm/utils/lit/tests/shtest-timeout.py
@@ -1,8 +1,5 @@
# REQUIRES: python-psutil

# PR33944
# XFAIL: windows

# FIXME: This test is fragile because it relies on time which can
# be affected by system performance. In particular we are currently
# assuming that `short.py` can be successfully executed within 2
Expand Down

0 comments on commit 8efc95a

Please sign in to comment.