mirror of
https://github.com/c-cube/nanoev.git
synced 2025-12-06 11:15:48 -05:00
add basic test
This commit is contained in:
parent
4da0257298
commit
a554d77671
3 changed files with 32 additions and 0 deletions
4
tests/unix/dune
Normal file
4
tests/unix/dune
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
(tests
|
||||||
|
(names t1)
|
||||||
|
(libraries nanoev nanoev.unix threads))
|
||||||
3
tests/unix/t1.expected
Normal file
3
tests/unix/t1.expected
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
writing
|
||||||
|
can read
|
||||||
|
done writing
|
||||||
25
tests/unix/t1.ml
Normal file
25
tests/unix/t1.ml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
module E = Nanoev_unix
|
||||||
|
|
||||||
|
let mkpipe () : Unix.file_descr * Unix.file_descr =
|
||||||
|
let f1, f2 = Unix.pipe () in
|
||||||
|
Unix.set_nonblock f1;
|
||||||
|
Unix.set_nonblock f2;
|
||||||
|
f1, f2
|
||||||
|
|
||||||
|
let loop (e : E.t) =
|
||||||
|
while true do
|
||||||
|
E.step e
|
||||||
|
done
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let ev = E.create () in
|
||||||
|
ignore (Thread.create loop ev : Thread.t);
|
||||||
|
let rd, wr = mkpipe () in
|
||||||
|
E.on_readable ev rd () () (fun () () -> print_endline "can read");
|
||||||
|
Thread.delay 0.05;
|
||||||
|
print_endline "writing";
|
||||||
|
ignore
|
||||||
|
(Unix.write wr (Bytes.unsafe_of_string "hello") 0 (String.length "hello")
|
||||||
|
: int);
|
||||||
|
Thread.delay 0.1;
|
||||||
|
print_endline "done writing"
|
||||||
Loading…
Add table
Reference in a new issue