Skip to content

Instantly share code, notes, and snippets.

@turnersr
Created January 3, 2019 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turnersr/b27e5c5f5bcf81163cf1d79aab7c9e18 to your computer and use it in GitHub Desktop.
Save turnersr/b27e5c5f5bcf81163cf1d79aab7c9e18 to your computer and use it in GitHub Desktop.
Let test
let test_eval_basic_block_formula ctxt =
let open Bap.Std in
let open Bap_primus.Std in
let open Monads.Std in
let module Machine = struct
type 'a m = 'a
include Primus.Machine.Make(Monad.Ident)
end in
let module Main = Primus.Machine.Main(Machine) in
let module Eval = Primus.Interpreter.Make(Machine) in
let open Machine.Syntax in
let empty_project arch =
let nil = Memmap.empty in
Project.Input.create arch "/bin/true" ~code:nil ~data:nil |>
Project.create |>
ok_exn in
let dummy_proj = empty_project `x86_64 in
let proj = dummy_proj in
let x = "(Let((var t34)(ind 0)(typ(Imm 8))(vir true))(Int 0x42:8u)(Let((var t38)(ind 0)(typ(Imm 8))(vir true))(Int 0x27:8u)(Let((var t74)(ind 0)(typ(Imm 1))(vir true))(BinOp EQ(Var((var t34)(ind 0)(typ(Imm 8))(vir true)))(Var((var t38)(ind 0)(typ(Imm 8))(vir true))))(Let((var t75)(ind 0)(typ(Imm 1))(vir true))(UnOp NOT(Var((var t74)(ind 0)(typ(Imm 1))(vir true))))(Var((var t75)(ind 0)(typ(Imm 1))(vir true)))))))" in
let expression_should_be_true = Sexp.of_string x |> Exp.t_of_sexp in
let assertion =
Eval.exp expression_should_be_true >>| fun r ->
let x = Bil.Int (Primus.Value.to_word r) in
assert_equal ~printer:Exp.to_string ~cmp:Exp.equal (Bil.int Word.b1) x in
let result,_ = Main.run proj assertion in
match result with
| Primus.Normal -> ()
| _ -> raise (Failure "Primus didn't return cleanly")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment