X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=ec6123aacf7981022faf85fcb758f0b69cf149c2;hp=efc8bfd85d242f55cd0285afb23996a2c4b10420;hb=4d5c22800214008b229e937dada2299de8353d9e;hpb=1020b212b189968ead013436cac79019fbd8fdad diff --git a/src/generator.ml b/src/generator.ml index efc8bfd..ec6123a 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -309,6 +309,9 @@ and test_prereq = (* As for 'If' but the test runs _unless_ the code returns true. *) | Unless of string + (* Run the test only if 'string' is available in the daemon. *) + | IfAvailable of string + (* Some initial scenarios for testing. *) and test_init = (* Do nothing, block devices could contain random stuff including @@ -2320,16 +2323,30 @@ any partition tables, filesystem superblocks and so on. See also: C, C."); ("grub_install", (RErr, [Pathname "root"; Device "device"]), 86, [], - (* Test disabled because grub-install incompatible with virtio-blk driver. - * See also: https://bugzilla.redhat.com/show_bug.cgi?id=479760 + (* See: + * https://bugzilla.redhat.com/show_bug.cgi?id=484986 + * https://bugzilla.redhat.com/show_bug.cgi?id=479760 *) - [InitBasicFS, Disabled, TestOutputTrue ( - [["grub_install"; "/"; "/dev/sda1"]; + [InitBasicFS, Always, TestOutputTrue ( + [["mkdir_p"; "/boot/grub"]; + ["write"; "/boot/grub/device.map"; "(hd0) /dev/vda"]; + ["grub_install"; "/"; "/dev/vda"]; ["is_dir"; "/boot"]])], "install GRUB", "\ This command installs GRUB (the Grand Unified Bootloader) on -C, with the root directory being C."); +C, with the root directory being C. + +Note: If grub-install reports the error +\"No suitable drive was found in the generated device map.\" +it may be that you need to create a C +file first that contains the mapping between grub device names +and Linux device names. It is usually sufficient to create +a file containing: + + (hd0) /dev/vda + +replacing C with the name of the installation device."); ("cp", (RErr, [Pathname "src"; Pathname "dest"]), 87, [], [InitBasicFS, Always, TestOutput ( @@ -3715,13 +3732,28 @@ and C"); ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"]; ["mount_options"; ""; "/dev/sda1"; "/"]; ["write"; "/new"; "new file contents"]; - ["cat"; "/new"]], "new file contents")], + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mkfs_b"; "vfat"; "32768"; "/dev/sda1"]]); + InitEmpty, Always, TestLastFail ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mkfs_b"; "vfat"; "32769"; "/dev/sda1"]]); + InitEmpty, Always, TestLastFail ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mkfs_b"; "vfat"; "33280"; "/dev/sda1"]]); + InitEmpty, IfAvailable "ntfsprogs", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mkfs_b"; "ntfs"; "32768"; "/dev/sda1"]])], "make a filesystem with block size", "\ This call is similar to C, but it allows you to control the block size of the resulting filesystem. Supported block sizes depend on the filesystem type, but typically they -are C<1024>, C<2048> or C<4096> only."); +are C<1024>, C<2048> or C<4096> only. + +For VFAT and NTFS the C parameter is treated as +the requested cluster size."); ("mke2journal", (RErr, [Int "blocksize"; Device "device"]), 188, [], [InitEmpty, Always, TestOutput ( @@ -6824,6 +6856,19 @@ static void print_table (char const *const *argv) } */ +static int +is_available (const char *group) +{ + const char *groups[] = { group, NULL }; + int r; + + suppress_error = 1; + r = guestfs_available (g, (char **) groups); + suppress_error = 0; + + return r == 0; +} + "; (* Generate a list of commands which are not tested anywhere. *) @@ -6835,7 +6880,7 @@ static void print_table (char const *const *argv) fun (_, _, _, _, tests, _, _) -> let tests = filter_map ( function - | (_, (Always|If _|Unless _), test) -> Some test + | (_, (Always|If _|Unless _|IfAvailable _), test) -> Some test | (_, Disabled, _) -> None ) tests in let seq = List.concat (List.map seq_of_test tests) in @@ -7041,7 +7086,7 @@ static int %s_skip (void) " test_name name (String.uppercase test_name) (String.uppercase name); (match prereq with - | Disabled | Always -> () + | Disabled | Always | IfAvailable _ -> () | If code | Unless code -> pr "static int %s_prereq (void)\n" test_name; pr "{\n"; @@ -7066,16 +7111,9 @@ static int %s (void) List.iter ( function | Optional group -> - pr " {\n"; - pr " const char *groups[] = { \"%s\", NULL };\n" group; - pr " int r;\n"; - pr " suppress_error = 1;\n"; - pr " r = guestfs_available (g, (char **) groups);\n"; - pr " suppress_error = 0;\n"; - pr " if (r == -1) {\n"; - pr " printf (\" %%s skipped (reason: group %%s not available in daemon)\\n\", \"%s\", groups[0]);\n" test_name; - pr " return 0;\n"; - pr " }\n"; + pr " if (!is_available (\"%s\")) {\n" group; + pr " printf (\" %%s skipped (reason: group %%s not available in daemon)\\n\", \"%s\", \"%s\");\n" test_name group; + pr " return 0;\n"; pr " }\n"; | _ -> () ) flags; @@ -7097,6 +7135,13 @@ static int %s (void) pr " }\n"; pr "\n"; generate_one_test_body name i test_name init test; + | IfAvailable group -> + pr " if (!is_available (\"%s\")) {\n" group; + pr " printf (\" %%s skipped (reason: %%s not available)\\n\", \"%s\", \"%s\");\n" test_name group; + pr " return 0;\n"; + pr " }\n"; + pr "\n"; + generate_one_test_body name i test_name init test; | Always -> generate_one_test_body name i test_name init test );