1#!/usr/bin/env python3 2 3import os 4import re 5import sys 6from concurrent.futures import ThreadPoolExecutor, as_completed 7 8 9def remove_prefix(i, d=0): 10 if d == 100: 11 return 2 12 s = os.popen("llvm-lit -a " + i).read() 13 r = re.search("no check strings found with (?:prefix|prefixes) '([^:]+)", s) 14 with open(i, "r+") as f: 15 s = f.read() 16 if r: 17 p = r.group(1) 18 s = re.sub("=" + p + ",", "=", s) 19 s = re.sub("," + p + "([, \n])", "\\1", s) 20 s = re.sub("\s+-?-check-prefix=" + p + "([ \n])", "\\1", s) 21 else: 22 s = re.sub( 23 "-?-check-prefixes=([\w-]+)(\Z|[ \t\n])", "--check-prefix=\\1\\2", s 24 ) 25 t = re.search( 26 "-?-check-(?:prefix|prefixes)=([^ ]+)\s+-?-check-(?:prefix|prefixes)=([^ ]+)", 27 s, 28 ) 29 while t: 30 s = re.sub( 31 t.group(), "--check-prefixes=" + t.group(1) + "," + t.group(2), s 32 ) 33 t = re.search( 34 "-?-check-(?:prefix|prefixes)=([^ ]+)\s+-?-check-(?:prefix|prefixes)=([^ ]+)", 35 s, 36 ) 37 s = re.sub("\s+-?-check-prefix=CHECK[ \t]*\n", "\n", s) 38 f.truncate(0) 39 f.seek(0) 40 f.write(s) 41 if not r: 42 t = re.search("Assertions have been autogenerated by (.*)", s) 43 if t: 44 s = os.popen("llvm/" + t.group(1) + " " + i + " 2>&1").read() 45 if "had conflicting output from different RUN lines for all functions" in s: 46 return -1 47 s = os.popen("git diff " + i).read() 48 if re.search("\n(?:-+)\n", s) or re.search("\n[+-].*(?<!RUN):", s): 49 return 1 50 return 0 51 return remove_prefix(i, d + 1) 52 53 54with ThreadPoolExecutor(max_workers=32) as e: 55 f = [] 56 c = [] 57 a = [] 58 t = {e.submit(remove_prefix, i): i for i in sys.argv[1:]} 59 for i in as_completed(t): 60 if i.result() == 0: 61 print("DONE:", end=" ") 62 elif i.result() == -1: 63 print("FAIL:", end=" ") 64 f.append(t[i]) 65 elif i.result() == 1: 66 print("CHANGE:", end=" ") 67 c.append(t[i]) 68 else: 69 print("ABORT:", end=" ") 70 a.append(t[i]) 71 print(t[i]) 72 for i in [(f, "Failed"), (c, "Changed"), (a, "Aborted")]: 73 if i[0]: 74 print("********************\n%s Tests (%d):" % (i[1], len(i[0]))) 75 for j in i[0]: 76 print(" " + j) 77