Mercurial > hg > CbC > CbC_llvm
comparison llvm/utils/abtest.py @ 252:1f2b6ac9f198 llvm-original
LLVM16-1
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Aug 2023 09:04:13 +0900 |
parents | 79ff65ed7e25 |
children |
comparison
equal
deleted
inserted
replaced
237:c80f45b162ad | 252:1f2b6ac9f198 |
---|---|
55 NORMAL = ESCAPE % "0" | 55 NORMAL = ESCAPE % "0" |
56 FAILED = RED + "failed" + NORMAL | 56 FAILED = RED + "failed" + NORMAL |
57 | 57 |
58 | 58 |
59 def find(dir, file_filter=None): | 59 def find(dir, file_filter=None): |
60 files = [ | 60 files = [walkdir[0] + "/" + file for walkdir in os.walk(dir) for file in walkdir[2]] |
61 walkdir[0]+"/"+file | |
62 for walkdir in os.walk(dir) | |
63 for file in walkdir[2] | |
64 ] | |
65 if file_filter is not None: | 61 if file_filter is not None: |
66 files = filter(files, file_filter) | 62 files = filter(files, file_filter) |
67 return sorted(files) | 63 return sorted(files) |
68 | 64 |
69 | 65 |
145 max_remaining_steps += (len(x) - 1) * 2 | 141 max_remaining_steps += (len(x) - 1) * 2 |
146 | 142 |
147 picks = dict(all_a) | 143 picks = dict(all_a) |
148 for x in partition: | 144 for x in partition: |
149 picks[x] = choice_map[x][1] | 145 picks[x] = choice_map[x][1] |
150 announce_test("checking %s [<=%d remaining]" % | 146 announce_test( |
151 (format_namelist(partition), max_remaining_steps)) | 147 "checking %s [<=%d remaining]" |
148 % (format_namelist(partition), max_remaining_steps) | |
149 ) | |
152 res = perform_test(picks) | 150 res = perform_test(picks) |
153 if res is True: | 151 if res is True: |
154 known_good.update(partition) | 152 known_good.update(partition) |
155 elif len(partition) > 1: | 153 elif len(partition) > 1: |
156 partitions_to_split.insert(0, partition) | 154 partitions_to_split.insert(0, partition) |
182 for line in open(file): | 180 for line in open(file): |
183 marker = line.find(" -- Begin function ") | 181 marker = line.find(" -- Begin function ") |
184 if marker != -1: | 182 if marker != -1: |
185 if in_function is not None: | 183 if in_function is not None: |
186 warn("Missing end of function %s" % (in_function,)) | 184 warn("Missing end of function %s" % (in_function,)) |
187 funcname = line[marker + 19:-1] | 185 funcname = line[marker + 19 : -1] |
188 in_function = funcname | 186 in_function = funcname |
189 text = line | 187 text = line |
190 continue | 188 continue |
191 | 189 |
192 marker = line.find(" -- End function") | 190 marker = line.find(" -- End function") |
208 for line in open(source): | 206 for line in open(source): |
209 marker = line.find(" -- Begin function ") | 207 marker = line.find(" -- Begin function ") |
210 if marker != -1: | 208 if marker != -1: |
211 if in_function is not None: | 209 if in_function is not None: |
212 warn("Missing end of function %s" % (in_function,)) | 210 warn("Missing end of function %s" % (in_function,)) |
213 funcname = line[marker + 19:-1] | 211 funcname = line[marker + 19 : -1] |
214 in_function = funcname | 212 in_function = funcname |
215 replacement = replacements.get(in_function) | 213 replacement = replacements.get(in_function) |
216 if replacement is not None: | 214 if replacement is not None: |
217 out.write(replacement) | 215 out.write(replacement) |
218 skip = True | 216 skip = True |
227 if not skip: | 225 if not skip: |
228 out.write(line) | 226 out.write(line) |
229 | 227 |
230 | 228 |
231 def testrun(files): | 229 def testrun(files): |
232 linkline = "%s %s" % (LINKTEST, " ".join(files),) | 230 linkline = "%s %s" % ( |
231 LINKTEST, | |
232 " ".join(files), | |
233 ) | |
233 res = subprocess.call(linkline, shell=True) | 234 res = subprocess.call(linkline, shell=True) |
234 if res != 0: | 235 if res != 0: |
235 announce_result(FAILED + ": '%s' exitcode != 0" % LINKTEST) | 236 announce_result(FAILED + ": '%s' exitcode != 0" % LINKTEST) |
236 return False | 237 return False |
237 else: | 238 else: |
242 def prepare_files(gooddir, baddir, rspfile): | 243 def prepare_files(gooddir, baddir, rspfile): |
243 files_a = [] | 244 files_a = [] |
244 files_b = [] | 245 files_b = [] |
245 | 246 |
246 if rspfile is not None: | 247 if rspfile is not None: |
248 | |
247 def get_basename(name): | 249 def get_basename(name): |
248 # remove prefix | 250 # remove prefix |
249 if name.startswith(gooddir): | 251 if name.startswith(gooddir): |
250 return name[len(gooddir):] | 252 return name[len(gooddir) :] |
251 if name.startswith(baddir): | 253 if name.startswith(baddir): |
252 return name[len(baddir):] | 254 return name[len(baddir) :] |
253 assert False, "" | 255 assert False, "" |
254 | 256 |
255 with open(rspfile, "r") as rf: | 257 with open(rspfile, "r") as rf: |
256 for line in rf.read().splitlines(): | 258 for line in rf.read().splitlines(): |
257 for obj in line.split(): | 259 for obj in line.split(): |
267 basenames_b = set(map(get_basename, files_b)) | 269 basenames_b = set(map(get_basename, files_b)) |
268 | 270 |
269 for name in files_b: | 271 for name in files_b: |
270 basename = get_basename(name) | 272 basename = get_basename(name) |
271 if basename not in basenames_a: | 273 if basename not in basenames_a: |
272 warn("There is no corresponding file to '%s' in %s" % | 274 warn("There is no corresponding file to '%s' in %s" % (name, gooddir)) |
273 (name, gooddir)) | |
274 choices = [] | 275 choices = [] |
275 skipped = [] | 276 skipped = [] |
276 for name in files_a: | 277 for name in files_a: |
277 basename = get_basename(name) | 278 basename = get_basename(name) |
278 if basename not in basenames_b: | 279 if basename not in basenames_b: |
279 warn("There is no corresponding file to '%s' in %s" % | 280 warn("There is no corresponding file to '%s' in %s" % (name, baddir)) |
280 (name, baddir)) | |
281 | 281 |
282 file_a = gooddir + "/" + basename | 282 file_a = gooddir + "/" + basename |
283 file_b = baddir + "/" + basename | 283 file_b = baddir + "/" + basename |
284 if filecmp.cmp(file_a, file_b): | 284 if filecmp.cmp(file_a, file_b): |
285 skipped.append(basename) | 285 skipped.append(basename) |
305 files.append(picked) | 305 files.append(picked) |
306 | 306 |
307 # If response file is used, create a temporary response file for the | 307 # If response file is used, create a temporary response file for the |
308 # picked files. | 308 # picked files. |
309 if rspfile is not None: | 309 if rspfile is not None: |
310 with tempfile.NamedTemporaryFile('w', suffix='.rsp', | 310 with tempfile.NamedTemporaryFile("w", suffix=".rsp", delete=False) as tf: |
311 delete=False) as tf: | |
312 tf.write(" ".join(files)) | 311 tf.write(" ".join(files)) |
313 tf.flush() | 312 tf.flush() |
314 ret = testrun([tf.name]) | 313 ret = testrun([tf.name]) |
315 os.remove(tf.name) | 314 os.remove(tf.name) |
316 return ret | 315 return ret |
344 choices.append(choice) | 343 choices.append(choice) |
345 | 344 |
346 if len(skipped) > 0: | 345 if len(skipped) > 0: |
347 info("Skipped (same content): %s" % format_namelist(skipped)) | 346 info("Skipped (same content): %s" % format_namelist(skipped)) |
348 | 347 |
349 combined_file = '/tmp/combined2.s' | 348 combined_file = "/tmp/combined2.s" |
350 files = [] | 349 files = [] |
351 found_good_file = False | 350 found_good_file = False |
352 for c in files_good: | 351 for c in files_good: |
353 if os.path.basename(c) == to_check: | 352 if os.path.basename(c) == to_check: |
354 found_good_file = True | 353 found_good_file = True |
360 def perform_test(picks): | 359 def perform_test(picks): |
361 for name, x in picks.items(): | 360 for name, x in picks.items(): |
362 assert x == functions_a_map[name] or x == functions_b_map[name] | 361 assert x == functions_a_map[name] or x == functions_b_map[name] |
363 replace_functions(goodfile, combined_file, picks) | 362 replace_functions(goodfile, combined_file, picks) |
364 return testrun(files) | 363 return testrun(files) |
364 | |
365 return perform_test, choices | 365 return perform_test, choices |
366 | 366 |
367 | 367 |
368 def main(): | 368 def main(): |
369 parser = argparse.ArgumentParser() | 369 parser = argparse.ArgumentParser() |
370 parser.add_argument('--a', dest='dir_a', default='before') | 370 parser.add_argument("--a", dest="dir_a", default="before") |
371 parser.add_argument('--b', dest='dir_b', default='after') | 371 parser.add_argument("--b", dest="dir_b", default="after") |
372 parser.add_argument('--rsp', default=None) | 372 parser.add_argument("--rsp", default=None) |
373 parser.add_argument('--test', default='./link_test') | 373 parser.add_argument("--test", default="./link_test") |
374 parser.add_argument('--insane', help='Skip sanity check', | 374 parser.add_argument("--insane", help="Skip sanity check", action="store_true") |
375 action='store_true') | 375 parser.add_argument( |
376 parser.add_argument('--seq', | 376 "--seq", help="Check sequentially instead of bisection", action="store_true" |
377 help='Check sequentially instead of bisection', | 377 ) |
378 action='store_true') | 378 parser.add_argument("file", metavar="file", nargs="?") |
379 parser.add_argument('file', metavar='file', nargs='?') | |
380 config = parser.parse_args() | 379 config = parser.parse_args() |
381 | 380 |
382 gooddir = config.dir_a | 381 gooddir = config.dir_a |
383 baddir = config.dir_b | 382 baddir = config.dir_b |
384 rspfile = config.rsp | 383 rspfile = config.rsp |
389 # choices each. The bisection algorithm will pick one choice for each name | 388 # choices each. The bisection algorithm will pick one choice for each name |
390 # and then run the perform_test function on it. | 389 # and then run the perform_test function on it. |
391 if config.file is not None: | 390 if config.file is not None: |
392 goodfile = gooddir + "/" + config.file | 391 goodfile = gooddir + "/" + config.file |
393 badfile = baddir + "/" + config.file | 392 badfile = baddir + "/" + config.file |
394 perform_test, choices = prepare_functions(config.file, gooddir, | 393 perform_test, choices = prepare_functions( |
395 goodfile, badfile) | 394 config.file, gooddir, goodfile, badfile |
395 ) | |
396 else: | 396 else: |
397 perform_test, choices = prepare_files(gooddir, baddir, rspfile) | 397 perform_test, choices = prepare_files(gooddir, baddir, rspfile) |
398 | 398 |
399 info("%d bisection choices" % len(choices)) | 399 info("%d bisection choices" % len(choices)) |
400 | 400 |
421 # This shouldn't happen when the sanity check works... | 421 # This shouldn't happen when the sanity check works... |
422 # Maybe link_test isn't deterministic? | 422 # Maybe link_test isn't deterministic? |
423 stderr.write("Could not identify failing parts?!?") | 423 stderr.write("Could not identify failing parts?!?") |
424 | 424 |
425 | 425 |
426 if __name__ == '__main__': | 426 if __name__ == "__main__": |
427 main() | 427 main() |