miragesdk: add mimimal tests for the SDK

Very minimal so far, but the plan is to add much more of them.

Signed-off-by: Thomas Gazagnaire <thomas@gazagnaire.org>
This commit is contained in:
Thomas Gazagnaire
2017-03-29 15:41:23 +02:00
parent c06454273b
commit df71c0f299
7 changed files with 96 additions and 12 deletions

View File

@@ -0,0 +1,10 @@
(jbuild_version 1)
(executables
((names (test))
(libraries (sdk alcotest))))
(alias
((name runtest)
(deps (test.exe))
(action (run ${<}))))

View File

@@ -0,0 +1,31 @@
open Lwt.Infix
open Sdk
let random_string n = Bytes.create n
let test_pipe pipe () =
let ic = Init.Fd.fd @@ Init.Pipe.(calf pipe) in
let oc = Init.Fd.fd @@ Init.Pipe.(priv pipe) in
let test str =
Init.IO.really_write oc str 0 (String.length str) >>= fun () ->
Init.IO.read_all ic >|= fun buf ->
Alcotest.(check string) "stdout" str buf
in
test (random_string 10241) >>= fun () ->
test (random_string 100) >>= fun () ->
test (random_string 1)
let run f () =
try Lwt_main.run (f ())
with e -> Fmt.epr "ERROR: %a" Fmt.exn e
let test_stderr () = ()
let test = [
"stdout", `Quick, run (test_pipe Init.Pipe.stdout);
"stdout", `Quick, run (test_pipe Init.Pipe.stderr);
]
let () = Alcotest.run "sdk" [
"init", test;
]