mirror of
https://github.com/anrieff/libcpuid
synced 2025-10-03 11:01:30 +00:00
Related to c2645d0
. Convert all python scripts to Python 3.
As stated in discussion, Python 2 is actively being deprecated and the fix is easy, almost automatic.
This commit is contained in:
parent
0419610804
commit
52c5f505cf
3 changed files with 48 additions and 50 deletions
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/env python2.7
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os, sys, re, glob
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage: check-consistency <path>"
|
||||
print("Usage: check-consistency <path>")
|
||||
sys.exit(0)
|
||||
|
||||
err = 0
|
||||
|
@ -37,24 +37,24 @@ def getConstant(constantName):
|
|||
return value
|
||||
|
||||
def checkEnumSize(enumName, constantName):
|
||||
print "Checking enum `%s':" % enumName,
|
||||
print("Checking enum `%s':" % enumName, end=' ')
|
||||
count = len(getEnumElements(enumName)) - 1
|
||||
themax = getConstant(constantName)
|
||||
print "%d elements; max size (%s=%d)..." % (count, constantName, themax),
|
||||
print("%d elements; max size (%s=%d)..." % (count, constantName, themax), end=' ')
|
||||
if count > themax:
|
||||
err += 1
|
||||
print "FAILED"
|
||||
print("FAILED")
|
||||
global firstError
|
||||
firstError = False
|
||||
else:
|
||||
print "OK"
|
||||
print("OK")
|
||||
|
||||
checkEnumSize("cpu_feature_t", "CPU_FLAGS_MAX")
|
||||
checkEnumSize("cpu_hint_t", "CPU_HINTS_MAX")
|
||||
checkEnumSize("cpu_sgx_feature_t", "SGX_FLAGS_MAX")
|
||||
|
||||
rexp = re.compile('.*{ CPU_FEATURE_([^,]+), "([^"]+)".*}.*')
|
||||
print "Finding features:"
|
||||
print("Finding features:")
|
||||
for fn in glob.glob("%s/*.c" % sys.argv[1]):
|
||||
f = open(fn, "rt")
|
||||
line = 1
|
||||
|
@ -63,15 +63,13 @@ for fn in glob.glob("%s/*.c" % sys.argv[1]):
|
|||
if rexp.match(s):
|
||||
nfeat += 1
|
||||
res = rexp.findall(s)
|
||||
if len(res) > 1:
|
||||
err += 1
|
||||
raise "..Too many matches"
|
||||
assert len(res) == 1, "Too many matches"
|
||||
if res[0][0].lower() != res[0][1]:
|
||||
err += 1
|
||||
print "..Mismatch - %s:%d - `%s' vs `%s'" % (os.path.basename(fn), line, res[0][0], res[0][1])
|
||||
print("..Mismatch - %s:%d - `%s' vs `%s'" % (os.path.basename(fn), line, res[0][0], res[0][1]))
|
||||
line += 1
|
||||
if nfeat:
|
||||
print " %s: %d features described" % (os.path.basename(fn), nfeat)
|
||||
print(" %s: %d features described" % (os.path.basename(fn), nfeat))
|
||||
f.close()
|
||||
|
||||
# Check whether all features are converted by cpu_feature_str():
|
||||
|
@ -93,19 +91,19 @@ for s in f.readlines():
|
|||
entry = rexp.findall(s)[0]
|
||||
if entry in impf:
|
||||
err += 1
|
||||
print "cpu_feature_str(): duplicate entry: %s" % entry
|
||||
print("cpu_feature_str(): duplicate entry: %s" % entry)
|
||||
impf.append(entry)
|
||||
f.close()
|
||||
|
||||
print "Found %d total features and %d named features" % (len(allf), len(impf))
|
||||
print("Found %d total features and %d named features" % (len(allf), len(impf)))
|
||||
|
||||
for feature in allf:
|
||||
if not feature in impf:
|
||||
err += 1
|
||||
print "cpu_feature_str(): don't have entry for %s" % feature
|
||||
print("cpu_feature_str(): don't have entry for %s" % feature)
|
||||
|
||||
# Check whether all features have detection code:
|
||||
print "Checking whether all features have detection code...",
|
||||
print("Checking whether all features have detection code...", end=' ')
|
||||
firstError = True
|
||||
|
||||
files_code = {}
|
||||
|
@ -129,22 +127,22 @@ for feature in allf:
|
|||
matching_files.append(fn)
|
||||
if len(matching_files) == 0 and feature not in features_whitelist:
|
||||
if firstError:
|
||||
print "FAILED:"
|
||||
print("FAILED:")
|
||||
firstError = False
|
||||
err += 1
|
||||
print "..No detection code for %s" % feature
|
||||
print("..No detection code for %s" % feature)
|
||||
if len(matching_files) > 1:
|
||||
if firstError:
|
||||
print "FAILED:"
|
||||
print("FAILED:")
|
||||
firstError = False
|
||||
err += 1
|
||||
print "..Conflicting detection code for %s in files %s" % (feature, " and ".join(matching_files))
|
||||
print("..Conflicting detection code for %s in files %s" % (feature, " and ".join(matching_files)))
|
||||
|
||||
if firstError:
|
||||
print "All OK."
|
||||
print ""
|
||||
print("All OK.")
|
||||
print("")
|
||||
|
||||
print "Checking processor definitions:"
|
||||
print("Checking processor definitions:")
|
||||
cache_exp = re.compile(".*([\(/ ][0-9]+K).*")
|
||||
# Check whether CPU codenames for consistency:
|
||||
# - Codenames should not exceed 31 characters
|
||||
|
@ -174,26 +172,26 @@ for fn in glob.glob("%s/*.c" % sys.argv[1]):
|
|||
s = parts[10].strip()
|
||||
if s[0] != '"' or s[-1] != '"':
|
||||
err += 1
|
||||
print "..Warning, %s:%d - cannot correctly handle the cpu codename" % (bfn, nline)
|
||||
print("..Warning, %s:%d - cannot correctly handle the cpu codename" % (bfn, nline))
|
||||
allok = False
|
||||
continue
|
||||
s = s[1:-1]
|
||||
if len(s) > 31:
|
||||
err += 1
|
||||
print "..%s:%d - codename (%s) is longer than 31 characters!" % (bfn, nline, s)
|
||||
print("..%s:%d - codename (%s) is longer than 31 characters!" % (bfn, nline, s))
|
||||
allok = False
|
||||
if cache_exp.match(s):
|
||||
cache_size = cache_exp.findall(s)[0][1:-1]
|
||||
if not cache_size in common_cache_sizes:
|
||||
err += 1
|
||||
print "..Warning, %s:%d - suspicious cache size in codename [%s] (%s)" % (bfn, nline, s, cache_size)
|
||||
print("..Warning, %s:%d - suspicious cache size in codename [%s] (%s)" % (bfn, nline, s, cache_size))
|
||||
allok = False
|
||||
if cdefs:
|
||||
print " %s: %d processor definitions," % (bfn, cdefs),
|
||||
print(" %s: %d processor definitions," % (bfn, cdefs), end=' ')
|
||||
if allok:
|
||||
print "all OK"
|
||||
print("all OK")
|
||||
else:
|
||||
print "some errors/warnings"
|
||||
print("some errors/warnings")
|
||||
f.close()
|
||||
|
||||
sys.exit(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue