X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=960973da0071709623e88cf8574d063e46dc02f0;hp=01a230954a66dbba50c5fc57fd488d87c751d045;hb=f850e1f065fb04df7cc87a921ab3c658741cc393;hpb=d1df2f342489bbbba086cae2bb95971c8e404cad diff --git a/src/generator.ml b/src/generator.ml index 01a2309..960973d 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -116,6 +116,7 @@ type flags = | FishAlias of string (* provide an alias for this cmd in guestfish *) | FishAction of string (* call this function in guestfish *) | NotInFish (* do not export via guestfish *) + | NotInDocs (* do not add this function to documentation *) let protocol_limit_warning = "Because of the message protocol, there is a transfer limit @@ -129,22 +130,19 @@ can easily destroy all your data>." (* You can supply zero or as many tests as you want per API call. * * Note that the test environment has 3 block devices, of size 500MB, - * 50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc). + * 50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc), and + * a fourth squashfs block device with some known files on it (/dev/sdd). + * * Note for partitioning purposes, the 500MB device has 63 cylinders. * + * The squashfs block device (/dev/sdd) comes from images/test.sqsh. + * * To be able to run the tests in a reasonable amount of time, * the virtual machine and block devices are reused between tests. * So don't try testing kill_subprocess :-x * * Between each test we blockdev-setrw, umount-all, lvm-remove-all. * - * If the appliance is running an older Linux kernel (eg. RHEL 5) then - * devices are named /dev/hda etc. To cope with this, the test suite - * adds some hairly logic to detect this case, and then automagically - * replaces all strings which match "/dev/sd.*" with "/dev/hd.*". - * When writing test cases you shouldn't have to worry about this - * difference. - * * Don't assume anything about the previous contents of the block * devices. Use 'Init*' to create some initial scenarios. * @@ -153,6 +151,11 @@ can easily destroy all your data>." * skipped. Useful if testing a command which might not work on * all variations of libguestfs builds. A test that has prerequisite * of 'Always' is run unconditionally. + * + * In addition, packagers can skip individual tests by setting the + * environment variables: eg: + * SKIP_TEST__=1 SKIP_TEST_COMMAND_3=1 (skips test #3 of command) + * SKIP_TEST_=1 SKIP_TEST_ZEROFREE=1 (skips all zerofree tests) *) type tests = (test_init * test_prereq * test) list and test = @@ -167,6 +170,12 @@ and test = *) | 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 @@ -240,11 +249,6 @@ and test_init = and seq = cmd list and cmd = string list -(* Canned test prerequisites. *) -let env_is_true env = - sprintf "const char *str = getenv (\"%s\"); - return str && strcmp (str, \"1\") == 0;" env - (* Note about long descriptions: When referring to another * action, use the format C (ie. the full name of * the C function). This will be replaced as appropriate in other @@ -253,7 +257,81 @@ let env_is_true env = * Apart from that, long descriptions are just perldoc paragraphs. *) -let non_daemon_functions = [ +(* These test functions are used in the language binding tests. *) + +let test_all_args = [ + String "str"; + OptString "optstr"; + StringList "strlist"; + Bool "b"; + Int "integer"; + FileIn "filein"; + FileOut "fileout"; +] + +let test_all_rets = [ + (* except for RErr, which is tested thoroughly elsewhere *) + "test0rint", RInt "valout"; + "test0rint64", RInt64 "valout"; + "test0rbool", RBool "valout"; + "test0rconststring", RConstString "valout"; + "test0rstring", RString "valout"; + "test0rstringlist", RStringList "valout"; + "test0rintbool", RIntBool ("valout", "valout"); + "test0rpvlist", RPVList "valout"; + "test0rvglist", RVGList "valout"; + "test0rlvlist", RLVList "valout"; + "test0rstat", RStat "valout"; + "test0rstatvfs", RStatVFS "valout"; + "test0rhashtable", RHashtable "valout"; +] + +let test_functions = [ + ("test0", (RErr, test_all_args), -1, [NotInFish; NotInDocs], + [], + "internal test function - do not use", + "\ +This is an internal test function which is used to test whether +the automatically generated bindings can handle every possible +parameter type correctly. + +It echos the contents of each parameter to stdout. + +You probably don't want to call this function."); +] @ List.flatten ( + List.map ( + fun (name, ret) -> + [(name, (ret, [String "val"]), -1, [NotInFish; NotInDocs], + [], + "internal test function - do not use", + "\ +This is an internal test function which is used to test whether +the automatically generated bindings can handle every possible +return type correctly. + +It converts string C to the return type. + +You probably don't want to call this function."); + (name ^ "err", (ret, []), -1, [NotInFish; NotInDocs], + [], + "internal test function - do not use", + "\ +This is an internal test function which is used to test whether +the automatically generated bindings can handle every possible +return type correctly. + +This function always returns an error. + +You probably don't want to call this function.")] + ) test_all_rets +) + +(* non_daemon_functions are any functions which don't get processed + * in the daemon, eg. functions for setting and getting local + * configuration values. + *) + +let non_daemon_functions = test_functions @ [ ("launch", (RErr, []), -1, [FishAlias "run"; FishAction "launch"], [], "launch the qemu subprocess", @@ -295,7 +373,12 @@ for whatever operations you want to perform (ie. read access if you just want to read the image or write access if you want to modify the image). -This is equivalent to the qemu parameter C<-drive file=filename>."); +This is equivalent to the qemu parameter C<-drive file=filename,cache=off>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead."); ("add_cdrom", (RErr, [String "filename"]), -1, [FishAlias "cdrom"], [], @@ -303,7 +386,33 @@ This is equivalent to the qemu parameter C<-drive file=filename>."); "\ This function adds a virtual CD-ROM disk image to the guest. -This is equivalent to the qemu parameter C<-cdrom filename>."); +This is equivalent to the qemu parameter C<-cdrom filename>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead."); + + ("add_drive_ro", (RErr, [String "filename"]), -1, [FishAlias "add-ro"], + [], + "add a drive in snapshot mode (read-only)", + "\ +This adds a drive in snapshot mode, making it effectively +read-only. + +Note that writes to the device are allowed, and will be seen for +the duration of the guestfs handle, but they are written +to a temporary file which is discarded as soon as the guestfs +handle is closed. We don't currently have any method to enable +changes to be committed, although qemu can support this. + +This is equivalent to the qemu parameter +C<-drive file=filename,snapshot=on>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C call instead."); ("config", (RErr, [String "qemuparam"; OptString "qemuvalue"]), -1, [], [], @@ -489,8 +598,41 @@ actions using the low-level API. For more information on states, see L."); + ("set_memsize", (RErr, [Int "memsize"]), -1, [FishAlias "memsize"], + [], + "set memory allocated to the qemu subprocess", + "\ +This sets the memory size in megabytes allocated to the +qemu subprocess. This only has any effect if called before +C. + +You can also change this by setting the environment +variable C before the handle is +created. + +For more information on the architecture of libguestfs, +see L."); + + ("get_memsize", (RInt "memsize", []), -1, [], + [], + "get memory allocated to the qemu subprocess", + "\ +This gets the memory size in megabytes allocated to the +qemu subprocess. + +If C was not called +on this handle, and if C was not set, +then this returns the compiled-in default value for memsize. + +For more information on the architecture of libguestfs, +see L."); + ] +(* daemon_functions are any functions which cause some action + * to take place in the daemon. + *) + let daemon_functions = [ ("mount", (RErr, [String "device"; String "mountpoint"]), 1, [], [InitEmpty, Always, TestOutput ( @@ -579,8 +721,8 @@ This command is mostly useful for interactive sessions. Programs should probably use C instead."); ("list_devices", (RStringList "devices", []), 7, [], - [InitEmpty, Always, TestOutputList ( - [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"])], + [InitEmpty, Always, TestOutputListOfDevices ( + [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])], "list the block devices", "\ List all the block devices. @@ -588,9 +730,9 @@ List all the block devices. The full block device names are returned, eg. C"); ("list_partitions", (RStringList "partitions", []), 8, [], - [InitBasicFS, Always, TestOutputList ( + [InitBasicFS, Always, TestOutputListOfDevices ( [["list_partitions"]], ["/dev/sda1"]); - InitEmpty, Always, TestOutputList ( + InitEmpty, Always, TestOutputListOfDevices ( [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",10 ,20 ,"]; ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])], "list the partitions", @@ -603,9 +745,9 @@ This does not return logical volumes. For that you will need to call C."); ("pvs", (RStringList "physvols", []), 9, [], - [InitBasicFSonLVM, Always, TestOutputList ( + [InitBasicFSonLVM, Always, TestOutputListOfDevices ( [["pvs"]], ["/dev/sda1"]); - InitEmpty, Always, TestOutputList ( + InitEmpty, Always, TestOutputListOfDevices ( [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",10 ,20 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; @@ -923,7 +1065,14 @@ Create a directory named C."); ["is_dir"; "/new/foo"]]; InitBasicFS, Always, TestOutputTrue [["mkdir_p"; "/new/foo/bar"]; - ["is_dir"; "/new"]]], + ["is_dir"; "/new"]]; + (* Regression tests for RHBZ#503133: *) + InitBasicFS, Always, TestRun + [["mkdir"; "/new"]; + ["mkdir_p"; "/new"]]; + InitBasicFS, Always, TestLastFail + [["touch"; "/new"]; + ["mkdir_p"; "/new"]]], "create a directory and parents", "\ Create a directory named C, creating any parent directories @@ -991,7 +1140,7 @@ other objects like files. See also C."); ("pvcreate", (RErr, [String "device"]), 39, [], - [InitEmpty, Always, TestOutputList ( + [InitEmpty, Always, TestOutputListOfDevices ( [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",10 ,20 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; @@ -1114,7 +1263,7 @@ We hope to resolve this bug in a future version. In the meantime use C."); ("umount", (RErr, [String "pathordevice"]), 45, [FishAlias "unmount"], - [InitEmpty, Always, TestOutputList ( + [InitEmpty, Always, TestOutputListOfDevices ( [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; @@ -1132,7 +1281,7 @@ specified either by its mountpoint (path) or the device which contains the filesystem."); ("mounts", (RStringList "devices", []), 46, [], - [InitBasicFS, Always, TestOutputList ( + [InitBasicFS, Always, TestOutputListOfDevices ( [["mounts"]], ["/dev/sda1"])], "show mounted filesystems", "\ @@ -1192,53 +1341,53 @@ particular that the filename is not prepended to the output (the C<-b> option)."); ("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning], - [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + [InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 1"]], "Result1"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 2"]], "Result2\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 3"]], "\nResult3"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 4"]], "\nResult4\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 5"]], "\nResult5\n\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 6"]], "\n\nResult6\n\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 7"]], ""); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 8"]], "\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 9"]], "\n\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( + InitBasicFS, Always, TestOutput ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command 11"]], "Result11-1\nResult11-2"); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestLastFail ( + InitBasicFS, Always, TestLastFail ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command"; "/test-command"]])], "run a command from the guest filesystem", "\ @@ -1250,7 +1399,9 @@ or compatible processor architecture). The single parameter is an argv-style list of arguments. The first element is the name of the program to run. Subsequent elements are parameters. The list must be -non-empty (ie. must contain a program name). +non-empty (ie. must contain a program name). Note that +the command runs directly, and is I invoked via +the shell (see C). The return value is anything printed to I by the command. @@ -1271,54 +1422,56 @@ all filesystems that are needed are mounted at the right locations."); ("command_lines", (RStringList "lines", [StringList "arguments"]), 51, [ProtocolLimitWarning], - [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + [InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 1"]], ["Result1"]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 2"]], ["Result2"]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 3"]], ["";"Result3"]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 4"]], ["";"Result4"]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 5"]], ["";"Result5";""]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 7"]], []); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 8"]], [""]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 9"]], ["";""]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]); - InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( + InitBasicFS, Always, TestOutputList ( [["upload"; "test-command"; "/test-command"]; - ["chmod"; "493"; "/test-command"]; + ["chmod"; "0o755"; "/test-command"]; ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])], "run a command, returning lines", "\ This is the same as C, but splits the -result into a list of lines."); +result into a list of lines. + +See also: C"); ("stat", (RStat "statbuf", [String "path"]), 52, [], [InitBasicFS, Always, TestOutputStruct ( @@ -1483,7 +1636,7 @@ This uses the L command."); ("upload", (RErr, [FileIn "filename"; String "remotefilename"]), 66, [], [InitBasicFS, Always, TestOutput ( (* Pick a file from cwd which isn't likely to change. *) - [["upload"; "COPYING.LIB"; "/COPYING.LIB"]; + [["upload"; "../COPYING.LIB"; "/COPYING.LIB"]; ["checksum"; "md5"; "/COPYING.LIB"]], "e3eda01d9815f8d24aae2dbd89b68b06")], "upload a file from the local machine", "\ @@ -1497,7 +1650,7 @@ See also C."); ("download", (RErr, [String "remotefilename"; FileOut "filename"]), 67, [], [InitBasicFS, Always, TestOutput ( (* Pick a file from cwd which isn't likely to change. *) - [["upload"; "COPYING.LIB"; "/COPYING.LIB"]; + [["upload"; "../COPYING.LIB"; "/COPYING.LIB"]; ["download"; "/COPYING.LIB"; "testdownload.tmp"]; ["upload"; "testdownload.tmp"; "/upload"]; ["checksum"; "md5"; "/upload"]], "e3eda01d9815f8d24aae2dbd89b68b06")], @@ -1533,7 +1686,13 @@ See also C, C."); ["checksum"; "sha384"; "/new"]], "109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d"); InitBasicFS, Always, TestOutput ( [["write_file"; "/new"; "test\n"; "0"]; - ["checksum"; "sha512"; "/new"]], "0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123")], + ["checksum"; "sha512"; "/new"]], "0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123"); + InitBasicFS, Always, TestOutput ( + (* RHEL 5 thinks this is an HFS+ filesystem unless we give + * the type explicitly. + *) + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c")], "compute MD5, SHAx or CRC checksum of file", "\ This call computes the MD5, SHAx or CRC checksum of the @@ -1579,7 +1738,7 @@ The checksum is returned as a printable string."); ("tar_in", (RErr, [FileIn "tarfile"; String "directory"]), 69, [], [InitBasicFS, Always, TestOutput ( - [["tar_in"; "images/helloworld.tar"; "/"]; + [["tar_in"; "../images/helloworld.tar"; "/"]; ["cat"; "/hello"]], "hello\n")], "unpack tarfile to directory", "\ @@ -1599,7 +1758,7 @@ To download a compressed tarball, use C."); ("tgz_in", (RErr, [FileIn "tarball"; String "directory"]), 71, [], [InitBasicFS, Always, TestOutput ( - [["tgz_in"; "images/helloworld.tar.gz"; "/"]; + [["tgz_in"; "../images/helloworld.tar.gz"; "/"]; ["cat"; "/hello"]], "hello\n")], "unpack compressed tarball to directory", "\ @@ -1662,22 +1821,25 @@ to find out what you can do."); ("lvremove", (RErr, [String "device"]), 77, [], [InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["lvremove"; "/dev/VG/LV1"]; ["lvs"]], ["/dev/VG/LV2"]); InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["lvremove"; "/dev/VG"]; ["lvs"]], []); InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["lvremove"; "/dev/VG"]; @@ -1692,15 +1854,17 @@ the VG name, C."); ("vgremove", (RErr, [String "vgname"]), 78, [], [InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["vgremove"; "VG"]; ["lvs"]], []); InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["vgremove"; "VG"]; @@ -1713,29 +1877,32 @@ This also forcibly removes all logical volumes in the volume group (if any)."); ("pvremove", (RErr, [String "device"]), 79, [], - [InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + [InitEmpty, Always, TestOutputListOfDevices ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["vgremove"; "VG"]; - ["pvremove"; "/dev/sda"]; + ["pvremove"; "/dev/sda1"]; ["lvs"]], []); - InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + InitEmpty, Always, TestOutputListOfDevices ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["vgremove"; "VG"]; - ["pvremove"; "/dev/sda"]; + ["pvremove"; "/dev/sda1"]; ["vgs"]], []); - InitEmpty, Always, TestOutputList ( - [["pvcreate"; "/dev/sda"]; - ["vgcreate"; "VG"; "/dev/sda"]; + InitEmpty, Always, TestOutputListOfDevices ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; ["lvcreate"; "LV2"; "VG"; "50"]; ["vgremove"; "VG"]; - ["pvremove"; "/dev/sda"]; + ["pvremove"; "/dev/sda1"]; ["pvs"]], [])], "remove an LVM physical volume", "\ @@ -1844,7 +2011,9 @@ This command writes zeroes over the first few blocks of C. How many blocks are zeroed isn't specified (but it's I enough to securely wipe the device). It should be sufficient to remove -any partition tables, filesystem superblocks and so on."); +any partition tables, filesystem superblocks and so on. + +See also: C."); ("grub_install", (RErr, [String "root"; String "device"]), 86, [], [InitBasicFS, Always, TestOutputTrue ( @@ -1991,7 +2160,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 @@ -2027,7 +2202,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], [], @@ -2106,6 +2281,7 @@ are activated or deactivated."); ["write_file"; "/new"; "test content"; "0"]; ["umount"; "/"]; ["lvresize"; "/dev/VG/LV"; "20"]; + ["e2fsck_f"; "/dev/VG/LV"]; ["resize2fs"; "/dev/VG/LV"]; ["mount"; "/dev/VG/LV"; "/"]; ["cat"; "/new"]], "test content")], @@ -2120,7 +2296,13 @@ is lost."); "resize an ext2/ext3 filesystem", "\ This resizes an ext2 or ext3 filesystem to match the size of -the underlying device."); +the underlying device. + +I It is sometimes required that you run C +on the C before calling this command. For unknown reasons +C sometimes gives an error about this and sometimes not. +In any case, it is always safe to call C before +calling this function."); ("find", (RStringList "names", [String "directory"]), 107, [], [InitBasicFS, Always, TestOutputList ( @@ -2161,6 +2343,409 @@ an error. The returned list is sorted."); + ("e2fsck_f", (RErr, [String "device"]), 108, [], + [], (* lvresize tests this *) + "check an ext2/ext3 filesystem", + "\ +This runs C, ie. runs the ext2/ext3 +filesystem checker on C, noninteractively (C<-p>), +even if the filesystem appears to be clean (C<-f>). + +This command is only needed because of C +(q.v.). Normally you should use C."); + + ("sleep", (RErr, [Int "secs"]), 109, [], + [InitNone, Always, TestRun ( + [["sleep"; "1"]])], + "sleep for some seconds", + "\ +Sleep for C seconds."); + + ("ntfs_3g_probe", (RInt "status", [Bool "rw"; String "device"]), 110, [], + [InitNone, Always, TestOutputInt ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["mkfs"; "ntfs"; "/dev/sda1"]; + ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0); + InitNone, Always, TestOutputInt ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["mkfs"; "ext2"; "/dev/sda1"]; + ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)], + "probe NTFS volume", + "\ +This command runs the L command which probes +an NTFS C for mountability. (Not all NTFS volumes can +be mounted read-write, and some cannot be mounted at all). + +C is a boolean flag. Set it to true if you want to test +if the volume can be mounted read-write. Set it to false if +you want to test if the volume can be mounted read-only. + +The return value is an integer which C<0> if the operation +would succeed, or some non-zero value documented in the +L manual page."); + + ("sh", (RString "output", [String "command"]), 111, [], + [], (* XXX needs tests *) + "run a command via the shell", + "\ +This call runs a command from the guest filesystem via the +guest's C. + +This is like C, but passes the command to: + + /bin/sh -c \"command\" + +Depending on the guest's shell, this usually results in +wildcards being expanded, shell expressions being interpolated +and so on. + +All the provisos about C apply to this call."); + + ("sh_lines", (RStringList "lines", [String "command"]), 112, [], + [], (* XXX needs tests *) + "run a command via the shell returning lines", + "\ +This is the same as C, but splits the result +into a list of lines. + +See also: C"); + + ("glob_expand", (RStringList "paths", [String "pattern"]), 113, [], + [InitBasicFS, Always, TestOutputList ( + [["mkdir_p"; "/a/b/c"]; + ["touch"; "/a/b/c/d"]; + ["touch"; "/a/b/c/e"]; + ["glob_expand"; "/a/b/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]); + InitBasicFS, Always, TestOutputList ( + [["mkdir_p"; "/a/b/c"]; + ["touch"; "/a/b/c/d"]; + ["touch"; "/a/b/c/e"]; + ["glob_expand"; "/a/*/c/*"]], ["/a/b/c/d"; "/a/b/c/e"]); + InitBasicFS, Always, TestOutputList ( + [["mkdir_p"; "/a/b/c"]; + ["touch"; "/a/b/c/d"]; + ["touch"; "/a/b/c/e"]; + ["glob_expand"; "/a/*/x/*"]], [])], + "expand a wildcard path", + "\ +This command searches for all the pathnames matching +C according to the wildcard expansion rules +used by the shell. + +If no paths match, then this returns an empty list +(note: not an error). + +It is just a wrapper around the C L function +with flags C. +See that manual page for more details."); + + ("scrub_device", (RErr, [String "device"]), 114, [DangerWillRobinson], + [InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *) + [["scrub_device"; "/dev/sdc"]])], + "scrub (securely wipe) a device", + "\ +This command writes patterns over C to make data retrieval +more difficult. + +It is an interface to the L program. See that +manual page for more details."); + + ("scrub_file", (RErr, [String "file"]), 115, [], + [InitBasicFS, Always, TestRun ( + [["write_file"; "/file"; "content"; "0"]; + ["scrub_file"; "/file"]])], + "scrub (securely wipe) a file", + "\ +This command writes patterns over a file to make data retrieval +more difficult. + +The file is I after scrubbing. + +It is an interface to the L program. See that +manual page for more details."); + + ("scrub_freespace", (RErr, [String "dir"]), 116, [], + [], (* XXX needs testing *) + "scrub (securely wipe) free space", + "\ +This command creates the directory C and then fills it +with files until the filesystem is full, and scrubs the files +as for C, and deletes them. +The intention is to scrub any free space on the partition +containing C. + +It is an interface to the L program. See that +manual page for more details."); + + ("mkdtemp", (RString "dir", [String "template"]), 117, [], + [InitBasicFS, Always, TestRun ( + [["mkdir"; "/tmp"]; + ["mkdtemp"; "/tmp/tmpXXXXXX"]])], + "create a temporary directory", + "\ +This command creates a temporary directory. The +C