Skip to content

Commit

Permalink
Stress_proc test code
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Dec 22, 2023
1 parent a26c3eb commit a05d7d0
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions stress/stress_proc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,37 @@ let n_rounds = 100
let n_procs_per_round_per_domain = 100 / n_domains

let run_in_domain mgr =
let echo n = Eio.Process.parse_out mgr Eio.Buf_read.line ["sh"; "-c"; "echo " ^ string_of_int n] in
Switch.run @@ fun sw ->
let _echo n = Eio.Process.parse_out mgr Eio.Buf_read.line ["sh"; "-c"; "sleep 0.2 && echo " ^ string_of_int n] in
(* let echo n = Eio.Process.parse_out mgr Eio.Buf_read.line ["/bin/echo"; string_of_int n] in *)
let _echo2 n =
let pipe1_r, pipe1_w = Eio_unix.pipe sw in
let fd flow = Eio_unix.Resource.fd flow in
let read_all pipe =
let r = Eio.Buf_read.of_flow pipe ~max_size:1024 in
Eio.Buf_read.take_all r
in
let child = Eio_posix.Low_level.Process.spawn ~sw [
Eio_posix.Low_level.Process.Fork_action.inherit_fds [
1, fd pipe1_w, `Blocking;
];
Eio_posix.Low_level.Process.Fork_action.execve
"/bin/sh"
~argv:[| "sh"; "-c"; "sleep 0.2 && printf " ^ string_of_int n |]
~env:[||]
]
in
Eio.Flow.close pipe1_w;
let s = read_all pipe1_r in
match Promise.await (Eio_posix.Low_level.Process.exit_status child) with
| WEXITED _ -> s
| WSIGNALED x ->
failwith (Format.asprintf "WSIGNALED %a" Fmt.Dump.signal x)
| WSTOPPED x -> failwith (Format.sprintf "WSTOPPED %d" x)
in
for j = 1 to n_procs_per_round_per_domain do
Fiber.fork ~sw (fun () ->
let result = echo j in
let result = _echo2 j in
assert (int_of_string result = j);
(* traceln "OK: %d" j *)
)
Expand All @@ -32,4 +58,4 @@ let main ~dm mgr =

let () =
Eio_main.run @@ fun env ->
main ~dm:env#domain_mgr env#process_mgr
main ~dm:env#domain_mgr env#process_mgr

0 comments on commit a05d7d0

Please sign in to comment.