Add a simple sleep test
This commit is contained in:
parent
27cae3fd33
commit
adf085a333
3 changed files with 41 additions and 0 deletions
13
test/dune
Normal file
13
test/dune
Normal file
|
@ -0,0 +1,13 @@
|
|||
(executable
|
||||
(name sleep)
|
||||
(modules sleep)
|
||||
(modes native)
|
||||
(link_flags :standard -cclib "-z solo5-abi=hvt")
|
||||
(enabled_if (= %{context_name} "solo5"))
|
||||
(libraries miou-solo5)
|
||||
(foreign_stubs (language c) (names manifest)))
|
||||
|
||||
(rule
|
||||
(targets manifest.c)
|
||||
(deps manifest.json)
|
||||
(action (run solo5-elftool gen-manifest manifest.json manifest.c)))
|
5
test/manifest.json
Normal file
5
test/manifest.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"type": "solo5.manifest",
|
||||
"version": 1,
|
||||
"devices": []
|
||||
}
|
23
test/sleep.ml
Normal file
23
test/sleep.ml
Normal file
|
@ -0,0 +1,23 @@
|
|||
let _1s = 1_000_000_000
|
||||
|
||||
let sleep_and ns fn =
|
||||
Miou_solo5.sleep ns;
|
||||
fn ()
|
||||
|
||||
let rec repeat_until n fn =
|
||||
if n > 0 then begin
|
||||
fn ();
|
||||
repeat_until (n - 1) fn
|
||||
end
|
||||
|
||||
let () = Miou_solo5.run @@ fun () ->
|
||||
let prm0 = Miou.async @@ fun () ->
|
||||
repeat_until 3 @@ fun () ->
|
||||
sleep_and _1s @@ fun () ->
|
||||
print_endline "Hello" in
|
||||
let prm1 = Miou.async @@ fun () ->
|
||||
repeat_until 3 @@ fun () ->
|
||||
sleep_and _1s @@ fun () ->
|
||||
print_endline "World" in
|
||||
let res = Miou.await_all [ prm0; prm1 ] in
|
||||
List.iter (function Ok () -> () | Error exn -> raise exn) res
|
Loading…
Reference in a new issue