X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=generator%2Fgenerator_capitests.ml;h=f5be3e7cbb54ab9860660fd68d970b1f31c7ec6a;hb=b034795a259fb5f255c1f9c835d722efab4d4f7c;hp=044c70d4a787440ca1b6791cca92633b93e4e129;hpb=b42262c3db6013c363e2532cf7a466ccaf4d49f0;p=libguestfs.git diff --git a/generator/generator_capitests.ml b/generator/generator_capitests.ml index 044c70d..f5be3e7 100644 --- a/generator/generator_capitests.ml +++ b/generator/generator_capitests.ml @@ -175,22 +175,14 @@ int main (int argc, char *argv[]) guestfs_set_error_handler (g, print_error, NULL); - guestfs_set_path (g, \"../appliance\"); - filename = \"test1.img\"; - fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); + fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC, 0666); if (fd == -1) { perror (filename); exit (EXIT_FAILURE); } - if (lseek (fd, %d, SEEK_SET) == -1) { - perror (\"lseek\"); - close (fd); - unlink (filename); - exit (EXIT_FAILURE); - } - if (write (fd, &c, 1) == -1) { - perror (\"write\"); + if (ftruncate (fd, %d) == -1) { + perror (\"ftruncate\"); close (fd); unlink (filename); exit (EXIT_FAILURE); @@ -206,19 +198,13 @@ int main (int argc, char *argv[]) } filename = \"test2.img\"; - fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); + fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC, 0666); if (fd == -1) { perror (filename); exit (EXIT_FAILURE); } - if (lseek (fd, %d, SEEK_SET) == -1) { - perror (\"lseek\"); - close (fd); - unlink (filename); - exit (EXIT_FAILURE); - } - if (write (fd, &c, 1) == -1) { - perror (\"write\"); + if (ftruncate (fd, %d) == -1) { + perror (\"ftruncate\"); close (fd); unlink (filename); exit (EXIT_FAILURE); @@ -234,19 +220,13 @@ int main (int argc, char *argv[]) } filename = \"test3.img\"; - fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); + fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC, 0666); if (fd == -1) { perror (filename); exit (EXIT_FAILURE); } - if (lseek (fd, %d, SEEK_SET) == -1) { - perror (\"lseek\"); - close (fd); - unlink (filename); - exit (EXIT_FAILURE); - } - if (write (fd, &c, 1) == -1) { - perror (\"write\"); + if (ftruncate (fd, %d) == -1) { + perror (\"ftruncate\"); close (fd); unlink (filename); exit (EXIT_FAILURE); @@ -277,6 +257,16 @@ int main (int argc, char *argv[]) /* Cancel previous alarm. */ alarm (0); + /* Create ext2 filesystem on /dev/sdb1 partition. */ + if (guestfs_part_disk (g, \"/dev/sdb\", \"mbr\") == -1) { + printf (\"guestfs_part_disk FAILED\\n\"); + exit (EXIT_FAILURE); + } + if (guestfs_mkfs (g, \"ext2\", \"/dev/sdb1\") == -1) { + printf (\"guestfs_mkfs (/dev/sdb1) FAILED\\n\"); + exit (EXIT_FAILURE); + } + nr_tests = %d; " (500 * 1024 * 1024) (50 * 1024 * 1024) (10 * 1024 * 1024) nr_tests; @@ -455,6 +445,13 @@ and generate_one_test_body name i test_name init test = ["umount_all"]; ["lvm_remove_all"]; ["mount_ro"; "/dev/sdd"; "/"]] + | InitScratchFS -> + pr " /* InitScratchFS for %s */\n" test_name; + List.iter (generate_test_command_call test_name) + [["blockdev_setrw"; "/dev/sda"]; + ["umount_all"]; + ["lvm_remove_all"]; + ["mount_options"; ""; "/dev/sdb1"; "/"]] ); let get_seq_last = function @@ -685,6 +682,19 @@ and generate_one_test_body name i test_name init test = in List.iter (generate_test_command_call test_name) seq; generate_test_command_call ~test test_name last + | TestOutputDevice (seq, expected) -> + pr " /* TestOutputDevice for %s (%d) */\n" name i; + pr " const char *expected = \"%s\";\n" (c_quote expected); + let seq, last = get_seq_last seq in + let test () = + pr " r[5] = 's';\n"; + pr " if (STRNEQ (r, expected)) {\n"; + pr " fprintf (stderr, \"%s: expected \\\"%%s\\\" but got \\\"%%s\\\"\\n\", expected, r);\n" test_name; + pr " return -1;\n"; + pr " }\n" + in + List.iter (generate_test_command_call test_name) seq; + generate_test_command_call ~test test_name last | TestLastFail seq -> pr " /* TestLastFail for %s (%d) */\n" name i; let seq, last = get_seq_last seq in @@ -707,6 +717,13 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = with Not_found -> failwithf "%s: in test, command %s was not found" test_name name in + (* If the call has optional args, fold them all together. We cannot + * test partial optional args yet. + *) + let style = + let ret, args, optargs = style in + ret, args@optargs in + if List.length (snd style) <> List.length args then failwithf "%s: in test, wrong number of args given to %s" test_name name; @@ -744,6 +761,9 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = ) strs; pr " NULL\n"; pr " };\n"; + | Pointer _, _ -> + (* Difficult to make these pointers in order to run a test. *) + assert false ) (List.combine (snd style) args); let error_code = @@ -799,6 +819,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = pr ", %Ld" i | Bool _, arg -> let b = bool_of_string arg in pr ", %d" (if b then 1 else 0) + | Pointer _, _ -> assert false ) (List.combine (snd style) args); (match fst style with