v2v: Add a binding for guestfs_int_drive_index and a unit test.

This commit is contained in:
Richard W.M. Jones
2015-07-01 15:14:58 +01:00
parent 36e22d1e8e
commit 4ef80f28c8
3 changed files with 34 additions and 0 deletions

View File

@@ -23,6 +23,7 @@
#include <unistd.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
@@ -43,3 +44,16 @@ v2v_utils_drive_name (value indexv)
CAMLreturn (namev);
}
value
v2v_utils_drive_index (value strv)
{
CAMLparam1 (strv);
ssize_t r;
r = guestfs_int_drive_index (String_val (strv));
if (r == -1)
caml_invalid_argument ("drive_index: invalid parameter");
CAMLreturn (Val_int (r));
}

View File

@@ -59,6 +59,7 @@ let uri_quote str =
String.concat "" (List.rev !xs)
external drive_name : int -> string = "v2v_utils_drive_name"
external drive_index : string -> int = "v2v_utils_drive_index"
(* Map guest architecture found by inspection to the architecture
* that KVM must emulate. Note for x86 we assume a 64 bit hypervisor.

View File

@@ -94,12 +94,31 @@ let test_drive_name ctx =
assert_equal ~printer "aaa" (Utils.drive_name 702);
assert_equal ~printer "zzz" (Utils.drive_name 18277)
let test_drive_index ctx =
let printer = string_of_int in
assert_equal ~printer 0 (Utils.drive_index "a");
assert_equal ~printer 25 (Utils.drive_index "z");
assert_equal ~printer 26 (Utils.drive_index "aa");
assert_equal ~printer 27 (Utils.drive_index "ab");
assert_equal ~printer 51 (Utils.drive_index "az");
assert_equal ~printer 52 (Utils.drive_index "ba");
assert_equal ~printer 701 (Utils.drive_index "zz");
assert_equal ~printer 702 (Utils.drive_index "aaa");
assert_equal ~printer 18277 (Utils.drive_index "zzz");
let exn = Invalid_argument "drive_index: invalid parameter" in
assert_raises exn (fun () -> Utils.drive_index "");
assert_raises exn (fun () -> Utils.drive_index "abc123");
assert_raises exn (fun () -> Utils.drive_index "123");
assert_raises exn (fun () -> Utils.drive_index "Z");
assert_raises exn (fun () -> Utils.drive_index "aB")
(* Suites declaration. *)
let suite =
"virt-v2v" >:::
[
"OVF.get_ostype" >:: test_get_ostype;
"Utils.drive_name" >:: test_drive_name;
"Utils.drive_index" >:: test_drive_index;
]
let () =