forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

pick.py31 lines, 1.5 KiBHistoryRawDownload
1# Usage: pick.py <list.json> <out-dir> <cap-per-candidate> <seed> <T1> [T2 ...]
2# Reads cargo-mutants --list --json and each candidate's regions.json (from regions.py).
3# Writes <out-dir>/sample.json: {"names": [...], "by_test": {T: [names]}, "tags": {name: [T,...]}}.
4import json, random, sys, os
5lst, out, cap, seed = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4])
6tests = sys.argv[5:]
7muts = json.load(open(lst))
8def name_of(m):
9 return m.get('name') or '%s:%s:%s' % (m['file'], m['line'], m.get('replacement', ''))
10rng = random.Random(seed)
11by_test, tags = {}, {}
12for t in tests:
13 reg = json.load(open(os.path.join(out, t + '.regions.json')))
14 cov = [(r[0], r[1], r[2]) for r in reg['covered']]
15 U = [(r[0], r[1], r[2]) for r in reg['U']]
16 def hits(rs, m):
17 for fn, ls, le in rs:
18 if fn.endswith(m['file']) and ls <= m['line'] <= le:
19 return True
20 return False
21 inU = [m for m in muts if hits(U, m)]
22 inC = [m for m in muts if hits(cov, m) and not hits(U, m)]
23 rng.shuffle(inU); rng.shuffle(inC)
24 pick = (inU + inC)[:cap]
25 names = [name_of(m) for m in pick]
26 by_test[t] = {'U_mutants': len(inU), 'covered_mutants': len(inC), 'sampled': len(names), 'names': names}
27 for n in names:
28 tags.setdefault(n, []).append(t)
29allnames = sorted(tags)
30json.dump({'names': allnames, 'by_test': by_test, 'tags': tags}, open(os.path.join(out, 'sample.json'), 'w'), indent=1)
31print(json.dumps({t: {k: v for k, v in d.items() if k != 'names'} for t, d in by_test.items()}), 'union=%d' % len(allnames))