X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=2446299fcca450e562bcd76f190de1394837b7d5;hp=fc320faf6584c4d3e22e3857d29cee57fc4437e8;hb=456446a86909dd05a5162aca4d676f680b47abc4;hpb=5b0a37c47aaec0a753a00026b52c305442fd6678 diff --git a/src/generator.ml b/src/generator.ml index fc320fa..2446299 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -24,8 +24,10 @@ * this one to describe the interface (see the big table below), and * daemon/.c to write the implementation. * - * After editing this file, run it (./src/generator.ml) to regenerate - * all the output files. + * After editing this file, run it (./src/generator.ml) to regenerate all the + * output files. Note that if you are using a separate build directory you must + * run generator.ml from your top level build directory. You must also have run + * configure before generator.ml will run. * * IMPORTANT: This script should NOT print any warnings. If it prints * warnings, you should treat them as errors. @@ -205,6 +207,10 @@ and test = *) | TestOutputInt of seq * int (* Run the command sequence and expect the output of the final + * command to be , eg. ">=", "1". + *) + | TestOutputIntOp of seq * string * int + (* Run the command sequence and expect the output of the final * command to be a true value (!= 0 or != NULL). *) | TestOutputTrue of seq @@ -228,6 +234,7 @@ and test = and test_field_compare = | CompareWithInt of string * int + | CompareWithIntOp of string * string * int | CompareWithString of string * string | CompareFieldsIntEq of string * string | CompareFieldsStrEq of string * string @@ -464,7 +471,8 @@ environment variable. Setting C to C restores the default qemu binary."); ("get_qemu", (RConstString "qemu", []), -1, [], - [], + [InitNone, Always, TestRun ( + [["get_qemu"]])], "get the qemu binary", "\ Return the current qemu binary. @@ -484,7 +492,8 @@ C environment variable. Setting C to C restores the default path."); ("get_path", (RConstString "path", []), -1, [], - [], + [InitNone, Always, TestRun ( + [["get_path"]])], "get the search path", "\ Return the current search path. @@ -506,6 +515,10 @@ Setting C to C means I additional options are passed (libguestfs always adds a few of its own)."); ("get_append", (RConstString "append", []), -1, [], + (* This cannot be tested with the current framework. The + * function can return NULL in normal operations, which the + * test framework interprets as an error. + *) [], "get the additional kernel options", "\ @@ -527,7 +540,8 @@ This is disabled by default (except in guestfish where it is enabled by default)."); ("get_autosync", (RBool "autosync", []), -1, [], - [], + [InitNone, Always, TestRun ( + [["get_autosync"]])], "get autosync mode", "\ Get the autosync flag."); @@ -548,7 +562,8 @@ C is defined and set to C<1>."); This returns the verbose messages flag."); ("is_ready", (RBool "ready", []), -1, [], - [], + [InitNone, Always, TestOutputTrue ( + [["is_ready"]])], "is ready to accept commands", "\ This returns true iff this handle is ready to accept commands @@ -557,7 +572,8 @@ This returns true iff this handle is ready to accept commands For more information on states, see L."); ("is_config", (RBool "config", []), -1, [], - [], + [InitNone, Always, TestOutputFalse ( + [["is_config"]])], "is in configuration state", "\ This returns true iff this handle is being configured @@ -566,7 +582,8 @@ This returns true iff this handle is being configured For more information on states, see L."); ("is_launching", (RBool "launching", []), -1, [], - [], + [InitNone, Always, TestOutputFalse ( + [["is_launching"]])], "is launching subprocess", "\ This returns true iff this handle is launching the subprocess @@ -575,7 +592,8 @@ This returns true iff this handle is launching the subprocess For more information on states, see L."); ("is_busy", (RBool "busy", []), -1, [], - [], + [InitNone, Always, TestOutputFalse ( + [["is_busy"]])], "is busy processing a command", "\ This returns true iff this handle is busy processing a command @@ -621,7 +639,9 @@ actions using the low-level API. For more information on states, see L."); ("set_memsize", (RErr, [Int "memsize"]), -1, [FishAlias "memsize"], - [], + [InitNone, Always, TestOutputInt ( + [["set_memsize"; "500"]; + ["get_memsize"]], 500)], "set memory allocated to the qemu subprocess", "\ This sets the memory size in megabytes allocated to the @@ -636,7 +656,8 @@ For more information on the architecture of libguestfs, see L."); ("get_memsize", (RInt "memsize", []), -1, [], - [], + [InitNone, Always, TestOutputIntOp ( + [["get_memsize"]], ">=", 256)], "get memory allocated to the qemu subprocess", "\ This gets the memory size in megabytes allocated to the @@ -650,7 +671,8 @@ For more information on the architecture of libguestfs, see L."); ("get_pid", (RInt "pid", []), -1, [FishAlias "pid"], - [], + [InitNone, Always, TestOutputIntOp ( + [["get_pid"]], ">=", 1)], "get PID of qemu subprocess", "\ Return the process ID of the qemu subprocess. If there is no @@ -3152,7 +3174,8 @@ let cols_of_struct typ = let seq_of_test = function | TestRun s | TestOutput (s, _) | TestOutputList (s, _) | TestOutputListOfDevices (s, _) - | TestOutputInt (s, _) | TestOutputTrue s | TestOutputFalse s + | TestOutputInt (s, _) | TestOutputIntOp (s, _, _) + | TestOutputTrue s | TestOutputFalse s | TestOutputLength (s, _) | TestOutputStruct (s, _) | TestLastFail s -> s @@ -4773,6 +4796,19 @@ and generate_one_test_body name i test_name init test = in List.iter (generate_test_command_call test_name) seq; generate_test_command_call ~test test_name last + | TestOutputIntOp (seq, op, expected) -> + pr " /* TestOutputIntOp for %s (%d) */\n" name i; + let seq, last = get_seq_last seq in + let test () = + pr " if (! (r %s %d)) {\n" op expected; + pr " fprintf (stderr, \"%s: expected %s %d but got %%d\\n\"," + test_name op expected; + pr " (int) r);\n"; + pr " return -1;\n"; + pr " }\n" + in + List.iter (generate_test_command_call test_name) seq; + generate_test_command_call ~test test_name last | TestOutputTrue seq -> pr " /* TestOutputTrue for %s (%d) */\n" name i; let seq, last = get_seq_last seq in @@ -4831,6 +4867,13 @@ and generate_one_test_body name i test_name init test = pr " (int) r->%s);\n" field; pr " return -1;\n"; pr " }\n" + | CompareWithIntOp (field, op, expected) -> + pr " if (!(r->%s %s %d)) {\n" field op expected; + pr " fprintf (stderr, \"%s: %s was %%d, expected %s %d\\n\",\n" + test_name field op expected; + pr " (int) r->%s);\n" field; + pr " return -1;\n"; + pr " }\n" | CompareWithString (field, expected) -> pr " if (strcmp (r->%s, \"%s\") != 0) {\n" field expected; pr " fprintf (stderr, \"%s: %s was \"%%s\", expected \"%s\"\\n\",\n" @@ -8171,7 +8214,7 @@ let output_to filename = let () = check_functions (); - if not (Sys.file_exists "HACKING") then ( + if not (Sys.file_exists "config.status") then ( eprintf "\ You are probably running this from the wrong directory. Run it from the top source directory using the command