[PATCH] D68222: [LNT] Python 3 support: fix text/binary confusion in profile support

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 06:56:47 PDT 2019


thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.
thopre added a parent revision: D68221: [LNT] Python 3 support: stable profile getFunctions output.

There is confusion between text and binary in the checkFile method of
the various profile format implementation modules. All of them compare
the first few bytes read in text mode against an expected value.
However, the header of the profile v1 contains some binary data, thus
causing an error in Python 3 when reading a profile v1 file and calling
any of the checkFile method.

This commit changes the checkFile method to read binary data and compare
against binary literals.


https://reviews.llvm.org/D68222

Files:
  lnt/testing/profile/perf.py
  lnt/testing/profile/profilev1impl.py
  lnt/testing/profile/profilev2impl.py


Index: lnt/testing/profile/profilev2impl.py
===================================================================
--- lnt/testing/profile/profilev2impl.py
+++ lnt/testing/profile/profilev2impl.py
@@ -561,7 +561,7 @@
     def checkFile(fn):
         # The first number is the version (2); ULEB encoded this is simply
         # 0x02.
-        return ord(open(fn).read(1)) == 2
+        return open(fn, 'rb').read(1) == b'\x02'
 
     @staticmethod
     def deserialize(fobj):
Index: lnt/testing/profile/profilev1impl.py
===================================================================
--- lnt/testing/profile/profilev1impl.py
+++ lnt/testing/profile/profilev1impl.py
@@ -45,7 +45,7 @@
     @staticmethod
     def checkFile(fn):
         # "zlib compressed data" - 78 9C
-        return open(fn).read(2) == '\x78\x9c'
+        return open(fn, 'rb').read(2) == b'\x78\x9c'
 
     @staticmethod
     def deserialize(fobj):
Index: lnt/testing/profile/perf.py
===================================================================
--- lnt/testing/profile/perf.py
+++ lnt/testing/profile/perf.py
@@ -18,7 +18,7 @@
 
     @staticmethod
     def checkFile(fn):
-        return open(fn).read(8) == 'PERFILE2'
+        return open(fn, 'rb').read(8) == b'PERFILE2'
 
     @staticmethod
     def deserialize(f, nm='nm', objdump='objdump', propagateExceptions=False):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68222.222418.patch
Type: text/x-patch
Size: 1352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/1d1a3635/attachment-0001.bin>


More information about the llvm-commits mailing list