brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 434dc84 Raw
77 lines · python
1#!/usr/bin/env python32 3import os4import re5import sys6from concurrent.futures import ThreadPoolExecutor, as_completed7 8 9def remove_prefix(i, d=0):10    if d == 100:11        return 212    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", s24            )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), s32                )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 -147            s = os.popen("git diff " + i).read()48            if re.search("\n(?:-+)\n", s) or re.search("\n[+-].*(?<!RUN):", s):49                return 150        return 051    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