Added test suite.
[libguestfs.git] / tests.c
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.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <fcntl.h>
28
29 #include "guestfs.h"
30
31 static guestfs_h *g;
32 static int suppress_error = 0;
33
34 static void print_error (guestfs_h *g, void *data, const char *msg)
35 {
36   if (!suppress_error)
37     fprintf (stderr, "%s\n", msg);
38 }
39
40 static void print_strings (char * const * const argv)
41 {
42   int argc;
43
44   for (argc = 0; argv[argc] != NULL; ++argc)
45     printf ("\t%s\n", argv[argc]);
46 }
47
48 static int test_mount_0 (void)
49 {
50   /* InitNone for mount (0) */
51   {
52     int r;
53     suppress_error = 0;
54     r = guestfs_umount_all (g);
55     if (r == -1)
56       return -1;
57   }
58   {
59     int r;
60     suppress_error = 0;
61     r = guestfs_lvm_remove_all (g);
62     if (r == -1)
63       return -1;
64   }
65   /* TestOutput for mount (0) */
66   {
67     char *lines[] = {
68       ",",
69       NULL
70     };
71     int r;
72     suppress_error = 0;
73     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
74     if (r == -1)
75       return -1;
76   }
77   {
78     int r;
79     suppress_error = 0;
80     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
81     if (r == -1)
82       return -1;
83   }
84   {
85     int r;
86     suppress_error = 0;
87     r = guestfs_mount (g, "/dev/sda1", "/");
88     if (r == -1)
89       return -1;
90   }
91   {
92     int r;
93     suppress_error = 0;
94     r = guestfs_write_file (g, "/new", "new file contents", 0);
95     if (r == -1)
96       return -1;
97   }
98   {
99     char *r;
100     suppress_error = 0;
101     r = guestfs_cat (g, "/new");
102     if (r == NULL)
103       return -1;
104     if (strcmp (r, "new file contents") != 0) {
105       fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r);
106       return -1;
107     }
108     free (r);
109   }
110   return 0;
111 }
112
113 static int test_sync_0 (void)
114 {
115   /* InitNone for sync (0) */
116   {
117     int r;
118     suppress_error = 0;
119     r = guestfs_umount_all (g);
120     if (r == -1)
121       return -1;
122   }
123   {
124     int r;
125     suppress_error = 0;
126     r = guestfs_lvm_remove_all (g);
127     if (r == -1)
128       return -1;
129   }
130   /* TestRun for sync (0) */
131   {
132     int r;
133     suppress_error = 0;
134     r = guestfs_sync (g);
135     if (r == -1)
136       return -1;
137   }
138   return 0;
139 }
140
141 static int test_touch_0 (void)
142 {
143   /* InitEmpty for touch (0): create ext2 on /dev/sda1 */
144   {
145     int r;
146     suppress_error = 0;
147     r = guestfs_umount_all (g);
148     if (r == -1)
149       return -1;
150   }
151   {
152     int r;
153     suppress_error = 0;
154     r = guestfs_lvm_remove_all (g);
155     if (r == -1)
156       return -1;
157   }
158   {
159     char *lines[] = {
160       ",",
161       NULL
162     };
163     int r;
164     suppress_error = 0;
165     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
166     if (r == -1)
167       return -1;
168   }
169   {
170     int r;
171     suppress_error = 0;
172     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
173     if (r == -1)
174       return -1;
175   }
176   {
177     int r;
178     suppress_error = 0;
179     r = guestfs_mount (g, "/dev/sda1", "/");
180     if (r == -1)
181       return -1;
182   }
183   /* TestOutputTrue for touch (0) */
184   {
185     int r;
186     suppress_error = 0;
187     r = guestfs_touch (g, "/new");
188     if (r == -1)
189       return -1;
190   }
191   {
192     int r;
193     suppress_error = 0;
194     r = guestfs_exists (g, "/new");
195     if (r == -1)
196       return -1;
197     if (!r) {
198       fprintf (stderr, "test_touch_0: expected true, got false\n");
199       return -1;
200     }
201   }
202   return 0;
203 }
204
205 static int test_cat_0 (void)
206 {
207   /* InitEmpty for cat (0): create ext2 on /dev/sda1 */
208   {
209     int r;
210     suppress_error = 0;
211     r = guestfs_umount_all (g);
212     if (r == -1)
213       return -1;
214   }
215   {
216     int r;
217     suppress_error = 0;
218     r = guestfs_lvm_remove_all (g);
219     if (r == -1)
220       return -1;
221   }
222   {
223     char *lines[] = {
224       ",",
225       NULL
226     };
227     int r;
228     suppress_error = 0;
229     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
230     if (r == -1)
231       return -1;
232   }
233   {
234     int r;
235     suppress_error = 0;
236     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
237     if (r == -1)
238       return -1;
239   }
240   {
241     int r;
242     suppress_error = 0;
243     r = guestfs_mount (g, "/dev/sda1", "/");
244     if (r == -1)
245       return -1;
246   }
247   /* TestOutput for cat (0) */
248   {
249     int r;
250     suppress_error = 0;
251     r = guestfs_write_file (g, "/new", "new file contents", 0);
252     if (r == -1)
253       return -1;
254   }
255   {
256     char *r;
257     suppress_error = 0;
258     r = guestfs_cat (g, "/new");
259     if (r == NULL)
260       return -1;
261     if (strcmp (r, "new file contents") != 0) {
262       fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r);
263       return -1;
264     }
265     free (r);
266   }
267   return 0;
268 }
269
270 static int test_ls_0 (void)
271 {
272   /* InitEmpty for ls (0): create ext2 on /dev/sda1 */
273   {
274     int r;
275     suppress_error = 0;
276     r = guestfs_umount_all (g);
277     if (r == -1)
278       return -1;
279   }
280   {
281     int r;
282     suppress_error = 0;
283     r = guestfs_lvm_remove_all (g);
284     if (r == -1)
285       return -1;
286   }
287   {
288     char *lines[] = {
289       ",",
290       NULL
291     };
292     int r;
293     suppress_error = 0;
294     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
295     if (r == -1)
296       return -1;
297   }
298   {
299     int r;
300     suppress_error = 0;
301     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
302     if (r == -1)
303       return -1;
304   }
305   {
306     int r;
307     suppress_error = 0;
308     r = guestfs_mount (g, "/dev/sda1", "/");
309     if (r == -1)
310       return -1;
311   }
312   /* TestOutputList for ls (0) */
313   {
314     int r;
315     suppress_error = 0;
316     r = guestfs_touch (g, "/new");
317     if (r == -1)
318       return -1;
319   }
320   {
321     int r;
322     suppress_error = 0;
323     r = guestfs_touch (g, "/newer");
324     if (r == -1)
325       return -1;
326   }
327   {
328     int r;
329     suppress_error = 0;
330     r = guestfs_touch (g, "/newest");
331     if (r == -1)
332       return -1;
333   }
334   {
335     char **r;
336     int i;
337     suppress_error = 0;
338     r = guestfs_ls (g, "/");
339     if (r == NULL)
340       return -1;
341     if (!r[0]) {
342       fprintf (stderr, "test_ls_0: short list returned from command\n");
343       print_strings (r);
344       return -1;
345     }
346     if (strcmp (r[0], "lost+found") != 0) {
347       fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]);
348       return -1;
349     }
350     if (!r[1]) {
351       fprintf (stderr, "test_ls_0: short list returned from command\n");
352       print_strings (r);
353       return -1;
354     }
355     if (strcmp (r[1], "new") != 0) {
356       fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]);
357       return -1;
358     }
359     if (!r[2]) {
360       fprintf (stderr, "test_ls_0: short list returned from command\n");
361       print_strings (r);
362       return -1;
363     }
364     if (strcmp (r[2], "newer") != 0) {
365       fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]);
366       return -1;
367     }
368     if (!r[3]) {
369       fprintf (stderr, "test_ls_0: short list returned from command\n");
370       print_strings (r);
371       return -1;
372     }
373     if (strcmp (r[3], "newest") != 0) {
374       fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]);
375       return -1;
376     }
377     if (r[4] != NULL) {
378       fprintf (stderr, "test_ls_0: extra elements returned from command\n");
379       print_strings (r);
380       return -1;
381     }
382     for (i = 0; r[i] != NULL; ++i)
383       free (r[i]);
384     free (r);
385   }
386   return 0;
387 }
388
389 static int test_list_devices_0 (void)
390 {
391   /* InitNone for list_devices (0) */
392   {
393     int r;
394     suppress_error = 0;
395     r = guestfs_umount_all (g);
396     if (r == -1)
397       return -1;
398   }
399   {
400     int r;
401     suppress_error = 0;
402     r = guestfs_lvm_remove_all (g);
403     if (r == -1)
404       return -1;
405   }
406   /* TestOutputList for list_devices (0) */
407   {
408     char **r;
409     int i;
410     suppress_error = 0;
411     r = guestfs_list_devices (g);
412     if (r == NULL)
413       return -1;
414     if (!r[0]) {
415       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
416       print_strings (r);
417       return -1;
418     }
419     if (strcmp (r[0], "/dev/sda") != 0) {
420       fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]);
421       return -1;
422     }
423     if (!r[1]) {
424       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
425       print_strings (r);
426       return -1;
427     }
428     if (strcmp (r[1], "/dev/sdb") != 0) {
429       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]);
430       return -1;
431     }
432     if (!r[2]) {
433       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
434       print_strings (r);
435       return -1;
436     }
437     if (strcmp (r[2], "/dev/sdc") != 0) {
438       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]);
439       return -1;
440     }
441     if (r[3] != NULL) {
442       fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
443       print_strings (r);
444       return -1;
445     }
446     for (i = 0; r[i] != NULL; ++i)
447       free (r[i]);
448     free (r);
449   }
450   return 0;
451 }
452
453 static int test_list_partitions_0 (void)
454 {
455   /* InitEmpty for list_partitions (0): create ext2 on /dev/sda1 */
456   {
457     int r;
458     suppress_error = 0;
459     r = guestfs_umount_all (g);
460     if (r == -1)
461       return -1;
462   }
463   {
464     int r;
465     suppress_error = 0;
466     r = guestfs_lvm_remove_all (g);
467     if (r == -1)
468       return -1;
469   }
470   {
471     char *lines[] = {
472       ",",
473       NULL
474     };
475     int r;
476     suppress_error = 0;
477     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
478     if (r == -1)
479       return -1;
480   }
481   {
482     int r;
483     suppress_error = 0;
484     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
485     if (r == -1)
486       return -1;
487   }
488   {
489     int r;
490     suppress_error = 0;
491     r = guestfs_mount (g, "/dev/sda1", "/");
492     if (r == -1)
493       return -1;
494   }
495   /* TestOutputList for list_partitions (0) */
496   {
497     char **r;
498     int i;
499     suppress_error = 0;
500     r = guestfs_list_partitions (g);
501     if (r == NULL)
502       return -1;
503     if (!r[0]) {
504       fprintf (stderr, "test_list_partitions_0: short list returned from command\n");
505       print_strings (r);
506       return -1;
507     }
508     if (strcmp (r[0], "/dev/sda1") != 0) {
509       fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
510       return -1;
511     }
512     if (r[1] != NULL) {
513       fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n");
514       print_strings (r);
515       return -1;
516     }
517     for (i = 0; r[i] != NULL; ++i)
518       free (r[i]);
519     free (r);
520   }
521   return 0;
522 }
523
524 static int test_list_partitions_1 (void)
525 {
526   /* InitNone for list_partitions (1) */
527   {
528     int r;
529     suppress_error = 0;
530     r = guestfs_umount_all (g);
531     if (r == -1)
532       return -1;
533   }
534   {
535     int r;
536     suppress_error = 0;
537     r = guestfs_lvm_remove_all (g);
538     if (r == -1)
539       return -1;
540   }
541   /* TestOutputList for list_partitions (1) */
542   {
543     char *lines[] = {
544       ",10",
545       ",20",
546       ",",
547       NULL
548     };
549     int r;
550     suppress_error = 0;
551     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
552     if (r == -1)
553       return -1;
554   }
555   {
556     char **r;
557     int i;
558     suppress_error = 0;
559     r = guestfs_list_partitions (g);
560     if (r == NULL)
561       return -1;
562     if (!r[0]) {
563       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
564       print_strings (r);
565       return -1;
566     }
567     if (strcmp (r[0], "/dev/sda1") != 0) {
568       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
569       return -1;
570     }
571     if (!r[1]) {
572       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
573       print_strings (r);
574       return -1;
575     }
576     if (strcmp (r[1], "/dev/sda2") != 0) {
577       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
578       return -1;
579     }
580     if (!r[2]) {
581       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
582       print_strings (r);
583       return -1;
584     }
585     if (strcmp (r[2], "/dev/sda3") != 0) {
586       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
587       return -1;
588     }
589     if (r[3] != NULL) {
590       fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n");
591       print_strings (r);
592       return -1;
593     }
594     for (i = 0; r[i] != NULL; ++i)
595       free (r[i]);
596     free (r);
597   }
598   return 0;
599 }
600
601 static int test_pvs_0 (void)
602 {
603   /* InitEmptyLVM for pvs (0): create ext2 on /dev/VG/LV */
604   {
605     int r;
606     suppress_error = 0;
607     r = guestfs_umount_all (g);
608     if (r == -1)
609       return -1;
610   }
611   {
612     int r;
613     suppress_error = 0;
614     r = guestfs_lvm_remove_all (g);
615     if (r == -1)
616       return -1;
617   }
618   {
619     char *lines[] = {
620       ",",
621       NULL
622     };
623     int r;
624     suppress_error = 0;
625     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
626     if (r == -1)
627       return -1;
628   }
629   {
630     int r;
631     suppress_error = 0;
632     r = guestfs_pvcreate (g, "/dev/sda1");
633     if (r == -1)
634       return -1;
635   }
636   {
637     char *physvols[] = {
638       "/dev/sda1",
639       NULL
640     };
641     int r;
642     suppress_error = 0;
643     r = guestfs_vgcreate (g, "VG", physvols);
644     if (r == -1)
645       return -1;
646   }
647   {
648     int r;
649     suppress_error = 0;
650     r = guestfs_lvcreate (g, "LV", "VG", 8);
651     if (r == -1)
652       return -1;
653   }
654   {
655     int r;
656     suppress_error = 0;
657     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
658     if (r == -1)
659       return -1;
660   }
661   {
662     int r;
663     suppress_error = 0;
664     r = guestfs_mount (g, "/dev/VG/LV", "/");
665     if (r == -1)
666       return -1;
667   }
668   /* TestOutputList for pvs (0) */
669   {
670     char **r;
671     int i;
672     suppress_error = 0;
673     r = guestfs_pvs (g);
674     if (r == NULL)
675       return -1;
676     if (!r[0]) {
677       fprintf (stderr, "test_pvs_0: short list returned from command\n");
678       print_strings (r);
679       return -1;
680     }
681     if (strcmp (r[0], "/dev/sda1") != 0) {
682       fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
683       return -1;
684     }
685     if (r[1] != NULL) {
686       fprintf (stderr, "test_pvs_0: extra elements returned from command\n");
687       print_strings (r);
688       return -1;
689     }
690     for (i = 0; r[i] != NULL; ++i)
691       free (r[i]);
692     free (r);
693   }
694   return 0;
695 }
696
697 static int test_pvs_1 (void)
698 {
699   /* InitNone for pvs (1) */
700   {
701     int r;
702     suppress_error = 0;
703     r = guestfs_umount_all (g);
704     if (r == -1)
705       return -1;
706   }
707   {
708     int r;
709     suppress_error = 0;
710     r = guestfs_lvm_remove_all (g);
711     if (r == -1)
712       return -1;
713   }
714   /* TestOutputList for pvs (1) */
715   {
716     char *lines[] = {
717       ",10",
718       ",20",
719       ",",
720       NULL
721     };
722     int r;
723     suppress_error = 0;
724     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
725     if (r == -1)
726       return -1;
727   }
728   {
729     int r;
730     suppress_error = 0;
731     r = guestfs_pvcreate (g, "/dev/sda1");
732     if (r == -1)
733       return -1;
734   }
735   {
736     int r;
737     suppress_error = 0;
738     r = guestfs_pvcreate (g, "/dev/sda2");
739     if (r == -1)
740       return -1;
741   }
742   {
743     int r;
744     suppress_error = 0;
745     r = guestfs_pvcreate (g, "/dev/sda3");
746     if (r == -1)
747       return -1;
748   }
749   {
750     char **r;
751     int i;
752     suppress_error = 0;
753     r = guestfs_pvs (g);
754     if (r == NULL)
755       return -1;
756     if (!r[0]) {
757       fprintf (stderr, "test_pvs_1: short list returned from command\n");
758       print_strings (r);
759       return -1;
760     }
761     if (strcmp (r[0], "/dev/sda1") != 0) {
762       fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
763       return -1;
764     }
765     if (!r[1]) {
766       fprintf (stderr, "test_pvs_1: short list returned from command\n");
767       print_strings (r);
768       return -1;
769     }
770     if (strcmp (r[1], "/dev/sda2") != 0) {
771       fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
772       return -1;
773     }
774     if (!r[2]) {
775       fprintf (stderr, "test_pvs_1: short list returned from command\n");
776       print_strings (r);
777       return -1;
778     }
779     if (strcmp (r[2], "/dev/sda3") != 0) {
780       fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
781       return -1;
782     }
783     if (r[3] != NULL) {
784       fprintf (stderr, "test_pvs_1: extra elements returned from command\n");
785       print_strings (r);
786       return -1;
787     }
788     for (i = 0; r[i] != NULL; ++i)
789       free (r[i]);
790     free (r);
791   }
792   return 0;
793 }
794
795 static int test_vgs_0 (void)
796 {
797   /* InitEmptyLVM for vgs (0): create ext2 on /dev/VG/LV */
798   {
799     int r;
800     suppress_error = 0;
801     r = guestfs_umount_all (g);
802     if (r == -1)
803       return -1;
804   }
805   {
806     int r;
807     suppress_error = 0;
808     r = guestfs_lvm_remove_all (g);
809     if (r == -1)
810       return -1;
811   }
812   {
813     char *lines[] = {
814       ",",
815       NULL
816     };
817     int r;
818     suppress_error = 0;
819     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
820     if (r == -1)
821       return -1;
822   }
823   {
824     int r;
825     suppress_error = 0;
826     r = guestfs_pvcreate (g, "/dev/sda1");
827     if (r == -1)
828       return -1;
829   }
830   {
831     char *physvols[] = {
832       "/dev/sda1",
833       NULL
834     };
835     int r;
836     suppress_error = 0;
837     r = guestfs_vgcreate (g, "VG", physvols);
838     if (r == -1)
839       return -1;
840   }
841   {
842     int r;
843     suppress_error = 0;
844     r = guestfs_lvcreate (g, "LV", "VG", 8);
845     if (r == -1)
846       return -1;
847   }
848   {
849     int r;
850     suppress_error = 0;
851     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
852     if (r == -1)
853       return -1;
854   }
855   {
856     int r;
857     suppress_error = 0;
858     r = guestfs_mount (g, "/dev/VG/LV", "/");
859     if (r == -1)
860       return -1;
861   }
862   /* TestOutputList for vgs (0) */
863   {
864     char **r;
865     int i;
866     suppress_error = 0;
867     r = guestfs_vgs (g);
868     if (r == NULL)
869       return -1;
870     if (!r[0]) {
871       fprintf (stderr, "test_vgs_0: short list returned from command\n");
872       print_strings (r);
873       return -1;
874     }
875     if (strcmp (r[0], "VG") != 0) {
876       fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]);
877       return -1;
878     }
879     if (r[1] != NULL) {
880       fprintf (stderr, "test_vgs_0: extra elements returned from command\n");
881       print_strings (r);
882       return -1;
883     }
884     for (i = 0; r[i] != NULL; ++i)
885       free (r[i]);
886     free (r);
887   }
888   return 0;
889 }
890
891 static int test_vgs_1 (void)
892 {
893   /* InitNone for vgs (1) */
894   {
895     int r;
896     suppress_error = 0;
897     r = guestfs_umount_all (g);
898     if (r == -1)
899       return -1;
900   }
901   {
902     int r;
903     suppress_error = 0;
904     r = guestfs_lvm_remove_all (g);
905     if (r == -1)
906       return -1;
907   }
908   /* TestOutputList for vgs (1) */
909   {
910     char *lines[] = {
911       ",10",
912       ",20",
913       ",",
914       NULL
915     };
916     int r;
917     suppress_error = 0;
918     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
919     if (r == -1)
920       return -1;
921   }
922   {
923     int r;
924     suppress_error = 0;
925     r = guestfs_pvcreate (g, "/dev/sda1");
926     if (r == -1)
927       return -1;
928   }
929   {
930     int r;
931     suppress_error = 0;
932     r = guestfs_pvcreate (g, "/dev/sda2");
933     if (r == -1)
934       return -1;
935   }
936   {
937     int r;
938     suppress_error = 0;
939     r = guestfs_pvcreate (g, "/dev/sda3");
940     if (r == -1)
941       return -1;
942   }
943   {
944     char *physvols[] = {
945       "/dev/sda1",
946       "/dev/sda2",
947       NULL
948     };
949     int r;
950     suppress_error = 0;
951     r = guestfs_vgcreate (g, "VG1", physvols);
952     if (r == -1)
953       return -1;
954   }
955   {
956     char *physvols[] = {
957       "/dev/sda3",
958       NULL
959     };
960     int r;
961     suppress_error = 0;
962     r = guestfs_vgcreate (g, "VG2", physvols);
963     if (r == -1)
964       return -1;
965   }
966   {
967     char **r;
968     int i;
969     suppress_error = 0;
970     r = guestfs_vgs (g);
971     if (r == NULL)
972       return -1;
973     if (!r[0]) {
974       fprintf (stderr, "test_vgs_1: short list returned from command\n");
975       print_strings (r);
976       return -1;
977     }
978     if (strcmp (r[0], "VG1") != 0) {
979       fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]);
980       return -1;
981     }
982     if (!r[1]) {
983       fprintf (stderr, "test_vgs_1: short list returned from command\n");
984       print_strings (r);
985       return -1;
986     }
987     if (strcmp (r[1], "VG2") != 0) {
988       fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]);
989       return -1;
990     }
991     if (r[2] != NULL) {
992       fprintf (stderr, "test_vgs_1: extra elements returned from command\n");
993       print_strings (r);
994       return -1;
995     }
996     for (i = 0; r[i] != NULL; ++i)
997       free (r[i]);
998     free (r);
999   }
1000   return 0;
1001 }
1002
1003 static int test_lvs_0 (void)
1004 {
1005   /* InitEmptyLVM for lvs (0): create ext2 on /dev/VG/LV */
1006   {
1007     int r;
1008     suppress_error = 0;
1009     r = guestfs_umount_all (g);
1010     if (r == -1)
1011       return -1;
1012   }
1013   {
1014     int r;
1015     suppress_error = 0;
1016     r = guestfs_lvm_remove_all (g);
1017     if (r == -1)
1018       return -1;
1019   }
1020   {
1021     char *lines[] = {
1022       ",",
1023       NULL
1024     };
1025     int r;
1026     suppress_error = 0;
1027     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1028     if (r == -1)
1029       return -1;
1030   }
1031   {
1032     int r;
1033     suppress_error = 0;
1034     r = guestfs_pvcreate (g, "/dev/sda1");
1035     if (r == -1)
1036       return -1;
1037   }
1038   {
1039     char *physvols[] = {
1040       "/dev/sda1",
1041       NULL
1042     };
1043     int r;
1044     suppress_error = 0;
1045     r = guestfs_vgcreate (g, "VG", physvols);
1046     if (r == -1)
1047       return -1;
1048   }
1049   {
1050     int r;
1051     suppress_error = 0;
1052     r = guestfs_lvcreate (g, "LV", "VG", 8);
1053     if (r == -1)
1054       return -1;
1055   }
1056   {
1057     int r;
1058     suppress_error = 0;
1059     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
1060     if (r == -1)
1061       return -1;
1062   }
1063   {
1064     int r;
1065     suppress_error = 0;
1066     r = guestfs_mount (g, "/dev/VG/LV", "/");
1067     if (r == -1)
1068       return -1;
1069   }
1070   /* TestOutputList for lvs (0) */
1071   {
1072     char **r;
1073     int i;
1074     suppress_error = 0;
1075     r = guestfs_lvs (g);
1076     if (r == NULL)
1077       return -1;
1078     if (!r[0]) {
1079       fprintf (stderr, "test_lvs_0: short list returned from command\n");
1080       print_strings (r);
1081       return -1;
1082     }
1083     if (strcmp (r[0], "/dev/VG/LV") != 0) {
1084       fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]);
1085       return -1;
1086     }
1087     if (r[1] != NULL) {
1088       fprintf (stderr, "test_lvs_0: extra elements returned from command\n");
1089       print_strings (r);
1090       return -1;
1091     }
1092     for (i = 0; r[i] != NULL; ++i)
1093       free (r[i]);
1094     free (r);
1095   }
1096   return 0;
1097 }
1098
1099 static int test_lvs_1 (void)
1100 {
1101   /* InitNone for lvs (1) */
1102   {
1103     int r;
1104     suppress_error = 0;
1105     r = guestfs_umount_all (g);
1106     if (r == -1)
1107       return -1;
1108   }
1109   {
1110     int r;
1111     suppress_error = 0;
1112     r = guestfs_lvm_remove_all (g);
1113     if (r == -1)
1114       return -1;
1115   }
1116   /* TestOutputList for lvs (1) */
1117   {
1118     char *lines[] = {
1119       ",10",
1120       ",20",
1121       ",",
1122       NULL
1123     };
1124     int r;
1125     suppress_error = 0;
1126     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1127     if (r == -1)
1128       return -1;
1129   }
1130   {
1131     int r;
1132     suppress_error = 0;
1133     r = guestfs_pvcreate (g, "/dev/sda1");
1134     if (r == -1)
1135       return -1;
1136   }
1137   {
1138     int r;
1139     suppress_error = 0;
1140     r = guestfs_pvcreate (g, "/dev/sda2");
1141     if (r == -1)
1142       return -1;
1143   }
1144   {
1145     int r;
1146     suppress_error = 0;
1147     r = guestfs_pvcreate (g, "/dev/sda3");
1148     if (r == -1)
1149       return -1;
1150   }
1151   {
1152     char *physvols[] = {
1153       "/dev/sda1",
1154       "/dev/sda2",
1155       NULL
1156     };
1157     int r;
1158     suppress_error = 0;
1159     r = guestfs_vgcreate (g, "VG1", physvols);
1160     if (r == -1)
1161       return -1;
1162   }
1163   {
1164     char *physvols[] = {
1165       "/dev/sda3",
1166       NULL
1167     };
1168     int r;
1169     suppress_error = 0;
1170     r = guestfs_vgcreate (g, "VG2", physvols);
1171     if (r == -1)
1172       return -1;
1173   }
1174   {
1175     int r;
1176     suppress_error = 0;
1177     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
1178     if (r == -1)
1179       return -1;
1180   }
1181   {
1182     int r;
1183     suppress_error = 0;
1184     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
1185     if (r == -1)
1186       return -1;
1187   }
1188   {
1189     int r;
1190     suppress_error = 0;
1191     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
1192     if (r == -1)
1193       return -1;
1194   }
1195   {
1196     char **r;
1197     int i;
1198     suppress_error = 0;
1199     r = guestfs_lvs (g);
1200     if (r == NULL)
1201       return -1;
1202     if (!r[0]) {
1203       fprintf (stderr, "test_lvs_1: short list returned from command\n");
1204       print_strings (r);
1205       return -1;
1206     }
1207     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
1208       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
1209       return -1;
1210     }
1211     if (!r[1]) {
1212       fprintf (stderr, "test_lvs_1: short list returned from command\n");
1213       print_strings (r);
1214       return -1;
1215     }
1216     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
1217       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
1218       return -1;
1219     }
1220     if (!r[2]) {
1221       fprintf (stderr, "test_lvs_1: short list returned from command\n");
1222       print_strings (r);
1223       return -1;
1224     }
1225     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
1226       fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
1227       return -1;
1228     }
1229     if (r[3] != NULL) {
1230       fprintf (stderr, "test_lvs_1: extra elements returned from command\n");
1231       print_strings (r);
1232       return -1;
1233     }
1234     for (i = 0; r[i] != NULL; ++i)
1235       free (r[i]);
1236     free (r);
1237   }
1238   return 0;
1239 }
1240
1241 static int test_pvs_full_0 (void)
1242 {
1243   /* InitEmptyLVM for pvs_full (0): create ext2 on /dev/VG/LV */
1244   {
1245     int r;
1246     suppress_error = 0;
1247     r = guestfs_umount_all (g);
1248     if (r == -1)
1249       return -1;
1250   }
1251   {
1252     int r;
1253     suppress_error = 0;
1254     r = guestfs_lvm_remove_all (g);
1255     if (r == -1)
1256       return -1;
1257   }
1258   {
1259     char *lines[] = {
1260       ",",
1261       NULL
1262     };
1263     int r;
1264     suppress_error = 0;
1265     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1266     if (r == -1)
1267       return -1;
1268   }
1269   {
1270     int r;
1271     suppress_error = 0;
1272     r = guestfs_pvcreate (g, "/dev/sda1");
1273     if (r == -1)
1274       return -1;
1275   }
1276   {
1277     char *physvols[] = {
1278       "/dev/sda1",
1279       NULL
1280     };
1281     int r;
1282     suppress_error = 0;
1283     r = guestfs_vgcreate (g, "VG", physvols);
1284     if (r == -1)
1285       return -1;
1286   }
1287   {
1288     int r;
1289     suppress_error = 0;
1290     r = guestfs_lvcreate (g, "LV", "VG", 8);
1291     if (r == -1)
1292       return -1;
1293   }
1294   {
1295     int r;
1296     suppress_error = 0;
1297     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
1298     if (r == -1)
1299       return -1;
1300   }
1301   {
1302     int r;
1303     suppress_error = 0;
1304     r = guestfs_mount (g, "/dev/VG/LV", "/");
1305     if (r == -1)
1306       return -1;
1307   }
1308   /* TestOutputLength for pvs_full (0) */
1309   {
1310     char **r;
1311     int i;
1312     suppress_error = 0;
1313     r = guestfs_pvs (g);
1314     if (r == NULL)
1315       return -1;
1316     int j;
1317     for (j = 0; j < 1; ++j)
1318       if (r[j] == NULL) {
1319         fprintf (stderr, "test_pvs_full_0: short list returned\n");
1320         print_strings (r);
1321         return -1;
1322       }
1323     if (r[j] != NULL) {
1324       fprintf (stderr, "test_pvs_full_0: long list returned\n");
1325       print_strings (r);
1326       return -1;
1327     }
1328     for (i = 0; r[i] != NULL; ++i)
1329       free (r[i]);
1330     free (r);
1331   }
1332   return 0;
1333 }
1334
1335 static int test_vgs_full_0 (void)
1336 {
1337   /* InitEmptyLVM for vgs_full (0): create ext2 on /dev/VG/LV */
1338   {
1339     int r;
1340     suppress_error = 0;
1341     r = guestfs_umount_all (g);
1342     if (r == -1)
1343       return -1;
1344   }
1345   {
1346     int r;
1347     suppress_error = 0;
1348     r = guestfs_lvm_remove_all (g);
1349     if (r == -1)
1350       return -1;
1351   }
1352   {
1353     char *lines[] = {
1354       ",",
1355       NULL
1356     };
1357     int r;
1358     suppress_error = 0;
1359     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1360     if (r == -1)
1361       return -1;
1362   }
1363   {
1364     int r;
1365     suppress_error = 0;
1366     r = guestfs_pvcreate (g, "/dev/sda1");
1367     if (r == -1)
1368       return -1;
1369   }
1370   {
1371     char *physvols[] = {
1372       "/dev/sda1",
1373       NULL
1374     };
1375     int r;
1376     suppress_error = 0;
1377     r = guestfs_vgcreate (g, "VG", physvols);
1378     if (r == -1)
1379       return -1;
1380   }
1381   {
1382     int r;
1383     suppress_error = 0;
1384     r = guestfs_lvcreate (g, "LV", "VG", 8);
1385     if (r == -1)
1386       return -1;
1387   }
1388   {
1389     int r;
1390     suppress_error = 0;
1391     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
1392     if (r == -1)
1393       return -1;
1394   }
1395   {
1396     int r;
1397     suppress_error = 0;
1398     r = guestfs_mount (g, "/dev/VG/LV", "/");
1399     if (r == -1)
1400       return -1;
1401   }
1402   /* TestOutputLength for vgs_full (0) */
1403   {
1404     char **r;
1405     int i;
1406     suppress_error = 0;
1407     r = guestfs_pvs (g);
1408     if (r == NULL)
1409       return -1;
1410     int j;
1411     for (j = 0; j < 1; ++j)
1412       if (r[j] == NULL) {
1413         fprintf (stderr, "test_vgs_full_0: short list returned\n");
1414         print_strings (r);
1415         return -1;
1416       }
1417     if (r[j] != NULL) {
1418       fprintf (stderr, "test_vgs_full_0: long list returned\n");
1419       print_strings (r);
1420       return -1;
1421     }
1422     for (i = 0; r[i] != NULL; ++i)
1423       free (r[i]);
1424     free (r);
1425   }
1426   return 0;
1427 }
1428
1429 static int test_lvs_full_0 (void)
1430 {
1431   /* InitEmptyLVM for lvs_full (0): create ext2 on /dev/VG/LV */
1432   {
1433     int r;
1434     suppress_error = 0;
1435     r = guestfs_umount_all (g);
1436     if (r == -1)
1437       return -1;
1438   }
1439   {
1440     int r;
1441     suppress_error = 0;
1442     r = guestfs_lvm_remove_all (g);
1443     if (r == -1)
1444       return -1;
1445   }
1446   {
1447     char *lines[] = {
1448       ",",
1449       NULL
1450     };
1451     int r;
1452     suppress_error = 0;
1453     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1454     if (r == -1)
1455       return -1;
1456   }
1457   {
1458     int r;
1459     suppress_error = 0;
1460     r = guestfs_pvcreate (g, "/dev/sda1");
1461     if (r == -1)
1462       return -1;
1463   }
1464   {
1465     char *physvols[] = {
1466       "/dev/sda1",
1467       NULL
1468     };
1469     int r;
1470     suppress_error = 0;
1471     r = guestfs_vgcreate (g, "VG", physvols);
1472     if (r == -1)
1473       return -1;
1474   }
1475   {
1476     int r;
1477     suppress_error = 0;
1478     r = guestfs_lvcreate (g, "LV", "VG", 8);
1479     if (r == -1)
1480       return -1;
1481   }
1482   {
1483     int r;
1484     suppress_error = 0;
1485     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
1486     if (r == -1)
1487       return -1;
1488   }
1489   {
1490     int r;
1491     suppress_error = 0;
1492     r = guestfs_mount (g, "/dev/VG/LV", "/");
1493     if (r == -1)
1494       return -1;
1495   }
1496   /* TestOutputLength for lvs_full (0) */
1497   {
1498     char **r;
1499     int i;
1500     suppress_error = 0;
1501     r = guestfs_pvs (g);
1502     if (r == NULL)
1503       return -1;
1504     int j;
1505     for (j = 0; j < 1; ++j)
1506       if (r[j] == NULL) {
1507         fprintf (stderr, "test_lvs_full_0: short list returned\n");
1508         print_strings (r);
1509         return -1;
1510       }
1511     if (r[j] != NULL) {
1512       fprintf (stderr, "test_lvs_full_0: long list returned\n");
1513       print_strings (r);
1514       return -1;
1515     }
1516     for (i = 0; r[i] != NULL; ++i)
1517       free (r[i]);
1518     free (r);
1519   }
1520   return 0;
1521 }
1522
1523 static int test_read_lines_0 (void)
1524 {
1525   /* InitEmpty for read_lines (0): create ext2 on /dev/sda1 */
1526   {
1527     int r;
1528     suppress_error = 0;
1529     r = guestfs_umount_all (g);
1530     if (r == -1)
1531       return -1;
1532   }
1533   {
1534     int r;
1535     suppress_error = 0;
1536     r = guestfs_lvm_remove_all (g);
1537     if (r == -1)
1538       return -1;
1539   }
1540   {
1541     char *lines[] = {
1542       ",",
1543       NULL
1544     };
1545     int r;
1546     suppress_error = 0;
1547     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1548     if (r == -1)
1549       return -1;
1550   }
1551   {
1552     int r;
1553     suppress_error = 0;
1554     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1555     if (r == -1)
1556       return -1;
1557   }
1558   {
1559     int r;
1560     suppress_error = 0;
1561     r = guestfs_mount (g, "/dev/sda1", "/");
1562     if (r == -1)
1563       return -1;
1564   }
1565   /* TestOutputList for read_lines (0) */
1566   {
1567     int r;
1568     suppress_error = 0;
1569     r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0);
1570     if (r == -1)
1571       return -1;
1572   }
1573   {
1574     char **r;
1575     int i;
1576     suppress_error = 0;
1577     r = guestfs_read_lines (g, "/new");
1578     if (r == NULL)
1579       return -1;
1580     if (!r[0]) {
1581       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
1582       print_strings (r);
1583       return -1;
1584     }
1585     if (strcmp (r[0], "line1") != 0) {
1586       fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]);
1587       return -1;
1588     }
1589     if (!r[1]) {
1590       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
1591       print_strings (r);
1592       return -1;
1593     }
1594     if (strcmp (r[1], "line2") != 0) {
1595       fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]);
1596       return -1;
1597     }
1598     if (!r[2]) {
1599       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
1600       print_strings (r);
1601       return -1;
1602     }
1603     if (strcmp (r[2], "line3") != 0) {
1604       fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]);
1605       return -1;
1606     }
1607     if (r[3] != NULL) {
1608       fprintf (stderr, "test_read_lines_0: extra elements returned from command\n");
1609       print_strings (r);
1610       return -1;
1611     }
1612     for (i = 0; r[i] != NULL; ++i)
1613       free (r[i]);
1614     free (r);
1615   }
1616   return 0;
1617 }
1618
1619 static int test_read_lines_1 (void)
1620 {
1621   /* InitEmpty for read_lines (1): create ext2 on /dev/sda1 */
1622   {
1623     int r;
1624     suppress_error = 0;
1625     r = guestfs_umount_all (g);
1626     if (r == -1)
1627       return -1;
1628   }
1629   {
1630     int r;
1631     suppress_error = 0;
1632     r = guestfs_lvm_remove_all (g);
1633     if (r == -1)
1634       return -1;
1635   }
1636   {
1637     char *lines[] = {
1638       ",",
1639       NULL
1640     };
1641     int r;
1642     suppress_error = 0;
1643     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1644     if (r == -1)
1645       return -1;
1646   }
1647   {
1648     int r;
1649     suppress_error = 0;
1650     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1651     if (r == -1)
1652       return -1;
1653   }
1654   {
1655     int r;
1656     suppress_error = 0;
1657     r = guestfs_mount (g, "/dev/sda1", "/");
1658     if (r == -1)
1659       return -1;
1660   }
1661   /* TestOutputList for read_lines (1) */
1662   {
1663     int r;
1664     suppress_error = 0;
1665     r = guestfs_write_file (g, "/new", "", 0);
1666     if (r == -1)
1667       return -1;
1668   }
1669   {
1670     char **r;
1671     int i;
1672     suppress_error = 0;
1673     r = guestfs_read_lines (g, "/new");
1674     if (r == NULL)
1675       return -1;
1676     if (r[0] != NULL) {
1677       fprintf (stderr, "test_read_lines_1: extra elements returned from command\n");
1678       print_strings (r);
1679       return -1;
1680     }
1681     for (i = 0; r[i] != NULL; ++i)
1682       free (r[i]);
1683     free (r);
1684   }
1685   return 0;
1686 }
1687
1688 static int test_rm_0 (void)
1689 {
1690   /* InitEmpty for rm (0): create ext2 on /dev/sda1 */
1691   {
1692     int r;
1693     suppress_error = 0;
1694     r = guestfs_umount_all (g);
1695     if (r == -1)
1696       return -1;
1697   }
1698   {
1699     int r;
1700     suppress_error = 0;
1701     r = guestfs_lvm_remove_all (g);
1702     if (r == -1)
1703       return -1;
1704   }
1705   {
1706     char *lines[] = {
1707       ",",
1708       NULL
1709     };
1710     int r;
1711     suppress_error = 0;
1712     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1713     if (r == -1)
1714       return -1;
1715   }
1716   {
1717     int r;
1718     suppress_error = 0;
1719     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1720     if (r == -1)
1721       return -1;
1722   }
1723   {
1724     int r;
1725     suppress_error = 0;
1726     r = guestfs_mount (g, "/dev/sda1", "/");
1727     if (r == -1)
1728       return -1;
1729   }
1730   /* TestRun for rm (0) */
1731   {
1732     int r;
1733     suppress_error = 0;
1734     r = guestfs_touch (g, "/new");
1735     if (r == -1)
1736       return -1;
1737   }
1738   {
1739     int r;
1740     suppress_error = 0;
1741     r = guestfs_rm (g, "/new");
1742     if (r == -1)
1743       return -1;
1744   }
1745   return 0;
1746 }
1747
1748 static int test_rm_1 (void)
1749 {
1750   /* InitEmpty for rm (1): create ext2 on /dev/sda1 */
1751   {
1752     int r;
1753     suppress_error = 0;
1754     r = guestfs_umount_all (g);
1755     if (r == -1)
1756       return -1;
1757   }
1758   {
1759     int r;
1760     suppress_error = 0;
1761     r = guestfs_lvm_remove_all (g);
1762     if (r == -1)
1763       return -1;
1764   }
1765   {
1766     char *lines[] = {
1767       ",",
1768       NULL
1769     };
1770     int r;
1771     suppress_error = 0;
1772     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1773     if (r == -1)
1774       return -1;
1775   }
1776   {
1777     int r;
1778     suppress_error = 0;
1779     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1780     if (r == -1)
1781       return -1;
1782   }
1783   {
1784     int r;
1785     suppress_error = 0;
1786     r = guestfs_mount (g, "/dev/sda1", "/");
1787     if (r == -1)
1788       return -1;
1789   }
1790   /* TestLastFail for rm (1) */
1791   {
1792     int r;
1793     suppress_error = 1;
1794     r = guestfs_rm (g, "/new");
1795     if (r != -1)
1796       return -1;
1797   }
1798   return 0;
1799 }
1800
1801 static int test_rm_2 (void)
1802 {
1803   /* InitEmpty for rm (2): create ext2 on /dev/sda1 */
1804   {
1805     int r;
1806     suppress_error = 0;
1807     r = guestfs_umount_all (g);
1808     if (r == -1)
1809       return -1;
1810   }
1811   {
1812     int r;
1813     suppress_error = 0;
1814     r = guestfs_lvm_remove_all (g);
1815     if (r == -1)
1816       return -1;
1817   }
1818   {
1819     char *lines[] = {
1820       ",",
1821       NULL
1822     };
1823     int r;
1824     suppress_error = 0;
1825     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1826     if (r == -1)
1827       return -1;
1828   }
1829   {
1830     int r;
1831     suppress_error = 0;
1832     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1833     if (r == -1)
1834       return -1;
1835   }
1836   {
1837     int r;
1838     suppress_error = 0;
1839     r = guestfs_mount (g, "/dev/sda1", "/");
1840     if (r == -1)
1841       return -1;
1842   }
1843   /* TestLastFail for rm (2) */
1844   {
1845     int r;
1846     suppress_error = 0;
1847     r = guestfs_mkdir (g, "/new");
1848     if (r == -1)
1849       return -1;
1850   }
1851   {
1852     int r;
1853     suppress_error = 1;
1854     r = guestfs_rm (g, "/new");
1855     if (r != -1)
1856       return -1;
1857   }
1858   return 0;
1859 }
1860
1861 static int test_rmdir_0 (void)
1862 {
1863   /* InitEmpty for rmdir (0): create ext2 on /dev/sda1 */
1864   {
1865     int r;
1866     suppress_error = 0;
1867     r = guestfs_umount_all (g);
1868     if (r == -1)
1869       return -1;
1870   }
1871   {
1872     int r;
1873     suppress_error = 0;
1874     r = guestfs_lvm_remove_all (g);
1875     if (r == -1)
1876       return -1;
1877   }
1878   {
1879     char *lines[] = {
1880       ",",
1881       NULL
1882     };
1883     int r;
1884     suppress_error = 0;
1885     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1886     if (r == -1)
1887       return -1;
1888   }
1889   {
1890     int r;
1891     suppress_error = 0;
1892     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1893     if (r == -1)
1894       return -1;
1895   }
1896   {
1897     int r;
1898     suppress_error = 0;
1899     r = guestfs_mount (g, "/dev/sda1", "/");
1900     if (r == -1)
1901       return -1;
1902   }
1903   /* TestRun for rmdir (0) */
1904   {
1905     int r;
1906     suppress_error = 0;
1907     r = guestfs_mkdir (g, "/new");
1908     if (r == -1)
1909       return -1;
1910   }
1911   {
1912     int r;
1913     suppress_error = 0;
1914     r = guestfs_rmdir (g, "/new");
1915     if (r == -1)
1916       return -1;
1917   }
1918   return 0;
1919 }
1920
1921 static int test_rmdir_1 (void)
1922 {
1923   /* InitEmpty for rmdir (1): create ext2 on /dev/sda1 */
1924   {
1925     int r;
1926     suppress_error = 0;
1927     r = guestfs_umount_all (g);
1928     if (r == -1)
1929       return -1;
1930   }
1931   {
1932     int r;
1933     suppress_error = 0;
1934     r = guestfs_lvm_remove_all (g);
1935     if (r == -1)
1936       return -1;
1937   }
1938   {
1939     char *lines[] = {
1940       ",",
1941       NULL
1942     };
1943     int r;
1944     suppress_error = 0;
1945     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1946     if (r == -1)
1947       return -1;
1948   }
1949   {
1950     int r;
1951     suppress_error = 0;
1952     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1953     if (r == -1)
1954       return -1;
1955   }
1956   {
1957     int r;
1958     suppress_error = 0;
1959     r = guestfs_mount (g, "/dev/sda1", "/");
1960     if (r == -1)
1961       return -1;
1962   }
1963   /* TestLastFail for rmdir (1) */
1964   {
1965     int r;
1966     suppress_error = 1;
1967     r = guestfs_rmdir (g, "/new");
1968     if (r != -1)
1969       return -1;
1970   }
1971   return 0;
1972 }
1973
1974 static int test_rmdir_2 (void)
1975 {
1976   /* InitEmpty for rmdir (2): create ext2 on /dev/sda1 */
1977   {
1978     int r;
1979     suppress_error = 0;
1980     r = guestfs_umount_all (g);
1981     if (r == -1)
1982       return -1;
1983   }
1984   {
1985     int r;
1986     suppress_error = 0;
1987     r = guestfs_lvm_remove_all (g);
1988     if (r == -1)
1989       return -1;
1990   }
1991   {
1992     char *lines[] = {
1993       ",",
1994       NULL
1995     };
1996     int r;
1997     suppress_error = 0;
1998     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1999     if (r == -1)
2000       return -1;
2001   }
2002   {
2003     int r;
2004     suppress_error = 0;
2005     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2006     if (r == -1)
2007       return -1;
2008   }
2009   {
2010     int r;
2011     suppress_error = 0;
2012     r = guestfs_mount (g, "/dev/sda1", "/");
2013     if (r == -1)
2014       return -1;
2015   }
2016   /* TestLastFail for rmdir (2) */
2017   {
2018     int r;
2019     suppress_error = 0;
2020     r = guestfs_touch (g, "/new");
2021     if (r == -1)
2022       return -1;
2023   }
2024   {
2025     int r;
2026     suppress_error = 1;
2027     r = guestfs_rmdir (g, "/new");
2028     if (r != -1)
2029       return -1;
2030   }
2031   return 0;
2032 }
2033
2034 static int test_rm_rf_0 (void)
2035 {
2036   /* InitEmpty for rm_rf (0): create ext2 on /dev/sda1 */
2037   {
2038     int r;
2039     suppress_error = 0;
2040     r = guestfs_umount_all (g);
2041     if (r == -1)
2042       return -1;
2043   }
2044   {
2045     int r;
2046     suppress_error = 0;
2047     r = guestfs_lvm_remove_all (g);
2048     if (r == -1)
2049       return -1;
2050   }
2051   {
2052     char *lines[] = {
2053       ",",
2054       NULL
2055     };
2056     int r;
2057     suppress_error = 0;
2058     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2059     if (r == -1)
2060       return -1;
2061   }
2062   {
2063     int r;
2064     suppress_error = 0;
2065     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2066     if (r == -1)
2067       return -1;
2068   }
2069   {
2070     int r;
2071     suppress_error = 0;
2072     r = guestfs_mount (g, "/dev/sda1", "/");
2073     if (r == -1)
2074       return -1;
2075   }
2076   /* TestOutputFalse for rm_rf (0) */
2077   {
2078     int r;
2079     suppress_error = 0;
2080     r = guestfs_mkdir (g, "/new");
2081     if (r == -1)
2082       return -1;
2083   }
2084   {
2085     int r;
2086     suppress_error = 0;
2087     r = guestfs_mkdir (g, "/new/foo");
2088     if (r == -1)
2089       return -1;
2090   }
2091   {
2092     int r;
2093     suppress_error = 0;
2094     r = guestfs_touch (g, "/new/foo/bar");
2095     if (r == -1)
2096       return -1;
2097   }
2098   {
2099     int r;
2100     suppress_error = 0;
2101     r = guestfs_rm_rf (g, "/new");
2102     if (r == -1)
2103       return -1;
2104   }
2105   {
2106     int r;
2107     suppress_error = 0;
2108     r = guestfs_exists (g, "/new");
2109     if (r == -1)
2110       return -1;
2111     if (r) {
2112       fprintf (stderr, "test_rm_rf_0: expected false, got true\n");
2113       return -1;
2114     }
2115   }
2116   return 0;
2117 }
2118
2119 static int test_mkdir_0 (void)
2120 {
2121   /* InitEmpty for mkdir (0): create ext2 on /dev/sda1 */
2122   {
2123     int r;
2124     suppress_error = 0;
2125     r = guestfs_umount_all (g);
2126     if (r == -1)
2127       return -1;
2128   }
2129   {
2130     int r;
2131     suppress_error = 0;
2132     r = guestfs_lvm_remove_all (g);
2133     if (r == -1)
2134       return -1;
2135   }
2136   {
2137     char *lines[] = {
2138       ",",
2139       NULL
2140     };
2141     int r;
2142     suppress_error = 0;
2143     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2144     if (r == -1)
2145       return -1;
2146   }
2147   {
2148     int r;
2149     suppress_error = 0;
2150     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2151     if (r == -1)
2152       return -1;
2153   }
2154   {
2155     int r;
2156     suppress_error = 0;
2157     r = guestfs_mount (g, "/dev/sda1", "/");
2158     if (r == -1)
2159       return -1;
2160   }
2161   /* TestOutputTrue for mkdir (0) */
2162   {
2163     int r;
2164     suppress_error = 0;
2165     r = guestfs_mkdir (g, "/new");
2166     if (r == -1)
2167       return -1;
2168   }
2169   {
2170     int r;
2171     suppress_error = 0;
2172     r = guestfs_is_dir (g, "/new");
2173     if (r == -1)
2174       return -1;
2175     if (!r) {
2176       fprintf (stderr, "test_mkdir_0: expected true, got false\n");
2177       return -1;
2178     }
2179   }
2180   return 0;
2181 }
2182
2183 static int test_mkdir_1 (void)
2184 {
2185   /* InitEmpty for mkdir (1): create ext2 on /dev/sda1 */
2186   {
2187     int r;
2188     suppress_error = 0;
2189     r = guestfs_umount_all (g);
2190     if (r == -1)
2191       return -1;
2192   }
2193   {
2194     int r;
2195     suppress_error = 0;
2196     r = guestfs_lvm_remove_all (g);
2197     if (r == -1)
2198       return -1;
2199   }
2200   {
2201     char *lines[] = {
2202       ",",
2203       NULL
2204     };
2205     int r;
2206     suppress_error = 0;
2207     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2208     if (r == -1)
2209       return -1;
2210   }
2211   {
2212     int r;
2213     suppress_error = 0;
2214     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2215     if (r == -1)
2216       return -1;
2217   }
2218   {
2219     int r;
2220     suppress_error = 0;
2221     r = guestfs_mount (g, "/dev/sda1", "/");
2222     if (r == -1)
2223       return -1;
2224   }
2225   /* TestLastFail for mkdir (1) */
2226   {
2227     int r;
2228     suppress_error = 1;
2229     r = guestfs_mkdir (g, "/new/foo/bar");
2230     if (r != -1)
2231       return -1;
2232   }
2233   return 0;
2234 }
2235
2236 static int test_mkdir_p_0 (void)
2237 {
2238   /* InitEmpty for mkdir_p (0): create ext2 on /dev/sda1 */
2239   {
2240     int r;
2241     suppress_error = 0;
2242     r = guestfs_umount_all (g);
2243     if (r == -1)
2244       return -1;
2245   }
2246   {
2247     int r;
2248     suppress_error = 0;
2249     r = guestfs_lvm_remove_all (g);
2250     if (r == -1)
2251       return -1;
2252   }
2253   {
2254     char *lines[] = {
2255       ",",
2256       NULL
2257     };
2258     int r;
2259     suppress_error = 0;
2260     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2261     if (r == -1)
2262       return -1;
2263   }
2264   {
2265     int r;
2266     suppress_error = 0;
2267     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2268     if (r == -1)
2269       return -1;
2270   }
2271   {
2272     int r;
2273     suppress_error = 0;
2274     r = guestfs_mount (g, "/dev/sda1", "/");
2275     if (r == -1)
2276       return -1;
2277   }
2278   /* TestOutputTrue for mkdir_p (0) */
2279   {
2280     int r;
2281     suppress_error = 0;
2282     r = guestfs_mkdir_p (g, "/new/foo/bar");
2283     if (r == -1)
2284       return -1;
2285   }
2286   {
2287     int r;
2288     suppress_error = 0;
2289     r = guestfs_is_dir (g, "/new/foo/bar");
2290     if (r == -1)
2291       return -1;
2292     if (!r) {
2293       fprintf (stderr, "test_mkdir_p_0: expected true, got false\n");
2294       return -1;
2295     }
2296   }
2297   return 0;
2298 }
2299
2300 static int test_mkdir_p_1 (void)
2301 {
2302   /* InitEmpty for mkdir_p (1): create ext2 on /dev/sda1 */
2303   {
2304     int r;
2305     suppress_error = 0;
2306     r = guestfs_umount_all (g);
2307     if (r == -1)
2308       return -1;
2309   }
2310   {
2311     int r;
2312     suppress_error = 0;
2313     r = guestfs_lvm_remove_all (g);
2314     if (r == -1)
2315       return -1;
2316   }
2317   {
2318     char *lines[] = {
2319       ",",
2320       NULL
2321     };
2322     int r;
2323     suppress_error = 0;
2324     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2325     if (r == -1)
2326       return -1;
2327   }
2328   {
2329     int r;
2330     suppress_error = 0;
2331     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2332     if (r == -1)
2333       return -1;
2334   }
2335   {
2336     int r;
2337     suppress_error = 0;
2338     r = guestfs_mount (g, "/dev/sda1", "/");
2339     if (r == -1)
2340       return -1;
2341   }
2342   /* TestOutputTrue for mkdir_p (1) */
2343   {
2344     int r;
2345     suppress_error = 0;
2346     r = guestfs_mkdir_p (g, "/new/foo/bar");
2347     if (r == -1)
2348       return -1;
2349   }
2350   {
2351     int r;
2352     suppress_error = 0;
2353     r = guestfs_is_dir (g, "/new/foo");
2354     if (r == -1)
2355       return -1;
2356     if (!r) {
2357       fprintf (stderr, "test_mkdir_p_1: expected true, got false\n");
2358       return -1;
2359     }
2360   }
2361   return 0;
2362 }
2363
2364 static int test_mkdir_p_2 (void)
2365 {
2366   /* InitEmpty for mkdir_p (2): create ext2 on /dev/sda1 */
2367   {
2368     int r;
2369     suppress_error = 0;
2370     r = guestfs_umount_all (g);
2371     if (r == -1)
2372       return -1;
2373   }
2374   {
2375     int r;
2376     suppress_error = 0;
2377     r = guestfs_lvm_remove_all (g);
2378     if (r == -1)
2379       return -1;
2380   }
2381   {
2382     char *lines[] = {
2383       ",",
2384       NULL
2385     };
2386     int r;
2387     suppress_error = 0;
2388     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2389     if (r == -1)
2390       return -1;
2391   }
2392   {
2393     int r;
2394     suppress_error = 0;
2395     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2396     if (r == -1)
2397       return -1;
2398   }
2399   {
2400     int r;
2401     suppress_error = 0;
2402     r = guestfs_mount (g, "/dev/sda1", "/");
2403     if (r == -1)
2404       return -1;
2405   }
2406   /* TestOutputTrue for mkdir_p (2) */
2407   {
2408     int r;
2409     suppress_error = 0;
2410     r = guestfs_mkdir_p (g, "/new/foo/bar");
2411     if (r == -1)
2412       return -1;
2413   }
2414   {
2415     int r;
2416     suppress_error = 0;
2417     r = guestfs_is_dir (g, "/new");
2418     if (r == -1)
2419       return -1;
2420     if (!r) {
2421       fprintf (stderr, "test_mkdir_p_2: expected true, got false\n");
2422       return -1;
2423     }
2424   }
2425   return 0;
2426 }
2427
2428 static int test_exists_0 (void)
2429 {
2430   /* InitEmpty for exists (0): create ext2 on /dev/sda1 */
2431   {
2432     int r;
2433     suppress_error = 0;
2434     r = guestfs_umount_all (g);
2435     if (r == -1)
2436       return -1;
2437   }
2438   {
2439     int r;
2440     suppress_error = 0;
2441     r = guestfs_lvm_remove_all (g);
2442     if (r == -1)
2443       return -1;
2444   }
2445   {
2446     char *lines[] = {
2447       ",",
2448       NULL
2449     };
2450     int r;
2451     suppress_error = 0;
2452     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2453     if (r == -1)
2454       return -1;
2455   }
2456   {
2457     int r;
2458     suppress_error = 0;
2459     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2460     if (r == -1)
2461       return -1;
2462   }
2463   {
2464     int r;
2465     suppress_error = 0;
2466     r = guestfs_mount (g, "/dev/sda1", "/");
2467     if (r == -1)
2468       return -1;
2469   }
2470   /* TestOutputTrue for exists (0) */
2471   {
2472     int r;
2473     suppress_error = 0;
2474     r = guestfs_touch (g, "/new");
2475     if (r == -1)
2476       return -1;
2477   }
2478   {
2479     int r;
2480     suppress_error = 0;
2481     r = guestfs_exists (g, "/new");
2482     if (r == -1)
2483       return -1;
2484     if (!r) {
2485       fprintf (stderr, "test_exists_0: expected true, got false\n");
2486       return -1;
2487     }
2488   }
2489   return 0;
2490 }
2491
2492 static int test_exists_1 (void)
2493 {
2494   /* InitEmpty for exists (1): create ext2 on /dev/sda1 */
2495   {
2496     int r;
2497     suppress_error = 0;
2498     r = guestfs_umount_all (g);
2499     if (r == -1)
2500       return -1;
2501   }
2502   {
2503     int r;
2504     suppress_error = 0;
2505     r = guestfs_lvm_remove_all (g);
2506     if (r == -1)
2507       return -1;
2508   }
2509   {
2510     char *lines[] = {
2511       ",",
2512       NULL
2513     };
2514     int r;
2515     suppress_error = 0;
2516     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2517     if (r == -1)
2518       return -1;
2519   }
2520   {
2521     int r;
2522     suppress_error = 0;
2523     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2524     if (r == -1)
2525       return -1;
2526   }
2527   {
2528     int r;
2529     suppress_error = 0;
2530     r = guestfs_mount (g, "/dev/sda1", "/");
2531     if (r == -1)
2532       return -1;
2533   }
2534   /* TestOutputTrue for exists (1) */
2535   {
2536     int r;
2537     suppress_error = 0;
2538     r = guestfs_mkdir (g, "/new");
2539     if (r == -1)
2540       return -1;
2541   }
2542   {
2543     int r;
2544     suppress_error = 0;
2545     r = guestfs_exists (g, "/new");
2546     if (r == -1)
2547       return -1;
2548     if (!r) {
2549       fprintf (stderr, "test_exists_1: expected true, got false\n");
2550       return -1;
2551     }
2552   }
2553   return 0;
2554 }
2555
2556 static int test_is_file_0 (void)
2557 {
2558   /* InitEmpty for is_file (0): create ext2 on /dev/sda1 */
2559   {
2560     int r;
2561     suppress_error = 0;
2562     r = guestfs_umount_all (g);
2563     if (r == -1)
2564       return -1;
2565   }
2566   {
2567     int r;
2568     suppress_error = 0;
2569     r = guestfs_lvm_remove_all (g);
2570     if (r == -1)
2571       return -1;
2572   }
2573   {
2574     char *lines[] = {
2575       ",",
2576       NULL
2577     };
2578     int r;
2579     suppress_error = 0;
2580     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2581     if (r == -1)
2582       return -1;
2583   }
2584   {
2585     int r;
2586     suppress_error = 0;
2587     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2588     if (r == -1)
2589       return -1;
2590   }
2591   {
2592     int r;
2593     suppress_error = 0;
2594     r = guestfs_mount (g, "/dev/sda1", "/");
2595     if (r == -1)
2596       return -1;
2597   }
2598   /* TestOutputTrue for is_file (0) */
2599   {
2600     int r;
2601     suppress_error = 0;
2602     r = guestfs_touch (g, "/new");
2603     if (r == -1)
2604       return -1;
2605   }
2606   {
2607     int r;
2608     suppress_error = 0;
2609     r = guestfs_is_file (g, "/new");
2610     if (r == -1)
2611       return -1;
2612     if (!r) {
2613       fprintf (stderr, "test_is_file_0: expected true, got false\n");
2614       return -1;
2615     }
2616   }
2617   return 0;
2618 }
2619
2620 static int test_is_file_1 (void)
2621 {
2622   /* InitEmpty for is_file (1): create ext2 on /dev/sda1 */
2623   {
2624     int r;
2625     suppress_error = 0;
2626     r = guestfs_umount_all (g);
2627     if (r == -1)
2628       return -1;
2629   }
2630   {
2631     int r;
2632     suppress_error = 0;
2633     r = guestfs_lvm_remove_all (g);
2634     if (r == -1)
2635       return -1;
2636   }
2637   {
2638     char *lines[] = {
2639       ",",
2640       NULL
2641     };
2642     int r;
2643     suppress_error = 0;
2644     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2645     if (r == -1)
2646       return -1;
2647   }
2648   {
2649     int r;
2650     suppress_error = 0;
2651     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2652     if (r == -1)
2653       return -1;
2654   }
2655   {
2656     int r;
2657     suppress_error = 0;
2658     r = guestfs_mount (g, "/dev/sda1", "/");
2659     if (r == -1)
2660       return -1;
2661   }
2662   /* TestOutputFalse for is_file (1) */
2663   {
2664     int r;
2665     suppress_error = 0;
2666     r = guestfs_mkdir (g, "/new");
2667     if (r == -1)
2668       return -1;
2669   }
2670   {
2671     int r;
2672     suppress_error = 0;
2673     r = guestfs_is_file (g, "/new");
2674     if (r == -1)
2675       return -1;
2676     if (r) {
2677       fprintf (stderr, "test_is_file_1: expected false, got true\n");
2678       return -1;
2679     }
2680   }
2681   return 0;
2682 }
2683
2684 static int test_is_dir_0 (void)
2685 {
2686   /* InitEmpty for is_dir (0): create ext2 on /dev/sda1 */
2687   {
2688     int r;
2689     suppress_error = 0;
2690     r = guestfs_umount_all (g);
2691     if (r == -1)
2692       return -1;
2693   }
2694   {
2695     int r;
2696     suppress_error = 0;
2697     r = guestfs_lvm_remove_all (g);
2698     if (r == -1)
2699       return -1;
2700   }
2701   {
2702     char *lines[] = {
2703       ",",
2704       NULL
2705     };
2706     int r;
2707     suppress_error = 0;
2708     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2709     if (r == -1)
2710       return -1;
2711   }
2712   {
2713     int r;
2714     suppress_error = 0;
2715     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2716     if (r == -1)
2717       return -1;
2718   }
2719   {
2720     int r;
2721     suppress_error = 0;
2722     r = guestfs_mount (g, "/dev/sda1", "/");
2723     if (r == -1)
2724       return -1;
2725   }
2726   /* TestOutputFalse for is_dir (0) */
2727   {
2728     int r;
2729     suppress_error = 0;
2730     r = guestfs_touch (g, "/new");
2731     if (r == -1)
2732       return -1;
2733   }
2734   {
2735     int r;
2736     suppress_error = 0;
2737     r = guestfs_is_dir (g, "/new");
2738     if (r == -1)
2739       return -1;
2740     if (r) {
2741       fprintf (stderr, "test_is_dir_0: expected false, got true\n");
2742       return -1;
2743     }
2744   }
2745   return 0;
2746 }
2747
2748 static int test_is_dir_1 (void)
2749 {
2750   /* InitEmpty for is_dir (1): create ext2 on /dev/sda1 */
2751   {
2752     int r;
2753     suppress_error = 0;
2754     r = guestfs_umount_all (g);
2755     if (r == -1)
2756       return -1;
2757   }
2758   {
2759     int r;
2760     suppress_error = 0;
2761     r = guestfs_lvm_remove_all (g);
2762     if (r == -1)
2763       return -1;
2764   }
2765   {
2766     char *lines[] = {
2767       ",",
2768       NULL
2769     };
2770     int r;
2771     suppress_error = 0;
2772     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2773     if (r == -1)
2774       return -1;
2775   }
2776   {
2777     int r;
2778     suppress_error = 0;
2779     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2780     if (r == -1)
2781       return -1;
2782   }
2783   {
2784     int r;
2785     suppress_error = 0;
2786     r = guestfs_mount (g, "/dev/sda1", "/");
2787     if (r == -1)
2788       return -1;
2789   }
2790   /* TestOutputTrue for is_dir (1) */
2791   {
2792     int r;
2793     suppress_error = 0;
2794     r = guestfs_mkdir (g, "/new");
2795     if (r == -1)
2796       return -1;
2797   }
2798   {
2799     int r;
2800     suppress_error = 0;
2801     r = guestfs_is_dir (g, "/new");
2802     if (r == -1)
2803       return -1;
2804     if (!r) {
2805       fprintf (stderr, "test_is_dir_1: expected true, got false\n");
2806       return -1;
2807     }
2808   }
2809   return 0;
2810 }
2811
2812 static int test_pvcreate_0 (void)
2813 {
2814   /* InitNone for pvcreate (0) */
2815   {
2816     int r;
2817     suppress_error = 0;
2818     r = guestfs_umount_all (g);
2819     if (r == -1)
2820       return -1;
2821   }
2822   {
2823     int r;
2824     suppress_error = 0;
2825     r = guestfs_lvm_remove_all (g);
2826     if (r == -1)
2827       return -1;
2828   }
2829   /* TestOutputList for pvcreate (0) */
2830   {
2831     char *lines[] = {
2832       ",10",
2833       ",20",
2834       ",",
2835       NULL
2836     };
2837     int r;
2838     suppress_error = 0;
2839     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2840     if (r == -1)
2841       return -1;
2842   }
2843   {
2844     int r;
2845     suppress_error = 0;
2846     r = guestfs_pvcreate (g, "/dev/sda1");
2847     if (r == -1)
2848       return -1;
2849   }
2850   {
2851     int r;
2852     suppress_error = 0;
2853     r = guestfs_pvcreate (g, "/dev/sda2");
2854     if (r == -1)
2855       return -1;
2856   }
2857   {
2858     int r;
2859     suppress_error = 0;
2860     r = guestfs_pvcreate (g, "/dev/sda3");
2861     if (r == -1)
2862       return -1;
2863   }
2864   {
2865     char **r;
2866     int i;
2867     suppress_error = 0;
2868     r = guestfs_pvs (g);
2869     if (r == NULL)
2870       return -1;
2871     if (!r[0]) {
2872       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
2873       print_strings (r);
2874       return -1;
2875     }
2876     if (strcmp (r[0], "/dev/sda1") != 0) {
2877       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
2878       return -1;
2879     }
2880     if (!r[1]) {
2881       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
2882       print_strings (r);
2883       return -1;
2884     }
2885     if (strcmp (r[1], "/dev/sda2") != 0) {
2886       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
2887       return -1;
2888     }
2889     if (!r[2]) {
2890       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
2891       print_strings (r);
2892       return -1;
2893     }
2894     if (strcmp (r[2], "/dev/sda3") != 0) {
2895       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
2896       return -1;
2897     }
2898     if (r[3] != NULL) {
2899       fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n");
2900       print_strings (r);
2901       return -1;
2902     }
2903     for (i = 0; r[i] != NULL; ++i)
2904       free (r[i]);
2905     free (r);
2906   }
2907   return 0;
2908 }
2909
2910 static int test_vgcreate_0 (void)
2911 {
2912   /* InitNone for vgcreate (0) */
2913   {
2914     int r;
2915     suppress_error = 0;
2916     r = guestfs_umount_all (g);
2917     if (r == -1)
2918       return -1;
2919   }
2920   {
2921     int r;
2922     suppress_error = 0;
2923     r = guestfs_lvm_remove_all (g);
2924     if (r == -1)
2925       return -1;
2926   }
2927   /* TestOutputList for vgcreate (0) */
2928   {
2929     char *lines[] = {
2930       ",10",
2931       ",20",
2932       ",",
2933       NULL
2934     };
2935     int r;
2936     suppress_error = 0;
2937     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2938     if (r == -1)
2939       return -1;
2940   }
2941   {
2942     int r;
2943     suppress_error = 0;
2944     r = guestfs_pvcreate (g, "/dev/sda1");
2945     if (r == -1)
2946       return -1;
2947   }
2948   {
2949     int r;
2950     suppress_error = 0;
2951     r = guestfs_pvcreate (g, "/dev/sda2");
2952     if (r == -1)
2953       return -1;
2954   }
2955   {
2956     int r;
2957     suppress_error = 0;
2958     r = guestfs_pvcreate (g, "/dev/sda3");
2959     if (r == -1)
2960       return -1;
2961   }
2962   {
2963     char *physvols[] = {
2964       "/dev/sda1",
2965       "/dev/sda2",
2966       NULL
2967     };
2968     int r;
2969     suppress_error = 0;
2970     r = guestfs_vgcreate (g, "VG1", physvols);
2971     if (r == -1)
2972       return -1;
2973   }
2974   {
2975     char *physvols[] = {
2976       "/dev/sda3",
2977       NULL
2978     };
2979     int r;
2980     suppress_error = 0;
2981     r = guestfs_vgcreate (g, "VG2", physvols);
2982     if (r == -1)
2983       return -1;
2984   }
2985   {
2986     char **r;
2987     int i;
2988     suppress_error = 0;
2989     r = guestfs_vgs (g);
2990     if (r == NULL)
2991       return -1;
2992     if (!r[0]) {
2993       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
2994       print_strings (r);
2995       return -1;
2996     }
2997     if (strcmp (r[0], "VG1") != 0) {
2998       fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]);
2999       return -1;
3000     }
3001     if (!r[1]) {
3002       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
3003       print_strings (r);
3004       return -1;
3005     }
3006     if (strcmp (r[1], "VG2") != 0) {
3007       fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]);
3008       return -1;
3009     }
3010     if (r[2] != NULL) {
3011       fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n");
3012       print_strings (r);
3013       return -1;
3014     }
3015     for (i = 0; r[i] != NULL; ++i)
3016       free (r[i]);
3017     free (r);
3018   }
3019   return 0;
3020 }
3021
3022 static int test_lvcreate_0 (void)
3023 {
3024   /* InitNone for lvcreate (0) */
3025   {
3026     int r;
3027     suppress_error = 0;
3028     r = guestfs_umount_all (g);
3029     if (r == -1)
3030       return -1;
3031   }
3032   {
3033     int r;
3034     suppress_error = 0;
3035     r = guestfs_lvm_remove_all (g);
3036     if (r == -1)
3037       return -1;
3038   }
3039   /* TestOutputList for lvcreate (0) */
3040   {
3041     char *lines[] = {
3042       ",10",
3043       ",20",
3044       ",",
3045       NULL
3046     };
3047     int r;
3048     suppress_error = 0;
3049     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3050     if (r == -1)
3051       return -1;
3052   }
3053   {
3054     int r;
3055     suppress_error = 0;
3056     r = guestfs_pvcreate (g, "/dev/sda1");
3057     if (r == -1)
3058       return -1;
3059   }
3060   {
3061     int r;
3062     suppress_error = 0;
3063     r = guestfs_pvcreate (g, "/dev/sda2");
3064     if (r == -1)
3065       return -1;
3066   }
3067   {
3068     int r;
3069     suppress_error = 0;
3070     r = guestfs_pvcreate (g, "/dev/sda3");
3071     if (r == -1)
3072       return -1;
3073   }
3074   {
3075     char *physvols[] = {
3076       "/dev/sda1",
3077       "/dev/sda2",
3078       NULL
3079     };
3080     int r;
3081     suppress_error = 0;
3082     r = guestfs_vgcreate (g, "VG1", physvols);
3083     if (r == -1)
3084       return -1;
3085   }
3086   {
3087     char *physvols[] = {
3088       "/dev/sda3",
3089       NULL
3090     };
3091     int r;
3092     suppress_error = 0;
3093     r = guestfs_vgcreate (g, "VG2", physvols);
3094     if (r == -1)
3095       return -1;
3096   }
3097   {
3098     int r;
3099     suppress_error = 0;
3100     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
3101     if (r == -1)
3102       return -1;
3103   }
3104   {
3105     int r;
3106     suppress_error = 0;
3107     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
3108     if (r == -1)
3109       return -1;
3110   }
3111   {
3112     int r;
3113     suppress_error = 0;
3114     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
3115     if (r == -1)
3116       return -1;
3117   }
3118   {
3119     int r;
3120     suppress_error = 0;
3121     r = guestfs_lvcreate (g, "LV4", "VG2", 50);
3122     if (r == -1)
3123       return -1;
3124   }
3125   {
3126     int r;
3127     suppress_error = 0;
3128     r = guestfs_lvcreate (g, "LV5", "VG2", 50);
3129     if (r == -1)
3130       return -1;
3131   }
3132   {
3133     char **r;
3134     int i;
3135     suppress_error = 0;
3136     r = guestfs_lvs (g);
3137     if (r == NULL)
3138       return -1;
3139     if (!r[0]) {
3140       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3141       print_strings (r);
3142       return -1;
3143     }
3144     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
3145       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
3146       return -1;
3147     }
3148     if (!r[1]) {
3149       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3150       print_strings (r);
3151       return -1;
3152     }
3153     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
3154       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
3155       return -1;
3156     }
3157     if (!r[2]) {
3158       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3159       print_strings (r);
3160       return -1;
3161     }
3162     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
3163       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
3164       return -1;
3165     }
3166     if (!r[3]) {
3167       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3168       print_strings (r);
3169       return -1;
3170     }
3171     if (strcmp (r[3], "/dev/VG2/LV4") != 0) {
3172       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]);
3173       return -1;
3174     }
3175     if (!r[4]) {
3176       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3177       print_strings (r);
3178       return -1;
3179     }
3180     if (strcmp (r[4], "/dev/VG2/LV5") != 0) {
3181       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]);
3182       return -1;
3183     }
3184     if (r[5] != NULL) {
3185       fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n");
3186       print_strings (r);
3187       return -1;
3188     }
3189     for (i = 0; r[i] != NULL; ++i)
3190       free (r[i]);
3191     free (r);
3192   }
3193   return 0;
3194 }
3195
3196 static int test_mkfs_0 (void)
3197 {
3198   /* InitNone for mkfs (0) */
3199   {
3200     int r;
3201     suppress_error = 0;
3202     r = guestfs_umount_all (g);
3203     if (r == -1)
3204       return -1;
3205   }
3206   {
3207     int r;
3208     suppress_error = 0;
3209     r = guestfs_lvm_remove_all (g);
3210     if (r == -1)
3211       return -1;
3212   }
3213   /* TestOutput for mkfs (0) */
3214   {
3215     char *lines[] = {
3216       ",",
3217       NULL
3218     };
3219     int r;
3220     suppress_error = 0;
3221     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3222     if (r == -1)
3223       return -1;
3224   }
3225   {
3226     int r;
3227     suppress_error = 0;
3228     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3229     if (r == -1)
3230       return -1;
3231   }
3232   {
3233     int r;
3234     suppress_error = 0;
3235     r = guestfs_mount (g, "/dev/sda1", "/");
3236     if (r == -1)
3237       return -1;
3238   }
3239   {
3240     int r;
3241     suppress_error = 0;
3242     r = guestfs_write_file (g, "/new", "new file contents", 0);
3243     if (r == -1)
3244       return -1;
3245   }
3246   {
3247     char *r;
3248     suppress_error = 0;
3249     r = guestfs_cat (g, "/new");
3250     if (r == NULL)
3251       return -1;
3252     if (strcmp (r, "new file contents") != 0) {
3253       fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r);
3254       return -1;
3255     }
3256     free (r);
3257   }
3258   return 0;
3259 }
3260
3261 static int test_write_file_0 (void)
3262 {
3263   /* InitNone for write_file (0) */
3264   {
3265     int r;
3266     suppress_error = 0;
3267     r = guestfs_umount_all (g);
3268     if (r == -1)
3269       return -1;
3270   }
3271   {
3272     int r;
3273     suppress_error = 0;
3274     r = guestfs_lvm_remove_all (g);
3275     if (r == -1)
3276       return -1;
3277   }
3278   /* TestOutput for write_file (0) */
3279   {
3280     char *lines[] = {
3281       ",",
3282       NULL
3283     };
3284     int r;
3285     suppress_error = 0;
3286     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3287     if (r == -1)
3288       return -1;
3289   }
3290   {
3291     int r;
3292     suppress_error = 0;
3293     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3294     if (r == -1)
3295       return -1;
3296   }
3297   {
3298     int r;
3299     suppress_error = 0;
3300     r = guestfs_mount (g, "/dev/sda1", "/");
3301     if (r == -1)
3302       return -1;
3303   }
3304   {
3305     int r;
3306     suppress_error = 0;
3307     r = guestfs_write_file (g, "/new", "new file contents", 0);
3308     if (r == -1)
3309       return -1;
3310   }
3311   {
3312     char *r;
3313     suppress_error = 0;
3314     r = guestfs_cat (g, "/new");
3315     if (r == NULL)
3316       return -1;
3317     if (strcmp (r, "new file contents") != 0) {
3318       fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r);
3319       return -1;
3320     }
3321     free (r);
3322   }
3323   return 0;
3324 }
3325
3326 static int test_umount_0 (void)
3327 {
3328   /* InitNone for umount (0) */
3329   {
3330     int r;
3331     suppress_error = 0;
3332     r = guestfs_umount_all (g);
3333     if (r == -1)
3334       return -1;
3335   }
3336   {
3337     int r;
3338     suppress_error = 0;
3339     r = guestfs_lvm_remove_all (g);
3340     if (r == -1)
3341       return -1;
3342   }
3343   /* TestOutputList for umount (0) */
3344   {
3345     char *lines[] = {
3346       ",",
3347       NULL
3348     };
3349     int r;
3350     suppress_error = 0;
3351     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3352     if (r == -1)
3353       return -1;
3354   }
3355   {
3356     int r;
3357     suppress_error = 0;
3358     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3359     if (r == -1)
3360       return -1;
3361   }
3362   {
3363     int r;
3364     suppress_error = 0;
3365     r = guestfs_mount (g, "/dev/sda1", "/");
3366     if (r == -1)
3367       return -1;
3368   }
3369   {
3370     char **r;
3371     int i;
3372     suppress_error = 0;
3373     r = guestfs_mounts (g);
3374     if (r == NULL)
3375       return -1;
3376     if (!r[0]) {
3377       fprintf (stderr, "test_umount_0: short list returned from command\n");
3378       print_strings (r);
3379       return -1;
3380     }
3381     if (strcmp (r[0], "/dev/sda1") != 0) {
3382       fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3383       return -1;
3384     }
3385     if (r[1] != NULL) {
3386       fprintf (stderr, "test_umount_0: extra elements returned from command\n");
3387       print_strings (r);
3388       return -1;
3389     }
3390     for (i = 0; r[i] != NULL; ++i)
3391       free (r[i]);
3392     free (r);
3393   }
3394   return 0;
3395 }
3396
3397 static int test_umount_1 (void)
3398 {
3399   /* InitNone for umount (1) */
3400   {
3401     int r;
3402     suppress_error = 0;
3403     r = guestfs_umount_all (g);
3404     if (r == -1)
3405       return -1;
3406   }
3407   {
3408     int r;
3409     suppress_error = 0;
3410     r = guestfs_lvm_remove_all (g);
3411     if (r == -1)
3412       return -1;
3413   }
3414   /* TestOutputList for umount (1) */
3415   {
3416     char *lines[] = {
3417       ",",
3418       NULL
3419     };
3420     int r;
3421     suppress_error = 0;
3422     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3423     if (r == -1)
3424       return -1;
3425   }
3426   {
3427     int r;
3428     suppress_error = 0;
3429     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3430     if (r == -1)
3431       return -1;
3432   }
3433   {
3434     int r;
3435     suppress_error = 0;
3436     r = guestfs_mount (g, "/dev/sda1", "/");
3437     if (r == -1)
3438       return -1;
3439   }
3440   {
3441     int r;
3442     suppress_error = 0;
3443     r = guestfs_umount (g, "/");
3444     if (r == -1)
3445       return -1;
3446   }
3447   {
3448     char **r;
3449     int i;
3450     suppress_error = 0;
3451     r = guestfs_mounts (g);
3452     if (r == NULL)
3453       return -1;
3454     if (r[0] != NULL) {
3455       fprintf (stderr, "test_umount_1: extra elements returned from command\n");
3456       print_strings (r);
3457       return -1;
3458     }
3459     for (i = 0; r[i] != NULL; ++i)
3460       free (r[i]);
3461     free (r);
3462   }
3463   return 0;
3464 }
3465
3466 static int test_mounts_0 (void)
3467 {
3468   /* InitEmpty for mounts (0): create ext2 on /dev/sda1 */
3469   {
3470     int r;
3471     suppress_error = 0;
3472     r = guestfs_umount_all (g);
3473     if (r == -1)
3474       return -1;
3475   }
3476   {
3477     int r;
3478     suppress_error = 0;
3479     r = guestfs_lvm_remove_all (g);
3480     if (r == -1)
3481       return -1;
3482   }
3483   {
3484     char *lines[] = {
3485       ",",
3486       NULL
3487     };
3488     int r;
3489     suppress_error = 0;
3490     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3491     if (r == -1)
3492       return -1;
3493   }
3494   {
3495     int r;
3496     suppress_error = 0;
3497     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3498     if (r == -1)
3499       return -1;
3500   }
3501   {
3502     int r;
3503     suppress_error = 0;
3504     r = guestfs_mount (g, "/dev/sda1", "/");
3505     if (r == -1)
3506       return -1;
3507   }
3508   /* TestOutputList for mounts (0) */
3509   {
3510     char **r;
3511     int i;
3512     suppress_error = 0;
3513     r = guestfs_mounts (g);
3514     if (r == NULL)
3515       return -1;
3516     if (!r[0]) {
3517       fprintf (stderr, "test_mounts_0: short list returned from command\n");
3518       print_strings (r);
3519       return -1;
3520     }
3521     if (strcmp (r[0], "/dev/sda1") != 0) {
3522       fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3523       return -1;
3524     }
3525     if (r[1] != NULL) {
3526       fprintf (stderr, "test_mounts_0: extra elements returned from command\n");
3527       print_strings (r);
3528       return -1;
3529     }
3530     for (i = 0; r[i] != NULL; ++i)
3531       free (r[i]);
3532     free (r);
3533   }
3534   return 0;
3535 }
3536
3537 static int test_umount_all_0 (void)
3538 {
3539   /* InitEmpty for umount_all (0): create ext2 on /dev/sda1 */
3540   {
3541     int r;
3542     suppress_error = 0;
3543     r = guestfs_umount_all (g);
3544     if (r == -1)
3545       return -1;
3546   }
3547   {
3548     int r;
3549     suppress_error = 0;
3550     r = guestfs_lvm_remove_all (g);
3551     if (r == -1)
3552       return -1;
3553   }
3554   {
3555     char *lines[] = {
3556       ",",
3557       NULL
3558     };
3559     int r;
3560     suppress_error = 0;
3561     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3562     if (r == -1)
3563       return -1;
3564   }
3565   {
3566     int r;
3567     suppress_error = 0;
3568     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3569     if (r == -1)
3570       return -1;
3571   }
3572   {
3573     int r;
3574     suppress_error = 0;
3575     r = guestfs_mount (g, "/dev/sda1", "/");
3576     if (r == -1)
3577       return -1;
3578   }
3579   /* TestOutputList for umount_all (0) */
3580   {
3581     int r;
3582     suppress_error = 0;
3583     r = guestfs_umount_all (g);
3584     if (r == -1)
3585       return -1;
3586   }
3587   {
3588     char **r;
3589     int i;
3590     suppress_error = 0;
3591     r = guestfs_mounts (g);
3592     if (r == NULL)
3593       return -1;
3594     if (r[0] != NULL) {
3595       fprintf (stderr, "test_umount_all_0: extra elements returned from command\n");
3596       print_strings (r);
3597       return -1;
3598     }
3599     for (i = 0; r[i] != NULL; ++i)
3600       free (r[i]);
3601     free (r);
3602   }
3603   return 0;
3604 }
3605
3606 int main (int argc, char *argv[])
3607 {
3608   char c = 0;
3609   int failed = 0;
3610   const char *srcdir;
3611   int fd;
3612   char buf[256];
3613
3614   g = guestfs_create ();
3615   if (g == NULL) {
3616     printf ("guestfs_create FAILED\n");
3617     exit (1);
3618   }
3619
3620   guestfs_set_error_handler (g, print_error, NULL);
3621
3622   srcdir = getenv ("srcdir");
3623   if (!srcdir) srcdir = ".";
3624   guestfs_set_path (g, srcdir);
3625
3626   snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
3627   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
3628   if (fd == -1) {
3629     perror (buf);
3630     exit (1);
3631   }
3632   if (lseek (fd, 524288000, SEEK_SET) == -1) {
3633     perror ("lseek");
3634     close (fd);
3635     unlink (buf);
3636     exit (1);
3637   }
3638   if (write (fd, &c, 1) == -1) {
3639     perror ("write");
3640     close (fd);
3641     unlink (buf);
3642     exit (1);
3643   }
3644   if (close (fd) == -1) {
3645     perror (buf);
3646     unlink (buf);
3647     exit (1);
3648   }
3649   if (guestfs_add_drive (g, buf) == -1) {
3650     printf ("guestfs_add_drive %s FAILED\n", buf);
3651     exit (1);
3652   }
3653
3654   snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
3655   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
3656   if (fd == -1) {
3657     perror (buf);
3658     exit (1);
3659   }
3660   if (lseek (fd, 52428800, SEEK_SET) == -1) {
3661     perror ("lseek");
3662     close (fd);
3663     unlink (buf);
3664     exit (1);
3665   }
3666   if (write (fd, &c, 1) == -1) {
3667     perror ("write");
3668     close (fd);
3669     unlink (buf);
3670     exit (1);
3671   }
3672   if (close (fd) == -1) {
3673     perror (buf);
3674     unlink (buf);
3675     exit (1);
3676   }
3677   if (guestfs_add_drive (g, buf) == -1) {
3678     printf ("guestfs_add_drive %s FAILED\n", buf);
3679     exit (1);
3680   }
3681
3682   snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
3683   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
3684   if (fd == -1) {
3685     perror (buf);
3686     exit (1);
3687   }
3688   if (lseek (fd, 10485760, SEEK_SET) == -1) {
3689     perror ("lseek");
3690     close (fd);
3691     unlink (buf);
3692     exit (1);
3693   }
3694   if (write (fd, &c, 1) == -1) {
3695     perror ("write");
3696     close (fd);
3697     unlink (buf);
3698     exit (1);
3699   }
3700   if (close (fd) == -1) {
3701     perror (buf);
3702     unlink (buf);
3703     exit (1);
3704   }
3705   if (guestfs_add_drive (g, buf) == -1) {
3706     printf ("guestfs_add_drive %s FAILED\n", buf);
3707     exit (1);
3708   }
3709
3710   if (guestfs_launch (g) == -1) {
3711     printf ("guestfs_launch FAILED\n");
3712     exit (1);
3713   }
3714   if (guestfs_wait_ready (g) == -1) {
3715     printf ("guestfs_wait_ready FAILED\n");
3716     exit (1);
3717   }
3718
3719   printf ("  1/ 46 test_mount_0\n");
3720   if (test_mount_0 () == -1) {
3721     printf ("test_mount_0 FAILED\n");
3722     failed++;
3723   }
3724   printf ("  2/ 46 test_sync_0\n");
3725   if (test_sync_0 () == -1) {
3726     printf ("test_sync_0 FAILED\n");
3727     failed++;
3728   }
3729   printf ("  3/ 46 test_touch_0\n");
3730   if (test_touch_0 () == -1) {
3731     printf ("test_touch_0 FAILED\n");
3732     failed++;
3733   }
3734   printf ("  4/ 46 test_cat_0\n");
3735   if (test_cat_0 () == -1) {
3736     printf ("test_cat_0 FAILED\n");
3737     failed++;
3738   }
3739   printf ("  5/ 46 test_ls_0\n");
3740   if (test_ls_0 () == -1) {
3741     printf ("test_ls_0 FAILED\n");
3742     failed++;
3743   }
3744   printf ("  6/ 46 test_list_devices_0\n");
3745   if (test_list_devices_0 () == -1) {
3746     printf ("test_list_devices_0 FAILED\n");
3747     failed++;
3748   }
3749   printf ("  7/ 46 test_list_partitions_0\n");
3750   if (test_list_partitions_0 () == -1) {
3751     printf ("test_list_partitions_0 FAILED\n");
3752     failed++;
3753   }
3754   printf ("  8/ 46 test_list_partitions_1\n");
3755   if (test_list_partitions_1 () == -1) {
3756     printf ("test_list_partitions_1 FAILED\n");
3757     failed++;
3758   }
3759   printf ("  9/ 46 test_pvs_0\n");
3760   if (test_pvs_0 () == -1) {
3761     printf ("test_pvs_0 FAILED\n");
3762     failed++;
3763   }
3764   printf (" 10/ 46 test_pvs_1\n");
3765   if (test_pvs_1 () == -1) {
3766     printf ("test_pvs_1 FAILED\n");
3767     failed++;
3768   }
3769   printf (" 11/ 46 test_vgs_0\n");
3770   if (test_vgs_0 () == -1) {
3771     printf ("test_vgs_0 FAILED\n");
3772     failed++;
3773   }
3774   printf (" 12/ 46 test_vgs_1\n");
3775   if (test_vgs_1 () == -1) {
3776     printf ("test_vgs_1 FAILED\n");
3777     failed++;
3778   }
3779   printf (" 13/ 46 test_lvs_0\n");
3780   if (test_lvs_0 () == -1) {
3781     printf ("test_lvs_0 FAILED\n");
3782     failed++;
3783   }
3784   printf (" 14/ 46 test_lvs_1\n");
3785   if (test_lvs_1 () == -1) {
3786     printf ("test_lvs_1 FAILED\n");
3787     failed++;
3788   }
3789   printf (" 15/ 46 test_pvs_full_0\n");
3790   if (test_pvs_full_0 () == -1) {
3791     printf ("test_pvs_full_0 FAILED\n");
3792     failed++;
3793   }
3794   printf (" 16/ 46 test_vgs_full_0\n");
3795   if (test_vgs_full_0 () == -1) {
3796     printf ("test_vgs_full_0 FAILED\n");
3797     failed++;
3798   }
3799   printf (" 17/ 46 test_lvs_full_0\n");
3800   if (test_lvs_full_0 () == -1) {
3801     printf ("test_lvs_full_0 FAILED\n");
3802     failed++;
3803   }
3804   printf (" 18/ 46 test_read_lines_0\n");
3805   if (test_read_lines_0 () == -1) {
3806     printf ("test_read_lines_0 FAILED\n");
3807     failed++;
3808   }
3809   printf (" 19/ 46 test_read_lines_1\n");
3810   if (test_read_lines_1 () == -1) {
3811     printf ("test_read_lines_1 FAILED\n");
3812     failed++;
3813   }
3814   printf (" 20/ 46 test_rm_0\n");
3815   if (test_rm_0 () == -1) {
3816     printf ("test_rm_0 FAILED\n");
3817     failed++;
3818   }
3819   printf (" 21/ 46 test_rm_1\n");
3820   if (test_rm_1 () == -1) {
3821     printf ("test_rm_1 FAILED\n");
3822     failed++;
3823   }
3824   printf (" 22/ 46 test_rm_2\n");
3825   if (test_rm_2 () == -1) {
3826     printf ("test_rm_2 FAILED\n");
3827     failed++;
3828   }
3829   printf (" 23/ 46 test_rmdir_0\n");
3830   if (test_rmdir_0 () == -1) {
3831     printf ("test_rmdir_0 FAILED\n");
3832     failed++;
3833   }
3834   printf (" 24/ 46 test_rmdir_1\n");
3835   if (test_rmdir_1 () == -1) {
3836     printf ("test_rmdir_1 FAILED\n");
3837     failed++;
3838   }
3839   printf (" 25/ 46 test_rmdir_2\n");
3840   if (test_rmdir_2 () == -1) {
3841     printf ("test_rmdir_2 FAILED\n");
3842     failed++;
3843   }
3844   printf (" 26/ 46 test_rm_rf_0\n");
3845   if (test_rm_rf_0 () == -1) {
3846     printf ("test_rm_rf_0 FAILED\n");
3847     failed++;
3848   }
3849   printf (" 27/ 46 test_mkdir_0\n");
3850   if (test_mkdir_0 () == -1) {
3851     printf ("test_mkdir_0 FAILED\n");
3852     failed++;
3853   }
3854   printf (" 28/ 46 test_mkdir_1\n");
3855   if (test_mkdir_1 () == -1) {
3856     printf ("test_mkdir_1 FAILED\n");
3857     failed++;
3858   }
3859   printf (" 29/ 46 test_mkdir_p_0\n");
3860   if (test_mkdir_p_0 () == -1) {
3861     printf ("test_mkdir_p_0 FAILED\n");
3862     failed++;
3863   }
3864   printf (" 30/ 46 test_mkdir_p_1\n");
3865   if (test_mkdir_p_1 () == -1) {
3866     printf ("test_mkdir_p_1 FAILED\n");
3867     failed++;
3868   }
3869   printf (" 31/ 46 test_mkdir_p_2\n");
3870   if (test_mkdir_p_2 () == -1) {
3871     printf ("test_mkdir_p_2 FAILED\n");
3872     failed++;
3873   }
3874   printf (" 32/ 46 test_exists_0\n");
3875   if (test_exists_0 () == -1) {
3876     printf ("test_exists_0 FAILED\n");
3877     failed++;
3878   }
3879   printf (" 33/ 46 test_exists_1\n");
3880   if (test_exists_1 () == -1) {
3881     printf ("test_exists_1 FAILED\n");
3882     failed++;
3883   }
3884   printf (" 34/ 46 test_is_file_0\n");
3885   if (test_is_file_0 () == -1) {
3886     printf ("test_is_file_0 FAILED\n");
3887     failed++;
3888   }
3889   printf (" 35/ 46 test_is_file_1\n");
3890   if (test_is_file_1 () == -1) {
3891     printf ("test_is_file_1 FAILED\n");
3892     failed++;
3893   }
3894   printf (" 36/ 46 test_is_dir_0\n");
3895   if (test_is_dir_0 () == -1) {
3896     printf ("test_is_dir_0 FAILED\n");
3897     failed++;
3898   }
3899   printf (" 37/ 46 test_is_dir_1\n");
3900   if (test_is_dir_1 () == -1) {
3901     printf ("test_is_dir_1 FAILED\n");
3902     failed++;
3903   }
3904   printf (" 38/ 46 test_pvcreate_0\n");
3905   if (test_pvcreate_0 () == -1) {
3906     printf ("test_pvcreate_0 FAILED\n");
3907     failed++;
3908   }
3909   printf (" 39/ 46 test_vgcreate_0\n");
3910   if (test_vgcreate_0 () == -1) {
3911     printf ("test_vgcreate_0 FAILED\n");
3912     failed++;
3913   }
3914   printf (" 40/ 46 test_lvcreate_0\n");
3915   if (test_lvcreate_0 () == -1) {
3916     printf ("test_lvcreate_0 FAILED\n");
3917     failed++;
3918   }
3919   printf (" 41/ 46 test_mkfs_0\n");
3920   if (test_mkfs_0 () == -1) {
3921     printf ("test_mkfs_0 FAILED\n");
3922     failed++;
3923   }
3924   printf (" 42/ 46 test_write_file_0\n");
3925   if (test_write_file_0 () == -1) {
3926     printf ("test_write_file_0 FAILED\n");
3927     failed++;
3928   }
3929   printf (" 43/ 46 test_umount_0\n");
3930   if (test_umount_0 () == -1) {
3931     printf ("test_umount_0 FAILED\n");
3932     failed++;
3933   }
3934   printf (" 44/ 46 test_umount_1\n");
3935   if (test_umount_1 () == -1) {
3936     printf ("test_umount_1 FAILED\n");
3937     failed++;
3938   }
3939   printf (" 45/ 46 test_mounts_0\n");
3940   if (test_mounts_0 () == -1) {
3941     printf ("test_mounts_0 FAILED\n");
3942     failed++;
3943   }
3944   printf (" 46/ 46 test_umount_all_0\n");
3945   if (test_umount_all_0 () == -1) {
3946     printf ("test_umount_all_0 FAILED\n");
3947     failed++;
3948   }
3949
3950   guestfs_close (g);
3951   snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
3952   unlink (buf);
3953   snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
3954   unlink (buf);
3955   snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
3956   unlink (buf);
3957
3958   if (failed > 0) {
3959     printf ("***** %d / 46 tests FAILED *****\n", failed);
3960     exit (1);
3961   }
3962
3963   exit (0);
3964 }