tests: Add tests that just including the header works.
[nbdkit/ericb.git] / tests / test_ocaml_plugin.ml
blob842f10e6d2640079e16dab51847356541a21f823
1 type handle = {
2 disk : bytes; (* The disk image. *)
5 let test_load () =
6 NBDKit.debug "test ocaml plugin loaded"
8 let test_unload () =
9 NBDKit.debug "test ocaml plugin unloaded"
11 let params = ref []
13 let test_config k v =
14 params := (k, v) :: !params
16 let test_config_complete () =
17 let params = List.rev !params in
18 assert (params = [ "a", "1"; "b", "2"; "c", "3" ])
20 let test_open readonly =
21 NBDKit.debug "test ocaml plugin handle opened readonly=%b" readonly;
22 let disk = Bytes.make (1024*1024) '\000' in
23 { disk }
25 let test_close h =
28 let test_get_size h =
29 Int64.of_int (Bytes.length h.disk)
31 let test_pread h buf offset _ =
32 let len = Bytes.length buf in
33 Bytes.blit h.disk (Int64.to_int offset) buf 0 len
35 let test_pwrite h buf offset _ =
36 let len = String.length buf in
37 String.blit buf 0 h.disk (Int64.to_int offset) len
39 let plugin = {
40 NBDKit.default_callbacks with
41 NBDKit.name = "testocaml";
42 version = "1.0";
44 load = Some test_load;
45 unload = Some test_unload;
46 config = Some test_config;
47 config_complete = Some test_config_complete;
49 open_connection = Some test_open;
50 close = Some test_close;
51 get_size = Some test_get_size;
52 pread = Some test_pread;
53 pwrite = Some test_pwrite;
56 let thread_model = NBDKit.THREAD_MODEL_SERIALIZE_CONNECTIONS
58 let () = NBDKit.register_plugin thread_model plugin