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