Blame SOURCES/0020-Switch-test-runner-script-to-print-function.patch

fc9b0e
From 85b75e22bf685948f417044676de42f2da66a902 Mon Sep 17 00:00:00 2001
fc9b0e
Message-Id: <85b75e22bf685948f417044676de42f2da66a902.1566225007.git.aquini@redhat.com>
fc9b0e
In-Reply-To: <d42f467a923dfc09309acb7a83b42e3285fbd8f4.1566225007.git.aquini@redhat.com>
fc9b0e
References: <d42f467a923dfc09309acb7a83b42e3285fbd8f4.1566225007.git.aquini@redhat.com>
fc9b0e
From: David Gibson <david@gibson.dropbear.id.au>
fc9b0e
Date: Sat, 17 Aug 2019 20:59:44 +1000
fc9b0e
Subject: [RHEL7 PATCH 20/31] Switch test runner script to print function
fc9b0e
fc9b0e
This is the more modern Python style, and reduces difference to Python3.
fc9b0e
fc9b0e
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
fc9b0e
Signed-off-by: Eric B Munson <eric@munsonfam.org>
fc9b0e
Signed-off-by: Rafael Aquini <aquini@redhat.com>
fc9b0e
---
fc9b0e
 tests/run_tests.py | 84 ++++++++++++++++++++++++++++--------------------------
fc9b0e
 1 file changed, 44 insertions(+), 40 deletions(-)
fc9b0e
ca0f40
diff --git a/tests/run_tests.py b/tests/run_tests.py
fc9b0e
index 721c1af..47eb183 100755
ca0f40
--- a/tests/run_tests.py
ca0f40
+++ b/tests/run_tests.py
fc9b0e
@@ -1,5 +1,7 @@
fc9b0e
 #! /usr/bin/python2
ca0f40
 
fc9b0e
+from __future__ import print_function
fc9b0e
+
ca0f40
 import subprocess
ca0f40
 import types
fc9b0e
 import os
fc9b0e
@@ -60,7 +62,7 @@ def snapshot_pool_state():
ca0f40
 def run_test_prog(bits, pagesize, cmd, **env):
ca0f40
     if paranoid_pool_check:
ca0f40
         beforepool = snapshot_pool_state()
ca0f40
-        print "Pool state: %s" % str(beforepool)
ca0f40
+        print("Pool state: %s" % str(beforepool))
ca0f40
 
ca0f40
     local_env = os.environ.copy()
ca0f40
     local_env.update(env)
fc9b0e
@@ -83,9 +85,9 @@ def run_test_prog(bits, pagesize, cmd, **env):
ca0f40
     if paranoid_pool_check:
ca0f40
         afterpool = snapshot_pool_state()
ca0f40
         if afterpool != beforepool:
ca0f40
-            print >>sys.stderr, "Hugepage pool state not preserved!"
ca0f40
-            print >>sys.stderr, "BEFORE: %s" % str(beforepool)
ca0f40
-            print >>sys.stderr, "AFTER: %s" % str(afterpool)
ca0f40
+            print("Hugepage pool state not preserved!", file=sys.stderr)
ca0f40
+            print("BEFORE: %s" % str(beforepool), file=sys.stderr)
ca0f40
+            print("AFTER: %s" % str(afterpool), file=sys.stderr)
ca0f40
             sys.exit(98)
ca0f40
 
fc9b0e
     return (rc, out)
fc9b0e
@@ -143,22 +145,24 @@ def print_per_size(title, values):
ca0f40
     Print the results of a given result type on one line.  The results for all
ca0f40
     page sizes and word sizes are written in a table format.
ca0f40
     """
ca0f40
-    print "*%20s: " % title,
fc9b0e
+    print("*%20s: " % title, end=" ")
ca0f40
     for sz in pagesizes:
ca0f40
-        print "%4s   %4s   " % (values[sz][32], values[sz][64]),
ca0f40
-    print
fc9b0e
+        print("%4s   %4s   " % (values[sz][32], values[sz][64]), end="")
ca0f40
+    print()
ca0f40
 
ca0f40
 def results_summary():
ca0f40
     """
ca0f40
     Display a summary of the test results
