Version 1.11.12
[nbdkit/ericb.git] / tests / test_ocaml_plugin.ml
blobd23884819f186f61588eb07acbcee7505556bde2
1 type handle = {
2 disk : string; (* The disk image. *)
5 let test_load () =
6 ()
7 let test_unload () =
8 ()
10 let params = ref []
12 let test_config k v =
13 params := (k, v) :: !params
15 let test_config_complete () =
16 let params = List.rev !params in
17 assert (params = [ "a", "1"; "b", "2"; "c", "3" ])
19 let test_open readonly =
20 let disk =
21 let s = String.create (512 * 8) in
22 for i = 0 to 511 do
23 for j = 0 to 7 do
24 s.[i*8+j] <- Char.chr (j+1)
25 done
26 done;
27 s in
28 { disk = disk }
30 let test_close h =
33 let test_get_size h =
34 Int64.of_int (String.length h.disk)
36 let test_pread h buf offset =
37 let len = String.length buf in
38 String.blit h.disk (Int64.to_int offset) buf 0 len
40 let test_pwrite h buf offset =
41 let len = String.length buf in
42 String.blit buf 0 h.disk (Int64.to_int offset) len
44 let plugin = {
45 NBDKit.default_callbacks with
46 NBDKit.name = "testocaml";
47 version = "1.0";
49 load = Some test_load;
50 unload = Some test_unload;
51 config = Some test_config;
52 config_complete = Some test_config_complete;
54 open_connection = Some test_open;
55 close = Some test_close;
56 get_size = Some test_get_size;
57 pread = Some test_pread;
58 pwrite = Some test_pwrite;
61 let thread_model = NBDKit.THREAD_MODEL_SERIALIZE_CONNECTIONS
63 let () = NBDKit.register_plugin thread_model plugin