Skip to content

Commit

Permalink
Add Eio.Stdenv.backend_id for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bord-o authored and talex5 committed Jun 20, 2023
1 parent a6c0be9 commit 148f8cd
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib_eio/eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Stdenv = struct
let fs (t : <fs : #Fs.dir Path.t; ..>) = t#fs
let cwd (t : <cwd : #Fs.dir Path.t; ..>) = t#cwd
let debug (t : <debug : 'a; ..>) = t#debug
let backend_id (t: <backend_id : string; ..>) = t#backend_id
end

exception Io = Exn.Io
6 changes: 6 additions & 0 deletions lib_eio/eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ module Stdenv : sig

val debug : <debug : <Debug.t; ..> as 'a; ..> -> 'a
(** [debug t] provides privileged controls for debugging. *)

val backend_id : <backend_id:string; ..> -> string
(** [backend_id t] provides the name of the backend being used.
The possible values are the same as the possible values of the "EIO_BACKEND"
environment variable used by {!Eio_main.run}. *)
end

(** {1 Errors and Debugging} *)
Expand Down
1 change: 1 addition & 0 deletions lib_eio/unix/eio_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ module Stdenv = struct
cwd : Eio.Fs.dir Eio.Path.t;
secure_random : Eio.Flow.source;
debug : Eio.Debug.t;
backend_id: string;
>
end
1 change: 1 addition & 0 deletions lib_eio/unix/eio_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module Stdenv : sig
cwd : Eio.Fs.dir Eio.Path.t;
secure_random : Eio.Flow.source;
debug : Eio.Debug.t;
backend_id : string;
>
(** The common set of features provided by all traditional operating systems (BSDs, Linux, Mac, Windows).
Expand Down
1 change: 1 addition & 0 deletions lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ let stdenv ~run_event_loop =
method cwd = (cwd :> Eio.Fs.dir Eio.Path.t)
method secure_random = secure_random
method debug = Eio.Private.Debug.v
method backend_id = "linux"
end

let run_event_loop (type a) ?fallback config (main : _ -> a) arg : a =
Expand Down
6 changes: 6 additions & 0 deletions lib_eio_linux/tests/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ let test_read_exact () =
let got = Uring.Region.to_string chunk ~len:(String.length msg) in
if got <> msg then Fmt.failwith "%S vs %S" got msg

let test_expose_backend () =
Eio_linux.run @@ fun env ->
let backend = Eio.Stdenv.backend_id env in
assert (backend = "linux")

let () =
let open Alcotest in
run "eio_linux" [
Expand All @@ -161,5 +166,6 @@ let () =
test_case "iovec" `Quick test_iovec;
test_case "no_sqe" `Quick test_no_sqe;
test_case "read_exact" `Quick test_read_exact;
test_case "expose_backend" `Quick test_expose_backend;
];
]
1 change: 1 addition & 0 deletions lib_eio_posix/eio_posix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ let run main =
method cwd = ((Fs.cwd, "") :> Eio.Fs.dir Eio.Path.t)
method fs = ((Fs.fs, "") :> Eio.Fs.dir Eio.Path.t)
method secure_random = Flow.secure_random
method backend_id = "posix"
end
1 change: 1 addition & 0 deletions lib_eio_windows/eio_windows.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ let run main =
method fs = ((Fs.fs, "") :> Eio.Fs.dir Eio.Path.t)
method process_mgr = failwith "process operations not supported on Windows yet"
method secure_random = Flow.secure_random
method backend_id = "windows"
end

0 comments on commit 148f8cd

Please sign in to comment.