99
1010err = 0
1111def getEnumElements (enumName ):
12- f = open ("%s /libcpuid.h" % args . root_dir , "r" )
12+ f = open (f" { args . root_dir } /libcpuid.h" , "r" )
1313 l = []
1414 on = False
1515 rexp = re .compile (r'^\s*([A-Z0-9_]+)(\s*=\s*[A-Z0-9_]+)?\s*,.*$' )
@@ -28,7 +28,7 @@ def getEnumElements(enumName):
2828 return []
2929
3030def getConstant (constantName ):
31- f = open ("%s /libcpuid_constants.h" % args . root_dir , "r" )
31+ f = open (f" { args . root_dir } /libcpuid_constants.h" , "r" )
3232 value = 0
3333 for line in f :
3434 items = line .strip ().split ()
@@ -38,10 +38,10 @@ def getConstant(constantName):
3838 return value
3939
4040def checkEnumSize (enumName , constantName ):
41- print ("Checking enum `%s ':" % enumName , end = ' ' )
41+ print (f "Checking enum `{ enumName } ':" , end = ' ' )
4242 count = len (getEnumElements (enumName )) - 1
4343 themax = getConstant (constantName )
44- print ("%d elements; max size (%s=%d )..." % ( count , constantName , themax ) , end = ' ' )
44+ print (f" { count } elements; max size ({ constantName } = { themax } )..." , end = ' ' )
4545 if count > themax :
4646 err += 1
4747 print ("FAILED" )
@@ -70,7 +70,7 @@ def check_type_directory(directory):
7070
7171rexp = re .compile ('.*{ CPU_FEATURE_([^,]+), "([^"]+)".*}.*' )
7272print ("Finding features:" )
73- for fn in glob .glob ("%s /*.c" % args . root_dir ):
73+ for fn in glob .glob (f" { args . root_dir } /*.c" ):
7474 f = open (fn , "rt" )
7575 line = 1
7676 nfeat = 0
@@ -81,16 +81,16 @@ def check_type_directory(directory):
8181 assert len (res ) == 1 , "Too many matches"
8282 if res [0 ][0 ].lower () != res [0 ][1 ]:
8383 err += 1
84- print ("..Mismatch - %s:%d - `%s' vs `%s'" % ( os .path .basename (fn ), line , res [0 ][0 ], res [0 ][1 ]) )
84+ print (f "..Mismatch - { os .path .basename (fn )} : { line } - ` { res [0 ][0 ]} ' vs ` { res [0 ][1 ]} '" )
8585 line += 1
8686 if nfeat :
87- print (" %s: %d features described" % ( os .path .basename (fn ), nfeat ) )
87+ print (f " { os .path .basename (fn )} : { nfeat } features described" )
8888 f .close ()
8989
9090# Check whether all features are converted by cpu_feature_str():
9191
9292allf = []
93- f = open ("%s /libcpuid.h" % args . root_dir , "rt" )
93+ f = open (f" { args . root_dir } /libcpuid.h" , "rt" )
9494rexp = re .compile ('\t (CPU_FEATURE_[^, ]+).*' )
9595for s in f .readlines ():
9696 if rexp .match (s ):
@@ -100,22 +100,22 @@ def check_type_directory(directory):
100100
101101impf = []
102102rexp = re .compile ('\t +{ (CPU_FEATURE_[^,]+).*' )
103- f = open ("%s /cpuid_main.c" % args . root_dir , "rt" )
103+ f = open (f" { args . root_dir } /cpuid_main.c" , "rt" )
104104for s in f .readlines ():
105105 if rexp .match (s ):
106106 entry = rexp .findall (s )[0 ]
107107 if entry in impf :
108108 err += 1
109- print ("cpu_feature_str(): duplicate entry: %s" % entry )
109+ print (f "cpu_feature_str(): duplicate entry: { entry } " )
110110 impf .append (entry )
111111f .close ()
112112
113- print ("Found %d total features and %d named features" % ( len ( allf ), len ( impf )) )
113+ print (f "Found { len ( allf ) } total features and { len ( impf ) } named features" )
114114
115115for feature in allf :
116116 if not feature in impf :
117117 err += 1
118- print ("cpu_feature_str(): don't have entry for %s" % feature )
118+ print (f "cpu_feature_str(): don't have entry for { feature } " )
119119
120120# Check whether all features have detection code:
121121print ("Checking whether all features have detection code..." , end = ' ' )
@@ -127,7 +127,7 @@ def check_type_directory(directory):
127127rexp2 = re .compile (r'.*(CPU_FEATURE_[^ ,]+),\s*FEATURE_LEVEL_ARM_.*' ) # e.g. "set_feature_status(data, ext_status, (mte_frac == 0b0000), CPU_FEATURE_MTE_ASYNC, FEATURE_LEVEL_ARM_V8_5_A, -1);"
128128rexp3 = re .compile (r'.*(CPU_FEATURE_[^ }]+).*' ) # e.g. "{ 28, CPU_FEATURE_HT },"
129129
130- for fn in glob .glob ("%s /*.c" % args . root_dir ):
130+ for fn in glob .glob (f" { args . root_dir } /*.c" ):
131131 f = open (fn , "rt" )
132132 files_code [fn ] = []
133133 for s in f .readlines ():
@@ -157,13 +157,13 @@ def check_type_directory(directory):
157157 print ("FAILED:" )
158158 firstError = False
159159 err += 1
160- print ("..No detection code for %s" % feature )
160+ print (f "..No detection code for { feature } " )
161161 if len (matching_files ) > 1 and feature not in features_whitelist :
162162 if firstError :
163163 print ("FAILED:" )
164164 firstError = False
165165 err += 1
166- print ("..Conflicting detection code for %s in files %s" % ( feature , " and " .join (matching_files )) )
166+ print (f "..Conflicting detection code for { feature } in files { ' and ' .join (matching_files )} " )
167167
168168if firstError :
169169 print ("All OK." )
@@ -178,7 +178,7 @@ def check_type_directory(directory):
178178match_entry_fields = 11 # this number needs to change if the definition of match_entry_t ever changes
179179codename_str_max = 64 - 1 # this number needs to change if the value of CODENAME_STR_MAX ever changes
180180common_cache_sizes = ["8" , "16" , "32" , "64" , "128" , "256" , "512" , "1024" , "2048" , "3072" , "4096" , "6144" , "8192" , "12288" , "16384" ]
181- for fn in glob .glob ("%s /*.c" % args . root_dir ):
181+ for fn in glob .glob (f" { args . root_dir } /*.c" ):
182182 bfn = os .path .basename (fn )
183183 nline = 0
184184 f = open (fn , "rt" )
@@ -202,23 +202,23 @@ def check_type_directory(directory):
202202 s = parts [match_entry_fields - 1 ].strip ()
203203 if s [0 ] != '"' or s [- 1 ] != '"' :
204204 err += 1
205- print ("..Warning, %s:%d - cannot correctly handle the cpu codename" % ( bfn , nline ) )
205+ print (f "..Warning, { bfn } : { nline } - cannot correctly handle the cpu codename" )
206206 allok = False
207207 continue
208208 s = s [1 :- 1 ]
209209 if len (s ) > codename_str_max :
210210 err += 1
211- print ("..%s:%d - codename (%s ) is longer than %d characters!" % ( bfn , nline , s , codename_str_max ) )
211+ print (f "..{ bfn } : { nline } - codename ({ s } ) is longer than { codename_str_max } characters!" )
212212 allok = False
213213 if cache_exp .match (s ):
214214 cache_size = cache_exp .findall (s )[0 ][1 :- 1 ]
215215 if not cache_size in common_cache_sizes :
216216 err += 1
217- print ("..Warning, %s:%d - suspicious cache size in codename [%s ] (%s)" % ( bfn , nline , s , cache_size ) )
217+ print (f "..Warning, { bfn } : { nline } - suspicious cache size in codename [{ s } ] ({ cache_size } )" )
218218 allok = False
219219 if cdefs :
220220 definitions += 1
221- print (" %s: %d processor definitions," % ( bfn , cdefs ) , end = ' ' )
221+ print (f " { bfn } : { cdefs } processor definitions," , end = ' ' )
222222 if allok :
223223 print ("all OK" )
224224 else :
0 commit comments