Skip to content

Commit

Permalink
[lit] Prevent hang when lit sees non-ASCII characters
Browse files Browse the repository at this point in the history
As per discussion in D69207, have lit ignore UnicodeDecodeErrors
when running with python 2 in an ASCII shell.

Differential Revision: https://reviews.llvm.org/D82754
  • Loading branch information
RichBarton-Arm committed Jul 14, 2020
1 parent 9017b9c commit f4476b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion llvm/utils/lit/lit/display.py
Expand Up @@ -86,7 +86,10 @@ def print_result(self, test):
errors="replace")
except UnicodeDecodeError:
pass
out = out.decode(encoding=sys.stdout.encoding)
# Python 2 can raise UnicodeDecodeError here too in cases
# where the stdout encoding is ASCII. Ignore decode errors
# in this case.
out = out.decode(encoding=sys.stdout.encoding, errors="ignore")
print(out)
print("*" * 20)

Expand Down
22 changes: 15 additions & 7 deletions llvm/utils/lit/tests/shtest-shell.py
Expand Up @@ -6,6 +6,14 @@
# RUN: cat %t.out
# RUN: FileCheck --input-file %t.out %s
#
# Test again in non-UTF shell to catch potential errors with python 2 seen
# on stdout-encoding.txt
# RUN: env PYTHONIOENCODING=ascii not %{lit} -j 1 -a %{inputs}/shtest-shell > %t.ascii.out
# FIXME: Temporarily dump test output so we can debug failing tests on
# buildbots.
# RUN: cat %t.ascii.out
# RUN: FileCheck --input-file %t.ascii.out %s
#
# END.

# CHECK: -- Testing:
Expand Down Expand Up @@ -64,7 +72,7 @@
# CHECK-NEXT: @@
# CHECK-NEXT: {{^ .f.o.o.$}}
# CHECK-NEXT: {{^-.b.a.r.$}}
# CHECK-NEXT: {{^\+.b.a.r..}}
# CHECK-NEXT: {{^\+.b.a.r.}}
# CHECK-NEXT: {{^ .b.a.z.$}}
# CHECK: error: command failed with exit status: 1
# CHECK: $ "true"
Expand All @@ -78,7 +86,7 @@
# CHECK-NEXT: -bar
# CHECK-NEXT: -baz
# CHECK-NEXT: {{^\+.f.o.o.$}}
# CHECK-NEXT: {{^\+.b.a.r..}}
# CHECK-NEXT: {{^\+.b.a.r.}}
# CHECK-NEXT: {{^\+.b.a.z.$}}
# CHECK: error: command failed with exit status: 1
# CHECK: $ "true"
Expand All @@ -89,7 +97,7 @@
# CHECK-NEXT: +++
# CHECK-NEXT: @@
# CHECK-NEXT: {{^\-.f.o.o.$}}
# CHECK-NEXT: {{^\-.b.a.r..}}
# CHECK-NEXT: {{^\-.b.a.r.}}
# CHECK-NEXT: {{^\-.b.a.z.$}}
# CHECK-NEXT: +foo
# CHECK-NEXT: +bar
Expand All @@ -116,7 +124,7 @@
# CHECK-NEXT: @@
# CHECK-NEXT: {{^ .f.o.o.$}}
# CHECK-NEXT: {{^-.b.a.r.$}}
# CHECK-NEXT: {{^\+.b.a.r..}}
# CHECK-NEXT: {{^\+.b.a.r.}}
# CHECK-NEXT: {{^ .b.a.z.$}}
# CHECK: error: command failed with exit status: 1
# CHECK: $ "true"
Expand All @@ -132,7 +140,7 @@
# CHECK-NEXT: -bar
# CHECK-NEXT: -baz
# CHECK-NEXT: {{^\+.f.o.o.$}}
# CHECK-NEXT: {{^\+.b.a.r..}}
# CHECK-NEXT: {{^\+.b.a.r.}}
# CHECK-NEXT: {{^\+.b.a.z.$}}
# CHECK: error: command failed with exit status: 1
# CHECK: $ "true"
Expand All @@ -143,7 +151,7 @@
# CHECK-NEXT: +++
# CHECK-NEXT: @@
# CHECK-NEXT: {{^\-.f.o.o.$}}
# CHECK-NEXT: {{^\-.b.a.r..}}
# CHECK-NEXT: {{^\-.b.a.r.}}
# CHECK-NEXT: {{^\-.b.a.z.$}}
# CHECK-NEXT: +foo
# CHECK-NEXT: +bar
Expand Down Expand Up @@ -576,7 +584,7 @@
# CHECK: $ "cat" "diff-in.bin"
# CHECK: # command output:
# CHECK-NEXT: {{^.f.o.o.$}}
# CHECK-NEXT: {{^.b.a.r..}}
# CHECK-NEXT: {{^.b.a.r.}}
# CHECK-NEXT: {{^.b.a.z.$}}
# CHECK-NOT: error
# CHECK: $ "false"
Expand Down

0 comments on commit f4476b7

Please sign in to comment.