-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdedup_case.py
56 lines (44 loc) · 1.52 KB
/
dedup_case.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from argparse import Namespace, ArgumentParser
import tvm
from polyleven import levenshtein
from gencog.debug.run import ErrorKind
args = Namespace()
def parse_args():
global args
p = ArgumentParser()
p.add_argument('-d', '--directory', type=str, help='Directory for storing error cases.')
args = p.parse_args()
class CaseDedup:
def __init__(self):
self._history = []
def is_dup(self, err: str):
if any(levenshtein(err, his) < 100 for his in self._history):
return True
else:
self._history.append(err)
return False
def main():
print(tvm.__version__)
compile_dedup = CaseDedup()
run_dedup = CaseDedup()
for case_id in sorted(os.listdir(args.directory), key=lambda s: int(s)):
case_path = os.path.join(args.directory, case_id)
err_path = os.path.join(case_path, 'error.txt')
if not os.path.exists(err_path):
continue
with open(err_path, 'r') as f:
err = f.read()
for kind, dedup in zip(
[ErrorKind.COMPILE, ErrorKind.RUN], [compile_dedup, run_dedup]
):
if not os.path.exists(os.path.join(case_path, kind.name)):
continue
if dedup.is_dup(err):
for filename in os.listdir(case_path):
os.remove(os.path.join(case_path, filename))
os.rmdir(case_path)
print(f'Case {case_id} removed.')
if __name__ == '__main__':
parse_args()
main()