Skip to content

Commit 6d45f6f

Browse files
committed
Move our create_process test into test/test_unix.ml and use Miou_unix.run
1 parent ef524b2 commit 6d45f6f

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

test/test_core.ml

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -825,43 +825,9 @@ let test42 =
825825
let prm1 = Miou.call @@ fun () -> Miou.yield () in
826826
Miou.await_exn prm1; Miou.cancel prm0; Test.check true
827827

828-
let test43 =
829-
let description = {text|Unix.create_process|text} in
830-
Test.test ~title:"test43" ~description @@ fun () ->
831-
let buf = Buffer.create 0x7ff in
832-
let prgm () =
833-
Miou.run @@ fun () ->
834-
let pid =
835-
Unix.create_process "sleep" [| "sleep"; "2" |] Unix.stdin Unix.stdout
836-
Unix.stderr
837-
in
838-
Buffer.add_string buf "sleep launched\n";
839-
let cmp = Miou.Computation.create () in
840-
let rec fn _sigchld =
841-
match Unix.waitpid [ WNOHANG ] pid with
842-
| 0, _ -> ignore (Miou.sys_signal Sys.sigchld (Sys.Signal_handle fn))
843-
| pid', status ->
844-
assert (pid = pid');
845-
assert (Miou.Computation.try_return cmp status)
846-
in
847-
ignore (Miou.sys_signal Sys.sigchld (Sys.Signal_handle fn));
848-
Buffer.add_string buf "signal handler installed\n";
849-
match Miou.Computation.await_exn cmp with
850-
| Unix.WEXITED n -> Buffer.add_string buf (Fmt.str "WEXITED(%d)\n%!" n)
851-
| Unix.WSIGNALED n -> Buffer.add_string buf (Fmt.str "WSIGNALED(%d)\n%!" n)
852-
| Unix.WSTOPPED n -> Buffer.add_string buf (Fmt.str "WSIGNALED(%d)\n%!" n)
853-
in
854-
match Sys.os_type with
855-
| "Win32" -> ()
856-
| _ ->
857-
prgm ();
858-
let serialized = Buffer.contents buf in
859-
let expected = "sleep launched\nsignal handler installed\nWEXITED(0)\n" in
860-
Test.check (serialized = expected)
861-
862828
module Bitv = Miou_unix.Bitv
863829

864-
let test44 =
830+
let test43 =
865831
let description = {text|Bitv.next|text} in
866832
Test.test ~title:"test44" ~description @@ fun () ->
867833
let t = Bitv.create 1024 false in
@@ -876,7 +842,7 @@ let test44 =
876842
Test.check !v;
877843
Test.check (Bitv.next t = None)
878844

879-
let test45 =
845+
let test44 =
880846
let description = {text|Bitv.max|text} in
881847
Test.test ~title:"test45" ~description @@ fun () ->
882848
let t = Bitv.create 1024 false in
@@ -896,7 +862,7 @@ let () =
896862
; test10; test11; test12; test13; test14; test15; test16; test17; test18
897863
; test19; test20; test21; test22; test23; test24; test25; test26; test27
898864
; test28; test29; test30; test31; test32; test33; test34; test35; test36
899-
; test37; test38; test39; test40; test41; test42; test43; test44; test45
865+
; test37; test38; test39; test40; test41; test42; test43; test44
900866
]
901867
in
902868
let ({ Test.directory } as runner) =

test/test_unix.ml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,42 @@ let test_eof_on_pipe =
4545
end;
4646
List.iter Miou.cancel jobs
4747

48+
let test_create_process =
49+
let description = {text|Unix.create_process|text} in
50+
Test.test ~title:"create process" ~description @@ fun () ->
51+
let buf = Buffer.create 0x7ff in
52+
let prgm () =
53+
Miou_unix.run ~domains:0 @@ fun () ->
54+
let pid =
55+
Unix.create_process "sleep" [| "sleep"; "2" |] Unix.stdin Unix.stdout
56+
Unix.stderr
57+
in
58+
Buffer.add_string buf "sleep launched\n";
59+
let cmp = Miou.Computation.create () in
60+
let rec fn _sigchld =
61+
match Unix.waitpid [ WNOHANG ] pid with
62+
| 0, _ -> ignore (Miou.sys_signal Sys.sigchld (Sys.Signal_handle fn))
63+
| pid', status ->
64+
assert (pid = pid');
65+
assert (Miou.Computation.try_return cmp status)
66+
in
67+
ignore (Miou.sys_signal Sys.sigchld (Sys.Signal_handle fn));
68+
Buffer.add_string buf "signal handler installed\n";
69+
match Miou.Computation.await_exn cmp with
70+
| Unix.WEXITED n -> Buffer.add_string buf (Fmt.str "WEXITED(%d)\n%!" n)
71+
| Unix.WSIGNALED n -> Buffer.add_string buf (Fmt.str "WSIGNALED(%d)\n%!" n)
72+
| Unix.WSTOPPED n -> Buffer.add_string buf (Fmt.str "WSIGNALED(%d)\n%!" n)
73+
in
74+
match Sys.os_type with
75+
| "Win32" -> ()
76+
| _ ->
77+
prgm ();
78+
let serialized = Buffer.contents buf in
79+
let expected = "sleep launched\nsignal handler installed\nWEXITED(0)\n" in
80+
Test.check (serialized = expected)
81+
4882
let () =
49-
let tests = [| test_eof_on_pipe |] in
83+
let tests = [| test_eof_on_pipe; test_create_process |] in
5084
let ({ Test.directory } as runner) =
5185
Test.runner (Filename.concat (Sys.getcwd ()) "_tests")
5286
in

0 commit comments

Comments
 (0)