Пример #1
0
def test_fts_unroller(create_solver):
    solver = create_solver(False)
    bvsort4 = solver.make_sort(ss.sortkinds.BV, 4)
    bvsort8 = solver.make_sort(ss.sortkinds.BV, 8)
    arrsort = solver.make_sort(ss.sortkinds.ARRAY, bvsort4, bvsort8)

    ts = c.FunctionalTransitionSystem(solver)
    x = ts.make_statevar('x', bvsort4)
    mem = ts.make_statevar('mem', arrsort)

    u = c.Unroller(ts, solver)

    x0 = u.at_time(x, 0)
    assert x0 != x
    assert x0 == u.at_time(x, 0)

    assert x0 != u.at_time(x, 1)
    assert u.at_time(x, 1) == u.at_time(x, 1)

    constarr0 = solver.make_term(solver.make_term(0, bvsort8), arrsort)
    ts.constrain_init(solver.make_term(ss.primops.Equal, mem, constarr0))
    ts.assign_next(
        mem,
        solver.make_term(ss.primops.Store, mem, x,
                         solver.make_term(1, bvsort8)))

    assert ts.init != u.at_time(ts.init, 0)
    assert u.at_time(ts.init, 0) == u.at_time(ts.init, 0)

    trans1 = u.at_time(ts.trans, 1)
    free_vars = get_free_vars(trans1)

    assert u.at_time(x, 1) in free_vars
Пример #2
0
def test_vcd_trace(create_solver):
    solver = create_solver(False)
    solver.set_opt("incremental", "true")
    solver.set_opt("produce-models", "true")
    bvsort8 = solver.make_sort(ss.sortkinds.BV, 8)
    ts = pono.FunctionalTransitionSystem(solver)
    x = ts.make_statevar('x', bvsort8)
    ts.constrain_init(
        solver.make_term(ss.primops.Equal, x,
                         solver.make_term(0, x.get_sort())))
    ts.assign_next(
        x, ts.make_term(ss.primops.BVAdd, x, solver.make_term(1,
                                                              x.get_sort())))

    prop_term = solver.make_term(ss.primops.BVUle, x,
                                 solver.make_term(9, x.get_sort()))

    prop = pono.Property(solver, prop_term)
    bmc = pono.Bmc(prop, ts, solver)
    res = bmc.check_until(10)
    assert res == False, "res should be false, not just unknown (i.e. None)"

    witness = bmc.witness()

    with tempfile.NamedTemporaryFile() as temp:
        assert os.stat(temp.name).st_size == 0, "Expect file to start empty"
        vcd_printer = pono.VCDWitnessPrinter(ts, witness)
        vcd_printer.dump_trace_to_file(temp.name)
        assert os.stat(temp.name).st_size, "Expect file to be non-empty"
Пример #3
0
def test_replace_terms(create_solver):
    solver = create_solver(False)
    bvsort8 = solver.make_sort(ss.sortkinds.BV, 8)
    fts = pono.FunctionalTransitionSystem(solver)
    x = fts.make_statevar("x", bvsort8)
    a = fts.make_statevar("a", bvsort8)
    b = fts.make_statevar("b", bvsort8)

    amb = fts.make_term(ss.primops.BVMul, a, b)
    fts.assign_next(x, amb)

    freshinput = fts.make_inputvar("freshinput", bvsort8)

    to_replace = {amb: freshinput}
    fts.replace_terms(to_replace)

    assert fts.state_updates[x] == freshinput, "Expecting terms to be replaced"