ca0f40
     """
ca0f40
-    print "********** TEST SUMMARY"
ca0f40
-    print "*%21s" % "",
ca0f40
-    for p in pagesizes: print "%-13s " % pretty_page_size(p),
ca0f40
-    print
ca0f40
-    print "*%21s" % "",
ca0f40
-    for p in pagesizes: print "32-bit 64-bit ",
ca0f40
-    print
ca0f40
+    print("********** TEST SUMMARY")
fc9b0e
+    print("*%21s" % "", end=" ")
fc9b0e
+    for p in pagesizes:
fc9b0e
+        print("%-13s " % pretty_page_size(p), end="")
ca0f40
+    print()
fc9b0e
+    print("*%21s" % "", end=" ")
fc9b0e
+    for p in pagesizes:
fc9b0e
+        print("32-bit 64-bit ", end="")
ca0f40
+    print()
ca0f40
 
ca0f40
     print_per_size("Total testcases", R["total"])
ca0f40
     print_per_size("Skipped", R["skip"])
fc9b0e
@@ -170,7 +174,7 @@ def results_summary():
ca0f40
     print_per_size("Unexpected PASS", R["xpass"])
ca0f40
     print_per_size("Test not present", R["nofile"])
ca0f40
     print_per_size("Strange test result", R["strange"])
ca0f40
-    print "**********"
ca0f40
+    print("**********")
ca0f40
 
fc9b0e
 def free_hpages(size=None):
ca0f40
     """
fc9b0e
@@ -276,13 +280,13 @@ def check_hugetlbfs_path():
ca0f40
                 okbits.append(b)
ca0f40
                 mounts.append(out)
ca0f40
         if len(okbits) == 0:
ca0f40
-            print "run_tests.py: No mountpoints available for page size %s" % \
ca0f40
-                  pretty_page_size(p)
fc9b0e
+            print("run_tests.py: No mountpoints available for page size %s" %
ca0f40
+                  pretty_page_size(p))
ca0f40
             wordsizes_by_pagesize[p] = set()
ca0f40
             continue
ca0f40
         for b in wordsizes - set(okbits):
ca0f40
-            print "run_tests.py: The %i bit word size is not compatible with " \
ca0f40
-                  "%s pages" % (b, pretty_page_size(p))
ca0f40
+            print("run_tests.py: The %i bit word size is not compatible with " \
ca0f40
+                  "%s pages" % (b, pretty_page_size(p)))
ca0f40
         wordsizes_by_pagesize[p] = set(okbits)
ca0f40
 
ca0f40
 def check_linkhuge_tests():
fc9b0e
@@ -304,10 +308,10 @@ def check_linkhuge_tests():
ca0f40
 
ca0f40
 def print_cmd(pagesize, bits, cmd, env):
ca0f40
     if env:
ca0f40
-        print ' '.join(['%s=%s' % (k, v) for k, v in env.items()]),
fc9b0e
+        print(' '.join(['%s=%s' % (k, v) for k, v in env.items()]), end=" ")
fc9b0e
     if type(cmd) != types.StringType:
fc9b0e
         cmd = ' '.join(cmd)
ca0f40
-    print "%s (%s: %i):\t" % (cmd, pretty_page_size(pagesize), bits),
fc9b0e
+    print("%s (%s: %i):\t" % (cmd, pretty_page_size(pagesize), bits), end="")
ca0f40
     sys.stdout.flush()
ca0f40
 
ca0f40
 def run_test(pagesize, bits, cmd, **env):
fc9b0e
@@ -327,7 +331,7 @@ def run_test(pagesize, bits, cmd, **env):
ca0f40
 
ca0f40
     print_cmd(pagesize, bits, cmd, env)
ca0f40
     (rc, out) = run_test_prog(bits, pagesize, cmd, **env)
ca0f40
-    print out
ca0f40
+    print(out)
ca0f40
 
ca0f40
     R["total"][pagesize][bits] += 1
ca0f40
     if rc == 0:    R["pass"][pagesize][bits] += 1
fc9b0e
@@ -348,7 +352,7 @@ def skip_test(pagesize, bits, cmd, **env):
ca0f40
     R["total"][pagesize][bits] += 1
ca0f40
     R["skip"][pagesize][bits] += 1
