[Pkg-libvirt-commits] [libguestfs] 18/29: v2v: Add a binding for guestfs_int_drive_index and a unit test.

Hilko Bengen bengen at moszumanska.debian.org
Sun Nov 1 17:15:05 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag upstream/1.29.49
in repository libguestfs.

commit 4ef80f28c819605f415a71a2337ae90b9b7888bc
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Jul 1 15:14:58 2015 +0100

    v2v: Add a binding for guestfs_int_drive_index and a unit test.
---
 v2v/utils-c.c         | 14 ++++++++++++++
 v2v/utils.ml          |  1 +
 v2v/v2v_unit_tests.ml | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/v2v/utils-c.c b/v2v/utils-c.c
index e88620f..c0fa260 100644
--- a/v2v/utils-c.c
+++ b/v2v/utils-c.c
@@ -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));
+}
diff --git a/v2v/utils.ml b/v2v/utils.ml
index 976fe85..4e6befc 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -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.
diff --git a/v2v/v2v_unit_tests.ml b/v2v/v2v_unit_tests.ml
index 1b84ed0..00d19e0 100644
--- a/v2v/v2v_unit_tests.ml
+++ b/v2v/v2v_unit_tests.ml
@@ -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 () =

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list