1 /* libguestfs generated file
2 * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3 * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
5 * Copyright (C) 2009 Red Hat Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <sys/types.h>
32 static int suppress_error = 0;
34 static void print_error (guestfs_h *g, void *data, const char *msg)
37 fprintf (stderr, "%s\n", msg);
40 static void print_strings (char * const * const argv)
44 for (argc = 0; argv[argc] != NULL; ++argc)
45 printf ("\t%s\n", argv[argc]);
49 static void print_table (char * const * const argv)
53 for (i = 0; argv[i] != NULL; i += 2)
54 printf ("%s: %s\n", argv[i], argv[i+1]);
58 static void no_test_warnings (void)
60 fprintf (stderr, "warning: \"guestfs_launch\" has no tests\n");
61 fprintf (stderr, "warning: \"guestfs_wait_ready\" has no tests\n");
62 fprintf (stderr, "warning: \"guestfs_kill_subprocess\" has no tests\n");
63 fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n");
64 fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n");
65 fprintf (stderr, "warning: \"guestfs_config\" has no tests\n");
66 fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n");
67 fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n");
68 fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n");
69 fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n");
70 fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n");
71 fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n");
72 fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n");
73 fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n");
74 fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n");
75 fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n");
76 fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n");
77 fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n");
78 fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n");
79 fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n");
80 fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n");
81 fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n");
82 fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n");
83 fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n");
84 fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n");
85 fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n");
86 fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n");
87 fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n");
88 fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n");
89 fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n");
90 fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n");
91 fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n");
92 fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n");
93 fprintf (stderr, "warning: \"guestfs_command\" has no tests\n");
94 fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n");
95 fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
96 fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
99 static int test_blockdev_rereadpt_0 (void)
101 /* InitEmpty for blockdev_rereadpt (0) */
105 r = guestfs_umount_all (g);
112 r = guestfs_lvm_remove_all (g);
116 /* TestRun for blockdev_rereadpt (0) */
120 r = guestfs_blockdev_rereadpt (g, "/dev/sda");
127 static int test_blockdev_flushbufs_0 (void)
129 /* InitEmpty for blockdev_flushbufs (0) */
133 r = guestfs_umount_all (g);
140 r = guestfs_lvm_remove_all (g);
144 /* TestRun for blockdev_flushbufs (0) */
148 r = guestfs_blockdev_flushbufs (g, "/dev/sda");
155 static int test_blockdev_getsize64_0 (void)
157 /* InitEmpty for blockdev_getsize64 (0) */
161 r = guestfs_umount_all (g);
168 r = guestfs_lvm_remove_all (g);
172 /* TestOutputInt for blockdev_getsize64 (0) */
176 r = guestfs_blockdev_getsize64 (g, "/dev/sda");
179 if (r != 524288000) {
180 fprintf (stderr, "test_blockdev_getsize64_0: expected 524288000 but got %d\n", (int) r);
187 static int test_blockdev_getsz_0 (void)
189 /* InitEmpty for blockdev_getsz (0) */
193 r = guestfs_umount_all (g);
200 r = guestfs_lvm_remove_all (g);
204 /* TestOutputInt for blockdev_getsz (0) */
208 r = guestfs_blockdev_getsz (g, "/dev/sda");
212 fprintf (stderr, "test_blockdev_getsz_0: expected 1024000 but got %d\n", (int) r);
219 static int test_blockdev_getbsz_0 (void)
221 /* InitEmpty for blockdev_getbsz (0) */
225 r = guestfs_umount_all (g);
232 r = guestfs_lvm_remove_all (g);
236 /* TestOutputInt for blockdev_getbsz (0) */
240 r = guestfs_blockdev_getbsz (g, "/dev/sda");
244 fprintf (stderr, "test_blockdev_getbsz_0: expected 4096 but got %d\n", (int) r);
251 static int test_blockdev_getss_0 (void)
253 /* InitEmpty for blockdev_getss (0) */
257 r = guestfs_umount_all (g);
264 r = guestfs_lvm_remove_all (g);
268 /* TestOutputInt for blockdev_getss (0) */
272 r = guestfs_blockdev_getss (g, "/dev/sda");
276 fprintf (stderr, "test_blockdev_getss_0: expected 512 but got %d\n", (int) r);
283 static int test_blockdev_getro_0 (void)
285 /* InitEmpty for blockdev_getro (0) */
289 r = guestfs_umount_all (g);
296 r = guestfs_lvm_remove_all (g);
300 /* TestOutputTrue for blockdev_getro (0) */
304 r = guestfs_blockdev_setro (g, "/dev/sda");
311 r = guestfs_blockdev_getro (g, "/dev/sda");
315 fprintf (stderr, "test_blockdev_getro_0: expected true, got false\n");
322 static int test_blockdev_setrw_0 (void)
324 /* InitEmpty for blockdev_setrw (0) */
328 r = guestfs_umount_all (g);
335 r = guestfs_lvm_remove_all (g);
339 /* TestOutputFalse for blockdev_setrw (0) */
343 r = guestfs_blockdev_setrw (g, "/dev/sda");
350 r = guestfs_blockdev_getro (g, "/dev/sda");
354 fprintf (stderr, "test_blockdev_setrw_0: expected false, got true\n");
361 static int test_blockdev_setro_0 (void)
363 /* InitEmpty for blockdev_setro (0) */
367 r = guestfs_umount_all (g);
374 r = guestfs_lvm_remove_all (g);
378 /* TestOutputTrue for blockdev_setro (0) */
382 r = guestfs_blockdev_setro (g, "/dev/sda");
389 r = guestfs_blockdev_getro (g, "/dev/sda");
393 fprintf (stderr, "test_blockdev_setro_0: expected true, got false\n");
400 static int test_statvfs_0 (void)
402 /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */
406 r = guestfs_umount_all (g);
413 r = guestfs_lvm_remove_all (g);
424 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
431 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
438 r = guestfs_mount (g, "/dev/sda1", "/");
442 /* TestOutputStruct for statvfs (0) */
444 struct guestfs_statvfs *r;
446 r = guestfs_statvfs (g, "/");
449 if (r->bfree != 487702) {
450 fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n",
454 if (r->blocks != 490020) {
455 fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n",
459 if (r->bsize != 1024) {
460 fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n",
469 static int test_lstat_0 (void)
471 /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */
475 r = guestfs_umount_all (g);
482 r = guestfs_lvm_remove_all (g);
493 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
500 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
507 r = guestfs_mount (g, "/dev/sda1", "/");
511 /* TestOutputStruct for lstat (0) */
515 r = guestfs_touch (g, "/new");
520 struct guestfs_stat *r;
522 r = guestfs_lstat (g, "/new");
526 fprintf (stderr, "test_lstat_0: size was %d, expected 0\n",
535 static int test_stat_0 (void)
537 /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */
541 r = guestfs_umount_all (g);
548 r = guestfs_lvm_remove_all (g);
559 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
566 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
573 r = guestfs_mount (g, "/dev/sda1", "/");
577 /* TestOutputStruct for stat (0) */
581 r = guestfs_touch (g, "/new");
586 struct guestfs_stat *r;
588 r = guestfs_stat (g, "/new");
592 fprintf (stderr, "test_stat_0: size was %d, expected 0\n",
601 static int test_file_0 (void)
603 /* InitBasicFS for file (0): create ext2 on /dev/sda1 */
607 r = guestfs_umount_all (g);
614 r = guestfs_lvm_remove_all (g);
625 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
632 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
639 r = guestfs_mount (g, "/dev/sda1", "/");
643 /* TestOutput for file (0) */
647 r = guestfs_touch (g, "/new");
654 r = guestfs_file (g, "/new");
657 if (strcmp (r, "empty") != 0) {
658 fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r);
666 static int test_file_1 (void)
668 /* InitBasicFS for file (1): create ext2 on /dev/sda1 */
672 r = guestfs_umount_all (g);
679 r = guestfs_lvm_remove_all (g);
690 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
697 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
704 r = guestfs_mount (g, "/dev/sda1", "/");
708 /* TestOutput for file (1) */
712 r = guestfs_write_file (g, "/new", "some content\n", 0);
719 r = guestfs_file (g, "/new");
722 if (strcmp (r, "ASCII text") != 0) {
723 fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r);
731 static int test_file_2 (void)
733 /* InitBasicFS for file (2): create ext2 on /dev/sda1 */
737 r = guestfs_umount_all (g);
744 r = guestfs_lvm_remove_all (g);
755 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
762 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
769 r = guestfs_mount (g, "/dev/sda1", "/");
773 /* TestLastFail for file (2) */
777 r = guestfs_file (g, "/nofile");
785 static int test_umount_all_0 (void)
787 /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */
791 r = guestfs_umount_all (g);
798 r = guestfs_lvm_remove_all (g);
809 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
816 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
823 r = guestfs_mount (g, "/dev/sda1", "/");
827 /* TestOutputList for umount_all (0) */
831 r = guestfs_umount_all (g);
839 r = guestfs_mounts (g);
843 fprintf (stderr, "test_umount_all_0: extra elements returned from command\n");
847 for (i = 0; r[i] != NULL; ++i)
854 static int test_mounts_0 (void)
856 /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */
860 r = guestfs_umount_all (g);
867 r = guestfs_lvm_remove_all (g);
878 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
885 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
892 r = guestfs_mount (g, "/dev/sda1", "/");
896 /* TestOutputList for mounts (0) */
901 r = guestfs_mounts (g);
905 fprintf (stderr, "test_mounts_0: short list returned from command\n");
909 if (strcmp (r[0], "/dev/sda1") != 0) {
910 fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
914 fprintf (stderr, "test_mounts_0: extra elements returned from command\n");
918 for (i = 0; r[i] != NULL; ++i)
925 static int test_umount_0 (void)
927 /* InitEmpty for umount (0) */
931 r = guestfs_umount_all (g);
938 r = guestfs_lvm_remove_all (g);
942 /* TestOutputList for umount (0) */
950 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
957 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
964 r = guestfs_mount (g, "/dev/sda1", "/");
972 r = guestfs_mounts (g);
976 fprintf (stderr, "test_umount_0: short list returned from command\n");
980 if (strcmp (r[0], "/dev/sda1") != 0) {
981 fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
985 fprintf (stderr, "test_umount_0: extra elements returned from command\n");
989 for (i = 0; r[i] != NULL; ++i)
996 static int test_umount_1 (void)
998 /* InitEmpty for umount (1) */
1002 r = guestfs_umount_all (g);
1009 r = guestfs_lvm_remove_all (g);
1013 /* TestOutputList for umount (1) */
1021 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1028 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1035 r = guestfs_mount (g, "/dev/sda1", "/");
1042 r = guestfs_umount (g, "/");
1050 r = guestfs_mounts (g);
1054 fprintf (stderr, "test_umount_1: extra elements returned from command\n");
1058 for (i = 0; r[i] != NULL; ++i)
1065 static int test_write_file_0 (void)
1067 /* InitBasicFS for write_file (0): create ext2 on /dev/sda1 */
1071 r = guestfs_umount_all (g);
1078 r = guestfs_lvm_remove_all (g);
1089 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1096 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1103 r = guestfs_mount (g, "/dev/sda1", "/");
1107 /* TestOutput for write_file (0) */
1111 r = guestfs_write_file (g, "/new", "new file contents", 0);
1118 r = guestfs_cat (g, "/new");
1121 if (strcmp (r, "new file contents") != 0) {
1122 fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r);
1130 static int test_write_file_1 (void)
1132 /* InitBasicFS for write_file (1): create ext2 on /dev/sda1 */
1136 r = guestfs_umount_all (g);
1143 r = guestfs_lvm_remove_all (g);
1154 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1161 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1168 r = guestfs_mount (g, "/dev/sda1", "/");
1172 /* TestOutput for write_file (1) */
1176 r = guestfs_write_file (g, "/new", "\nnew file contents\n", 0);
1183 r = guestfs_cat (g, "/new");
1186 if (strcmp (r, "\nnew file contents\n") != 0) {
1187 fprintf (stderr, "test_write_file_1: expected \"\nnew file contents\n\" but got \"%s\"\n", r);
1195 static int test_write_file_2 (void)
1197 /* InitBasicFS for write_file (2): create ext2 on /dev/sda1 */
1201 r = guestfs_umount_all (g);
1208 r = guestfs_lvm_remove_all (g);
1219 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1226 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1233 r = guestfs_mount (g, "/dev/sda1", "/");
1237 /* TestOutput for write_file (2) */
1241 r = guestfs_write_file (g, "/new", "\n\n", 0);
1248 r = guestfs_cat (g, "/new");
1251 if (strcmp (r, "\n\n") != 0) {
1252 fprintf (stderr, "test_write_file_2: expected \"\n\n\" but got \"%s\"\n", r);
1260 static int test_write_file_3 (void)
1262 /* InitBasicFS for write_file (3): create ext2 on /dev/sda1 */
1266 r = guestfs_umount_all (g);
1273 r = guestfs_lvm_remove_all (g);
1284 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1291 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1298 r = guestfs_mount (g, "/dev/sda1", "/");
1302 /* TestOutput for write_file (3) */
1306 r = guestfs_write_file (g, "/new", "", 0);
1313 r = guestfs_cat (g, "/new");
1316 if (strcmp (r, "") != 0) {
1317 fprintf (stderr, "test_write_file_3: expected \"\" but got \"%s\"\n", r);
1325 static int test_write_file_4 (void)
1327 /* InitBasicFS for write_file (4): create ext2 on /dev/sda1 */
1331 r = guestfs_umount_all (g);
1338 r = guestfs_lvm_remove_all (g);
1349 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1356 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1363 r = guestfs_mount (g, "/dev/sda1", "/");
1367 /* TestOutput for write_file (4) */
1371 r = guestfs_write_file (g, "/new", "\n\n\n", 0);
1378 r = guestfs_cat (g, "/new");
1381 if (strcmp (r, "\n\n\n") != 0) {
1382 fprintf (stderr, "test_write_file_4: expected \"\n\n\n\" but got \"%s\"\n", r);
1390 static int test_write_file_5 (void)
1392 /* InitBasicFS for write_file (5): create ext2 on /dev/sda1 */
1396 r = guestfs_umount_all (g);
1403 r = guestfs_lvm_remove_all (g);
1414 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1421 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1428 r = guestfs_mount (g, "/dev/sda1", "/");
1432 /* TestOutput for write_file (5) */
1436 r = guestfs_write_file (g, "/new", "\n", 0);
1443 r = guestfs_cat (g, "/new");
1446 if (strcmp (r, "\n") != 0) {
1447 fprintf (stderr, "test_write_file_5: expected \"\n\" but got \"%s\"\n", r);
1455 static int test_mkfs_0 (void)
1457 /* InitEmpty for mkfs (0) */
1461 r = guestfs_umount_all (g);
1468 r = guestfs_lvm_remove_all (g);
1472 /* TestOutput for mkfs (0) */
1480 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1487 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1494 r = guestfs_mount (g, "/dev/sda1", "/");
1501 r = guestfs_write_file (g, "/new", "new file contents", 0);
1508 r = guestfs_cat (g, "/new");
1511 if (strcmp (r, "new file contents") != 0) {
1512 fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r);
1520 static int test_lvcreate_0 (void)
1522 /* InitEmpty for lvcreate (0) */
1526 r = guestfs_umount_all (g);
1533 r = guestfs_lvm_remove_all (g);
1537 /* TestOutputList for lvcreate (0) */
1547 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1554 r = guestfs_pvcreate (g, "/dev/sda1");
1561 r = guestfs_pvcreate (g, "/dev/sda2");
1568 r = guestfs_pvcreate (g, "/dev/sda3");
1573 char *physvols[] = {
1580 r = guestfs_vgcreate (g, "VG1", physvols);
1585 char *physvols[] = {
1591 r = guestfs_vgcreate (g, "VG2", physvols);
1598 r = guestfs_lvcreate (g, "LV1", "VG1", 50);
1605 r = guestfs_lvcreate (g, "LV2", "VG1", 50);
1612 r = guestfs_lvcreate (g, "LV3", "VG2", 50);
1619 r = guestfs_lvcreate (g, "LV4", "VG2", 50);
1626 r = guestfs_lvcreate (g, "LV5", "VG2", 50);
1634 r = guestfs_lvs (g);
1638 fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1642 if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
1643 fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
1647 fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1651 if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
1652 fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
1656 fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1660 if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
1661 fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
1665 fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1669 if (strcmp (r[3], "/dev/VG2/LV4") != 0) {
1670 fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]);
1674 fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1678 if (strcmp (r[4], "/dev/VG2/LV5") != 0) {
1679 fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]);
1683 fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n");
1687 for (i = 0; r[i] != NULL; ++i)
1694 static int test_vgcreate_0 (void)
1696 /* InitEmpty for vgcreate (0) */
1700 r = guestfs_umount_all (g);
1707 r = guestfs_lvm_remove_all (g);
1711 /* TestOutputList for vgcreate (0) */
1721 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1728 r = guestfs_pvcreate (g, "/dev/sda1");
1735 r = guestfs_pvcreate (g, "/dev/sda2");
1742 r = guestfs_pvcreate (g, "/dev/sda3");
1747 char *physvols[] = {
1754 r = guestfs_vgcreate (g, "VG1", physvols);
1759 char *physvols[] = {
1765 r = guestfs_vgcreate (g, "VG2", physvols);
1773 r = guestfs_vgs (g);
1777 fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
1781 if (strcmp (r[0], "VG1") != 0) {
1782 fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]);
1786 fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
1790 if (strcmp (r[1], "VG2") != 0) {
1791 fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]);
1795 fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n");
1799 for (i = 0; r[i] != NULL; ++i)
1806 static int test_pvcreate_0 (void)
1808 /* InitEmpty for pvcreate (0) */
1812 r = guestfs_umount_all (g);
1819 r = guestfs_lvm_remove_all (g);
1823 /* TestOutputList for pvcreate (0) */
1833 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1840 r = guestfs_pvcreate (g, "/dev/sda1");
1847 r = guestfs_pvcreate (g, "/dev/sda2");
1854 r = guestfs_pvcreate (g, "/dev/sda3");
1862 r = guestfs_pvs (g);
1866 fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1870 if (strcmp (r[0], "/dev/sda1") != 0) {
1871 fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
1875 fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1879 if (strcmp (r[1], "/dev/sda2") != 0) {
1880 fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
1884 fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1888 if (strcmp (r[2], "/dev/sda3") != 0) {
1889 fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
1893 fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n");
1897 for (i = 0; r[i] != NULL; ++i)
1904 static int test_is_dir_0 (void)
1906 /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */
1910 r = guestfs_umount_all (g);
1917 r = guestfs_lvm_remove_all (g);
1928 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1935 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1942 r = guestfs_mount (g, "/dev/sda1", "/");
1946 /* TestOutputFalse for is_dir (0) */
1950 r = guestfs_touch (g, "/new");
1957 r = guestfs_is_dir (g, "/new");
1961 fprintf (stderr, "test_is_dir_0: expected false, got true\n");
1968 static int test_is_dir_1 (void)
1970 /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */
1974 r = guestfs_umount_all (g);
1981 r = guestfs_lvm_remove_all (g);
1992 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1999 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2006 r = guestfs_mount (g, "/dev/sda1", "/");
2010 /* TestOutputTrue for is_dir (1) */
2014 r = guestfs_mkdir (g, "/new");
2021 r = guestfs_is_dir (g, "/new");
2025 fprintf (stderr, "test_is_dir_1: expected true, got false\n");
2032 static int test_is_file_0 (void)
2034 /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */
2038 r = guestfs_umount_all (g);
2045 r = guestfs_lvm_remove_all (g);
2056 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2063 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2070 r = guestfs_mount (g, "/dev/sda1", "/");
2074 /* TestOutputTrue for is_file (0) */
2078 r = guestfs_touch (g, "/new");
2085 r = guestfs_is_file (g, "/new");
2089 fprintf (stderr, "test_is_file_0: expected true, got false\n");
2096 static int test_is_file_1 (void)
2098 /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */
2102 r = guestfs_umount_all (g);
2109 r = guestfs_lvm_remove_all (g);
2120 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2127 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2134 r = guestfs_mount (g, "/dev/sda1", "/");
2138 /* TestOutputFalse for is_file (1) */
2142 r = guestfs_mkdir (g, "/new");
2149 r = guestfs_is_file (g, "/new");
2153 fprintf (stderr, "test_is_file_1: expected false, got true\n");
2160 static int test_exists_0 (void)
2162 /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */
2166 r = guestfs_umount_all (g);
2173 r = guestfs_lvm_remove_all (g);
2184 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2191 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2198 r = guestfs_mount (g, "/dev/sda1", "/");
2202 /* TestOutputTrue for exists (0) */
2206 r = guestfs_touch (g, "/new");
2213 r = guestfs_exists (g, "/new");
2217 fprintf (stderr, "test_exists_0: expected true, got false\n");
2224 static int test_exists_1 (void)
2226 /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */
2230 r = guestfs_umount_all (g);
2237 r = guestfs_lvm_remove_all (g);
2248 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2255 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2262 r = guestfs_mount (g, "/dev/sda1", "/");
2266 /* TestOutputTrue for exists (1) */
2270 r = guestfs_mkdir (g, "/new");
2277 r = guestfs_exists (g, "/new");
2281 fprintf (stderr, "test_exists_1: expected true, got false\n");
2288 static int test_mkdir_p_0 (void)
2290 /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */
2294 r = guestfs_umount_all (g);
2301 r = guestfs_lvm_remove_all (g);
2312 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2319 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2326 r = guestfs_mount (g, "/dev/sda1", "/");
2330 /* TestOutputTrue for mkdir_p (0) */
2334 r = guestfs_mkdir_p (g, "/new/foo/bar");
2341 r = guestfs_is_dir (g, "/new/foo/bar");
2345 fprintf (stderr, "test_mkdir_p_0: expected true, got false\n");
2352 static int test_mkdir_p_1 (void)
2354 /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */
2358 r = guestfs_umount_all (g);
2365 r = guestfs_lvm_remove_all (g);
2376 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2383 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2390 r = guestfs_mount (g, "/dev/sda1", "/");
2394 /* TestOutputTrue for mkdir_p (1) */
2398 r = guestfs_mkdir_p (g, "/new/foo/bar");
2405 r = guestfs_is_dir (g, "/new/foo");
2409 fprintf (stderr, "test_mkdir_p_1: expected true, got false\n");
2416 static int test_mkdir_p_2 (void)
2418 /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */
2422 r = guestfs_umount_all (g);
2429 r = guestfs_lvm_remove_all (g);
2440 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2447 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2454 r = guestfs_mount (g, "/dev/sda1", "/");
2458 /* TestOutputTrue for mkdir_p (2) */
2462 r = guestfs_mkdir_p (g, "/new/foo/bar");
2469 r = guestfs_is_dir (g, "/new");
2473 fprintf (stderr, "test_mkdir_p_2: expected true, got false\n");
2480 static int test_mkdir_0 (void)
2482 /* InitBasicFS for mkdir (0): create ext2 on /dev/sda1 */
2486 r = guestfs_umount_all (g);
2493 r = guestfs_lvm_remove_all (g);
2504 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2511 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2518 r = guestfs_mount (g, "/dev/sda1", "/");
2522 /* TestOutputTrue for mkdir (0) */
2526 r = guestfs_mkdir (g, "/new");
2533 r = guestfs_is_dir (g, "/new");
2537 fprintf (stderr, "test_mkdir_0: expected true, got false\n");
2544 static int test_mkdir_1 (void)
2546 /* InitBasicFS for mkdir (1): create ext2 on /dev/sda1 */
2550 r = guestfs_umount_all (g);
2557 r = guestfs_lvm_remove_all (g);
2568 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2575 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2582 r = guestfs_mount (g, "/dev/sda1", "/");
2586 /* TestLastFail for mkdir (1) */
2590 r = guestfs_mkdir (g, "/new/foo/bar");
2597 static int test_rm_rf_0 (void)
2599 /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */
2603 r = guestfs_umount_all (g);
2610 r = guestfs_lvm_remove_all (g);
2621 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2628 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2635 r = guestfs_mount (g, "/dev/sda1", "/");
2639 /* TestOutputFalse for rm_rf (0) */
2643 r = guestfs_mkdir (g, "/new");
2650 r = guestfs_mkdir (g, "/new/foo");
2657 r = guestfs_touch (g, "/new/foo/bar");
2664 r = guestfs_rm_rf (g, "/new");
2671 r = guestfs_exists (g, "/new");
2675 fprintf (stderr, "test_rm_rf_0: expected false, got true\n");
2682 static int test_rmdir_0 (void)
2684 /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */
2688 r = guestfs_umount_all (g);
2695 r = guestfs_lvm_remove_all (g);
2706 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2713 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2720 r = guestfs_mount (g, "/dev/sda1", "/");
2724 /* TestRun for rmdir (0) */
2728 r = guestfs_mkdir (g, "/new");
2735 r = guestfs_rmdir (g, "/new");
2742 static int test_rmdir_1 (void)
2744 /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */
2748 r = guestfs_umount_all (g);
2755 r = guestfs_lvm_remove_all (g);
2766 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2773 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2780 r = guestfs_mount (g, "/dev/sda1", "/");
2784 /* TestLastFail for rmdir (1) */
2788 r = guestfs_rmdir (g, "/new");
2795 static int test_rmdir_2 (void)
2797 /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */
2801 r = guestfs_umount_all (g);
2808 r = guestfs_lvm_remove_all (g);
2819 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2826 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2833 r = guestfs_mount (g, "/dev/sda1", "/");
2837 /* TestLastFail for rmdir (2) */
2841 r = guestfs_touch (g, "/new");
2848 r = guestfs_rmdir (g, "/new");
2855 static int test_rm_0 (void)
2857 /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */
2861 r = guestfs_umount_all (g);
2868 r = guestfs_lvm_remove_all (g);
2879 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2886 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2893 r = guestfs_mount (g, "/dev/sda1", "/");
2897 /* TestRun for rm (0) */
2901 r = guestfs_touch (g, "/new");
2908 r = guestfs_rm (g, "/new");
2915 static int test_rm_1 (void)
2917 /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */
2921 r = guestfs_umount_all (g);
2928 r = guestfs_lvm_remove_all (g);
2939 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2946 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2953 r = guestfs_mount (g, "/dev/sda1", "/");
2957 /* TestLastFail for rm (1) */
2961 r = guestfs_rm (g, "/new");
2968 static int test_rm_2 (void)
2970 /* InitBasicFS for rm (2): create ext2 on /dev/sda1 */
2974 r = guestfs_umount_all (g);
2981 r = guestfs_lvm_remove_all (g);
2992 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2999 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3006 r = guestfs_mount (g, "/dev/sda1", "/");
3010 /* TestLastFail for rm (2) */
3014 r = guestfs_mkdir (g, "/new");
3021 r = guestfs_rm (g, "/new");
3028 static int test_read_lines_0 (void)
3030 /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */
3034 r = guestfs_umount_all (g);
3041 r = guestfs_lvm_remove_all (g);
3052 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3059 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3066 r = guestfs_mount (g, "/dev/sda1", "/");
3070 /* TestOutputList for read_lines (0) */
3074 r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0);
3082 r = guestfs_read_lines (g, "/new");
3086 fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3090 if (strcmp (r[0], "line1") != 0) {
3091 fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]);
3095 fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3099 if (strcmp (r[1], "line2") != 0) {
3100 fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]);
3104 fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3108 if (strcmp (r[2], "line3") != 0) {
3109 fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]);
3113 fprintf (stderr, "test_read_lines_0: extra elements returned from command\n");
3117 for (i = 0; r[i] != NULL; ++i)
3124 static int test_read_lines_1 (void)
3126 /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */
3130 r = guestfs_umount_all (g);
3137 r = guestfs_lvm_remove_all (g);
3148 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3155 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3162 r = guestfs_mount (g, "/dev/sda1", "/");
3166 /* TestOutputList for read_lines (1) */
3170 r = guestfs_write_file (g, "/new", "", 0);
3178 r = guestfs_read_lines (g, "/new");
3182 fprintf (stderr, "test_read_lines_1: extra elements returned from command\n");
3186 for (i = 0; r[i] != NULL; ++i)
3193 static int test_lvs_0 (void)
3195 /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */
3199 r = guestfs_umount_all (g);
3206 r = guestfs_lvm_remove_all (g);
3217 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3224 r = guestfs_pvcreate (g, "/dev/sda1");
3229 char *physvols[] = {
3235 r = guestfs_vgcreate (g, "VG", physvols);
3242 r = guestfs_lvcreate (g, "LV", "VG", 8);
3249 r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3256 r = guestfs_mount (g, "/dev/VG/LV", "/");
3260 /* TestOutputList for lvs (0) */
3265 r = guestfs_lvs (g);
3269 fprintf (stderr, "test_lvs_0: short list returned from command\n");
3273 if (strcmp (r[0], "/dev/VG/LV") != 0) {
3274 fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]);
3278 fprintf (stderr, "test_lvs_0: extra elements returned from command\n");
3282 for (i = 0; r[i] != NULL; ++i)
3289 static int test_lvs_1 (void)
3291 /* InitEmpty for lvs (1) */
3295 r = guestfs_umount_all (g);
3302 r = guestfs_lvm_remove_all (g);
3306 /* TestOutputList for lvs (1) */
3316 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3323 r = guestfs_pvcreate (g, "/dev/sda1");
3330 r = guestfs_pvcreate (g, "/dev/sda2");
3337 r = guestfs_pvcreate (g, "/dev/sda3");
3342 char *physvols[] = {
3349 r = guestfs_vgcreate (g, "VG1", physvols);
3354 char *physvols[] = {
3360 r = guestfs_vgcreate (g, "VG2", physvols);
3367 r = guestfs_lvcreate (g, "LV1", "VG1", 50);
3374 r = guestfs_lvcreate (g, "LV2", "VG1", 50);
3381 r = guestfs_lvcreate (g, "LV3", "VG2", 50);
3389 r = guestfs_lvs (g);
3393 fprintf (stderr, "test_lvs_1: short list returned from command\n");
3397 if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
3398 fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
3402 fprintf (stderr, "test_lvs_1: short list returned from command\n");
3406 if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
3407 fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
3411 fprintf (stderr, "test_lvs_1: short list returned from command\n");
3415 if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
3416 fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
3420 fprintf (stderr, "test_lvs_1: extra elements returned from command\n");
3424 for (i = 0; r[i] != NULL; ++i)
3431 static int test_vgs_0 (void)
3433 /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */
3437 r = guestfs_umount_all (g);
3444 r = guestfs_lvm_remove_all (g);
3455 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3462 r = guestfs_pvcreate (g, "/dev/sda1");
3467 char *physvols[] = {
3473 r = guestfs_vgcreate (g, "VG", physvols);
3480 r = guestfs_lvcreate (g, "LV", "VG", 8);
3487 r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3494 r = guestfs_mount (g, "/dev/VG/LV", "/");
3498 /* TestOutputList for vgs (0) */
3503 r = guestfs_vgs (g);
3507 fprintf (stderr, "test_vgs_0: short list returned from command\n");
3511 if (strcmp (r[0], "VG") != 0) {
3512 fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]);
3516 fprintf (stderr, "test_vgs_0: extra elements returned from command\n");
3520 for (i = 0; r[i] != NULL; ++i)
3527 static int test_vgs_1 (void)
3529 /* InitEmpty for vgs (1) */
3533 r = guestfs_umount_all (g);
3540 r = guestfs_lvm_remove_all (g);
3544 /* TestOutputList for vgs (1) */
3554 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3561 r = guestfs_pvcreate (g, "/dev/sda1");
3568 r = guestfs_pvcreate (g, "/dev/sda2");
3575 r = guestfs_pvcreate (g, "/dev/sda3");
3580 char *physvols[] = {
3587 r = guestfs_vgcreate (g, "VG1", physvols);
3592 char *physvols[] = {
3598 r = guestfs_vgcreate (g, "VG2", physvols);
3606 r = guestfs_vgs (g);
3610 fprintf (stderr, "test_vgs_1: short list returned from command\n");
3614 if (strcmp (r[0], "VG1") != 0) {
3615 fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]);
3619 fprintf (stderr, "test_vgs_1: short list returned from command\n");
3623 if (strcmp (r[1], "VG2") != 0) {
3624 fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]);
3628 fprintf (stderr, "test_vgs_1: extra elements returned from command\n");
3632 for (i = 0; r[i] != NULL; ++i)
3639 static int test_pvs_0 (void)
3641 /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */
3645 r = guestfs_umount_all (g);
3652 r = guestfs_lvm_remove_all (g);
3663 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3670 r = guestfs_pvcreate (g, "/dev/sda1");
3675 char *physvols[] = {
3681 r = guestfs_vgcreate (g, "VG", physvols);
3688 r = guestfs_lvcreate (g, "LV", "VG", 8);
3695 r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3702 r = guestfs_mount (g, "/dev/VG/LV", "/");
3706 /* TestOutputList for pvs (0) */
3711 r = guestfs_pvs (g);
3715 fprintf (stderr, "test_pvs_0: short list returned from command\n");
3719 if (strcmp (r[0], "/dev/sda1") != 0) {
3720 fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3724 fprintf (stderr, "test_pvs_0: extra elements returned from command\n");
3728 for (i = 0; r[i] != NULL; ++i)
3735 static int test_pvs_1 (void)
3737 /* InitEmpty for pvs (1) */
3741 r = guestfs_umount_all (g);
3748 r = guestfs_lvm_remove_all (g);
3752 /* TestOutputList for pvs (1) */
3762 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3769 r = guestfs_pvcreate (g, "/dev/sda1");
3776 r = guestfs_pvcreate (g, "/dev/sda2");
3783 r = guestfs_pvcreate (g, "/dev/sda3");
3791 r = guestfs_pvs (g);
3795 fprintf (stderr, "test_pvs_1: short list returned from command\n");
3799 if (strcmp (r[0], "/dev/sda1") != 0) {
3800 fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3804 fprintf (stderr, "test_pvs_1: short list returned from command\n");
3808 if (strcmp (r[1], "/dev/sda2") != 0) {
3809 fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3813 fprintf (stderr, "test_pvs_1: short list returned from command\n");
3817 if (strcmp (r[2], "/dev/sda3") != 0) {
3818 fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3822 fprintf (stderr, "test_pvs_1: extra elements returned from command\n");
3826 for (i = 0; r[i] != NULL; ++i)
3833 static int test_list_partitions_0 (void)
3835 /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */
3839 r = guestfs_umount_all (g);
3846 r = guestfs_lvm_remove_all (g);
3857 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3864 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3871 r = guestfs_mount (g, "/dev/sda1", "/");
3875 /* TestOutputList for list_partitions (0) */
3880 r = guestfs_list_partitions (g);
3884 fprintf (stderr, "test_list_partitions_0: short list returned from command\n");
3888 if (strcmp (r[0], "/dev/sda1") != 0) {
3889 fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3893 fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n");
3897 for (i = 0; r[i] != NULL; ++i)
3904 static int test_list_partitions_1 (void)
3906 /* InitEmpty for list_partitions (1) */
3910 r = guestfs_umount_all (g);
3917 r = guestfs_lvm_remove_all (g);
3921 /* TestOutputList for list_partitions (1) */
3931 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3939 r = guestfs_list_partitions (g);
3943 fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3947 if (strcmp (r[0], "/dev/sda1") != 0) {
3948 fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3952 fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3956 if (strcmp (r[1], "/dev/sda2") != 0) {
3957 fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3961 fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3965 if (strcmp (r[2], "/dev/sda3") != 0) {
3966 fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3970 fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n");
3974 for (i = 0; r[i] != NULL; ++i)
3981 static int test_list_devices_0 (void)
3983 /* InitEmpty for list_devices (0) */
3987 r = guestfs_umount_all (g);
3994 r = guestfs_lvm_remove_all (g);
3998 /* TestOutputList for list_devices (0) */
4003 r = guestfs_list_devices (g);
4007 fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4011 if (strcmp (r[0], "/dev/sda") != 0) {
4012 fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]);
4016 fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4020 if (strcmp (r[1], "/dev/sdb") != 0) {
4021 fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]);
4025 fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4029 if (strcmp (r[2], "/dev/sdc") != 0) {
4030 fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]);
4034 fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
4038 for (i = 0; r[i] != NULL; ++i)
4045 static int test_ls_0 (void)
4047 /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */
4051 r = guestfs_umount_all (g);
4058 r = guestfs_lvm_remove_all (g);
4069 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4076 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4083 r = guestfs_mount (g, "/dev/sda1", "/");
4087 /* TestOutputList for ls (0) */
4091 r = guestfs_touch (g, "/new");
4098 r = guestfs_touch (g, "/newer");
4105 r = guestfs_touch (g, "/newest");
4113 r = guestfs_ls (g, "/");
4117 fprintf (stderr, "test_ls_0: short list returned from command\n");
4121 if (strcmp (r[0], "lost+found") != 0) {
4122 fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]);
4126 fprintf (stderr, "test_ls_0: short list returned from command\n");
4130 if (strcmp (r[1], "new") != 0) {
4131 fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]);
4135 fprintf (stderr, "test_ls_0: short list returned from command\n");
4139 if (strcmp (r[2], "newer") != 0) {
4140 fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]);
4144 fprintf (stderr, "test_ls_0: short list returned from command\n");
4148 if (strcmp (r[3], "newest") != 0) {
4149 fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]);
4153 fprintf (stderr, "test_ls_0: extra elements returned from command\n");
4157 for (i = 0; r[i] != NULL; ++i)
4164 static int test_cat_0 (void)
4166 /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */
4170 r = guestfs_umount_all (g);
4177 r = guestfs_lvm_remove_all (g);
4188 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4195 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4202 r = guestfs_mount (g, "/dev/sda1", "/");
4206 /* TestOutput for cat (0) */
4210 r = guestfs_write_file (g, "/new", "new file contents", 0);
4217 r = guestfs_cat (g, "/new");
4220 if (strcmp (r, "new file contents") != 0) {
4221 fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r);
4229 static int test_touch_0 (void)
4231 /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */
4235 r = guestfs_umount_all (g);
4242 r = guestfs_lvm_remove_all (g);
4253 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4260 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4267 r = guestfs_mount (g, "/dev/sda1", "/");
4271 /* TestOutputTrue for touch (0) */
4275 r = guestfs_touch (g, "/new");
4282 r = guestfs_exists (g, "/new");
4286 fprintf (stderr, "test_touch_0: expected true, got false\n");
4293 static int test_sync_0 (void)
4295 /* InitEmpty for sync (0) */
4299 r = guestfs_umount_all (g);
4306 r = guestfs_lvm_remove_all (g);
4310 /* TestRun for sync (0) */
4314 r = guestfs_sync (g);
4321 static int test_mount_0 (void)
4323 /* InitEmpty for mount (0) */
4327 r = guestfs_umount_all (g);
4334 r = guestfs_lvm_remove_all (g);
4338 /* TestOutput for mount (0) */
4346 r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4353 r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4360 r = guestfs_mount (g, "/dev/sda1", "/");
4367 r = guestfs_write_file (g, "/new", "new file contents", 0);
4374 r = guestfs_cat (g, "/new");
4377 if (strcmp (r, "new file contents") != 0) {
4378 fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r);
4386 int main (int argc, char *argv[])
4393 int nr_tests, test_num = 0;
4395 no_test_warnings ();
4397 g = guestfs_create ();
4399 printf ("guestfs_create FAILED\n");
4403 guestfs_set_error_handler (g, print_error, NULL);
4405 srcdir = getenv ("srcdir");
4406 if (!srcdir) srcdir = ".";
4407 guestfs_set_path (g, srcdir);
4409 snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
4410 fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4415 if (lseek (fd, 524288000, SEEK_SET) == -1) {
4421 if (write (fd, &c, 1) == -1) {
4427 if (close (fd) == -1) {
4432 if (guestfs_add_drive (g, buf) == -1) {
4433 printf ("guestfs_add_drive %s FAILED\n", buf);
4437 snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
4438 fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4443 if (lseek (fd, 52428800, SEEK_SET) == -1) {
4449 if (write (fd, &c, 1) == -1) {
4455 if (close (fd) == -1) {
4460 if (guestfs_add_drive (g, buf) == -1) {
4461 printf ("guestfs_add_drive %s FAILED\n", buf);
4465 snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
4466 fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4471 if (lseek (fd, 10485760, SEEK_SET) == -1) {
4477 if (write (fd, &c, 1) == -1) {
4483 if (close (fd) == -1) {
4488 if (guestfs_add_drive (g, buf) == -1) {
4489 printf ("guestfs_add_drive %s FAILED\n", buf);
4493 if (guestfs_launch (g) == -1) {
4494 printf ("guestfs_launch FAILED\n");
4497 if (guestfs_wait_ready (g) == -1) {
4498 printf ("guestfs_wait_ready FAILED\n");
4505 printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests);
4506 if (test_blockdev_rereadpt_0 () == -1) {
4507 printf ("test_blockdev_rereadpt_0 FAILED\n");
4511 printf ("%3d/%3d test_blockdev_flushbufs_0\n", test_num, nr_tests);
4512 if (test_blockdev_flushbufs_0 () == -1) {
4513 printf ("test_blockdev_flushbufs_0 FAILED\n");
4517 printf ("%3d/%3d test_blockdev_getsize64_0\n", test_num, nr_tests);
4518 if (test_blockdev_getsize64_0 () == -1) {
4519 printf ("test_blockdev_getsize64_0 FAILED\n");
4523 printf ("%3d/%3d test_blockdev_getsz_0\n", test_num, nr_tests);
4524 if (test_blockdev_getsz_0 () == -1) {
4525 printf ("test_blockdev_getsz_0 FAILED\n");
4529 printf ("%3d/%3d test_blockdev_getbsz_0\n", test_num, nr_tests);
4530 if (test_blockdev_getbsz_0 () == -1) {
4531 printf ("test_blockdev_getbsz_0 FAILED\n");
4535 printf ("%3d/%3d test_blockdev_getss_0\n", test_num, nr_tests);
4536 if (test_blockdev_getss_0 () == -1) {
4537 printf ("test_blockdev_getss_0 FAILED\n");
4541 printf ("%3d/%3d test_blockdev_getro_0\n", test_num, nr_tests);
4542 if (test_blockdev_getro_0 () == -1) {
4543 printf ("test_blockdev_getro_0 FAILED\n");
4547 printf ("%3d/%3d test_blockdev_setrw_0\n", test_num, nr_tests);
4548 if (test_blockdev_setrw_0 () == -1) {
4549 printf ("test_blockdev_setrw_0 FAILED\n");
4553 printf ("%3d/%3d test_blockdev_setro_0\n", test_num, nr_tests);
4554 if (test_blockdev_setro_0 () == -1) {
4555 printf ("test_blockdev_setro_0 FAILED\n");
4559 printf ("%3d/%3d test_statvfs_0\n", test_num, nr_tests);
4560 if (test_statvfs_0 () == -1) {
4561 printf ("test_statvfs_0 FAILED\n");
4565 printf ("%3d/%3d test_lstat_0\n", test_num, nr_tests);
4566 if (test_lstat_0 () == -1) {
4567 printf ("test_lstat_0 FAILED\n");
4571 printf ("%3d/%3d test_stat_0\n", test_num, nr_tests);
4572 if (test_stat_0 () == -1) {
4573 printf ("test_stat_0 FAILED\n");
4577 printf ("%3d/%3d test_file_0\n", test_num, nr_tests);
4578 if (test_file_0 () == -1) {
4579 printf ("test_file_0 FAILED\n");
4583 printf ("%3d/%3d test_file_1\n", test_num, nr_tests);
4584 if (test_file_1 () == -1) {
4585 printf ("test_file_1 FAILED\n");
4589 printf ("%3d/%3d test_file_2\n", test_num, nr_tests);
4590 if (test_file_2 () == -1) {
4591 printf ("test_file_2 FAILED\n");
4595 printf ("%3d/%3d test_umount_all_0\n", test_num, nr_tests);
4596 if (test_umount_all_0 () == -1) {
4597 printf ("test_umount_all_0 FAILED\n");
4601 printf ("%3d/%3d test_mounts_0\n", test_num, nr_tests);
4602 if (test_mounts_0 () == -1) {
4603 printf ("test_mounts_0 FAILED\n");
4607 printf ("%3d/%3d test_umount_0\n", test_num, nr_tests);
4608 if (test_umount_0 () == -1) {
4609 printf ("test_umount_0 FAILED\n");
4613 printf ("%3d/%3d test_umount_1\n", test_num, nr_tests);
4614 if (test_umount_1 () == -1) {
4615 printf ("test_umount_1 FAILED\n");
4619 printf ("%3d/%3d test_write_file_0\n", test_num, nr_tests);
4620 if (test_write_file_0 () == -1) {
4621 printf ("test_write_file_0 FAILED\n");
4625 printf ("%3d/%3d test_write_file_1\n", test_num, nr_tests);
4626 if (test_write_file_1 () == -1) {
4627 printf ("test_write_file_1 FAILED\n");
4631 printf ("%3d/%3d test_write_file_2\n", test_num, nr_tests);
4632 if (test_write_file_2 () == -1) {
4633 printf ("test_write_file_2 FAILED\n");
4637 printf ("%3d/%3d test_write_file_3\n", test_num, nr_tests);
4638 if (test_write_file_3 () == -1) {
4639 printf ("test_write_file_3 FAILED\n");
4643 printf ("%3d/%3d test_write_file_4\n", test_num, nr_tests);
4644 if (test_write_file_4 () == -1) {
4645 printf ("test_write_file_4 FAILED\n");
4649 printf ("%3d/%3d test_write_file_5\n", test_num, nr_tests);
4650 if (test_write_file_5 () == -1) {
4651 printf ("test_write_file_5 FAILED\n");
4655 printf ("%3d/%3d test_mkfs_0\n", test_num, nr_tests);
4656 if (test_mkfs_0 () == -1) {
4657 printf ("test_mkfs_0 FAILED\n");
4661 printf ("%3d/%3d test_lvcreate_0\n", test_num, nr_tests);
4662 if (test_lvcreate_0 () == -1) {
4663 printf ("test_lvcreate_0 FAILED\n");
4667 printf ("%3d/%3d test_vgcreate_0\n", test_num, nr_tests);
4668 if (test_vgcreate_0 () == -1) {
4669 printf ("test_vgcreate_0 FAILED\n");
4673 printf ("%3d/%3d test_pvcreate_0\n", test_num, nr_tests);
4674 if (test_pvcreate_0 () == -1) {
4675 printf ("test_pvcreate_0 FAILED\n");
4679 printf ("%3d/%3d test_is_dir_0\n", test_num, nr_tests);
4680 if (test_is_dir_0 () == -1) {
4681 printf ("test_is_dir_0 FAILED\n");
4685 printf ("%3d/%3d test_is_dir_1\n", test_num, nr_tests);
4686 if (test_is_dir_1 () == -1) {
4687 printf ("test_is_dir_1 FAILED\n");
4691 printf ("%3d/%3d test_is_file_0\n", test_num, nr_tests);
4692 if (test_is_file_0 () == -1) {
4693 printf ("test_is_file_0 FAILED\n");
4697 printf ("%3d/%3d test_is_file_1\n", test_num, nr_tests);
4698 if (test_is_file_1 () == -1) {
4699 printf ("test_is_file_1 FAILED\n");
4703 printf ("%3d/%3d test_exists_0\n", test_num, nr_tests);
4704 if (test_exists_0 () == -1) {
4705 printf ("test_exists_0 FAILED\n");
4709 printf ("%3d/%3d test_exists_1\n", test_num, nr_tests);
4710 if (test_exists_1 () == -1) {
4711 printf ("test_exists_1 FAILED\n");
4715 printf ("%3d/%3d test_mkdir_p_0\n", test_num, nr_tests);
4716 if (test_mkdir_p_0 () == -1) {
4717 printf ("test_mkdir_p_0 FAILED\n");
4721 printf ("%3d/%3d test_mkdir_p_1\n", test_num, nr_tests);
4722 if (test_mkdir_p_1 () == -1) {
4723 printf ("test_mkdir_p_1 FAILED\n");
4727 printf ("%3d/%3d test_mkdir_p_2\n", test_num, nr_tests);
4728 if (test_mkdir_p_2 () == -1) {
4729 printf ("test_mkdir_p_2 FAILED\n");
4733 printf ("%3d/%3d test_mkdir_0\n", test_num, nr_tests);
4734 if (test_mkdir_0 () == -1) {
4735 printf ("test_mkdir_0 FAILED\n");
4739 printf ("%3d/%3d test_mkdir_1\n", test_num, nr_tests);
4740 if (test_mkdir_1 () == -1) {
4741 printf ("test_mkdir_1 FAILED\n");
4745 printf ("%3d/%3d test_rm_rf_0\n", test_num, nr_tests);
4746 if (test_rm_rf_0 () == -1) {
4747 printf ("test_rm_rf_0 FAILED\n");
4751 printf ("%3d/%3d test_rmdir_0\n", test_num, nr_tests);
4752 if (test_rmdir_0 () == -1) {
4753 printf ("test_rmdir_0 FAILED\n");
4757 printf ("%3d/%3d test_rmdir_1\n", test_num, nr_tests);
4758 if (test_rmdir_1 () == -1) {
4759 printf ("test_rmdir_1 FAILED\n");
4763 printf ("%3d/%3d test_rmdir_2\n", test_num, nr_tests);
4764 if (test_rmdir_2 () == -1) {
4765 printf ("test_rmdir_2 FAILED\n");
4769 printf ("%3d/%3d test_rm_0\n", test_num, nr_tests);
4770 if (test_rm_0 () == -1) {
4771 printf ("test_rm_0 FAILED\n");
4775 printf ("%3d/%3d test_rm_1\n", test_num, nr_tests);
4776 if (test_rm_1 () == -1) {
4777 printf ("test_rm_1 FAILED\n");
4781 printf ("%3d/%3d test_rm_2\n", test_num, nr_tests);
4782 if (test_rm_2 () == -1) {
4783 printf ("test_rm_2 FAILED\n");
4787 printf ("%3d/%3d test_read_lines_0\n", test_num, nr_tests);
4788 if (test_read_lines_0 () == -1) {
4789 printf ("test_read_lines_0 FAILED\n");
4793 printf ("%3d/%3d test_read_lines_1\n", test_num, nr_tests);
4794 if (test_read_lines_1 () == -1) {
4795 printf ("test_read_lines_1 FAILED\n");
4799 printf ("%3d/%3d test_lvs_0\n", test_num, nr_tests);
4800 if (test_lvs_0 () == -1) {
4801 printf ("test_lvs_0 FAILED\n");
4805 printf ("%3d/%3d test_lvs_1\n", test_num, nr_tests);
4806 if (test_lvs_1 () == -1) {
4807 printf ("test_lvs_1 FAILED\n");
4811 printf ("%3d/%3d test_vgs_0\n", test_num, nr_tests);
4812 if (test_vgs_0 () == -1) {
4813 printf ("test_vgs_0 FAILED\n");
4817 printf ("%3d/%3d test_vgs_1\n", test_num, nr_tests);
4818 if (test_vgs_1 () == -1) {
4819 printf ("test_vgs_1 FAILED\n");
4823 printf ("%3d/%3d test_pvs_0\n", test_num, nr_tests);
4824 if (test_pvs_0 () == -1) {
4825 printf ("test_pvs_0 FAILED\n");
4829 printf ("%3d/%3d test_pvs_1\n", test_num, nr_tests);
4830 if (test_pvs_1 () == -1) {
4831 printf ("test_pvs_1 FAILED\n");
4835 printf ("%3d/%3d test_list_partitions_0\n", test_num, nr_tests);
4836 if (test_list_partitions_0 () == -1) {
4837 printf ("test_list_partitions_0 FAILED\n");
4841 printf ("%3d/%3d test_list_partitions_1\n", test_num, nr_tests);
4842 if (test_list_partitions_1 () == -1) {
4843 printf ("test_list_partitions_1 FAILED\n");
4847 printf ("%3d/%3d test_list_devices_0\n", test_num, nr_tests);
4848 if (test_list_devices_0 () == -1) {
4849 printf ("test_list_devices_0 FAILED\n");
4853 printf ("%3d/%3d test_ls_0\n", test_num, nr_tests);
4854 if (test_ls_0 () == -1) {
4855 printf ("test_ls_0 FAILED\n");
4859 printf ("%3d/%3d test_cat_0\n", test_num, nr_tests);
4860 if (test_cat_0 () == -1) {
4861 printf ("test_cat_0 FAILED\n");
4865 printf ("%3d/%3d test_touch_0\n", test_num, nr_tests);
4866 if (test_touch_0 () == -1) {
4867 printf ("test_touch_0 FAILED\n");
4871 printf ("%3d/%3d test_sync_0\n", test_num, nr_tests);
4872 if (test_sync_0 () == -1) {
4873 printf ("test_sync_0 FAILED\n");
4877 printf ("%3d/%3d test_mount_0\n", test_num, nr_tests);
4878 if (test_mount_0 () == -1) {
4879 printf ("test_mount_0 FAILED\n");
4884 snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
4886 snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
4888 snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
4892 printf ("***** %d / %d tests FAILED *****\n", failed, nr_tests);