File size: 1,940 Bytes
e042d72 | 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 | """Check every catalog mutant inside the image: the untouched workspace must fail and the original code must pass,
at both levels. Writes the indices that pass to /out/valid.json.
docker run --rm -e PYTHONPATH=/app -v $PWD/codedesk/build/out:/out -v $PWD/codedesk/build/validate.py:/v.py:ro \
five-desks-code:native python /v.py
"""
import json
import random
import sys
from concurrent.futures import ThreadPoolExecutor
from codedesk.families.bugfix import LIBS, LibBugfix, catalog
def check(i_m):
i, m = i_m
try:
for level in (1, 2):
t = LibBugfix(random.Random(i), level, LIBS[m["lib"]][1], mutant=m)
try:
if t.grade({}) != 0.0:
return i, "untouched passes"
t.oracle()
if t.grade({}) != 1.0:
return i, f"oracle fails (level {level})"
finally:
t.close()
return i, "ok"
except Exception as exc: # generation problems count as failures
return i, f"error {type(exc).__name__}: {exc}"[:200]
def main():
cat = catalog()
results = {}
with ThreadPoolExecutor(int(sys.argv[1]) if len(sys.argv) > 1 else 4) as pool:
for i, verdict in pool.map(check, list(enumerate(cat))):
results[i] = verdict
ok = [i for i, v in sorted(results.items()) if v == "ok"]
keys = [[cat[i]["lib"], cat[i]["file"], cat[i]["line"], cat[i]["col"], cat[i]["new"]] for i in ok]
bad = {}
for i, v in results.items():
if v != "ok":
bad.setdefault(cat[i]["lib"], []).append(v)
json.dump({"ok": keys, "failures": {k: v[:5] for k, v in bad.items()}}, open("/out/valid.json", "w"), indent=1)
by = {}
for i in ok:
by[cat[i]["lib"]] = by.get(cat[i]["lib"], 0) + 1
print(len(ok), "of", len(cat), "valid", by)
print({k: len(v) for k, v in bad.items()})
if __name__ == "__main__":
main()
|