You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libhugetlbfs/SOURCES/0020-Switch-test-runner-scr...

217 lines
7.9 KiB

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