示例#1
0
文件: test_pdr.py 项目: aman-goel/pdr
def verify_program(title, variables, primes, init, trans, post, show_result = True, show_trans = True):
    fname = inspect.stack()[1][3]
    with open(fname + ".out", 'w') as f:
        print_and_write(f, title)
        print_and_write(f, "---------------------------------------")
        print_and_write(f, "Init: " + str(init))
        f.write("Trans: " + str(trans) + "\n")
        if show_trans:
            print "Trans:", trans
        print_and_write(f, "Post:" + str(post))
        pdr = PDR(variables, primes, init, trans, post)
        print
        sat, output = pdr.run()
        res_string = ("SAT\n" if sat else "UNSAT\n") + str(output)
        f.write(res_string + "\n")
        print res_string if show_result else (("SAT\n" if sat else "UNSAT\n") + "Hidden result due to length")
        print
        print
示例#2
0
}


def listTests():
    for name in tests:
        print name


if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(
        description="Run tests examples on the PDR algorithm")
    parser.add_argument('-ls', action='store_true')
    parser.add_argument('testname',
                        type=str,
                        help='The name of the test to run',
                        default=None,
                        nargs='?')
    args = parser.parse_args()
    if (args.ls):
        listTests()
    elif (args.testname != None):
        name = args.testname
        print "=========== Running test", name, "==========="
        solver = PDR(*tests[name]())
        solver.run()
    else:
        for name in tests:
            print "=========== Running test", name, "==========="
            solver = PDR(*tests[name]())
            solver.run()
示例#3
0
	trans = And(*[primes[i] == Xor(Xor(variables[i],variables[i+len/2]),carryout(i+1)) for i in range(len/2)] \
		+ [primes[i+len/2] == variables[i+len/2] for i in range(len/2)])
	post = Not(variables[len/2-1])
	return (variables, primes, init, trans, post)

tests = {'Swapper':Swapper, 'BooleanShifter':BooleanShifter, 'BooleanIncrementer':BooleanIncrementer, 'IncrementerOverflow':IncrementerOverflow,
'EvenIncrementer':EvenIncrementer, 'OneAtATime':OneAtATime, 'ThreeAtATimeEven':ThreeAtATimeEven,
'ThreeAtATimeOdd':ThreeAtATimeOdd}

def listTests():
	for name in tests:
		print name

if __name__ == "__main__":
	import argparse
	parser = argparse.ArgumentParser(description="Run tests examples on the PDR algorithm")
	parser.add_argument('-ls', action='store_true')
	parser.add_argument('testname', type=str, help='The name of the test to run', default=None, nargs='?')
	args = parser.parse_args()
	if(args.ls):
		listTests()
	elif(args.testname!=None):
		name = args.testname
		print "=========== Running test", name,"==========="
		solver = PDR(*tests[name]())
		solver.run()
	else:
		for name in tests:
			print "=========== Running test", name,"==========="
			solver = PDR(*tests[name]())
			solver.run()
示例#4
0
#!/usr/bin/python
from z3 import *
from pdr import PDR


def ExampleOne():
    x = Bool('x')
    y = Bool('y')
    z = Bool('z')
    xp = Bool('xp')
    yp = Bool('yp')
    zp = Bool('zp')

    variables = [x, y, z]
    primes = [xp, yp, zp]
    init = And(x, y, Not(z))
    trans = And(Or(Not(x), zp), Or(x, Not(zp)), Or(y, Not(yp)),
                Or(Not(x), Not(y), Not(xp)), Or(Not(z), xp, x),
                Or(Not(z), xp, y))
    post = Or(Not(x), Not(y), Not(z))
    return (variables, primes, init, trans, post)


if __name__ == "__main__":
    solver = PDR(*ExampleOne())
    solver.run()