import os, re, sys, collections
os.chdir('/storage/projects/code/hypercore-kb/hyper-fleeky/.scope/keetd')
src = open('tools/m5e/drill.py').read()
g = {}
exec(src[:src.index('MUTANTS, FILES, TARGET, GATE = SETS[sys.argv[1]]')], g)
# storage-call tokens in core/store/repl
TOK = re.compile(r'l2::|\bhs::|storage|Storage|\btx\b|\brx\b|CoreTX|CoreRX|\.read\(\)|\.write\(\)|\bAtom\b|atom|\bflush\b|flushed|createBlockStream|createTreeNodeStream|createBitfieldStream|createMarkStream|createUserDataStream|createLocalStream|resumeCore|createCore|getInfo|hasCore|getAlias|createGroup|exportCore|deleteCore|setRecovering|getSeed|setSeed|DefaultDiscoveryKey|createDiscoveryKeyStream|createAliasStream|createCoreStream|createGroupUpdateStream|resumeSession|createSession|createAtomicSession|deleteSessions|setDependencyHead|updateDependencyLength|getDependency|dependencies\(\)|putBlock|putTreeNode|putBitfieldPage|putMark|putUserData|putLocal|deleteBlockRange|deleteTreeNodeRange|deleteBitfieldPageRange|deleteMarkRange|getTreeNode|getBitfieldPage|getMark\(|getLocal|setHead|setHints|setAuth|setSessions|setDependency|setGroup|deleteHead|putGroupUpdate')
def where(f, anchor):
s = open(f).read()
i = s.find(anchor)
if i < 0: return None
return s[:i].count('\n') + 1
res = {}
for name, (mutants, files, target, gate) in g['SETS'].items():
c = collections.Counter(); hits = []
for m in mutants:
f, label, anchor = m[0], m[1], m[2]
top = f.split('/')[0]
line = where(f, anchor)
if top == 'l2': c['l2'] += 1; hits.append(('l2', f, line, label))
elif top == 'storage': c['storage'] += 1; hits.append(('storage', f, line, label))
elif top in ('core', 'store', 'repl'):
if TOK.search(anchor) or (len(m) > 3 and TOK.search(m[3] or '')):
c['callsite'] += 1; hits.append(('call', f, line, label))
else: c['other-csr'] += 1
else: c['other'] += 1
res[name] = (len(mutants), c, target, gate, hits)
mode = sys.argv[1] if len(sys.argv) > 1 else 'summary'
for name, (n, c, target, gate, hits) in res.items():
if c['l2'] or c['storage'] or c['callsite']:
print(f"{name}\t{n}\tl2={c['l2']}\tstorage={c['storage']}\tcallsite={c['callsite']}\tother-core/store/repl={c['other-csr']}\tother={c['other']}\ttarget={target}\tgate={gate}")
if mode == 'detail':
for h in hits: print(' ', h[0], f'{h[1]}:{h[2]}', '-', h[3])