X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=5885ff3f91f7f2924ed2f73814e25316b1217455;hp=9c0632ef7b7c8f17c63213021a7566a748efd783;hb=9a92446bcad09b492dee42dd5950bac67073fbea;hpb=ef2b0cf761b6281a6a728aacb6ac0ec91fad33c8 diff --git a/src/generator.ml b/src/generator.ml index 9c0632e..5885ff3 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2131,7 +2131,13 @@ The returned strings are transcoded to UTF-8."); ("hexdump", (RString "dump", [String "path"]), 96, [ProtocolLimitWarning], [InitBasicFS, Always, TestOutput ( [["write_file"; "/new"; "hello\nworld\n"; "12"]; - ["hexdump"; "/new"]], "00000000 68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a |hello.world.|\n0000000c\n")], + ["hexdump"; "/new"]], "00000000 68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a |hello.world.|\n0000000c\n"); + (* Test for RHBZ#501888c2 regression which caused large hexdump + * commands to segfault. + *) + InitBasicFS, Always, TestRun ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["hexdump"; "/100krandom"]])], "dump a file in hexadecimal", "\ This runs C on the given C. The result is @@ -2167,7 +2173,7 @@ or data on the filesystem."); This resizes (expands or shrinks) an existing LVM physical volume to match the new size of the underlying device."); - ("sfdisk_N", (RErr, [String "device"; Int "n"; + ("sfdisk_N", (RErr, [String "device"; Int "partnum"; Int "cyls"; Int "heads"; Int "sectors"; String "line"]), 99, [DangerWillRobinson], [], @@ -2467,6 +2473,132 @@ directory and its contents after use. See also: L"); + ("wc_l", (RInt "lines", [String "path"]), 118, [], + [InitBasicFS, Always, TestOutputInt ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["wc_l"; "/10klines"]], 10000)], + "count lines in a file", + "\ +This command counts the lines in a file, using the +C external command."); + + ("wc_w", (RInt "words", [String "path"]), 119, [], + [InitBasicFS, Always, TestOutputInt ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["wc_w"; "/10klines"]], 10000)], + "count words in a file", + "\ +This command counts the words in a file, using the +C external command."); + + ("wc_c", (RInt "chars", [String "path"]), 120, [], + [InitBasicFS, Always, TestOutputInt ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["wc_c"; "/100kallspaces"]], 102400)], + "count characters in a file", + "\ +This command counts the characters in a file, using the +C external command."); + + ("head", (RStringList "lines", [String "path"]), 121, [ProtocolLimitWarning], + [InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])], + "return first 10 lines of a file", + "\ +This command returns up to the first 10 lines of a file as +a list of strings."); + + ("head_n", (RStringList "lines", [Int "nrlines"; String "path"]), 122, [ProtocolLimitWarning], + [InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]); + InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["head_n"; "-9997"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]); + InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["head_n"; "0"; "/10klines"]], [])], + "return first N lines of a file", + "\ +If the parameter C is a positive number, this returns the first +C lines of the file C. + +If the parameter C is a negative number, this returns lines +from the file C, excluding the last C lines. + +If the parameter C is zero, this returns an empty list."); + + ("tail", (RStringList "lines", [String "path"]), 123, [ProtocolLimitWarning], + [InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])], + "return last 10 lines of a file", + "\ +This command returns up to the last 10 lines of a file as +a list of strings."); + + ("tail_n", (RStringList "lines", [Int "nrlines"; String "path"]), 124, [ProtocolLimitWarning], + [InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]); + InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["tail_n"; "-9998"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]); + InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["tail_n"; "0"; "/10klines"]], [])], + "return last N lines of a file", + "\ +If the parameter C is a positive number, this returns the last +C lines of the file C. + +If the parameter C is a negative number, this returns lines +from the file C, starting with the C<-nrlines>th line. + +If the parameter C is zero, this returns an empty list."); + + ("df", (RString "output", []), 125, [], + [], (* XXX Tricky to test because it depends on the exact format + * of the 'df' command and other imponderables. + *) + "report file system disk space usage", + "\ +This command runs the C command to report disk space used. + +This command is mostly useful for interactive sessions. It +is I intended that you try to parse the output string. +Use C from programs."); + + ("df_h", (RString "output", []), 126, [], + [], (* XXX Tricky to test because it depends on the exact format + * of the 'df' command and other imponderables. + *) + "report file system disk space usage (human readable)", + "\ +This command runs the C command to report disk space used +in human-readable format. + +This command is mostly useful for interactive sessions. It +is I intended that you try to parse the output string. +Use C from programs."); + + ("du", (RInt64 "sizekb", [String "path"]), 127, [], + [InitBasicFS, Always, TestOutputInt ( + [["mkdir"; "/p"]; + ["du"; "/p"]], 1 (* ie. 1 block, so depends on ext3 blocksize *))], + "estimate file space usage", + "\ +This command runs the C command to estimate file space +usage for C. + +C can be a file or a directory. If C is a directory +then the estimate includes the contents of the directory and all +subdirectories (recursively). + +The result is the estimated size in I +(ie. units of 1024 bytes)."); + ] let all_functions = non_daemon_functions @ daemon_functions @@ -2747,8 +2879,8 @@ let check_functions () = failwithf "%s has a param/ret called 'value', which causes conflicts in the OCaml bindings, use something like 'val' or a more descriptive name" name; if n = "int" || n = "char" || n = "short" || n = "long" then failwithf "%s has a param/ret which conflicts with a C type (eg. 'int', 'char' etc.)" name; - if n = "i" then - failwithf "%s has a param/ret called 'i', which will cause some conflicts in the generated code" name; + if n = "i" || n = "n" then + failwithf "%s has a param/ret called 'i' or 'n', which will cause some conflicts in the generated code" name; if n = "argv" || n = "args" then failwithf "%s has a param/ret called 'argv' or 'args', which will cause some conflicts in the generated code" name in @@ -4154,6 +4286,9 @@ static int %s_skip (void) { const char *str; + str = getenv (\"TEST_ONLY\"); + if (str) + return strstr (str, \"%s\") == NULL; str = getenv (\"SKIP_%s\"); if (str && strcmp (str, \"1\") == 0) return 1; str = getenv (\"SKIP_TEST_%s\"); @@ -4161,7 +4296,7 @@ static int %s_skip (void) return 0; } -" test_name (String.uppercase test_name) (String.uppercase name); +" test_name name (String.uppercase test_name) (String.uppercase name); (match prereq with | Disabled | Always -> () @@ -4177,7 +4312,7 @@ static int %s_skip (void) static int %s (void) { if (%s_skip ()) { - printf (\"%%s skipped (reason: SKIP_TEST_* variable set)\\n\", \"%s\"); + printf (\"%%s skipped (reason: environment variable set)\\n\", \"%s\"); return 0; } @@ -7806,7 +7941,38 @@ public class Bindtests { " and generate_haskell_bindtests () = - () (* XXX Haskell bindings need to be fleshed out. *) + generate_header HaskellStyle GPLv2; + + pr "\ +module Bindtests where +import qualified Guestfs + +main = do + g <- Guestfs.create +"; + + let mkargs args = + String.concat " " ( + List.map ( + function + | CallString s -> "\"" ^ s ^ "\"" + | CallOptString None -> "Nothing" + | CallOptString (Some s) -> sprintf "(Just \"%s\")" s + | CallStringList xs -> + "[" ^ String.concat "," (List.map (sprintf "\"%s\"") xs) ^ "]" + | CallInt i when i < 0 -> "(" ^ string_of_int i ^ ")" + | CallInt i -> string_of_int i + | CallBool true -> "True" + | CallBool false -> "False" + ) args + ) + in + + generate_lang_bindtests ( + fun f args -> pr " Guestfs.%s g %s\n" f (mkargs args) + ); + + pr " putStrLn \"EOF\"\n" (* Language-independent bindings tests - we do it this way to * ensure there is parity in testing bindings across all languages. @@ -8036,7 +8202,7 @@ Run it from the top source directory using the command generate_haskell_hs (); close (); - let close = output_to "haskell/bindtests.hs" in + let close = output_to "haskell/Bindtests.hs" in generate_haskell_bindtests (); close ();