[LNT] r373617 - [LNT] Python 3 support: fix text/binary confusion in profile support

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 3 08:37:16 PDT 2019


Author: thopre
Date: Thu Oct  3 08:37:16 2019
New Revision: 373617

URL: http://llvm.org/viewvc/llvm-project?rev=373617&view=rev
Log:
[LNT] Python 3 support: fix text/binary confusion in profile support

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.

Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls

Reviewed By: hubert.reinterpretcast

Subscribers: llvm-commits

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

Modified:
    lnt/trunk/lnt/testing/profile/perf.py
    lnt/trunk/lnt/testing/profile/profilev1impl.py
    lnt/trunk/lnt/testing/profile/profilev2impl.py

Modified: lnt/trunk/lnt/testing/profile/perf.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/profile/perf.py?rev=373617&r1=373616&r2=373617&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/profile/perf.py (original)
+++ lnt/trunk/lnt/testing/profile/perf.py Thu Oct  3 08:37:16 2019
@@ -18,7 +18,7 @@ class LinuxPerfProfile(ProfileImpl):
 
     @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):

Modified: lnt/trunk/lnt/testing/profile/profilev1impl.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/profile/profilev1impl.py?rev=373617&r1=373616&r2=373617&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/profile/profilev1impl.py (original)
+++ lnt/trunk/lnt/testing/profile/profilev1impl.py Thu Oct  3 08:37:16 2019
@@ -43,7 +43,7 @@ The ``self.data`` member has this format
     @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):

Modified: lnt/trunk/lnt/testing/profile/profilev2impl.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/profile/profilev2impl.py?rev=373617&r1=373616&r2=373617&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/profile/profilev2impl.py (original)
+++ lnt/trunk/lnt/testing/profile/profilev2impl.py Thu Oct  3 08:37:16 2019
@@ -558,7 +558,7 @@ class ProfileV2(ProfileImpl):
     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):




More information about the llvm-commits mailing list