[llvm] r329466 - [lit] Fix several Python 2/3 compatibility issues and tests

Aaron Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 6 17:21:28 PDT 2018


Author: asmith
Date: Fri Apr  6 17:21:28 2018
New Revision: 329466

URL: http://llvm.org/viewvc/llvm-project?rev=329466&view=rev
Log:
[lit] Fix several Python 2/3 compatibility issues and tests

- In Python 2.x, basestring is the base string type, but in 
  Python 3.x basestring is not defined and instead str includes 
  unicode strings.

- When Python is in a path that includes spaces, it needs to 
  be specified with quotes in the test files for it to run.

- The cache.ll test relies on files of a specific size being 
  created by Python, but on some versions of Windows the 
  files that are created by the current code are one byte 
  larger than expected. To fix the test, update file creation 
  to always make files of the expected size.

Patch by Stella Stamenova!

Modified:
    llvm/trunk/test/Other/opt-bisect-legacy-pass-manager.ll
    llvm/trunk/test/ThinLTO/X86/cache.ll
    llvm/trunk/utils/lit/lit/TestRunner.py

Modified: llvm/trunk/test/Other/opt-bisect-legacy-pass-manager.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/opt-bisect-legacy-pass-manager.ll?rev=329466&r1=329465&r2=329466&view=diff
==============================================================================
--- llvm/trunk/test/Other/opt-bisect-legacy-pass-manager.ll (original)
+++ llvm/trunk/test/Other/opt-bisect-legacy-pass-manager.ll Fri Apr  6 17:21:28 2018
@@ -38,7 +38,7 @@
 ; utils/bisect) to locate the optimization that inlines the call to
 ; f2() in f3().
 
-; RUN: %python %S/opt-bisect-helper.py --start=0 --end=256 --optcmd=opt \
+; RUN: '%python' %S/opt-bisect-helper.py --start=0 --end=256 --optcmd=opt \
 ; RUN:         --filecheckcmd=FileCheck --test=%s \
 ; RUN:         --prefix=CHECK-BISECT-INLINE-HELPER \
 ; RUN:         | FileCheck %s --check-prefix=CHECK-BISECT-INLINE-RESULT

Modified: llvm/trunk/test/ThinLTO/X86/cache.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/cache.ll?rev=329466&r1=329465&r2=329466&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/cache.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/cache.ll Fri Apr  6 17:21:28 2018
@@ -85,11 +85,11 @@
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; Create cache files with different sizes.
 ; Only 8B, 16B and 76B files should stay after pruning.
-; RUN: %python -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
-; RUN: %python -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
-; RUN: %python -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
-; RUN: %python -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
-; RUN: %python -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
+; RUN: "%python" -c "with open(r'%t.cache/llvmcache-foo-1024', 'w') as file: file.truncate(1024)"
+; RUN: "%python" -c "with open(r'%t.cache/llvmcache-foo-16', 'w') as file: file.truncate(16)"
+; RUN: "%python" -c "with open(r'%t.cache/llvmcache-foo-8', 'w') as file: file.truncate(8)"
+; RUN: "%python" -c "with open(r'%t.cache/llvmcache-foo-76', 'w') as file: file.truncate(76)"
+; RUN: "%python" -c "with open(r'%t.cache/llvmcache-foo-77', 'w') as file: file.truncate(77)"
 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-bytes 100
 ; RUN: ls %t.cache/llvmcache-foo-16
 ; RUN: ls %t.cache/llvmcache-foo-8
@@ -102,11 +102,11 @@
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; Create cache files with different sizes.
 ; Only 8B and 16B files should stay after pruning.
-; RUN: %python -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
-; RUN: %python -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
-; RUN: %python -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
-; RUN: %python -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
-; RUN: %python -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
+; RUN: "%python" -c "print(' ' * 1023)" > %t.cache/llvmcache-foo-1024
+; RUN: "%python" -c "print(' ' * 15)" > %t.cache/llvmcache-foo-16
+; RUN: "%python" -c "print(' ' * 7)" > %t.cache/llvmcache-foo-8
+; RUN: "%python" -c "print(' ' * 75)" > %t.cache/llvmcache-foo-76
+; RUN: "%python" -c "print(' ' * 76)" > %t.cache/llvmcache-foo-77
 ; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc %t.bc -thinlto-cache-dir %t.cache --thinlto-cache-max-size-files 2
 ; RUN: ls %t.cache/llvmcache-foo-16
 ; RUN: ls %t.cache/llvmcache-foo-8

Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=329466&r1=329465&r2=329466&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Fri Apr  6 17:21:28 2018
@@ -845,8 +845,14 @@ def _executeShCmd(cmd, shenv, results, t
 
         # Replace uses of /dev/null with temporary files.
         if kAvoidDevNull:
+            # In Python 2.x, basestring is the base class for all string (including unicode)
+            # In Python 3.x, basestring no longer exist and str is always unicode
+            try:
+                str_type = basestring
+            except NameError:
+                str_type = str
             for i,arg in enumerate(args):
-                if isinstance(arg, basestring) and kDevNull in arg:
+                if isinstance(arg, str_type) and kDevNull in arg:
                     f = tempfile.NamedTemporaryFile(delete=False)
                     f.close()
                     named_temp_files.append(f.name)




More information about the llvm-commits mailing list