Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lofs fid improvements #35

Merged
merged 11 commits into from
Nov 30, 2015
64 changes: 63 additions & 1 deletion lib_test/lofs_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ let create_remove_file () =

let create_remove_dir () =
with_client1 (fun _client1 ->
let filemode = Types.FileMode.make ~owner:[`Write] () in
let filemode = Types.FileMode.make ~owner:[`Read; `Write] () in
Client1.mkdir _client1 [] "foo" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [] foo: " ^ err)
Expand All @@ -177,6 +177,66 @@ let create_remove_dir () =
Lwt.return ()
)

let failed_remove_clunk_fid () =
with_client1 (fun _client1 ->
let filemode = Types.FileMode.make ~owner:[`Read; `Write; `Execute] () in
Client1.mkdir _client1 [] "foo" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [] foo: " ^ err)
| Ok _ ->
Client1.mkdir _client1 ["foo"] "bar" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [foo] bar: " ^ err)
| Ok _ ->
Client1.with_fid _client1
(fun fid ->
Client1.walk_from_root _client1 fid ["foo"]
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: walk_from_root [foo]: " ^ err)
| Ok _ ->
Client1.LowLevel.remove _client1 fid
>>= function
| Ok () -> Alcotest.fail ("client1: remove a non-empty dir should fail")
| Error (`Msg _) ->
(* The fid should have been clunked so I can now re-use it *)
Client1.walk_from_root _client1 fid []
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: walk_from_root after failed remove: " ^ err)
| Ok _ ->
Lwt.return ()
)
)

let check_directory_boundary_read () =
with_client1 (fun _client1 ->
let filemode = Types.FileMode.make ~owner:[`Read; `Execute] () in
Client1.mkdir _client1 [] "foo" filemode
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: mkdir [] foo: " ^ err)
| Ok _ ->
Client1.with_fid _client1
(fun fid ->
Client1.walk_from_root _client1 fid ["foo"]
>>= function
| Error (`Msg err) -> Alcotest.fail ("client1: walk_from_root [foo]: " ^ err)
| Ok _ ->
Client1.LowLevel.openfid _client1 fid Types.OpenMode.read_only
>>= function
| Error (`Msg err) ->
Alcotest.fail ("client1: open: " ^ err)
| Ok _ ->
Client1.LowLevel.read _client1 fid 1024L 16l
>>= function
| Error (`Msg err) ->
Alcotest.fail ("client1: read: " ^ err)
| Ok { Response.Read.data } ->
let n = Cstruct.len data in
if n = 0
then Lwt.return ()
else Alcotest.fail ("client1: read non-zero: " ^ (string_of_int n))
)
)

let () = LogServer.print_debug := false
let () = LogClient1.print_debug := false
let () = LogClient2.print_debug := false
Expand All @@ -190,6 +250,8 @@ let test_client = [
lwt_test "check that create rebinds fids" (fun () -> with_server create_rebind_fid);
lwt_test "check that we can remove a file" (fun () -> with_server create_remove_file);
lwt_test "check that we can remove a directory" (fun () -> with_server create_remove_dir);
lwt_test "failed remove should clunk the fid" (fun () -> with_server failed_remove_clunk_fid);
lwt_test "check reading out-of-bounds on a directory doesn't fail badly" (fun () -> with_server check_directory_boundary_read);
]

let tests = [
Expand Down
Loading