*
* IMPORTANT: This script should NOT print any warnings. If it prints
* warnings, you should treat them as errors.
- * [Need to add -warn-error to ocaml command line]
*)
#load "unix.cma";;
and test =
(* Run the command sequence and just expect nothing to fail. *)
| TestRun of seq
+
(* Run the command sequence and expect the output of the final
* command to be the string.
*)
| TestOutput of seq * string
+
(* Run the command sequence and expect the output of the final
* command to be the list of strings.
*)
| TestOutputList of seq * string list
+
(* Run the command sequence and expect the output of the final
* command to be the list of block devices (could be either
* "/dev/sd.." or "/dev/hd.." form - we don't check the 5th
* character of each string).
*)
| TestOutputListOfDevices of seq * string list
+
(* Run the command sequence and expect the output of the final
* command to be the integer.
*)
| TestOutputInt of seq * int
+
(* Run the command sequence and expect the output of the final
* command to be <op> <int>, 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
+
(* Run the command sequence and expect the output of the final
* command to be a false value (== 0 or == NULL, but not an error).
*)
| TestOutputFalse of seq
+
(* Run the command sequence and expect the output of the final
* command to be a list of the given length (but don't care about
* content).
*)
| TestOutputLength of seq * int
+
(* Run the command sequence and expect the output of the final
* command to be a buffer (RBufferOut), ie. string + size.
*)
| TestOutputBuffer of seq * string
+
(* Run the command sequence and expect the output of the final
* command to be a structure.
*)
| TestOutputStruct of seq * test_field_compare list
+
(* Run the command sequence and expect the final command (only)
* to fail.
*)
and test_prereq =
(* Test always runs. *)
| Always
+
(* Test is currently disabled - eg. it fails, or it tests some
* unimplemented feature.
*)
| Disabled
+
(* 'string' is some C code (a function body) that should return
* true or false. The test will run if the code returns true.
*)
| If of string
+
(* As for 'If' but the test runs _unless_ the code returns true. *)
| Unless of string
["mkswap_L"; "hello"; "/dev/sda1"]])],
"create a swap partition with a label",
"\
-Create a swap partition on C<device> with label C<label>.");
+Create a swap partition on C<device> with label C<label>.
+
+Note that you cannot attach a swap label to a block device
+(eg. C</dev/sda>), just to a partition. This appears to be
+a limitation of the kernel or swap tools.");
("mkswap_U", (RErr, [String "uuid"; String "device"]), 132, [],
[InitEmpty, Always, TestRun (
This calls the external C<zfgrep -i> program and returns the
matching lines.");
+ ("realpath", (RString "rpath", [String "path"]), 163, [],
+ [InitSquashFS, Always, TestOutput (
+ [["realpath"; "/../directory"]], "/directory")],
+ "canonicalized absolute pathname",
+ "\
+Return the canonicalized absolute pathname of C<path>. The
+returned path has no C<.>, C<..> or symbolic link path elements.");
+
+ ("ln", (RErr, [String "target"; String "linkname"]), 164, [],
+ [InitBasicFS, Always, TestOutputStruct (
+ [["touch"; "/a"];
+ ["ln"; "/a"; "/b"];
+ ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
+ "create a hard link",
+ "\
+This command creates a hard link using the C<ln> command.");
+
+ ("ln_f", (RErr, [String "target"; String "linkname"]), 165, [],
+ [InitBasicFS, Always, TestOutputStruct (
+ [["touch"; "/a"];
+ ["touch"; "/b"];
+ ["ln_f"; "/a"; "/b"];
+ ["stat"; "/b"]], [CompareWithInt ("nlink", 2)])],
+ "create a hard link",
+ "\
+This command creates a hard link using the C<ln -f> command.
+The C<-f> option removes the link (C<linkname>) if it exists already.");
+
+ ("ln_s", (RErr, [String "target"; String "linkname"]), 166, [],
+ [InitBasicFS, Always, TestOutputStruct (
+ [["touch"; "/a"];
+ ["ln_s"; "a"; "/b"];
+ ["lstat"; "/b"]], [CompareWithInt ("mode", 0o120777)])],
+ "create a symbolic link",
+ "\
+This command creates a symbolic link using the C<ln -s> command.");
+
+ ("ln_sf", (RErr, [String "target"; String "linkname"]), 167, [],
+ [InitBasicFS, Always, TestOutput (
+ [["mkdir_p"; "/a/b"];
+ ["touch"; "/a/b/c"];
+ ["ln_sf"; "../d"; "/a/b/c"];
+ ["readlink"; "/a/b/c"]], "../d")],
+ "create a symbolic link",
+ "\
+This command creates a symbolic link using the C<ln -sf> command,
+The C<-f> option removes the link (C<linkname>) if it exists already.");
+
+ ("readlink", (RString "link", [String "path"]), 168, [],
+ [] (* XXX tested above *),
+ "read the target of a symbolic link",
+ "\
+This command reads the target of a symbolic link.");
+
+ ("fallocate", (RErr, [String "path"; Int "len"]), 169, [],
+ [InitBasicFS, Always, TestOutputStruct (
+ [["fallocate"; "/a"; "1000000"];
+ ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])],
+ "preallocate a file in the guest filesystem",
+ "\
+This command preallocates a file (containing zero bytes) named
+C<path> of size C<len> bytes. If the file exists already, it
+is overwritten.
+
+Do not confuse this with the guestfish-specific
+C<alloc> command which allocates a file in the host and
+attaches it as a device.");
+
+ ("swapon_device", (RErr, [String "device"]), 170, [],
+ [InitNone, Always, TestRun (
+ [["mkswap"; "/dev/sdb"];
+ ["swapon_device"; "/dev/sdb"];
+ ["swapoff_device"; "/dev/sdb"]])],
+ "enable swap on device",
+ "\
+This command enables the libguestfs appliance to use the
+swap device or partition named C<device>. The increased
+memory is made available for all commands, for example
+those run using C<guestfs_command> or C<guestfs_sh>.
+
+Note that you should not swap to existing guest swap
+partitions unless you know what you are doing. They may
+contain hibernation information, or other information that
+the guest doesn't want you to trash. You also risk leaking
+information about the host to the guest this way. Instead,
+attach a new host device to the guest and swap on that.");
+
+ ("swapoff_device", (RErr, [String "device"]), 171, [],
+ [], (* XXX tested by swapon_device *)
+ "disable swap on device",
+ "\
+This command disables the libguestfs appliance swap
+device or partition named C<device>.
+See C<guestfs_swapon_device>.");
+
+ ("swapon_file", (RErr, [String "file"]), 172, [],
+ [InitBasicFS, Always, TestRun (
+ [["fallocate"; "/swap"; "8388608"];
+ ["mkswap_file"; "/swap"];
+ ["swapon_file"; "/swap"];
+ ["swapoff_file"; "/swap"]])],
+ "enable swap on file",
+ "\
+This command enables swap to a file.
+See C<guestfs_swapon_device> for other notes.");
+
+ ("swapoff_file", (RErr, [String "file"]), 173, [],
+ [], (* XXX tested by swapon_file *)
+ "disable swap on file",
+ "\
+This command disables the libguestfs appliance swap on file.");
+
+ ("swapon_label", (RErr, [String "label"]), 174, [],
+ [InitEmpty, Always, TestRun (
+ [["sfdiskM"; "/dev/sdb"; ","];
+ ["mkswap_L"; "swapit"; "/dev/sdb1"];
+ ["swapon_label"; "swapit"];
+ ["swapoff_label"; "swapit"]])],
+ "enable swap on labelled swap partition",
+ "\
+This command enables swap to a labelled swap partition.
+See C<guestfs_swapon_device> for other notes.");
+
+ ("swapoff_label", (RErr, [String "label"]), 175, [],
+ [], (* XXX tested by swapon_label *)
+ "disable swap on labelled swap partition",
+ "\
+This command disables the libguestfs appliance swap on
+labelled swap partition.");
+
+ ("swapon_uuid", (RErr, [String "uuid"]), 176, [],
+ [InitEmpty, Always, TestRun (
+ [["mkswap_U"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"; "/dev/sdb"];
+ ["swapon_uuid"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"];
+ ["swapoff_uuid"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]])],
+ "enable swap on swap partition by UUID",
+ "\
+This command enables swap to a swap partition with the given UUID.
+See C<guestfs_swapon_device> for other notes.");
+
+ ("swapoff_uuid", (RErr, [String "uuid"]), 177, [],
+ [], (* XXX tested by swapon_uuid *)
+ "disable swap on swap partition by UUID",
+ "\
+This command disables the libguestfs appliance swap partition
+with the given UUID.");
+
+ ("mkswap_file", (RErr, [String "path"]), 178, [],
+ [InitBasicFS, Always, TestRun (
+ [["fallocate"; "/swap"; "8388608"];
+ ["mkswap_file"; "/swap"]])],
+ "create a swap file",
+ "\
+Create a swap file.
+
+This command just writes a swap file signature to an existing
+file. To create the file itself, use something like C<guestfs_fallocate>.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
| 1 -> false
| i -> failwithf "%s: failed with error code %d" cmd i
+let rec filter_map f = function
+ | [] -> []
+ | x :: xs ->
+ match f x with
+ | Some y -> y :: filter_map f xs
+ | None -> filter_map f xs
+
let rec find_map f = function
| [] -> raise Not_found
| x :: xs ->
}
*/
-static void no_test_warnings (void)
-{
";
+ (* Generate a list of commands which are not tested anywhere. *)
+ pr "static void no_test_warnings (void)\n";
+ pr "{\n";
+
+ let hash : (string, bool) Hashtbl.t = Hashtbl.create 13 in
List.iter (
- function
- | name, _, _, _, [], _, _ ->
+ fun (_, _, _, _, tests, _, _) ->
+ let tests = filter_map (
+ function
+ | (_, (Always|If _|Unless _), test) -> Some test
+ | (_, Disabled, _) -> None
+ ) tests in
+ let seq = List.concat (List.map seq_of_test tests) in
+ let cmds_tested = List.map List.hd seq in
+ List.iter (fun cmd -> Hashtbl.replace hash cmd true) cmds_tested
+ ) all_functions;
+
+ List.iter (
+ fun (name, _, _, _, _, _, _) ->
+ if not (Hashtbl.mem hash name) then
pr " fprintf (stderr, \"warning: \\\"guestfs_%s\\\" has no tests\\n\");\n" name
- | name, _, _, _, tests, _, _ -> ()
) all_functions;
pr "}\n";
(* list_commands function, which implements guestfish -h *)
pr "void list_commands (void)\n";
pr "{\n";
- pr " printf (\" %%-16s %%s\\n\", \"Command\", \"Description\");\n";
+ pr " printf (\" %%-16s %%s\\n\", _(\"Command\"), _(\"Description\"));\n";
pr " list_builtin_commands ();\n";
List.iter (
fun (name, _, _, flags, _, shortdesc, _) ->
let name = replace_char name '_' '-' in
- pr " printf (\"%%-20s %%s\\n\", \"%s\", \"%s\");\n"
+ pr " printf (\"%%-20s %%s\\n\", \"%s\", _(\"%s\"));\n"
name shortdesc
) all_functions_sorted;
- pr " printf (\" Use -h <cmd> / help <cmd> to show detailed help for a command.\\n\");\n";
+ pr " printf (\" %%s\\n\",";
+ pr " _(\"Use -h <cmd> / help <cmd> to show detailed help for a command.\"));\n";
pr "}\n";
pr "\n";
if name <> alias then
pr " || strcasecmp (cmd, \"%s\") == 0" alias;
pr ")\n";
- pr " pod2text (\"%s - %s\", %S);\n"
+ pr " pod2text (\"%s\", _(\"%s\"), %S);\n"
name2 shortdesc
(" " ^ synopsis ^ "\n\n" ^ longdesc ^ warnings ^ describe_alias);
pr " else\n"
(* Check and convert parameters. *)
let argc_expected = List.length (snd style) in
pr " if (argc != %d) {\n" argc_expected;
- pr " fprintf (stderr, \"%%s should have %d parameter(s)\\n\", cmd);\n"
+ pr " fprintf (stderr, _(\"%%s should have %%d parameter(s)\\n\"), cmd, %d);\n"
argc_expected;
- pr " fprintf (stderr, \"type 'help %%s' for help on %%s\\n\", cmd, cmd);\n";
+ pr " fprintf (stderr, _(\"type 'help %%s' for help on %%s\\n\"), cmd, cmd);\n";
pr " return -1;\n";
pr " }\n";
iteri (
pr " else\n";
) all_functions;
pr " {\n";
- pr " fprintf (stderr, \"%%s: unknown command\\n\", cmd);\n";
+ pr " fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd);\n";
pr " return -1;\n";
pr " }\n";
pr " return 0;\n";