X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=8ebfafbbbcf048684eea03345aeff79a5134b18f;hp=009b9804594685fb51aa3196df39eb277cc303c0;hb=0695593702b8612b500ff0b3bf800e5934f9b56e;hpb=17fa7abbb83024deb639aebf27686848e232e085 diff --git a/src/generator.ml b/src/generator.ml index 009b980..8ebfafb 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -136,8 +136,7 @@ can easily destroy all your data>." * 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 - * (except InitNone). + * 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 @@ -207,6 +206,12 @@ and test_prereq = * 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 (* Some initial scenarios for testing. *) and test_init = @@ -235,6 +240,11 @@ 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 @@ -1065,7 +1075,9 @@ information refer to the L manpage. To create a single partition occupying the whole disk, you would pass C as a single element list, when the single element being -the string C<,> (comma)."); +the string C<,> (comma). + +See also: C, C"); ("write_file", (RErr, [String "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning], [InitBasicFS, Always, TestOutput ( @@ -1180,51 +1192,51 @@ particular that the filename is not prepended to the output (the C<-b> option)."); ("command", (RString "output", [StringList "arguments"]), 50, [ProtocolLimitWarning], - [InitBasicFS, Always, TestOutput ( + [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 1"]], "Result1"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 2"]], "Result2\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 3"]], "\nResult3"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 4"]], "\nResult4\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 5"]], "\nResult5\n\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 6"]], "\n\nResult6\n\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 7"]], ""); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 8"]], "\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 9"]], "\n\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 10"]], "Result10-1\nResult10-2\n"); - InitBasicFS, Always, TestOutput ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutput ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command 11"]], "Result11-1\nResult11-2"); - InitBasicFS, Always, TestLastFail ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestLastFail ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command"; "/test-command"]])], @@ -1259,47 +1271,47 @@ all filesystems that are needed are mounted at the right locations."); ("command_lines", (RStringList "lines", [StringList "arguments"]), 51, [ProtocolLimitWarning], - [InitBasicFS, Always, TestOutputList ( + [InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 1"]], ["Result1"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 2"]], ["Result2"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 3"]], ["";"Result3"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 4"]], ["";"Result4"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 5"]], ["";"Result5";""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 6"]], ["";"";"Result6";""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 7"]], []); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 8"]], [""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 9"]], ["";""]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 10"]], ["Result10-1";"Result10-2"]); - InitBasicFS, Always, TestOutputList ( + InitBasicFS, Unless (env_is_true "SKIP_TEST_COMMAND"), TestOutputList ( [["upload"; "test-command"; "/test-command"]; ["chmod"; "493"; "/test-command"]; ["command_lines"; "/test-command 11"]], ["Result11-1";"Result11-2"])], @@ -1985,6 +1997,131 @@ The returned strings are transcoded to UTF-8."); This runs C on the given C. The result is the human-readable, canonical hex dump of the file."); + ("zerofree", (RErr, [String "device"]), 97, [], + [InitNone, Always, TestOutput ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["mkfs"; "ext3"; "/dev/sda1"]; + ["mount"; "/dev/sda1"; "/"]; + ["write_file"; "/new"; "test file"; "0"]; + ["umount"; "/dev/sda1"]; + ["zerofree"; "/dev/sda1"]; + ["mount"; "/dev/sda1"; "/"]; + ["cat"; "/new"]], "test file")], + "zero unused inodes and disk blocks on ext2/3 filesystem", + "\ +This runs the I program on C. This program +claims to zero unused inodes and disk blocks on an ext2/3 +filesystem, thus making it possible to compress the filesystem +more effectively. + +You should B run this program if the filesystem is +mounted. + +It is possible that using this program can damage the filesystem +or data on the filesystem."); + + ("pvresize", (RErr, [String "device"]), 98, [], + [], + "resize an LVM physical volume", + "\ +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"; + Int "cyls"; Int "heads"; Int "sectors"; + String "line"]), 99, [DangerWillRobinson], + [], + "modify a single partition on a block device", + "\ +This runs L option to modify just the single +partition C (note: C counts from 1). + +For other parameters, see C. You should usually +pass C<0> for the cyls/heads/sectors parameters."); + + ("sfdisk_l", (RString "partitions", [String "device"]), 100, [], + [], + "display the partition table", + "\ +This displays the partition table on C, in the +human-readable output of the L command. It is +not intended to be parsed."); + + ("sfdisk_kernel_geometry", (RString "partitions", [String "device"]), 101, [], + [], + "display the kernel geometry", + "\ +This displays the kernel's idea of the geometry of C. + +The result is in human-readable format, and not designed to +be parsed."); + + ("sfdisk_disk_geometry", (RString "partitions", [String "device"]), 102, [], + [], + "display the disk geometry from the partition table", + "\ +This displays the disk geometry of C read from the +partition table. Especially in the case where the underlying +block device has been resized, this can be different from the +kernel's idea of the geometry (see C). + +The result is in human-readable format, and not designed to +be parsed."); + + ("vg_activate_all", (RErr, [Bool "activate"]), 103, [], + [], + "activate or deactivate all volume groups", + "\ +This command activates or (if C is false) deactivates +all logical volumes in all volume groups. +If activated, then they are made known to the +kernel, ie. they appear as C devices. If deactivated, +then those devices disappear. + +This command is the same as running C"); + + ("vg_activate", (RErr, [Bool "activate"; StringList "volgroups"]), 104, [], + [], + "activate or deactivate some volume groups", + "\ +This command activates or (if C is false) deactivates +all logical volumes in the listed volume groups C. +If activated, then they are made known to the +kernel, ie. they appear as C devices. If deactivated, +then those devices disappear. + +This command is the same as running C + +Note that if C is an empty list then B volume groups +are activated or deactivated."); + + ("lvresize", (RErr, [String "device"; Int "mbytes"]), 105, [], + [InitNone, Always, TestOutput ( + [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; + ["lvcreate"; "LV"; "VG"; "10"]; + ["mkfs"; "ext2"; "/dev/VG/LV"]; + ["mount"; "/dev/VG/LV"; "/"]; + ["write_file"; "/new"; "test content"; "0"]; + ["umount"; "/"]; + ["lvresize"; "/dev/VG/LV"; "20"]; + ["resize2fs"; "/dev/VG/LV"]; + ["mount"; "/dev/VG/LV"; "/"]; + ["cat"; "/new"]], "test content")], + "resize an LVM logical volume", + "\ +This resizes (expands or shrinks) an existing LVM logical +volume to C. When reducing, data in the reduced part +is lost."); + + ("resize2fs", (RErr, [String "device"]), 106, [], + [], (* lvresize tests this *) + "resize an ext2/ext3 filesystem", + "\ +This resizes an ext2 or ext3 filesystem to match the size of +the underlying device."); + ] let all_functions = non_daemon_functions @ daemon_functions @@ -2233,8 +2370,10 @@ let check_functions () = fun (name, _, _, _, _, _, _) -> if String.length name >= 7 && String.sub name 0 7 = "guestfs" then failwithf "function name %s does not need 'guestfs' prefix" name; - if contains_uppercase name then - failwithf "function name %s should not contain uppercase chars" name; + if name = "" then + failwithf "function name is empty"; + if name.[0] < 'a' || name.[0] > 'z' then + failwithf "function name %s must start with lowercase a-z" name; if String.contains name '-' then failwithf "function name %s should not contain '-', use '_' instead." name @@ -3666,12 +3805,32 @@ int main (int argc, char *argv[]) and generate_one_test name i (init, prereq, test) = let test_name = sprintf "test_%s_%d" name i in + (match prereq with + | Disabled | Always -> () + | If code | Unless code -> + pr "static int %s_prereq (void)\n" test_name; + pr "{\n"; + pr " %s\n" code; + pr "}\n"; + pr "\n"; + ); + pr "static int %s (void)\n" test_name; pr "{\n"; (match prereq with | Disabled -> - pr " printf (\"%%s skipped (test disabled in generator)\\n\", \"%s\");\n" test_name + pr " printf (\"%%s skipped (reason: test disabled in generator)\\n\", \"%s\");\n" test_name + | If _ -> + pr " if (%s_prereq ()) {\n" test_name; + generate_one_test_body name i test_name init test; + pr " } else\n"; + pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name + | Unless _ -> + pr " if (! %s_prereq ()) {\n" test_name; + generate_one_test_body name i test_name init test; + pr " } else\n"; + pr " printf (\"%%s skipped (reason: test prerequisite)\\n\", \"%s\");\n" test_name | Always -> generate_one_test_body name i test_name init test ); @@ -3683,15 +3842,15 @@ and generate_one_test name i (init, prereq, test) = and generate_one_test_body name i test_name init test = (match init with - | InitNone -> () + | InitNone | InitEmpty -> - pr " /* InitEmpty for %s (%d) */\n" name i; + pr " /* InitNone|InitEmpty for %s */\n" test_name; List.iter (generate_test_command_call test_name) [["blockdev_setrw"; "/dev/sda"]; ["umount_all"]; ["lvm_remove_all"]] | InitBasicFS -> - pr " /* InitBasicFS for %s (%d): create ext2 on /dev/sda1 */\n" name i; + pr " /* InitBasicFS for %s: create ext2 on /dev/sda1 */\n" test_name; List.iter (generate_test_command_call test_name) [["blockdev_setrw"; "/dev/sda"]; ["umount_all"]; @@ -3700,8 +3859,8 @@ and generate_one_test_body name i test_name init test = ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]] | InitBasicFSonLVM -> - pr " /* InitBasicFSonLVM for %s (%d): create ext2 on /dev/VG/LV */\n" - name i; + pr " /* InitBasicFSonLVM for %s: create ext2 on /dev/VG/LV */\n" + test_name; List.iter (generate_test_command_call test_name) [["blockdev_setrw"; "/dev/sda"]; ["umount_all"];