def test_swap(self): saw.connect(reset_server=True) if __name__ == "__main__": saw.view(saw.LogResults()) swap_bc = str(Path('tests', 'saw', 'test-files', 'swap.bc')) mod = saw.llvm_load_module(swap_bc) result = saw.llvm_verify(mod, 'swap', Swap()) self.assertIs(result.is_success(), True)
def test_ghost(self): saw.connect(reset_server=True) if __name__ == "__main__": saw.view(saw.LogResults()) ghost_bc = str(Path('tests', 'saw', 'test-files', 'ghost.bc')) mod = saw.llvm_load_module(ghost_bc) counter = saw.create_ghost_variable('counter') get_and_increment_ov = saw.llvm_assume( mod, 'get_and_increment', GetAndIncrementContract(counter)) self.assertIs(get_and_increment_ov.is_success(), True) f_ov = saw.llvm_verify(mod, 'f', FContract(counter), lemmas=[get_and_increment_ov]) self.assertIs(f_ov.is_success(), True)
def test_provers(self): saw.connect(reset_server=True) if __name__ == "__main__": saw.view(saw.LogResults()) simple_thm = cry('\(x:[8]) -> x != x+1') self.assertTrue(saw.prove(simple_thm, ProofScript([abc])).is_valid()) self.assertTrue( saw.prove(simple_thm, ProofScript([z3([])])).is_valid()) self.assertTrue( saw.prove(simple_thm, ProofScript([Admit()])).is_valid()) self.assertTrue( saw.prove(cry('True'), ProofScript([Trivial()])).is_valid()) simple_non_thm = cry('\(x:[8]) -> x != 5') pr = saw.prove(simple_non_thm, ProofScript([z3([])])) self.assertFalse(pr.is_valid()) cex = pr.get_counterexample() self.assertEqual(cex, [('x', BV(8, 0x05))])
def test_add(self): saw.connect(reset_server=True) if __name__ == "__main__": saw.view(saw.LogResults()) cls = saw.jvm_load_class("Add") add_result1 = saw.jvm_verify(cls, 'add', Add()) self.assertIs(add_result1.is_success(), True) add_result2 = saw.jvm_assume(cls, 'add', Add()) self.assertIs(add_result2.is_success(), True) dbl_result1 = saw.jvm_verify(cls, 'dbl', Double(), lemmas=[add_result1]) self.assertIs(dbl_result1.is_success(), True) dbl_result2 = saw.jvm_verify(cls, 'dbl', Double(), lemmas=[add_result2]) self.assertIs(dbl_result2.is_success(), True)
import os import os.path from saw_client import LogResults, connect, llvm_load_module, view dir_path = os.path.dirname(os.path.realpath(__file__)) connect() view(LogResults()) path = [os.path.dirname(dir_path), "c", "libsignal-everything.bc"] bcname = os.path.join(*path) print(bcname) mod = llvm_load_module(bcname)