def test_usefulness(s, n): benchmark = importlib.import_module("adaptive_bench.{}".format(s)) (size, edb, idb) = benchmark.make_data(n) d = DiffLog() add_data(benchmark, d, size, edb, idb) d.parse_rules_max(benchmark.true_rules) d.eval_program() all_useful = True for r in benchmark.true_rules: y = benchmark.true_rules[:] y.remove(r) removed = DiffLog() add_data(benchmark, removed, size, edb, idb) d.parse_rules_max(benchmark.true_rules) good = False for x in benchmark.output_relations: if not good: for t in d.valuation[x]: if t not in removed.valuation[x]: good = True break if not good: all_useful = False print "{} not useful".format(r) else: print "{} useful".format(r) return all_useful
def make_data(n): idb = {} edb = {} sizes = {} edb['parent'] = [] idb['sgen'] = [] parent = edb['parent'] sgen = idb['sgen'] if n % 2 == 0: n += 1 sizes['P'] = n lasts = (1, 2) parent.append((1,0)) parent.append((2,0)) for i in range(n/2 - 1): parent.append((lasts[0] + 2, lasts[0])) parent.append((lasts[1] + 2, lasts[1])) lasts = (lasts[0] + 2, lasts[1] + 2) evaluator = DiffLog() evaluator.parse_rules_max(true_rules) evaluator.add_input_domain('parent', (n, n), parent) evaluator.add_result_domain('sgen', (n, n), []) evaluator.eval_program() for r in idb: for x in evaluator.valuation[r]: idb[r].append(x) return (sizes, edb, idb)
def test_degenerate(s, n): benchmark = importlib.import_module("adaptive_bench.{}".format(s)) (size, edb, idb) = benchmark.make_data(n) d = DiffLog() add_data(benchmark, d, size, edb, idb) d.parse_rules_max(benchmark.true_rules) d.eval_program() for x in benchmark.output_relations: if np.array_equal(d.relation_map[x], np.ones(d.relation_map[x].shape)): print "{} degenerate".format(x) return False return True
def test_correctness(s, n): benchmark = importlib.import_module("adaptive_bench.{}".format(s)) (size, edb, idb) = benchmark.make_data(n) d = DiffLog() add_data(benchmark, d, size, edb, idb) d.parse_rules_max(benchmark.true_rules) d.eval_program() for x in benchmark.input_relations: for t in edb[x]: if t not in d.valuation[x]: print d.valuation[x].keys() print edb[x] print x assert (False) for t in d.valuation[x]: if t not in edb[x]: print d.valuation[x].keys() print edb[x] print x assert (False) for x in benchmark.output_relations: for t in idb[x]: if t not in d.valuation[x]: print d.valuation[x].keys() print idb[x] print x print edb assert (False) for t in d.valuation[x]: if t not in idb[x]: assert (False)
def make_data(n): if n < 8: n = 8 sizes = {} edb = {} idb = {} sizes['H'] = n load = edb['load'] = [(7, 2)] assgn = edb['assgn'] = [(4, 1)] addr = edb['addr'] = [(1, 2), (2, 3), (3, 5), (5, 6)] store = edb['store'] = [(4, 5)] pt = idb['pt'] = [(1, 2), (2, 3), (3, 5), (5, 6), (4, 2), (7, 5), (2, 6)] r_load = [] r_store = [] r_addr = [] r_assgn = [] ds = n - 8 for x in indices_of((ds, ds)): if random.random() < 0.02: r_store.append(x) if random.random() < 0.02: r_load.append(x) if random.random() < 0.04: r_addr.append(x) if random.random() < 0.04: r_assgn.append(x) d = DiffLog() d.add_input_domain("store", (ds, ds), r_store) d.add_input_domain("load", (ds, ds), r_load) d.add_input_domain("addr", (ds, ds), r_addr) d.add_input_domain("assgn", (ds, ds), r_assgn) d.add_result_domain("pt", (ds, ds), []) d.parse_rules_max(true_rules) d.eval_program() for r in idb: for x in d.valuation[r]: idb[r].append((x[0] + 8, x[1] + 8)) for r in edb: for x in d.valuation[r]: edb[r].append((x[0] + 8, x[1] + 8)) return sizes, edb, idb
def make_data(n): if n < 12: n = 12 sizes = {} edb = {} idb = {} sizes['H'] = n sizes['Z'] = 5 sizes['F'] = n / 4 sizes['V'] = n sizes['C'] = n / 3 sizes['M'] = 5 original_sizes = {} original_sizes['H'] = 12 original_sizes['Z'] = 3 original_sizes['F'] = 3 original_sizes['C'] = 4 original_sizes['V'] = 12 original_sizes['M'] = 3 points_initial = edb['points_initial'] = [(1, 1), (2, 2), (5, 1), (9, 9), (11, 11)] load = edb['load'] = [(2, 2, 8), (5, 1, 10), (5, 1, 7)] assign = edb['assign'] = [(2, 5, 1, 5), (2, 7, 1, 7), (2, 5, 3, 6), (2, 7, 3, 2)] store = edb['store'] = [(7, 2, 5), (5, 1, 1), (9, 2, 5), (9, 1, 11)] invocation = edb['invocation'] = [(1, 1, 2, 1), (3, 2, 2, 1), (2, 9, 1, 1), (3, 11, 1, 1)] actual = edb['actual'] = [(1, 0, 5), (1, 1, 7), (2, 0, 6), (2, 1, 2)] formal = edb['formal'] = [(1, 0, 5), (1, 1, 7), (2, 0, 3), (2, 1, 6)] pointsto = idb['pointsto'] = [(1, 1, 1), (1, 5, 1), (3, 2, 2), (3, 11, 11), (2, 9, 9), (2, 5, 1), (2, 7, 2), (1, 10, 1), (1, 7, 1), (2, 7, 1), (3, 8, 1), (2, 10, 1)] heappointsto = idb['heappointsto'] = [(1, 1, 1), (2, 2, 1), (1, 2, 1), (9, 2, 1)] r_load = [] r_store = [] r_points_initial = [] r_assign = [] r_invocation = [] r_actual = [] r_formal = [] ds = n - 12 for x in indices_of((ds, 2, ds)): if random.random() < 0.1: r_store.append(x) store.append((x[0] + 12, x[1] + 3, x[2] + 12)) if random.random() < 0.1: r_load.append(x) load.append((x[0] + 12, x[1] + 3, x[2] + 12)) for x in indices_of((ds, ds)): if random.random() < 0.1: r_points_initial.append(x) points_initial.append((x[0] + 12, x[1] + 12)) for x in indices_of((ds, 2, ds)): if random.random() < 0.01: formal_rand = random.randint(0, 1) r_actual.append(x) r_formal.append((formal_rand, x[1], x[2])) actual.append((x[0] + 12, x[1] + 3, x[2] + 12)) formal.append((formal_rand + 3, x[1] + 3, x[2] + 12)) for x in indices_of((ds / 3, ds, ds / 3, 2)): if random.random() < 0.1: r_invocation.append(x) invocation.append((x[0] + 4, x[1] + 12, x[2] + 4, x[3] + 3)) for x in indices_of((ds / 3, ds, ds / 3, ds)): if random.random() < 0.01: r_assign.append(x) assign.append((x[0] + 4, x[1] + 12, x[2] + 4, x[3] + 12)) d = DiffLog() d.add_input_domain("points_initial", (ds, ds), r_points_initial) d.add_input_domain("load", (ds, 2, ds), r_load) d.add_input_domain("store", (ds, 2, ds), r_store) d.add_input_domain("assign", (ds / 3, ds, ds / 3, ds), r_assign) d.add_input_domain("invocation", (ds / 3, ds, ds / 3, 2), r_invocation) d.add_input_domain("actual", (ds, 2, ds), r_actual) d.add_input_domain("formal", (2, 2, ds), r_formal) d.add_result_domain("pointsto", (ds / 3, ds, ds), []) d.add_result_domain("heappointsto", (ds, 2, ds), []) d.parse_rules_max(true_rules) d.eval_program() for x in d.valuation['heappointsto']: heappointsto.append((x[0] + 12, x[1] + 3, x[2] + 12)) for x in d.valuation['pointsto']: pointsto.append((x[0] + 4, x[1] + 12, x[2] + 12)) return sizes, edb, idb
def make_data(n): sizes = {} edb = {} idb = {} sizes['I'] = n sizes['C'] = 2 sizes['M'] = n CICM = edb['CICM'] = [] virtIM = edb['virtIM'] = [] Mneq = edb['Mneq'] = [] virtI = idb['virtI'] = [] polySite = idb['polysite'] = [] insvIM = idb['insvIM'] = [] ds = n for i in range(n - 1): for j in range(n - 1): if i != j: Mneq.append((i + 1, j + 1)) for x in indices_of((ds, ds)): if random.random() < 0.1: if random.random() < 0.5: CICM.append((0, x[0], x[1])) else: CICM.append((1, x[0], x[1])) if random.random() < 0.1: virtIM.append(x) d = DiffLog() d.add_input_domain("CICM", (2, ds, ds), CICM) d.add_input_domain("virtIM", (ds, ds), virtIM) d.add_input_domain("Mneq", (ds, ds), Mneq) d.add_result_domain("virtI", (ds, ), []) d.add_result_domain("polysite", (ds, ), []) d.add_result_domain("insvIM", (ds, ds), []) d.parse_rules_max(true_rules) d.eval_program() for x in d.valuation['insvIM']: insvIM.append(x) for r in ['polysite', 'virtI']: for x in d.valuation[r]: idb[r].append(x) return sizes, edb, idb
def make_data(n): if n < 8: n = 8 edb = {} idb = {} sizes = {} sizes['M'] = n sizes['V'] = n sizes['H'] = n sizes['I'] = n sizes['F'] = n MgetInstFldInst = edb['MgetInstFldInst'] = [(4, 3, 2, 2)] MputInstFldInst = edb['MputInstFldInst'] = [(4, 4, 3, 5)] MgetStatFldInst = edb['MgetStatFldInst'] = [(4, 0, 0), (5, 6, 4), (7, 6, 6)] MputStatFldInst = edb['MputStatFldInst'] = [(4, 1, 1), (6, 5, 7), (7, 6, 7)] VH = edb['VH'] = [(2, 2), (4, 4)] MI = edb['MI'] = [(0, 0), (1, 1), (2, 2), (3, 3)] IM = edb['IM'] = [(0, 1), (1, 2), (2, 3), (3, 4)] rMM = idb['rMM'] = [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] refStatField = idb['refStatField'] = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 4), (7, 6)] modStatField = idb['modStatField'] = [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (6, 5), (7, 6)] refInstField = idb['refInstField'] = [(0, 2, 2), (1, 2, 2), (2, 2, 2), (3, 2, 2), (4, 2, 2)] modInstField = idb['modInstField'] = [(0, 4, 3), (1, 4, 3), (2, 4, 3), (3, 4, 3), (4, 4, 3)] r_MgetInstFldInst = [] r_MputInstFldInst = [] r_MgetStatFldInst = [] r_MputStatFldInst = [] r_VH = [] r_MI = [] r_IM = [] ds = n - 8 for x in indices_of((ds, ds)): if random.random() < 0.1: r_IM.append(x) if random.random() < 0.1: r_MI.append(x) if random.random() < 0.1: r_VH.append(x) for x in indices_of((ds, ds, ds)): if random.random() < 0.01: r_MputStatFldInst.append(x) if random.random() < 0.01: r_MgetStatFldInst.append(x) for x in indices_of((ds, ds, ds, ds)): if random.random() < 0.001: r_MputInstFldInst.append(x) if random.random() < 0.001: r_MgetInstFldInst.append(x) d = DiffLog() d.add_input_domain("MI", (ds, ds), r_MI) d.add_input_domain("IM", (ds, ds), r_IM) d.add_input_domain("VH", (ds, ds), r_VH) d.add_input_domain("MputStatFldInst", (ds, ds, ds), r_MputStatFldInst) d.add_input_domain("MgetStatFldInst", (ds, ds, ds), r_MgetStatFldInst) d.add_input_domain("MputInstFldInst", (ds, ds, ds, ds), r_MputInstFldInst) d.add_input_domain("MgetInstFldInst", (ds, ds, ds, ds), r_MgetInstFldInst) d.add_result_domain("rMM", (ds, ds), []) d.add_result_domain("refStatField", (ds, ds), []) d.add_result_domain("modStatField", (ds, ds), []) d.add_result_domain("refInstField", (ds, ds, ds), []) d.add_result_domain("modInstField", (ds, ds, ds), []) d.parse_rules_max(true_rules) d.eval_program() for r in idb: for x in d.valuation[r]: idb[r].append((x[0] + 8, x[1] + 8)) for r in edb: for x in d.valuation[r]: edb[r].append((x[0] + 8, x[1] + 8)) return sizes, edb, idb
def make_data(n): if n % 2 == 0: n += 1 idb = {} edb = {} sizes = {} sizes['P'] = n edb['father'] = [] father = edb['father'] edb['mother'] = [] mother = edb['mother'] male = False last = 0 for i in range(n / 2): father.append((last + 1, last)) mother.append((last + 2, last)) if male: last = last + 1 else: last = last + 2 male = not male idb['parent'] = [] parent = idb['parent'] idb['ancestor'] = [] ancestor = idb['ancestor'] evaluator = DiffLog() evaluator.parse_rules_max(true_rules) evaluator.add_input_domain('father', (n, n), father) evaluator.add_input_domain('mother', (n, n), mother) evaluator.add_result_domain('parent', (n, n), []) evaluator.add_result_domain('ancestor', (n, n), []) evaluator.eval_program() for r in idb: for x in evaluator.valuation[r]: idb[r].append(x) return (sizes, edb, idb)
def make_data(n): if n < 4: n = 4 edb = {} idb = {} sizes = {} sizes['H'] = n sizes['M'] = n sizes['V'] = n HFH = edb['HFH'] = [(0, 1), (1, 2), (2, 3), (0, 2)] VH = edb['VH'] = [(1, 1), (0, 0), (2, 2), (3, 3)] MmethRet = edb['MmethRet'] = [(0, 1), (2, 1)] MmethArg = edb['MmethArg'] = [(0, 0), (1, 3), (2, 2)] rMH = idb['rMH'] = [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (2, 2), (2, 3)] rRH = idb['rRH'] = [(0, 1), (0, 2), (0, 3), (2, 1), (2, 2), (2, 3)] rHH = idb['rHH'] = [(0, 1), (1, 2), (2, 3), (0, 2), (1, 3), (0, 3)] r_HFH = [] r_VH = [] r_MmethRet = [] r_MmethArg = [] ds = n - 4 for x in indices_of((ds, ds)): if random.random() < 0.1: r_HFH.append(x) if random.random() < 0.1: r_VH.append(x) if random.random() < 0.1: r_MmethRet.append(x) if random.random() < 0.1: r_MmethArg.append(x) d = DiffLog() d.add_input_domain("HFH", (ds, ds), r_HFH) d.add_input_domain("VH", (ds, ds), r_VH) d.add_input_domain("MmethRet", (ds, ds), r_MmethRet) d.add_input_domain("MmethArg", (ds, ds), r_MmethArg) d.add_result_domain("rMH", (ds, ds), []) d.add_result_domain("rRH", (ds, ds), []) d.add_result_domain("rHH", (ds, ds), []) d.parse_rules_max(true_rules) d.eval_program() for r in idb: for x in d.valuation[r]: idb[r].append((x[0] + 4, x[1] + 4)) for r in edb: for x in d.valuation[r]: edb[r].append((x[0] + 4, x[1] + 4)) return sizes, edb, idb