ca0f40
     print_cmd(pagesize, bits, cmd, env)
ca0f40
-    print "SKIPPED"
ca0f40
+    print("SKIPPED")
ca0f40
 
ca0f40
 def do_test(cmd, bits=None, **env):
ca0f40
     """
fc9b0e
@@ -495,7 +499,7 @@ def setup_shm_sysctl(limit):
ca0f40
         fh = open(f, "w")
fc9b0e
         fh.write(`limit`)
ca0f40
         fh.close()
ca0f40
-    print "set shmmax limit to %s" % limit
ca0f40
+    print("set shmmax limit to %s" % limit)
ca0f40
     return sysctls
ca0f40
 
ca0f40
 def restore_shm_sysctl(sysctls):
fc9b0e
@@ -725,17 +729,17 @@ def stress_tests():
ca0f40
     do_test("fallocate_stress.sh")
ca0f40
 
ca0f40
 def print_help():
ca0f40
-    print "Usage: %s [options]" % sys.argv[0]
ca0f40
-    print "Options:"
ca0f40
-    print "  -v	\t Verbose output."
ca0f40
-    print "  -V	\t Highly verbose output."
ca0f40
-    print "  -f	\t Force all tests."
ca0f40
-    print "  -t <set> 	 Run test set, allowed are func and stress."
ca0f40
-    print "  -b <wordsize>  Define wordsizes to be used. "
ca0f40
-    print "  -p <pagesize>  Define the page sizes to be used."
ca0f40
-    print "  -c	\t Do a paranoid pool check."
ca0f40
-    print "  -l	\t Use custom ld scripts."
ca0f40
-    print "  -h	\t This help."
ca0f40
+    print("Usage: %s [options]" % sys.argv[0])
ca0f40
+    print("Options:")
ca0f40
+    print("  -v	\t Verbose output.")
ca0f40
+    print("  -V	\t Highly verbose output.")
ca0f40
+    print("  -f	\t Force all tests.")
ca0f40
+    print("  -t <set> 	 Run test set, allowed are func and stress.")
ca0f40
+    print("  -b <wordsize>  Define wordsizes to be used. ")
ca0f40
+    print("  -p <pagesize>  Define the page sizes to be used.")
ca0f40
+    print("  -c	\t Do a paranoid pool check.")
ca0f40
+    print("  -l	\t Use custom ld scripts.")
ca0f40
+    print("  -h	\t This help.")
ca0f40
     sys.exit(0)
ca0f40
 
ca0f40
 def main():
fc9b0e
@@ -752,7 +756,7 @@ def main():
ca0f40
     try:
ca0f40
         opts, args = getopt.getopt(sys.argv[1:], "vVft:b:p:c:lh")
fc9b0e
     except getopt.GetoptError, err:
ca0f40
-        print str(err)
ca0f40
+        print(str(err))
ca0f40
         sys.exit(1)
ca0f40
     for opt, arg in opts:
ca0f40
        if opt == "-v":
fc9b0e
@@ -781,8 +785,8 @@ def main():
ca0f40
     if len(pagesizes) == 0: pagesizes = get_pagesizes()
ca0f40
 
ca0f40
     if len(pagesizes) == 0:
ca0f40
-        print "Unable to find available page sizes, are you sure hugetlbfs"
ca0f40
-        print "is mounted and there are available huge pages?"
ca0f40
+        print("Unable to find available page sizes, are you sure hugetlbfs")
ca0f40
+        print("is mounted and there are available huge pages?")
ca0f40
         return 1
ca0f40
 
ca0f40
     setup_env(env_override, env_defaults)
fc9b0e
@@ -790,8 +794,8 @@ def main():
ca0f40
 
ca0f40
     (rc, system_default_hpage_size) = hpage_size()
ca0f40
     if rc != 0:
ca0f40
-        print "Unable to find system default hugepage size."
ca0f40
-        print "Is hugepage supported included in this kernel?"
ca0f40
+        print("Unable to find system default hugepage size.")
ca0f40
+        print("Is hugepage supported included in this kernel?")
ca0f40
         return 1
ca0f40
 
ca0f40
     check_hugetlbfs_path()
fc9b0e
-- 
fc9b0e
1.8.3.1
fc9b0e