We have a function somewhere in lit utils that does this, but I’m OOO so I can’t look for it.  Can you try to find it?<br><div class="gmail_quote"><div dir="ltr">On Tue, Aug 7, 2018 at 1:29 PM Stella Stamenova via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">stella.stamenova created this revision.<br>
stella.stamenova added reviewers: asmith, zturner.<br>
Herald added subscribers: llvm-commits, delcypher.<br>
<br>
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.<br>
<br>
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.<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D50397" rel="noreferrer" target="_blank">https://reviews.llvm.org/D50397</a><br>
<br>
Files:<br>
  utils/lit/lit/Test.py<br>
  utils/lit/lit/llvm/config.py<br>
  utils/lit/tests/Inputs/shtest-env/lit.cfg<br>
  utils/lit/tests/Inputs/shtest-shell/lit.cfg<br>
  utils/lit/tests/Inputs/shtest-timeout/lit.cfg<br>
  utils/lit/tests/lit.cfg<br>
  utils/lit/tests/shtest-timeout.py<br>
<br>
<br>
Index: utils/lit/tests/shtest-timeout.py<br>
===================================================================<br>
--- utils/lit/tests/shtest-timeout.py<br>
+++ utils/lit/tests/shtest-timeout.py<br>
@@ -1,8 +1,5 @@<br>
 # REQUIRES: python-psutil<br>
<br>
-# PR33944<br>
-# XFAIL: windows<br>
-<br>
 # FIXME: This test is fragile because it relies on time which can<br>
 # be affected by system performance. In particular we are currently<br>
 # assuming that `short.py` can be successfully executed within 2<br>
Index: utils/lit/tests/lit.cfg<br>
===================================================================<br>
--- utils/lit/tests/lit.cfg<br>
+++ utils/lit/tests/lit.cfg<br>
@@ -40,7 +40,7 @@<br>
             src_root, 'tests', 'Inputs')))<br>
 config.substitutions.append(('%{lit}', "%%{python} %s" % (<br>
             os.path.join(lit_path, 'lit.py'),)))<br>
-config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))<br>
+config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))<br>
<br>
<br>
 # Enable coverage.py reporting, assuming the coverage module has been installed<br>
Index: utils/lit/tests/Inputs/shtest-timeout/lit.cfg<br>
===================================================================<br>
--- utils/lit/tests/Inputs/shtest-timeout/lit.cfg<br>
+++ utils/lit/tests/Inputs/shtest-timeout/lit.cfg<br>
@@ -29,4 +29,4 @@<br>
 config.target_triple = '(unused)'<br>
 src_root = os.path.join(config.test_source_root, '..')<br>
 config.environment['PYTHONPATH'] = src_root<br>
-config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))<br>
+config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))<br>
Index: utils/lit/tests/Inputs/shtest-shell/lit.cfg<br>
===================================================================<br>
--- utils/lit/tests/Inputs/shtest-shell/lit.cfg<br>
+++ utils/lit/tests/Inputs/shtest-shell/lit.cfg<br>
@@ -4,4 +4,4 @@<br>
 config.test_format = lit.formats.ShTest()<br>
 config.test_source_root = None<br>
 config.test_exec_root = None<br>
-config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))<br>
+config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))<br>
Index: utils/lit/tests/Inputs/shtest-env/lit.cfg<br>
===================================================================<br>
--- utils/lit/tests/Inputs/shtest-env/lit.cfg<br>
+++ utils/lit/tests/Inputs/shtest-env/lit.cfg<br>
@@ -6,4 +6,4 @@<br>
 config.test_exec_root = None<br>
 config.environment['FOO'] = '1'<br>
 config.environment['BAR'] = '2'<br>
-config.substitutions.append(('%{python}', "'%s'" % (sys.executable)))<br>
+config.substitutions.append(('%{python}', '"%s"' % (sys.executable)))<br>
Index: utils/lit/lit/llvm/config.py<br>
===================================================================<br>
--- utils/lit/lit/llvm/config.py<br>
+++ utils/lit/lit/llvm/config.py<br>
@@ -299,7 +299,7 @@<br>
                 'count'), verbatim=True, unresolved='fatal'),<br>
             ToolSubst(r'\| \bnot\b', command=FindTool('not'), verbatim=True, unresolved='fatal')]<br>
<br>
-        self.config.substitutions.append(('%python', "'%s'" % (sys.executable)))<br>
+        self.config.substitutions.append(('%python', '"%s"' % (sys.executable)))<br>
<br>
         self.add_tool_substitutions(<br>
             tool_patterns, [self.config.llvm_tools_dir])<br>
Index: utils/lit/lit/Test.py<br>
===================================================================<br>
--- utils/lit/lit/Test.py<br>
+++ utils/lit/lit/Test.py<br>
@@ -378,10 +378,15 @@<br>
         fil.write(testcase_xml)<br>
         if self.result.code.isFailure:<br>
             fil.write(">\n\t<failure ><![CDATA[")<br>
-            if type(self.result.output) == unicode:<br>
-                encoded_output = self.result.output.encode("utf-8", 'ignore')<br>
-            else:<br>
+            # In Python2, 'str' and 'unicode' are distinct types, but in Python3, the type 'unicode' does not exist<br>
+            # and instead 'bytes' is distinct<br>
+            # in Python3, there's no unicode<br>
+            if isinstance(self.result.output, str):<br>
                 encoded_output = self.result.output<br>
+            elif isinstance(self.result.output, bytes):<br>
+                encoded_output = self.result.output.decode("utf-8", 'ignore')<br>
+            else:<br>
+                encoded_output = self.result.output.encode("utf-8", 'ignore')<br>
             # In the unlikely case that the output contains the CDATA terminator<br>
             # we wrap it by creating a new CDATA block<br>
             fil.write(encoded_output.replace("]]>", "]]]]><![CDATA[>"))<br>
<br>
<br>
</blockquote></div>