[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 09/10] bindtests: Test optargs in test0



On Fri, Jan 20, 2012 at 11:07:52AM +0000, Matthew Booth wrote:

> Note that this change disables compiling and running the haskell
> bindtests. The haskell bindings to not implement optargs, and adding

Typo: s/to/do/

> optargs to test0 causes that method not to be bound in the haskell
> bindings. This prevents the haskell bindtests from compiling. These
> should be re-enabled when optargs are implemented.

>  bindtests                        |   52 ++++++++++
>  generator/generator_actions.ml   |   10 ++-
>  generator/generator_bindtests.ml |  194 ++++++++++++++++++++++++++++++++------
>  generator/generator_types.ml     |    6 +
>  haskell/Makefile.am              |    8 +-
>  5 files changed, 237 insertions(+), 33 deletions(-)
> 
> diff --git a/bindtests b/bindtests
> index 23da165..c42feda 100644
> --- a/bindtests
> +++ b/bindtests
> @@ -7,6 +7,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: true
> +oint: 1
> +oint64: unset
> +ostring: unset
>  abc
>  null
>  []
> @@ -16,6 +20,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: 1
> +ostring: string
>  
>  def
>  []
> @@ -25,6 +33,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: false
> +oint: unset
> +oint64: unset
> +ostring: unset
>  
>  
>  []
> @@ -34,6 +46,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -43,6 +59,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1", "2"]
> @@ -52,6 +72,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -61,6 +85,10 @@ true
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -70,6 +98,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -79,6 +111,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -88,6 +124,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -97,6 +137,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -106,6 +150,10 @@ false
>  123
>  456
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  abc
>  def
>  ["1"]
> @@ -115,4 +163,8 @@ false
>  
>  
>  <61><62><63><00><61><62><63>
> +obool: unset
> +oint: unset
> +oint64: unset
> +ostring: unset
>  EOF
> diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
> index 3d8cc4b..3a7be79 100644
> --- a/generator/generator_actions.ml
> +++ b/generator/generator_actions.ml
> @@ -43,6 +43,13 @@ let test_all_args = [
>    BufferIn "bufferin";
>  ]
>  
> +let test_all_optargs = [
> +  OBool   "obool";
> +  OInt    "oint";
> +  OInt64  "oint64";
> +  OString "ostring"
> +]
> +
>  let test_all_rets = [
>    (* except for RErr, which is tested thoroughly elsewhere *)
>    "test0rint",         RInt "valout";
> @@ -59,7 +66,8 @@ let test_all_rets = [
>  ]
>  
>  let test_functions = [
> -  ("test0", (RErr, test_all_args, []), -1, [NotInFish; NotInDocs; Cancellable],
> +  ("test0", (RErr, test_all_args, test_all_optargs), -1,
> +   [NotInFish; NotInDocs; Cancellable],
>     [],
>     "internal test function - do not use",
>     "\
> diff --git a/generator/generator_bindtests.ml b/generator/generator_bindtests.ml
> index e64afff..1c04ecf 100644
> --- a/generator/generator_bindtests.ml
> +++ b/generator/generator_bindtests.ml
> @@ -65,9 +65,9 @@ print_strings (char *const *argv)
>      | test0 :: tests -> test0, tests in
>  
>    let () =
> -    let (name, (ret, args, _ as style), _, _, _, _, _) = test0 in
> +    let (name, (ret, args, optargs as style), _, _, _, _, _) = test0 in
>      generate_prototype ~extern:false ~semicolon:false ~newline:true
> -      ~handle:"g" ~prefix:"guestfs__" name style;
> +      ~handle:"g" ~prefix:"guestfs__" ~optarg_proto:Argv name style;
>      pr "{\n";
>      List.iter (
>        function
> @@ -91,6 +91,31 @@ print_strings (char *const *argv)
>        | Int64 n -> pr "  printf (\"%%\" PRIi64 \"\\n\", %s);\n" n
>        | Pointer _ -> assert false
>      ) args;
> +    let check_optarg n printf_args =
> +      pr "  printf (\"%s: \");\n" n;
> +      pr "  if (optargs->bitmask & GUESTFS_TEST0_%s_BITMASK) {\n"
> +        (String.uppercase n);
> +      pr "    printf(%s);\n" printf_args;
> +      pr "  } else {\n";
> +      pr "    printf (\"unset\\n\");\n";
> +      pr "  }\n";
> +    in
> +    List.iter (
> +      function
> +      | OBool n ->
> +        let printf_args =
> +          sprintf "\"%%s\\n\", optargs->%s ? \"true\" : \"false\"" n in
> +        check_optarg n printf_args;
> +      | OInt n ->
> +        let printf_args = sprintf "\"%%i\\n\", optargs->%s" n in
> +        check_optarg n printf_args;
> +      | OInt64 n ->
> +        let printf_args = sprintf "\"%%\" PRIi64 \"\\n\", optargs->%s" n in
> +        check_optarg n printf_args;
> +      | OString n ->
> +        let printf_args = sprintf "\"%%s\\n\", optargs->%s" n in
> +        check_optarg n printf_args;
> +    ) optargs;
>      pr "  /* Java changes stdout line buffering so we need this: */\n";
>      pr "  fflush (stdout);\n";
>      pr "  return 0;\n";
> @@ -215,7 +240,12 @@ let () =
>    let g = Guestfs.create () in
>  ";
>  
> -  let mkargs args =
> +  let mkargs args optargs =
> +    let optargs =
> +      match optargs with
> +      | Some n -> n
> +      | None -> []
> +    in
>      String.concat " " (
>        List.map (
>          function
> @@ -231,11 +261,19 @@ let () =
>          | CallBool b -> string_of_bool b
>          | CallBuffer s -> sprintf "%S" s
>        ) args
> +      @
> +      List.map (
> +        function
> +        | CallOBool (n, v)    -> "~" ^ n ^ ":" ^ string_of_bool v
> +        | CallOInt (n, v)     -> "~" ^ n ^ ":" ^ string_of_int v
> +        | CallOInt64 (n, v)   -> "~" ^ n ^ ":" ^ Int64.to_string v ^ "L"
> +        | CallOString (n, v)  -> "~" ^ n ^ ":\"" ^ v ^ "\""
> +      ) optargs
>      )
>    in
>  
>    generate_lang_bindtests (
> -    fun f args -> pr "  Guestfs.%s g %s;\n" f (mkargs args)
> +    fun f args optargs -> pr "  Guestfs.%s g %s;\n" f (mkargs args optargs)
>    );
>  
>    pr "print_endline \"EOF\"\n"
> @@ -252,7 +290,12 @@ use Sys::Guestfs;
>  my $g = Sys::Guestfs->new ();
>  ";
>  
> -  let mkargs args =
> +  let mkargs args optargs =
> +    let optargs =
> +      match optargs with
> +      | Some n -> n
> +      | None -> []
> +    in
>      String.concat ", " (
>        List.map (
>          function
> @@ -266,11 +309,19 @@ my $g = Sys::Guestfs->new ();
>          | CallBool b -> if b then "1" else "0"
>          | CallBuffer s -> "\"" ^ c_quote s ^ "\""
>        ) args
> +      @
> +      List.map (
> +        function
> +        | CallOBool (n, v)    -> "'" ^ n ^ "' => " ^ if v then "1" else "0"
> +        | CallOInt (n, v)     -> "'" ^ n ^ "' => " ^ string_of_int v
> +        | CallOInt64 (n, v)   -> "'" ^ n ^ "' => " ^ Int64.to_string v
> +        | CallOString (n, v)  -> "'" ^ n ^ "' => '" ^ v ^ "'"
> +      ) optargs
>      )
>    in
>  
>    generate_lang_bindtests (
> -    fun f args -> pr "$g->%s (%s);\n" f (mkargs args)
> +    fun f args optargs -> pr "$g->%s (%s);\n" f (mkargs args optargs)
>    );
>  
>    pr "print \"EOF\\n\"\n"
> @@ -284,7 +335,12 @@ import guestfs
>  g = guestfs.GuestFS ()
>  ";
>  
> -  let mkargs args =
> +  let mkargs args optargs =
> +    let optargs =
> +      match optargs with
> +      | Some n -> n
> +      | None -> []
> +    in
>      String.concat ", " (
>        List.map (
>          function
> @@ -298,11 +354,19 @@ g = guestfs.GuestFS ()
>          | CallBool b -> if b then "1" else "0"
>          | CallBuffer s -> "\"" ^ c_quote s ^ "\""
>        ) args
> +      @
> +      List.map (
> +        function
> +        | CallOBool (n, v)    -> n ^ "=" ^ if v then "True" else "False"
> +        | CallOInt (n, v)     -> n ^ "=" ^ string_of_int v
> +        | CallOInt64 (n, v)   -> n ^ "=" ^ Int64.to_string v
> +        | CallOString (n, v)  -> n ^ "=\"" ^ v ^ "\""
> +      ) optargs
>      )
>    in
>  
>    generate_lang_bindtests (
> -    fun f args -> pr "g.%s (%s)\n" f (mkargs args)
> +    fun f args optargs -> pr "g.%s (%s)\n" f (mkargs args optargs)
>    );
>  
>    pr "print (\"EOF\")\n"
> @@ -316,7 +380,12 @@ require 'guestfs'
>  g = Guestfs::create()
>  ";
>  
> -  let mkargs args =
> +  let mkargs args optargs =
> +    let optargs =
> +      match optargs with
> +      | Some n -> n
> +      | None -> []
> +    in
>      String.concat ", " (
>        List.map (
>          function
> @@ -330,11 +399,22 @@ g = Guestfs::create()
>          | CallBool b -> string_of_bool b
>          | CallBuffer s -> "\"" ^ c_quote s ^ "\""
>        ) args
> -    )
> +    ) ^
> +    ", {" ^
> +    String.concat ", " (
> +      List.map (
> +        function
> +        | CallOBool (n, v)    -> ":" ^ n ^ " => " ^ string_of_bool v
> +        | CallOInt (n, v)     -> ":" ^ n ^ " => " ^ string_of_int v
> +        | CallOInt64 (n, v)   -> ":" ^ n ^ " => " ^ Int64.to_string v
> +        | CallOString (n, v)  -> ":" ^ n ^ " => \"" ^ v ^ "\""
> +      ) optargs
> +    ) ^
> +    "}"
>    in
>  
>    generate_lang_bindtests (
> -    fun f args -> pr "g.%s(%s)\n" f (mkargs args)
> +    fun f args optargs -> pr "g.%s(%s)\n" f (mkargs args optargs)
>    );
>  
>    pr "print \"EOF\\n\"\n"
> @@ -343,6 +423,8 @@ and generate_java_bindtests () =
>    generate_header CStyle GPLv2plus;
>  
>    pr "\
> +import java.util.Map;
> +import java.util.HashMap;
>  import com.redhat.et.libguestfs.*;
>  
>  public class Bindtests {
> @@ -350,8 +432,30 @@ public class Bindtests {
>      {
>          try {
>              GuestFS g = new GuestFS ();
> +            Map<String, Object> o;
> +
>  ";
>  
> +  let mkoptargs =
> +    function
> +    | Some optargs ->
> +      "o = new HashMap<String, Object>() {{" ::
> +      List.map (
> +        function
> +        | CallOBool (n, v)    ->
> +          "  put(\"" ^ n ^ "\", Boolean." ^ (if v then "TRUE" else "FALSE") ^ ");"
> +        | CallOInt (n, v)     ->
> +          "  put(\"" ^ n ^ "\", " ^ string_of_int v ^ ");"
> +        | CallOInt64 (n, v)   ->
> +          "  put(\"" ^ n ^ "\", " ^ Int64.to_string v ^ "l);"
> +        | CallOString (n, v)  ->
> +          "  put(\"" ^ n ^ "\", \"" ^ v ^ "\");"
> +      ) optargs @
> +      [ "}};\n" ]
> +    | None ->
> +      [ "o = null;" ]
> +  in
> +
>    let mkargs args =
>      String.concat ", " (
>        List.map (
> @@ -373,8 +477,14 @@ public class Bindtests {
>      )
>    in
>  
> +  let pr_indent indent strings =
> +    List.iter ( fun s -> pr "%s%s\n" indent s) strings
> +  in
> +
>    generate_lang_bindtests (
> -    fun f args -> pr "            g.%s (%s);\n" f (mkargs args)
> +    fun f args optargs ->
> +      pr_indent "            " (mkoptargs optargs);
> +      pr "            g.%s (%s, o);\n" f (mkargs args)
>    );
>  
>    pr "
> @@ -420,7 +530,7 @@ main = do
>    in
>  
>    generate_lang_bindtests (
> -    fun f args -> pr "  Guestfs.%s g %s\n" f (mkargs args)
> +    fun f args optargs -> pr "  Guestfs.%s g %s\n" f (mkargs args)
>    );
>  
>    pr "  putStrLn \"EOF\"\n"
> @@ -432,9 +542,29 @@ and generate_gobject_js_bindtests () =
>  const Guestfs = imports.gi.Guestfs;
>  
>  var g = new Guestfs.Session();
> +var o;
>  
>  ";
>  
> +    let mkoptargs = function
> +    | Some optargs ->
> +      "o = new Guestfs.Test0({" ^
> +      (
> +        String.concat ", " (
> +          List.map (
> +            function
> +            | CallOBool (n, v)    -> n ^ ": " ^ (if v then "true" else "false")
> +            | CallOInt (n, v)     -> n ^ ": " ^ (string_of_int v)
> +            | CallOInt64 (n, v)   -> n ^ ": " ^ Int64.to_string v
> +            | CallOString (n, v)  -> n ^ ": \"" ^ v ^ "\""
> +          ) optargs
> +        )
> +      ) ^
> +      "});"
> +    | None ->
> +      "o = null;"
> +    in
> +
>      let mkargs args =
>        String.concat ", " (
>          (List.map (
> @@ -450,11 +580,12 @@ var g = new Guestfs.Session();
>            | CallBool false -> "false"
>            | CallBuffer s -> "\"" ^ c_quote s ^ "\""
>          ) args)
> -        @ ["null"]
> +        @ ["o"; "null"]
>        )
>      in
>      generate_lang_bindtests (
> -      fun f args -> pr "g.%s(%s);\n" f (mkargs args)
> +      fun f args optargs ->
> +        pr "%s\ng.%s(%s);\n" (mkoptargs optargs) f (mkargs args)
>      );
>  
>      pr "\nprint(\"EOF\");\n"
> @@ -466,54 +597,59 @@ and generate_lang_bindtests call =
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList []; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"]
> +               (Some [CallOBool ("obool", true); CallOInt ("oint", 1)]);
>    call "test0" [CallString "abc"; CallOptString None;
>                  CallStringList []; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"]
> +               (Some [CallOInt64 ("oint64", 1L);
> +                      CallOString ("ostring", "string")]);
>    call "test0" [CallString ""; CallOptString (Some "def");
>                  CallStringList []; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"]
> +               (Some [CallOBool ("obool", false)]);
>    call "test0" [CallString ""; CallOptString (Some "");
>                  CallStringList []; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"]
> +                (Some []);
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"; "2"]; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool true;
>                  CallInt 0; CallInt64 0L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
>                  CallInt (-1); CallInt64 (-1L); CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
> -                CallInt (-2); CallInt64 (-2L); CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallInt (-2); CallInt64 (-2L); CallString "123";CallString "456";
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
>                  CallInt 1; CallInt64 1L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
>                  CallInt 2; CallInt64 2L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
>                  CallInt 4095; CallInt64 4095L; CallString "123"; CallString "456";
> -                CallBuffer "abc\000abc"];
> +                CallBuffer "abc\000abc"] None;
>    call "test0" [CallString "abc"; CallOptString (Some "def");
>                  CallStringList ["1"]; CallBool false;
>                  CallInt 0; CallInt64 0L; CallString ""; CallString "";
> -                CallBuffer "abc\000abc"]
> +                CallBuffer "abc\000abc"] None;
>  
>  (* XXX Add here tests of the return and error functions. *)
> diff --git a/generator/generator_types.ml b/generator/generator_types.ml
> index 233be54..5a0c425 100644
> --- a/generator/generator_types.ml
> +++ b/generator/generator_types.ml
> @@ -420,3 +420,9 @@ type callt =
>    | CallInt64 of int64
>    | CallBool of bool
>    | CallBuffer of string
> +
> +type call_optargt =
> +  | CallOBool of string * bool
> +  | CallOInt of string * int
> +  | CallOInt64 of string * int64
> +  | CallOString of string * string
> diff --git a/haskell/Makefile.am b/haskell/Makefile.am
> index 5c1ff98..3781f07 100644
> --- a/haskell/Makefile.am
> +++ b/haskell/Makefile.am
> @@ -33,13 +33,15 @@ TESTS_ENVIRONMENT = \
>  	TMPDIR=$(top_builddir) \
>  	$(VG)
>  
> -TESTS = run-bindtests Guestfs005Load Guestfs010Basic
> +# Don't run the bindtests: they don't build since the addition of optargs.
> +# Haskell bindings are incomplete.
> +TESTS = Guestfs005Load Guestfs010Basic
>  
> -check_DATA = Bindtests
> +#check_DATA = Bindtests
>  
>  GHCFLAGS = -I$(top_builddir)/src -L$(top_builddir)/src/.libs -i$(srcdir)
>  
> -all_targets = Bindtests Guestfs005Load Guestfs010Basic
> +all_targets = Guestfs005Load Guestfs010Basic
>  $(all_targets): $(top_builddir)/src/libguestfs.la
>  
>  all: $(all_targets)

Looks OK, ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]