diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-09-03 08:52:33 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-09-03 09:36:04 +0100 |
commit | 3820a2578c120056683a4b152b72021f82b2c821 (patch) | |
tree | b274c15c15ecc12902923de03d65a104ae6ceac5 | |
parent | f65dee769d1fc53c5963c381bf8a1bf02654f78c (diff) | |
download | libguestfs-3820a2578c120056683a4b152b72021f82b2c821.tar.gz libguestfs-3820a2578c120056683a4b152b72021f82b2c821.tar.xz libguestfs-3820a2578c120056683a4b152b72021f82b2c821.zip |
generator: Test zero args, one optarg; and 63 optargs.
This just generates the code; it's not called.
-rw-r--r-- | generator/actions.ml | 37 | ||||
-rw-r--r-- | generator/bindtests.ml | 135 | ||||
-rw-r--r-- | gobject/Makefile.inc | 4 | ||||
-rw-r--r-- | po/POTFILES | 2 |
4 files changed, 110 insertions, 68 deletions
diff --git a/generator/actions.ml b/generator/actions.ml index 65012adb..9c2470dc 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -86,7 +86,39 @@ parameter type correctly. It echos the contents of each parameter to stdout (by default) or to a file (if C<guestfs_internal_test_set_output> was called). +You probably don't want to call this function." }; + + { defaults with + name = "internal_test_only_optargs"; + style = RErr, [], [OInt "test"]; + in_fish = false; in_docs = false; cancellable = true; + shortdesc = "internal test function - do not use"; + longdesc = "\ +This is an internal test function which is used to test whether +the automatically generated bindings can handle no args, some +optargs correctly. + +It echos the contents of each parameter to stdout (by default) +or to a file (if C<guestfs_internal_test_set_output> was called). + +You probably don't want to call this function." }; + + { defaults with + name = "internal_test_63_optargs"; + style = RErr, [], [OInt "opt1"; OInt "opt2"; OInt "opt3"; OInt "opt4"; OInt "opt5"; OInt "opt6"; OInt "opt7"; OInt "opt8"; OInt "opt9"; OInt "opt10"; OInt "opt11"; OInt "opt12"; OInt "opt13"; OInt "opt14"; OInt "opt15"; OInt "opt16"; OInt "opt17"; OInt "opt18"; OInt "opt19"; OInt "opt20"; OInt "opt21"; OInt "opt22"; OInt "opt23"; OInt "opt24"; OInt "opt25"; OInt "opt26"; OInt "opt27"; OInt "opt28"; OInt "opt29"; OInt "opt30"; OInt "opt31"; OInt "opt32"; OInt "opt33"; OInt "opt34"; OInt "opt35"; OInt "opt36"; OInt "opt37"; OInt "opt38"; OInt "opt39"; OInt "opt40"; OInt "opt41"; OInt "opt42"; OInt "opt43"; OInt "opt44"; OInt "opt45"; OInt "opt46"; OInt "opt47"; OInt "opt48"; OInt "opt49"; OInt "opt50"; OInt "opt51"; OInt "opt52"; OInt "opt53"; OInt "opt54"; OInt "opt55"; OInt "opt56"; OInt "opt57"; OInt "opt58"; OInt "opt59"; OInt "opt60"; OInt "opt61"; OInt "opt62"; OInt "opt63"]; + in_fish = false; in_docs = false; cancellable = true; + shortdesc = "internal test function - do not use"; + longdesc = "\ +This is an internal test function which is used to test whether +the automatically generated bindings can handle the full range +of 63 optargs correctly. (Note that 63 is not an absolute limit +and it could be raised by changing the XDR protocol). + +It echos the contents of each parameter to stdout (by default) +or to a file (if C<guestfs_internal_test_set_output> was called). + You probably don't want to call this function." } + ] @ List.flatten ( List.map ( fun (name, ret) -> [ @@ -10016,7 +10048,7 @@ Remove C<VAR> from the environment." }; * c_function = full name that non-C bindings should call * c_optarg_prefix = prefix for optarg / bitmask names *) -let non_daemon_functions, daemon_functions = +let test_functions, non_daemon_functions, daemon_functions = let make_c_function f = match f with | { style = _, _, [] } -> @@ -10036,9 +10068,10 @@ let non_daemon_functions, daemon_functions = c_optarg_prefix = "GUESTFS_" ^ String.uppercase f.name ^ "_OPTS"; non_c_aliases = [ f.name ^ "_opts" ] } in + let test_functions = List.map make_c_function test_functions in let non_daemon_functions = List.map make_c_function non_daemon_functions in let daemon_functions = List.map make_c_function daemon_functions in - non_daemon_functions, daemon_functions + test_functions, non_daemon_functions, daemon_functions (* Create a camel-case version of each name, unless the camel_name * field was set above. diff --git a/generator/bindtests.ml b/generator/bindtests.ml index 37abb054..bb035b34 100644 --- a/generator/bindtests.ml +++ b/generator/bindtests.ml @@ -104,85 +104,88 @@ print_strings (guestfs_h *g, char *const *argv) fprintf (fp, \"]\\n\"); } -/* The internal_test function prints its parameters to stdout or the - * file set by internal_test_set_output. - */ "; - let test, tests = + let ptests, rtests = match test_functions with - | [] -> assert false - | test :: tests -> test, tests in - - let () = - let { name = name; style = (ret, args, optargs as style) } = test in - generate_prototype ~extern:false ~semicolon:false ~newline:true - ~handle:"g" ~prefix:"guestfs__" ~optarg_proto:Argv name style; - pr "{\n"; - pr " FILE *fp = get_fp (g);\n"; - pr "\n"; - - List.iter ( - function - | Pathname n - | Device n | Dev_or_Path n - | String n - | FileIn n - | FileOut n - | Key n -> pr " fprintf (fp, \"%%s\\n\", %s);\n" n - | BufferIn n -> + | t :: t1 :: t2 :: rtests -> [ t; t1; t2 ], rtests + | _ -> assert false in + + List.iter ( + fun { name = name; style = (ret, args, optargs as style); + c_optarg_prefix = c_optarg_prefix } -> + pr "/* The %s function prints its parameters to stdout or the\n" name; + pr " * file set by internal_test_set_output.\n"; + pr " */\n"; + + generate_prototype ~extern:false ~semicolon:false ~newline:true + ~handle:"g" ~prefix:"guestfs__" ~optarg_proto:Argv name style; + pr "{\n"; + pr " FILE *fp = get_fp (g);\n"; + pr "\n"; + + List.iter ( + function + | Pathname n + | Device n | Dev_or_Path n + | String n + | FileIn n + | FileOut n + | Key n -> pr " fprintf (fp, \"%%s\\n\", %s);\n" n + | BufferIn n -> pr " {\n"; pr " size_t i;\n"; pr " for (i = 0; i < %s_size; ++i)\n" n; pr " fprintf (fp, \"<%%02x>\", %s[i]);\n" n; pr " fprintf (fp, \"\\n\");\n"; pr " }\n"; - | OptString n -> pr " fprintf (fp, \"%%s\\n\", %s ? %s : \"null\");\n" n n - | StringList n | DeviceList n -> pr " print_strings (g, %s);\n" n - | Bool n -> pr " fprintf (fp, \"%%s\\n\", %s ? \"true\" : \"false\");\n" n - | Int n -> pr " fprintf (fp, \"%%d\\n\", %s);\n" n - | Int64 n -> pr " fprintf (fp, \"%%\" PRIi64 \"\\n\", %s);\n" n - | Pointer _ -> assert false - ) args; - - let check_optarg n printf_args = - pr " fprintf (fp, \"%s: \");\n" n; - pr " if (optargs->bitmask & GUESTFS_INTERNAL_TEST_%s_BITMASK) {\n" - (String.uppercase n); - pr " fprintf (fp, %s);\n" printf_args; - pr " } else {\n"; - pr " fprintf (fp, \"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; - | OStringList n -> + | OptString n -> pr " fprintf (fp, \"%%s\\n\", %s ? %s : \"null\");\n" n n + | StringList n | DeviceList n -> pr " print_strings (g, %s);\n" n + | Bool n -> pr " fprintf (fp, \"%%s\\n\", %s ? \"true\" : \"false\");\n" n + | Int n -> pr " fprintf (fp, \"%%d\\n\", %s);\n" n + | Int64 n -> pr " fprintf (fp, \"%%\" PRIi64 \"\\n\", %s);\n" n + | Pointer _ -> assert false + ) args; + + let check_optarg n printf_args = pr " fprintf (fp, \"%s: \");\n" n; - pr " if (optargs->bitmask & GUESTFS_INTERNAL_TEST_%s_BITMASK) {\n" + pr " if (optargs->bitmask & %s_%s_BITMASK) {\n" c_optarg_prefix (String.uppercase n); - pr " print_strings (g, optargs->%s);\n" n; + pr " fprintf (fp, %s);\n" printf_args; pr " } else {\n"; pr " fprintf (fp, \"unset\\n\");\n"; pr " }\n"; - ) optargs; - pr " /* Java changes stdout line buffering so we need this: */\n"; - pr " fflush (fp);\n"; - pr " return 0;\n"; - pr "}\n"; - pr "\n" in + 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; + | OStringList n -> + pr " fprintf (fp, \"%s: \");\n" n; + pr " if (optargs->bitmask & %s_%s_BITMASK) {\n" c_optarg_prefix + (String.uppercase n); + pr " print_strings (g, optargs->%s);\n" n; + pr " } else {\n"; + pr " fprintf (fp, \"unset\\n\");\n"; + pr " }\n"; + ) optargs; + pr " /* Java changes stdout line buffering so we need this: */\n"; + pr " fflush (fp);\n"; + pr " return 0;\n"; + pr "}\n"; + pr "\n" + ) ptests; List.iter ( fun { name = name; style = (ret, args, _ as style) } -> @@ -292,7 +295,7 @@ print_strings (guestfs_h *g, char *const *argv) pr "}\n"; pr "\n" ) - ) tests + ) rtests and generate_ocaml_bindtests () = generate_header OCamlStyle GPLv2plus; diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index ba41b488..e0d00d54 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -43,6 +43,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/struct-hivex_node.h \ include/guestfs-gobject/struct-hivex_value.h \ include/guestfs-gobject/optargs-internal_test.h \ + include/guestfs-gobject/optargs-internal_test_only_optargs.h \ + include/guestfs-gobject/optargs-internal_test_63_optargs.h \ include/guestfs-gobject/optargs-add_drive.h \ include/guestfs-gobject/optargs-add_domain.h \ include/guestfs-gobject/optargs-inspect_get_icon.h \ @@ -103,6 +105,8 @@ guestfs_gobject_sources= \ src/struct-hivex_node.c \ src/struct-hivex_value.c \ src/optargs-internal_test.c \ + src/optargs-internal_test_only_optargs.c \ + src/optargs-internal_test_63_optargs.c \ src/optargs-add_drive.c \ src/optargs-add_domain.c \ src/optargs-inspect_get_icon.c \ diff --git a/po/POTFILES b/po/POTFILES index 19cb0b50..87e521c0 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -152,6 +152,8 @@ gobject/src/optargs-grep.c gobject/src/optargs-hivex_open.c gobject/src/optargs-inspect_get_icon.c gobject/src/optargs-internal_test.c +gobject/src/optargs-internal_test_63_optargs.c +gobject/src/optargs-internal_test_only_optargs.c gobject/src/optargs-md_create.c gobject/src/optargs-mkfs.c gobject/src/optargs-mkfs_btrfs.c |