Skip to content

Commit

Permalink
fixup! CP-47001: [xapi-fdcaps]: wrap more Unix operations
Browse files Browse the repository at this point in the history
  • Loading branch information
edwintorok committed Dec 21, 2023
1 parent 936dc6a commit ebcfa50
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/xapi-fdcaps/test/test_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,31 +233,38 @@ let test_repeat_read () =
let available = String.length buf - off in
let len = Int.min len 11 in
let len = Int.min len available in
Bytes.blit_string buf off dst off len;
Bytes.blit_string buf off dst off len ;
len
in
let dst = Bytes.make 300 '_' in
let@ placeholder = with_fd @@ dev_zero () in
(* not actually used, just to make the types work, we simulate the read using string ops *)
let actual = repeat_read read placeholder dst 0 (Bytes.length dst) in
Alcotest.(check' int) ~msg:"amount read" ~actual ~expected:(String.length buf);
Alcotest.(check' string) ~msg:"contents" ~actual:(Bytes.sub_string dst 0 actual) ~expected:buf
Alcotest.(check' int) ~msg:"amount read" ~actual ~expected:(String.length buf) ;
Alcotest.(check' string)
~msg:"contents"
~actual:(Bytes.sub_string dst 0 actual)
~expected:buf

let test_repeat_write () =
let buf = Bytes.make 255 '_' in
let write _ src off len =
let available = Bytes.length buf - off in
let len = Int.min len 11 in
let len = Int.min len available in
Bytes.blit_string src off buf off len;
Bytes.blit_string src off buf off len ;
len
in
let src = String.init 255 Char.chr in
let@ placeholder = with_fd @@ dev_zero () in
(* not actually used, just to make the types work, we simulate the read using string ops *)
let actual = repeat_write write placeholder src 0 (String.length src) in
Alcotest.(check' int) ~msg:"amount written" ~actual ~expected:(Bytes.length buf);
Alcotest.(check' string) ~msg:"contents" ~actual:(Bytes.sub_string buf 0 actual) ~expected:src
Alcotest.(check' int)
~msg:"amount written" ~actual ~expected:(Bytes.length buf) ;
Alcotest.(check' string)
~msg:"contents"
~actual:(Bytes.sub_string buf 0 actual)
~expected:src

let tests =
Alcotest.
Expand Down

0 comments on commit ebcfa50

Please sign in to comment.