Separate out the high-level API actions.
[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 /*
49 static void print_table (char * const * const argv)
50 {
51   int i;
52
53   for (i = 0; argv[i] != NULL; i += 2)
54     printf ("%s: %s\n", argv[i], argv[i+1]);
55 }
56 */
57
58 static void no_test_warnings (void)
59 {
60   fprintf (stderr, "warning: \"guestfs_launch\" has no tests\n");
61   fprintf (stderr, "warning: \"guestfs_wait_ready\" has no tests\n");
62   fprintf (stderr, "warning: \"guestfs_kill_subprocess\" has no tests\n");
63   fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n");
64   fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n");
65   fprintf (stderr, "warning: \"guestfs_config\" has no tests\n");
66   fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n");
67   fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n");
68   fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n");
69   fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n");
70   fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n");
71   fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n");
72   fprintf (stderr, "warning: \"guestfs_is_ready\" has no tests\n");
73   fprintf (stderr, "warning: \"guestfs_is_config\" has no tests\n");
74   fprintf (stderr, "warning: \"guestfs_is_launching\" has no tests\n");
75   fprintf (stderr, "warning: \"guestfs_is_busy\" has no tests\n");
76   fprintf (stderr, "warning: \"guestfs_get_state\" has no tests\n");
77   fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n");
78   fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n");
79   fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n");
80   fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n");
81   fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n");
82   fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n");
83   fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n");
84   fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n");
85   fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n");
86   fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n");
87   fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n");
88   fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n");
89   fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n");
90   fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n");
91   fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n");
92   fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n");
93   fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n");
94   fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n");
95   fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n");
96   fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n");
97   fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n");
98   fprintf (stderr, "warning: \"guestfs_command\" has no tests\n");
99   fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n");
100   fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
101   fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
102 }
103
104 static int test_blockdev_rereadpt_0 (void)
105 {
106   /* InitEmpty for blockdev_rereadpt (0) */
107   {
108     int r;
109     suppress_error = 0;
110     r = guestfs_umount_all (g);
111     if (r == -1)
112       return -1;
113   }
114   {
115     int r;
116     suppress_error = 0;
117     r = guestfs_lvm_remove_all (g);
118     if (r == -1)
119       return -1;
120   }
121   /* TestRun for blockdev_rereadpt (0) */
122   {
123     int r;
124     suppress_error = 0;
125     r = guestfs_blockdev_rereadpt (g, "/dev/sda");
126     if (r == -1)
127       return -1;
128   }
129   return 0;
130 }
131
132 static int test_blockdev_flushbufs_0 (void)
133 {
134   /* InitEmpty for blockdev_flushbufs (0) */
135   {
136     int r;
137     suppress_error = 0;
138     r = guestfs_umount_all (g);
139     if (r == -1)
140       return -1;
141   }
142   {
143     int r;
144     suppress_error = 0;
145     r = guestfs_lvm_remove_all (g);
146     if (r == -1)
147       return -1;
148   }
149   /* TestRun for blockdev_flushbufs (0) */
150   {
151     int r;
152     suppress_error = 0;
153     r = guestfs_blockdev_flushbufs (g, "/dev/sda");
154     if (r == -1)
155       return -1;
156   }
157   return 0;
158 }
159
160 static int test_blockdev_getsize64_0 (void)
161 {
162   /* InitEmpty for blockdev_getsize64 (0) */
163   {
164     int r;
165     suppress_error = 0;
166     r = guestfs_umount_all (g);
167     if (r == -1)
168       return -1;
169   }
170   {
171     int r;
172     suppress_error = 0;
173     r = guestfs_lvm_remove_all (g);
174     if (r == -1)
175       return -1;
176   }
177   /* TestOutputInt for blockdev_getsize64 (0) */
178   {
179     int64_t r;
180     suppress_error = 0;
181     r = guestfs_blockdev_getsize64 (g, "/dev/sda");
182     if (r == -1)
183       return -1;
184     if (r != 524288000) {
185       fprintf (stderr, "test_blockdev_getsize64_0: expected 524288000 but got %d\n",               (int) r);
186       return -1;
187     }
188   }
189   return 0;
190 }
191
192 static int test_blockdev_getsz_0 (void)
193 {
194   /* InitEmpty for blockdev_getsz (0) */
195   {
196     int r;
197     suppress_error = 0;
198     r = guestfs_umount_all (g);
199     if (r == -1)
200       return -1;
201   }
202   {
203     int r;
204     suppress_error = 0;
205     r = guestfs_lvm_remove_all (g);
206     if (r == -1)
207       return -1;
208   }
209   /* TestOutputInt for blockdev_getsz (0) */
210   {
211     int64_t r;
212     suppress_error = 0;
213     r = guestfs_blockdev_getsz (g, "/dev/sda");
214     if (r == -1)
215       return -1;
216     if (r != 1024000) {
217       fprintf (stderr, "test_blockdev_getsz_0: expected 1024000 but got %d\n",               (int) r);
218       return -1;
219     }
220   }
221   return 0;
222 }
223
224 static int test_blockdev_getbsz_0 (void)
225 {
226   /* InitEmpty for blockdev_getbsz (0) */
227   {
228     int r;
229     suppress_error = 0;
230     r = guestfs_umount_all (g);
231     if (r == -1)
232       return -1;
233   }
234   {
235     int r;
236     suppress_error = 0;
237     r = guestfs_lvm_remove_all (g);
238     if (r == -1)
239       return -1;
240   }
241   /* TestOutputInt for blockdev_getbsz (0) */
242   {
243     int r;
244     suppress_error = 0;
245     r = guestfs_blockdev_getbsz (g, "/dev/sda");
246     if (r == -1)
247       return -1;
248     if (r != 4096) {
249       fprintf (stderr, "test_blockdev_getbsz_0: expected 4096 but got %d\n",               (int) r);
250       return -1;
251     }
252   }
253   return 0;
254 }
255
256 static int test_blockdev_getss_0 (void)
257 {
258   /* InitEmpty for blockdev_getss (0) */
259   {
260     int r;
261     suppress_error = 0;
262     r = guestfs_umount_all (g);
263     if (r == -1)
264       return -1;
265   }
266   {
267     int r;
268     suppress_error = 0;
269     r = guestfs_lvm_remove_all (g);
270     if (r == -1)
271       return -1;
272   }
273   /* TestOutputInt for blockdev_getss (0) */
274   {
275     int r;
276     suppress_error = 0;
277     r = guestfs_blockdev_getss (g, "/dev/sda");
278     if (r == -1)
279       return -1;
280     if (r != 512) {
281       fprintf (stderr, "test_blockdev_getss_0: expected 512 but got %d\n",               (int) r);
282       return -1;
283     }
284   }
285   return 0;
286 }
287
288 static int test_blockdev_getro_0 (void)
289 {
290   /* InitEmpty for blockdev_getro (0) */
291   {
292     int r;
293     suppress_error = 0;
294     r = guestfs_umount_all (g);
295     if (r == -1)
296       return -1;
297   }
298   {
299     int r;
300     suppress_error = 0;
301     r = guestfs_lvm_remove_all (g);
302     if (r == -1)
303       return -1;
304   }
305   /* TestOutputTrue for blockdev_getro (0) */
306   {
307     int r;
308     suppress_error = 0;
309     r = guestfs_blockdev_setro (g, "/dev/sda");
310     if (r == -1)
311       return -1;
312   }
313   {
314     int r;
315     suppress_error = 0;
316     r = guestfs_blockdev_getro (g, "/dev/sda");
317     if (r == -1)
318       return -1;
319     if (!r) {
320       fprintf (stderr, "test_blockdev_getro_0: expected true, got false\n");
321       return -1;
322     }
323   }
324   return 0;
325 }
326
327 static int test_blockdev_setrw_0 (void)
328 {
329   /* InitEmpty for blockdev_setrw (0) */
330   {
331     int r;
332     suppress_error = 0;
333     r = guestfs_umount_all (g);
334     if (r == -1)
335       return -1;
336   }
337   {
338     int r;
339     suppress_error = 0;
340     r = guestfs_lvm_remove_all (g);
341     if (r == -1)
342       return -1;
343   }
344   /* TestOutputFalse for blockdev_setrw (0) */
345   {
346     int r;
347     suppress_error = 0;
348     r = guestfs_blockdev_setrw (g, "/dev/sda");
349     if (r == -1)
350       return -1;
351   }
352   {
353     int r;
354     suppress_error = 0;
355     r = guestfs_blockdev_getro (g, "/dev/sda");
356     if (r == -1)
357       return -1;
358     if (r) {
359       fprintf (stderr, "test_blockdev_setrw_0: expected false, got true\n");
360       return -1;
361     }
362   }
363   return 0;
364 }
365
366 static int test_blockdev_setro_0 (void)
367 {
368   /* InitEmpty for blockdev_setro (0) */
369   {
370     int r;
371     suppress_error = 0;
372     r = guestfs_umount_all (g);
373     if (r == -1)
374       return -1;
375   }
376   {
377     int r;
378     suppress_error = 0;
379     r = guestfs_lvm_remove_all (g);
380     if (r == -1)
381       return -1;
382   }
383   /* TestOutputTrue for blockdev_setro (0) */
384   {
385     int r;
386     suppress_error = 0;
387     r = guestfs_blockdev_setro (g, "/dev/sda");
388     if (r == -1)
389       return -1;
390   }
391   {
392     int r;
393     suppress_error = 0;
394     r = guestfs_blockdev_getro (g, "/dev/sda");
395     if (r == -1)
396       return -1;
397     if (!r) {
398       fprintf (stderr, "test_blockdev_setro_0: expected true, got false\n");
399       return -1;
400     }
401   }
402   return 0;
403 }
404
405 static int test_statvfs_0 (void)
406 {
407   /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */
408   {
409     int r;
410     suppress_error = 0;
411     r = guestfs_umount_all (g);
412     if (r == -1)
413       return -1;
414   }
415   {
416     int r;
417     suppress_error = 0;
418     r = guestfs_lvm_remove_all (g);
419     if (r == -1)
420       return -1;
421   }
422   {
423     char *lines[] = {
424       ",",
425       NULL
426     };
427     int r;
428     suppress_error = 0;
429     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
430     if (r == -1)
431       return -1;
432   }
433   {
434     int r;
435     suppress_error = 0;
436     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
437     if (r == -1)
438       return -1;
439   }
440   {
441     int r;
442     suppress_error = 0;
443     r = guestfs_mount (g, "/dev/sda1", "/");
444     if (r == -1)
445       return -1;
446   }
447   /* TestOutputStruct for statvfs (0) */
448   {
449     struct guestfs_statvfs *r;
450     suppress_error = 0;
451     r = guestfs_statvfs (g, "/");
452     if (r == NULL)
453       return -1;
454     if (r->bfree != 487702) {
455       fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n",
456                (int) r->bfree);
457       return -1;
458     }
459     if (r->blocks != 490020) {
460       fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n",
461                (int) r->blocks);
462       return -1;
463     }
464     if (r->bsize != 1024) {
465       fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n",
466                (int) r->bsize);
467       return -1;
468     }
469     free (r);
470   }
471   return 0;
472 }
473
474 static int test_lstat_0 (void)
475 {
476   /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */
477   {
478     int r;
479     suppress_error = 0;
480     r = guestfs_umount_all (g);
481     if (r == -1)
482       return -1;
483   }
484   {
485     int r;
486     suppress_error = 0;
487     r = guestfs_lvm_remove_all (g);
488     if (r == -1)
489       return -1;
490   }
491   {
492     char *lines[] = {
493       ",",
494       NULL
495     };
496     int r;
497     suppress_error = 0;
498     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
499     if (r == -1)
500       return -1;
501   }
502   {
503     int r;
504     suppress_error = 0;
505     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
506     if (r == -1)
507       return -1;
508   }
509   {
510     int r;
511     suppress_error = 0;
512     r = guestfs_mount (g, "/dev/sda1", "/");
513     if (r == -1)
514       return -1;
515   }
516   /* TestOutputStruct for lstat (0) */
517   {
518     int r;
519     suppress_error = 0;
520     r = guestfs_touch (g, "/new");
521     if (r == -1)
522       return -1;
523   }
524   {
525     struct guestfs_stat *r;
526     suppress_error = 0;
527     r = guestfs_lstat (g, "/new");
528     if (r == NULL)
529       return -1;
530     if (r->size != 0) {
531       fprintf (stderr, "test_lstat_0: size was %d, expected 0\n",
532                (int) r->size);
533       return -1;
534     }
535     free (r);
536   }
537   return 0;
538 }
539
540 static int test_stat_0 (void)
541 {
542   /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */
543   {
544     int r;
545     suppress_error = 0;
546     r = guestfs_umount_all (g);
547     if (r == -1)
548       return -1;
549   }
550   {
551     int r;
552     suppress_error = 0;
553     r = guestfs_lvm_remove_all (g);
554     if (r == -1)
555       return -1;
556   }
557   {
558     char *lines[] = {
559       ",",
560       NULL
561     };
562     int r;
563     suppress_error = 0;
564     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
565     if (r == -1)
566       return -1;
567   }
568   {
569     int r;
570     suppress_error = 0;
571     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
572     if (r == -1)
573       return -1;
574   }
575   {
576     int r;
577     suppress_error = 0;
578     r = guestfs_mount (g, "/dev/sda1", "/");
579     if (r == -1)
580       return -1;
581   }
582   /* TestOutputStruct for stat (0) */
583   {
584     int r;
585     suppress_error = 0;
586     r = guestfs_touch (g, "/new");
587     if (r == -1)
588       return -1;
589   }
590   {
591     struct guestfs_stat *r;
592     suppress_error = 0;
593     r = guestfs_stat (g, "/new");
594     if (r == NULL)
595       return -1;
596     if (r->size != 0) {
597       fprintf (stderr, "test_stat_0: size was %d, expected 0\n",
598                (int) r->size);
599       return -1;
600     }
601     free (r);
602   }
603   return 0;
604 }
605
606 static int test_file_0 (void)
607 {
608   /* InitBasicFS for file (0): create ext2 on /dev/sda1 */
609   {
610     int r;
611     suppress_error = 0;
612     r = guestfs_umount_all (g);
613     if (r == -1)
614       return -1;
615   }
616   {
617     int r;
618     suppress_error = 0;
619     r = guestfs_lvm_remove_all (g);
620     if (r == -1)
621       return -1;
622   }
623   {
624     char *lines[] = {
625       ",",
626       NULL
627     };
628     int r;
629     suppress_error = 0;
630     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
631     if (r == -1)
632       return -1;
633   }
634   {
635     int r;
636     suppress_error = 0;
637     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
638     if (r == -1)
639       return -1;
640   }
641   {
642     int r;
643     suppress_error = 0;
644     r = guestfs_mount (g, "/dev/sda1", "/");
645     if (r == -1)
646       return -1;
647   }
648   /* TestOutput for file (0) */
649   {
650     int r;
651     suppress_error = 0;
652     r = guestfs_touch (g, "/new");
653     if (r == -1)
654       return -1;
655   }
656   {
657     char *r;
658     suppress_error = 0;
659     r = guestfs_file (g, "/new");
660     if (r == NULL)
661       return -1;
662     if (strcmp (r, "empty") != 0) {
663       fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r);
664       return -1;
665     }
666     free (r);
667   }
668   return 0;
669 }
670
671 static int test_file_1 (void)
672 {
673   /* InitBasicFS for file (1): create ext2 on /dev/sda1 */
674   {
675     int r;
676     suppress_error = 0;
677     r = guestfs_umount_all (g);
678     if (r == -1)
679       return -1;
680   }
681   {
682     int r;
683     suppress_error = 0;
684     r = guestfs_lvm_remove_all (g);
685     if (r == -1)
686       return -1;
687   }
688   {
689     char *lines[] = {
690       ",",
691       NULL
692     };
693     int r;
694     suppress_error = 0;
695     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
696     if (r == -1)
697       return -1;
698   }
699   {
700     int r;
701     suppress_error = 0;
702     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
703     if (r == -1)
704       return -1;
705   }
706   {
707     int r;
708     suppress_error = 0;
709     r = guestfs_mount (g, "/dev/sda1", "/");
710     if (r == -1)
711       return -1;
712   }
713   /* TestOutput for file (1) */
714   {
715     int r;
716     suppress_error = 0;
717     r = guestfs_write_file (g, "/new", "some content\n", 0);
718     if (r == -1)
719       return -1;
720   }
721   {
722     char *r;
723     suppress_error = 0;
724     r = guestfs_file (g, "/new");
725     if (r == NULL)
726       return -1;
727     if (strcmp (r, "ASCII text") != 0) {
728       fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r);
729       return -1;
730     }
731     free (r);
732   }
733   return 0;
734 }
735
736 static int test_file_2 (void)
737 {
738   /* InitBasicFS for file (2): create ext2 on /dev/sda1 */
739   {
740     int r;
741     suppress_error = 0;
742     r = guestfs_umount_all (g);
743     if (r == -1)
744       return -1;
745   }
746   {
747     int r;
748     suppress_error = 0;
749     r = guestfs_lvm_remove_all (g);
750     if (r == -1)
751       return -1;
752   }
753   {
754     char *lines[] = {
755       ",",
756       NULL
757     };
758     int r;
759     suppress_error = 0;
760     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
761     if (r == -1)
762       return -1;
763   }
764   {
765     int r;
766     suppress_error = 0;
767     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
768     if (r == -1)
769       return -1;
770   }
771   {
772     int r;
773     suppress_error = 0;
774     r = guestfs_mount (g, "/dev/sda1", "/");
775     if (r == -1)
776       return -1;
777   }
778   /* TestLastFail for file (2) */
779   {
780     char *r;
781     suppress_error = 1;
782     r = guestfs_file (g, "/nofile");
783     if (r != NULL)
784       return -1;
785     free (r);
786   }
787   return 0;
788 }
789
790 static int test_umount_all_0 (void)
791 {
792   /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */
793   {
794     int r;
795     suppress_error = 0;
796     r = guestfs_umount_all (g);
797     if (r == -1)
798       return -1;
799   }
800   {
801     int r;
802     suppress_error = 0;
803     r = guestfs_lvm_remove_all (g);
804     if (r == -1)
805       return -1;
806   }
807   {
808     char *lines[] = {
809       ",",
810       NULL
811     };
812     int r;
813     suppress_error = 0;
814     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
815     if (r == -1)
816       return -1;
817   }
818   {
819     int r;
820     suppress_error = 0;
821     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
822     if (r == -1)
823       return -1;
824   }
825   {
826     int r;
827     suppress_error = 0;
828     r = guestfs_mount (g, "/dev/sda1", "/");
829     if (r == -1)
830       return -1;
831   }
832   /* TestOutputList for umount_all (0) */
833   {
834     int r;
835     suppress_error = 0;
836     r = guestfs_umount_all (g);
837     if (r == -1)
838       return -1;
839   }
840   {
841     char **r;
842     int i;
843     suppress_error = 0;
844     r = guestfs_mounts (g);
845     if (r == NULL)
846       return -1;
847     if (r[0] != NULL) {
848       fprintf (stderr, "test_umount_all_0: extra elements returned from command\n");
849       print_strings (r);
850       return -1;
851     }
852     for (i = 0; r[i] != NULL; ++i)
853       free (r[i]);
854     free (r);
855   }
856   return 0;
857 }
858
859 static int test_mounts_0 (void)
860 {
861   /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */
862   {
863     int r;
864     suppress_error = 0;
865     r = guestfs_umount_all (g);
866     if (r == -1)
867       return -1;
868   }
869   {
870     int r;
871     suppress_error = 0;
872     r = guestfs_lvm_remove_all (g);
873     if (r == -1)
874       return -1;
875   }
876   {
877     char *lines[] = {
878       ",",
879       NULL
880     };
881     int r;
882     suppress_error = 0;
883     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
884     if (r == -1)
885       return -1;
886   }
887   {
888     int r;
889     suppress_error = 0;
890     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
891     if (r == -1)
892       return -1;
893   }
894   {
895     int r;
896     suppress_error = 0;
897     r = guestfs_mount (g, "/dev/sda1", "/");
898     if (r == -1)
899       return -1;
900   }
901   /* TestOutputList for mounts (0) */
902   {
903     char **r;
904     int i;
905     suppress_error = 0;
906     r = guestfs_mounts (g);
907     if (r == NULL)
908       return -1;
909     if (!r[0]) {
910       fprintf (stderr, "test_mounts_0: short list returned from command\n");
911       print_strings (r);
912       return -1;
913     }
914     if (strcmp (r[0], "/dev/sda1") != 0) {
915       fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
916       return -1;
917     }
918     if (r[1] != NULL) {
919       fprintf (stderr, "test_mounts_0: extra elements returned from command\n");
920       print_strings (r);
921       return -1;
922     }
923     for (i = 0; r[i] != NULL; ++i)
924       free (r[i]);
925     free (r);
926   }
927   return 0;
928 }
929
930 static int test_umount_0 (void)
931 {
932   /* InitEmpty for umount (0) */
933   {
934     int r;
935     suppress_error = 0;
936     r = guestfs_umount_all (g);
937     if (r == -1)
938       return -1;
939   }
940   {
941     int r;
942     suppress_error = 0;
943     r = guestfs_lvm_remove_all (g);
944     if (r == -1)
945       return -1;
946   }
947   /* TestOutputList for umount (0) */
948   {
949     char *lines[] = {
950       ",",
951       NULL
952     };
953     int r;
954     suppress_error = 0;
955     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
956     if (r == -1)
957       return -1;
958   }
959   {
960     int r;
961     suppress_error = 0;
962     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
963     if (r == -1)
964       return -1;
965   }
966   {
967     int r;
968     suppress_error = 0;
969     r = guestfs_mount (g, "/dev/sda1", "/");
970     if (r == -1)
971       return -1;
972   }
973   {
974     char **r;
975     int i;
976     suppress_error = 0;
977     r = guestfs_mounts (g);
978     if (r == NULL)
979       return -1;
980     if (!r[0]) {
981       fprintf (stderr, "test_umount_0: short list returned from command\n");
982       print_strings (r);
983       return -1;
984     }
985     if (strcmp (r[0], "/dev/sda1") != 0) {
986       fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
987       return -1;
988     }
989     if (r[1] != NULL) {
990       fprintf (stderr, "test_umount_0: extra elements returned from command\n");
991       print_strings (r);
992       return -1;
993     }
994     for (i = 0; r[i] != NULL; ++i)
995       free (r[i]);
996     free (r);
997   }
998   return 0;
999 }
1000
1001 static int test_umount_1 (void)
1002 {
1003   /* InitEmpty for umount (1) */
1004   {
1005     int r;
1006     suppress_error = 0;
1007     r = guestfs_umount_all (g);
1008     if (r == -1)
1009       return -1;
1010   }
1011   {
1012     int r;
1013     suppress_error = 0;
1014     r = guestfs_lvm_remove_all (g);
1015     if (r == -1)
1016       return -1;
1017   }
1018   /* TestOutputList for umount (1) */
1019   {
1020     char *lines[] = {
1021       ",",
1022       NULL
1023     };
1024     int r;
1025     suppress_error = 0;
1026     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1027     if (r == -1)
1028       return -1;
1029   }
1030   {
1031     int r;
1032     suppress_error = 0;
1033     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1034     if (r == -1)
1035       return -1;
1036   }
1037   {
1038     int r;
1039     suppress_error = 0;
1040     r = guestfs_mount (g, "/dev/sda1", "/");
1041     if (r == -1)
1042       return -1;
1043   }
1044   {
1045     int r;
1046     suppress_error = 0;
1047     r = guestfs_umount (g, "/");
1048     if (r == -1)
1049       return -1;
1050   }
1051   {
1052     char **r;
1053     int i;
1054     suppress_error = 0;
1055     r = guestfs_mounts (g);
1056     if (r == NULL)
1057       return -1;
1058     if (r[0] != NULL) {
1059       fprintf (stderr, "test_umount_1: extra elements returned from command\n");
1060       print_strings (r);
1061       return -1;
1062     }
1063     for (i = 0; r[i] != NULL; ++i)
1064       free (r[i]);
1065     free (r);
1066   }
1067   return 0;
1068 }
1069
1070 static int test_write_file_0 (void)
1071 {
1072   /* InitBasicFS for write_file (0): create ext2 on /dev/sda1 */
1073   {
1074     int r;
1075     suppress_error = 0;
1076     r = guestfs_umount_all (g);
1077     if (r == -1)
1078       return -1;
1079   }
1080   {
1081     int r;
1082     suppress_error = 0;
1083     r = guestfs_lvm_remove_all (g);
1084     if (r == -1)
1085       return -1;
1086   }
1087   {
1088     char *lines[] = {
1089       ",",
1090       NULL
1091     };
1092     int r;
1093     suppress_error = 0;
1094     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1095     if (r == -1)
1096       return -1;
1097   }
1098   {
1099     int r;
1100     suppress_error = 0;
1101     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1102     if (r == -1)
1103       return -1;
1104   }
1105   {
1106     int r;
1107     suppress_error = 0;
1108     r = guestfs_mount (g, "/dev/sda1", "/");
1109     if (r == -1)
1110       return -1;
1111   }
1112   /* TestOutput for write_file (0) */
1113   {
1114     int r;
1115     suppress_error = 0;
1116     r = guestfs_write_file (g, "/new", "new file contents", 0);
1117     if (r == -1)
1118       return -1;
1119   }
1120   {
1121     char *r;
1122     suppress_error = 0;
1123     r = guestfs_cat (g, "/new");
1124     if (r == NULL)
1125       return -1;
1126     if (strcmp (r, "new file contents") != 0) {
1127       fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r);
1128       return -1;
1129     }
1130     free (r);
1131   }
1132   return 0;
1133 }
1134
1135 static int test_write_file_1 (void)
1136 {
1137   /* InitBasicFS for write_file (1): create ext2 on /dev/sda1 */
1138   {
1139     int r;
1140     suppress_error = 0;
1141     r = guestfs_umount_all (g);
1142     if (r == -1)
1143       return -1;
1144   }
1145   {
1146     int r;
1147     suppress_error = 0;
1148     r = guestfs_lvm_remove_all (g);
1149     if (r == -1)
1150       return -1;
1151   }
1152   {
1153     char *lines[] = {
1154       ",",
1155       NULL
1156     };
1157     int r;
1158     suppress_error = 0;
1159     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1160     if (r == -1)
1161       return -1;
1162   }
1163   {
1164     int r;
1165     suppress_error = 0;
1166     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1167     if (r == -1)
1168       return -1;
1169   }
1170   {
1171     int r;
1172     suppress_error = 0;
1173     r = guestfs_mount (g, "/dev/sda1", "/");
1174     if (r == -1)
1175       return -1;
1176   }
1177   /* TestOutput for write_file (1) */
1178   {
1179     int r;
1180     suppress_error = 0;
1181     r = guestfs_write_file (g, "/new", "\nnew file contents\n", 0);
1182     if (r == -1)
1183       return -1;
1184   }
1185   {
1186     char *r;
1187     suppress_error = 0;
1188     r = guestfs_cat (g, "/new");
1189     if (r == NULL)
1190       return -1;
1191     if (strcmp (r, "\nnew file contents\n") != 0) {
1192       fprintf (stderr, "test_write_file_1: expected \"\nnew file contents\n\" but got \"%s\"\n", r);
1193       return -1;
1194     }
1195     free (r);
1196   }
1197   return 0;
1198 }
1199
1200 static int test_write_file_2 (void)
1201 {
1202   /* InitBasicFS for write_file (2): create ext2 on /dev/sda1 */
1203   {
1204     int r;
1205     suppress_error = 0;
1206     r = guestfs_umount_all (g);
1207     if (r == -1)
1208       return -1;
1209   }
1210   {
1211     int r;
1212     suppress_error = 0;
1213     r = guestfs_lvm_remove_all (g);
1214     if (r == -1)
1215       return -1;
1216   }
1217   {
1218     char *lines[] = {
1219       ",",
1220       NULL
1221     };
1222     int r;
1223     suppress_error = 0;
1224     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1225     if (r == -1)
1226       return -1;
1227   }
1228   {
1229     int r;
1230     suppress_error = 0;
1231     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1232     if (r == -1)
1233       return -1;
1234   }
1235   {
1236     int r;
1237     suppress_error = 0;
1238     r = guestfs_mount (g, "/dev/sda1", "/");
1239     if (r == -1)
1240       return -1;
1241   }
1242   /* TestOutput for write_file (2) */
1243   {
1244     int r;
1245     suppress_error = 0;
1246     r = guestfs_write_file (g, "/new", "\n\n", 0);
1247     if (r == -1)
1248       return -1;
1249   }
1250   {
1251     char *r;
1252     suppress_error = 0;
1253     r = guestfs_cat (g, "/new");
1254     if (r == NULL)
1255       return -1;
1256     if (strcmp (r, "\n\n") != 0) {
1257       fprintf (stderr, "test_write_file_2: expected \"\n\n\" but got \"%s\"\n", r);
1258       return -1;
1259     }
1260     free (r);
1261   }
1262   return 0;
1263 }
1264
1265 static int test_write_file_3 (void)
1266 {
1267   /* InitBasicFS for write_file (3): create ext2 on /dev/sda1 */
1268   {
1269     int r;
1270     suppress_error = 0;
1271     r = guestfs_umount_all (g);
1272     if (r == -1)
1273       return -1;
1274   }
1275   {
1276     int r;
1277     suppress_error = 0;
1278     r = guestfs_lvm_remove_all (g);
1279     if (r == -1)
1280       return -1;
1281   }
1282   {
1283     char *lines[] = {
1284       ",",
1285       NULL
1286     };
1287     int r;
1288     suppress_error = 0;
1289     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1290     if (r == -1)
1291       return -1;
1292   }
1293   {
1294     int r;
1295     suppress_error = 0;
1296     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1297     if (r == -1)
1298       return -1;
1299   }
1300   {
1301     int r;
1302     suppress_error = 0;
1303     r = guestfs_mount (g, "/dev/sda1", "/");
1304     if (r == -1)
1305       return -1;
1306   }
1307   /* TestOutput for write_file (3) */
1308   {
1309     int r;
1310     suppress_error = 0;
1311     r = guestfs_write_file (g, "/new", "", 0);
1312     if (r == -1)
1313       return -1;
1314   }
1315   {
1316     char *r;
1317     suppress_error = 0;
1318     r = guestfs_cat (g, "/new");
1319     if (r == NULL)
1320       return -1;
1321     if (strcmp (r, "") != 0) {
1322       fprintf (stderr, "test_write_file_3: expected \"\" but got \"%s\"\n", r);
1323       return -1;
1324     }
1325     free (r);
1326   }
1327   return 0;
1328 }
1329
1330 static int test_write_file_4 (void)
1331 {
1332   /* InitBasicFS for write_file (4): create ext2 on /dev/sda1 */
1333   {
1334     int r;
1335     suppress_error = 0;
1336     r = guestfs_umount_all (g);
1337     if (r == -1)
1338       return -1;
1339   }
1340   {
1341     int r;
1342     suppress_error = 0;
1343     r = guestfs_lvm_remove_all (g);
1344     if (r == -1)
1345       return -1;
1346   }
1347   {
1348     char *lines[] = {
1349       ",",
1350       NULL
1351     };
1352     int r;
1353     suppress_error = 0;
1354     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1355     if (r == -1)
1356       return -1;
1357   }
1358   {
1359     int r;
1360     suppress_error = 0;
1361     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1362     if (r == -1)
1363       return -1;
1364   }
1365   {
1366     int r;
1367     suppress_error = 0;
1368     r = guestfs_mount (g, "/dev/sda1", "/");
1369     if (r == -1)
1370       return -1;
1371   }
1372   /* TestOutput for write_file (4) */
1373   {
1374     int r;
1375     suppress_error = 0;
1376     r = guestfs_write_file (g, "/new", "\n\n\n", 0);
1377     if (r == -1)
1378       return -1;
1379   }
1380   {
1381     char *r;
1382     suppress_error = 0;
1383     r = guestfs_cat (g, "/new");
1384     if (r == NULL)
1385       return -1;
1386     if (strcmp (r, "\n\n\n") != 0) {
1387       fprintf (stderr, "test_write_file_4: expected \"\n\n\n\" but got \"%s\"\n", r);
1388       return -1;
1389     }
1390     free (r);
1391   }
1392   return 0;
1393 }
1394
1395 static int test_write_file_5 (void)
1396 {
1397   /* InitBasicFS for write_file (5): create ext2 on /dev/sda1 */
1398   {
1399     int r;
1400     suppress_error = 0;
1401     r = guestfs_umount_all (g);
1402     if (r == -1)
1403       return -1;
1404   }
1405   {
1406     int r;
1407     suppress_error = 0;
1408     r = guestfs_lvm_remove_all (g);
1409     if (r == -1)
1410       return -1;
1411   }
1412   {
1413     char *lines[] = {
1414       ",",
1415       NULL
1416     };
1417     int r;
1418     suppress_error = 0;
1419     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1420     if (r == -1)
1421       return -1;
1422   }
1423   {
1424     int r;
1425     suppress_error = 0;
1426     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1427     if (r == -1)
1428       return -1;
1429   }
1430   {
1431     int r;
1432     suppress_error = 0;
1433     r = guestfs_mount (g, "/dev/sda1", "/");
1434     if (r == -1)
1435       return -1;
1436   }
1437   /* TestOutput for write_file (5) */
1438   {
1439     int r;
1440     suppress_error = 0;
1441     r = guestfs_write_file (g, "/new", "\n", 0);
1442     if (r == -1)
1443       return -1;
1444   }
1445   {
1446     char *r;
1447     suppress_error = 0;
1448     r = guestfs_cat (g, "/new");
1449     if (r == NULL)
1450       return -1;
1451     if (strcmp (r, "\n") != 0) {
1452       fprintf (stderr, "test_write_file_5: expected \"\n\" but got \"%s\"\n", r);
1453       return -1;
1454     }
1455     free (r);
1456   }
1457   return 0;
1458 }
1459
1460 static int test_mkfs_0 (void)
1461 {
1462   /* InitEmpty for mkfs (0) */
1463   {
1464     int r;
1465     suppress_error = 0;
1466     r = guestfs_umount_all (g);
1467     if (r == -1)
1468       return -1;
1469   }
1470   {
1471     int r;
1472     suppress_error = 0;
1473     r = guestfs_lvm_remove_all (g);
1474     if (r == -1)
1475       return -1;
1476   }
1477   /* TestOutput for mkfs (0) */
1478   {
1479     char *lines[] = {
1480       ",",
1481       NULL
1482     };
1483     int r;
1484     suppress_error = 0;
1485     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1486     if (r == -1)
1487       return -1;
1488   }
1489   {
1490     int r;
1491     suppress_error = 0;
1492     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1493     if (r == -1)
1494       return -1;
1495   }
1496   {
1497     int r;
1498     suppress_error = 0;
1499     r = guestfs_mount (g, "/dev/sda1", "/");
1500     if (r == -1)
1501       return -1;
1502   }
1503   {
1504     int r;
1505     suppress_error = 0;
1506     r = guestfs_write_file (g, "/new", "new file contents", 0);
1507     if (r == -1)
1508       return -1;
1509   }
1510   {
1511     char *r;
1512     suppress_error = 0;
1513     r = guestfs_cat (g, "/new");
1514     if (r == NULL)
1515       return -1;
1516     if (strcmp (r, "new file contents") != 0) {
1517       fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r);
1518       return -1;
1519     }
1520     free (r);
1521   }
1522   return 0;
1523 }
1524
1525 static int test_lvcreate_0 (void)
1526 {
1527   /* InitEmpty for lvcreate (0) */
1528   {
1529     int r;
1530     suppress_error = 0;
1531     r = guestfs_umount_all (g);
1532     if (r == -1)
1533       return -1;
1534   }
1535   {
1536     int r;
1537     suppress_error = 0;
1538     r = guestfs_lvm_remove_all (g);
1539     if (r == -1)
1540       return -1;
1541   }
1542   /* TestOutputList for lvcreate (0) */
1543   {
1544     char *lines[] = {
1545       ",10",
1546       ",20",
1547       ",",
1548       NULL
1549     };
1550     int r;
1551     suppress_error = 0;
1552     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1553     if (r == -1)
1554       return -1;
1555   }
1556   {
1557     int r;
1558     suppress_error = 0;
1559     r = guestfs_pvcreate (g, "/dev/sda1");
1560     if (r == -1)
1561       return -1;
1562   }
1563   {
1564     int r;
1565     suppress_error = 0;
1566     r = guestfs_pvcreate (g, "/dev/sda2");
1567     if (r == -1)
1568       return -1;
1569   }
1570   {
1571     int r;
1572     suppress_error = 0;
1573     r = guestfs_pvcreate (g, "/dev/sda3");
1574     if (r == -1)
1575       return -1;
1576   }
1577   {
1578     char *physvols[] = {
1579       "/dev/sda1",
1580       "/dev/sda2",
1581       NULL
1582     };
1583     int r;
1584     suppress_error = 0;
1585     r = guestfs_vgcreate (g, "VG1", physvols);
1586     if (r == -1)
1587       return -1;
1588   }
1589   {
1590     char *physvols[] = {
1591       "/dev/sda3",
1592       NULL
1593     };
1594     int r;
1595     suppress_error = 0;
1596     r = guestfs_vgcreate (g, "VG2", physvols);
1597     if (r == -1)
1598       return -1;
1599   }
1600   {
1601     int r;
1602     suppress_error = 0;
1603     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
1604     if (r == -1)
1605       return -1;
1606   }
1607   {
1608     int r;
1609     suppress_error = 0;
1610     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
1611     if (r == -1)
1612       return -1;
1613   }
1614   {
1615     int r;
1616     suppress_error = 0;
1617     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
1618     if (r == -1)
1619       return -1;
1620   }
1621   {
1622     int r;
1623     suppress_error = 0;
1624     r = guestfs_lvcreate (g, "LV4", "VG2", 50);
1625     if (r == -1)
1626       return -1;
1627   }
1628   {
1629     int r;
1630     suppress_error = 0;
1631     r = guestfs_lvcreate (g, "LV5", "VG2", 50);
1632     if (r == -1)
1633       return -1;
1634   }
1635   {
1636     char **r;
1637     int i;
1638     suppress_error = 0;
1639     r = guestfs_lvs (g);
1640     if (r == NULL)
1641       return -1;
1642     if (!r[0]) {
1643       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1644       print_strings (r);
1645       return -1;
1646     }
1647     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
1648       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
1649       return -1;
1650     }
1651     if (!r[1]) {
1652       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1653       print_strings (r);
1654       return -1;
1655     }
1656     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
1657       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
1658       return -1;
1659     }
1660     if (!r[2]) {
1661       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1662       print_strings (r);
1663       return -1;
1664     }
1665     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
1666       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
1667       return -1;
1668     }
1669     if (!r[3]) {
1670       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1671       print_strings (r);
1672       return -1;
1673     }
1674     if (strcmp (r[3], "/dev/VG2/LV4") != 0) {
1675       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]);
1676       return -1;
1677     }
1678     if (!r[4]) {
1679       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1680       print_strings (r);
1681       return -1;
1682     }
1683     if (strcmp (r[4], "/dev/VG2/LV5") != 0) {
1684       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]);
1685       return -1;
1686     }
1687     if (r[5] != NULL) {
1688       fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n");
1689       print_strings (r);
1690       return -1;
1691     }
1692     for (i = 0; r[i] != NULL; ++i)
1693       free (r[i]);
1694     free (r);
1695   }
1696   return 0;
1697 }
1698
1699 static int test_vgcreate_0 (void)
1700 {
1701   /* InitEmpty for vgcreate (0) */
1702   {
1703     int r;
1704     suppress_error = 0;
1705     r = guestfs_umount_all (g);
1706     if (r == -1)
1707       return -1;
1708   }
1709   {
1710     int r;
1711     suppress_error = 0;
1712     r = guestfs_lvm_remove_all (g);
1713     if (r == -1)
1714       return -1;
1715   }
1716   /* TestOutputList for vgcreate (0) */
1717   {
1718     char *lines[] = {
1719       ",10",
1720       ",20",
1721       ",",
1722       NULL
1723     };
1724     int r;
1725     suppress_error = 0;
1726     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1727     if (r == -1)
1728       return -1;
1729   }
1730   {
1731     int r;
1732     suppress_error = 0;
1733     r = guestfs_pvcreate (g, "/dev/sda1");
1734     if (r == -1)
1735       return -1;
1736   }
1737   {
1738     int r;
1739     suppress_error = 0;
1740     r = guestfs_pvcreate (g, "/dev/sda2");
1741     if (r == -1)
1742       return -1;
1743   }
1744   {
1745     int r;
1746     suppress_error = 0;
1747     r = guestfs_pvcreate (g, "/dev/sda3");
1748     if (r == -1)
1749       return -1;
1750   }
1751   {
1752     char *physvols[] = {
1753       "/dev/sda1",
1754       "/dev/sda2",
1755       NULL
1756     };
1757     int r;
1758     suppress_error = 0;
1759     r = guestfs_vgcreate (g, "VG1", physvols);
1760     if (r == -1)
1761       return -1;
1762   }
1763   {
1764     char *physvols[] = {
1765       "/dev/sda3",
1766       NULL
1767     };
1768     int r;
1769     suppress_error = 0;
1770     r = guestfs_vgcreate (g, "VG2", physvols);
1771     if (r == -1)
1772       return -1;
1773   }
1774   {
1775     char **r;
1776     int i;
1777     suppress_error = 0;
1778     r = guestfs_vgs (g);
1779     if (r == NULL)
1780       return -1;
1781     if (!r[0]) {
1782       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
1783       print_strings (r);
1784       return -1;
1785     }
1786     if (strcmp (r[0], "VG1") != 0) {
1787       fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]);
1788       return -1;
1789     }
1790     if (!r[1]) {
1791       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
1792       print_strings (r);
1793       return -1;
1794     }
1795     if (strcmp (r[1], "VG2") != 0) {
1796       fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]);
1797       return -1;
1798     }
1799     if (r[2] != NULL) {
1800       fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n");
1801       print_strings (r);
1802       return -1;
1803     }
1804     for (i = 0; r[i] != NULL; ++i)
1805       free (r[i]);
1806     free (r);
1807   }
1808   return 0;
1809 }
1810
1811 static int test_pvcreate_0 (void)
1812 {
1813   /* InitEmpty for pvcreate (0) */
1814   {
1815     int r;
1816     suppress_error = 0;
1817     r = guestfs_umount_all (g);
1818     if (r == -1)
1819       return -1;
1820   }
1821   {
1822     int r;
1823     suppress_error = 0;
1824     r = guestfs_lvm_remove_all (g);
1825     if (r == -1)
1826       return -1;
1827   }
1828   /* TestOutputList for pvcreate (0) */
1829   {
1830     char *lines[] = {
1831       ",10",
1832       ",20",
1833       ",",
1834       NULL
1835     };
1836     int r;
1837     suppress_error = 0;
1838     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1839     if (r == -1)
1840       return -1;
1841   }
1842   {
1843     int r;
1844     suppress_error = 0;
1845     r = guestfs_pvcreate (g, "/dev/sda1");
1846     if (r == -1)
1847       return -1;
1848   }
1849   {
1850     int r;
1851     suppress_error = 0;
1852     r = guestfs_pvcreate (g, "/dev/sda2");
1853     if (r == -1)
1854       return -1;
1855   }
1856   {
1857     int r;
1858     suppress_error = 0;
1859     r = guestfs_pvcreate (g, "/dev/sda3");
1860     if (r == -1)
1861       return -1;
1862   }
1863   {
1864     char **r;
1865     int i;
1866     suppress_error = 0;
1867     r = guestfs_pvs (g);
1868     if (r == NULL)
1869       return -1;
1870     if (!r[0]) {
1871       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1872       print_strings (r);
1873       return -1;
1874     }
1875     if (strcmp (r[0], "/dev/sda1") != 0) {
1876       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
1877       return -1;
1878     }
1879     if (!r[1]) {
1880       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1881       print_strings (r);
1882       return -1;
1883     }
1884     if (strcmp (r[1], "/dev/sda2") != 0) {
1885       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
1886       return -1;
1887     }
1888     if (!r[2]) {
1889       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1890       print_strings (r);
1891       return -1;
1892     }
1893     if (strcmp (r[2], "/dev/sda3") != 0) {
1894       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
1895       return -1;
1896     }
1897     if (r[3] != NULL) {
1898       fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n");
1899       print_strings (r);
1900       return -1;
1901     }
1902     for (i = 0; r[i] != NULL; ++i)
1903       free (r[i]);
1904     free (r);
1905   }
1906   return 0;
1907 }
1908
1909 static int test_is_dir_0 (void)
1910 {
1911   /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */
1912   {
1913     int r;
1914     suppress_error = 0;
1915     r = guestfs_umount_all (g);
1916     if (r == -1)
1917       return -1;
1918   }
1919   {
1920     int r;
1921     suppress_error = 0;
1922     r = guestfs_lvm_remove_all (g);
1923     if (r == -1)
1924       return -1;
1925   }
1926   {
1927     char *lines[] = {
1928       ",",
1929       NULL
1930     };
1931     int r;
1932     suppress_error = 0;
1933     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1934     if (r == -1)
1935       return -1;
1936   }
1937   {
1938     int r;
1939     suppress_error = 0;
1940     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1941     if (r == -1)
1942       return -1;
1943   }
1944   {
1945     int r;
1946     suppress_error = 0;
1947     r = guestfs_mount (g, "/dev/sda1", "/");
1948     if (r == -1)
1949       return -1;
1950   }
1951   /* TestOutputFalse for is_dir (0) */
1952   {
1953     int r;
1954     suppress_error = 0;
1955     r = guestfs_touch (g, "/new");
1956     if (r == -1)
1957       return -1;
1958   }
1959   {
1960     int r;
1961     suppress_error = 0;
1962     r = guestfs_is_dir (g, "/new");
1963     if (r == -1)
1964       return -1;
1965     if (r) {
1966       fprintf (stderr, "test_is_dir_0: expected false, got true\n");
1967       return -1;
1968     }
1969   }
1970   return 0;
1971 }
1972
1973 static int test_is_dir_1 (void)
1974 {
1975   /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */
1976   {
1977     int r;
1978     suppress_error = 0;
1979     r = guestfs_umount_all (g);
1980     if (r == -1)
1981       return -1;
1982   }
1983   {
1984     int r;
1985     suppress_error = 0;
1986     r = guestfs_lvm_remove_all (g);
1987     if (r == -1)
1988       return -1;
1989   }
1990   {
1991     char *lines[] = {
1992       ",",
1993       NULL
1994     };
1995     int r;
1996     suppress_error = 0;
1997     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1998     if (r == -1)
1999       return -1;
2000   }
2001   {
2002     int r;
2003     suppress_error = 0;
2004     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2005     if (r == -1)
2006       return -1;
2007   }
2008   {
2009     int r;
2010     suppress_error = 0;
2011     r = guestfs_mount (g, "/dev/sda1", "/");
2012     if (r == -1)
2013       return -1;
2014   }
2015   /* TestOutputTrue for is_dir (1) */
2016   {
2017     int r;
2018     suppress_error = 0;
2019     r = guestfs_mkdir (g, "/new");
2020     if (r == -1)
2021       return -1;
2022   }
2023   {
2024     int r;
2025     suppress_error = 0;
2026     r = guestfs_is_dir (g, "/new");
2027     if (r == -1)
2028       return -1;
2029     if (!r) {
2030       fprintf (stderr, "test_is_dir_1: expected true, got false\n");
2031       return -1;
2032     }
2033   }
2034   return 0;
2035 }
2036
2037 static int test_is_file_0 (void)
2038 {
2039   /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */
2040   {
2041     int r;
2042     suppress_error = 0;
2043     r = guestfs_umount_all (g);
2044     if (r == -1)
2045       return -1;
2046   }
2047   {
2048     int r;
2049     suppress_error = 0;
2050     r = guestfs_lvm_remove_all (g);
2051     if (r == -1)
2052       return -1;
2053   }
2054   {
2055     char *lines[] = {
2056       ",",
2057       NULL
2058     };
2059     int r;
2060     suppress_error = 0;
2061     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2062     if (r == -1)
2063       return -1;
2064   }
2065   {
2066     int r;
2067     suppress_error = 0;
2068     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2069     if (r == -1)
2070       return -1;
2071   }
2072   {
2073     int r;
2074     suppress_error = 0;
2075     r = guestfs_mount (g, "/dev/sda1", "/");
2076     if (r == -1)
2077       return -1;
2078   }
2079   /* TestOutputTrue for is_file (0) */
2080   {
2081     int r;
2082     suppress_error = 0;
2083     r = guestfs_touch (g, "/new");
2084     if (r == -1)
2085       return -1;
2086   }
2087   {
2088     int r;
2089     suppress_error = 0;
2090     r = guestfs_is_file (g, "/new");
2091     if (r == -1)
2092       return -1;
2093     if (!r) {
2094       fprintf (stderr, "test_is_file_0: expected true, got false\n");
2095       return -1;
2096     }
2097   }
2098   return 0;
2099 }
2100
2101 static int test_is_file_1 (void)
2102 {
2103   /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */
2104   {
2105     int r;
2106     suppress_error = 0;
2107     r = guestfs_umount_all (g);
2108     if (r == -1)
2109       return -1;
2110   }
2111   {
2112     int r;
2113     suppress_error = 0;
2114     r = guestfs_lvm_remove_all (g);
2115     if (r == -1)
2116       return -1;
2117   }
2118   {
2119     char *lines[] = {
2120       ",",
2121       NULL
2122     };
2123     int r;
2124     suppress_error = 0;
2125     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2126     if (r == -1)
2127       return -1;
2128   }
2129   {
2130     int r;
2131     suppress_error = 0;
2132     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2133     if (r == -1)
2134       return -1;
2135   }
2136   {
2137     int r;
2138     suppress_error = 0;
2139     r = guestfs_mount (g, "/dev/sda1", "/");
2140     if (r == -1)
2141       return -1;
2142   }
2143   /* TestOutputFalse for is_file (1) */
2144   {
2145     int r;
2146     suppress_error = 0;
2147     r = guestfs_mkdir (g, "/new");
2148     if (r == -1)
2149       return -1;
2150   }
2151   {
2152     int r;
2153     suppress_error = 0;
2154     r = guestfs_is_file (g, "/new");
2155     if (r == -1)
2156       return -1;
2157     if (r) {
2158       fprintf (stderr, "test_is_file_1: expected false, got true\n");
2159       return -1;
2160     }
2161   }
2162   return 0;
2163 }
2164
2165 static int test_exists_0 (void)
2166 {
2167   /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */
2168   {
2169     int r;
2170     suppress_error = 0;
2171     r = guestfs_umount_all (g);
2172     if (r == -1)
2173       return -1;
2174   }
2175   {
2176     int r;
2177     suppress_error = 0;
2178     r = guestfs_lvm_remove_all (g);
2179     if (r == -1)
2180       return -1;
2181   }
2182   {
2183     char *lines[] = {
2184       ",",
2185       NULL
2186     };
2187     int r;
2188     suppress_error = 0;
2189     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2190     if (r == -1)
2191       return -1;
2192   }
2193   {
2194     int r;
2195     suppress_error = 0;
2196     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2197     if (r == -1)
2198       return -1;
2199   }
2200   {
2201     int r;
2202     suppress_error = 0;
2203     r = guestfs_mount (g, "/dev/sda1", "/");
2204     if (r == -1)
2205       return -1;
2206   }
2207   /* TestOutputTrue for exists (0) */
2208   {
2209     int r;
2210     suppress_error = 0;
2211     r = guestfs_touch (g, "/new");
2212     if (r == -1)
2213       return -1;
2214   }
2215   {
2216     int r;
2217     suppress_error = 0;
2218     r = guestfs_exists (g, "/new");
2219     if (r == -1)
2220       return -1;
2221     if (!r) {
2222       fprintf (stderr, "test_exists_0: expected true, got false\n");
2223       return -1;
2224     }
2225   }
2226   return 0;
2227 }
2228
2229 static int test_exists_1 (void)
2230 {
2231   /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */
2232   {
2233     int r;
2234     suppress_error = 0;
2235     r = guestfs_umount_all (g);
2236     if (r == -1)
2237       return -1;
2238   }
2239   {
2240     int r;
2241     suppress_error = 0;
2242     r = guestfs_lvm_remove_all (g);
2243     if (r == -1)
2244       return -1;
2245   }
2246   {
2247     char *lines[] = {
2248       ",",
2249       NULL
2250     };
2251     int r;
2252     suppress_error = 0;
2253     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2254     if (r == -1)
2255       return -1;
2256   }
2257   {
2258     int r;
2259     suppress_error = 0;
2260     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2261     if (r == -1)
2262       return -1;
2263   }
2264   {
2265     int r;
2266     suppress_error = 0;
2267     r = guestfs_mount (g, "/dev/sda1", "/");
2268     if (r == -1)
2269       return -1;
2270   }
2271   /* TestOutputTrue for exists (1) */
2272   {
2273     int r;
2274     suppress_error = 0;
2275     r = guestfs_mkdir (g, "/new");
2276     if (r == -1)
2277       return -1;
2278   }
2279   {
2280     int r;
2281     suppress_error = 0;
2282     r = guestfs_exists (g, "/new");
2283     if (r == -1)
2284       return -1;
2285     if (!r) {
2286       fprintf (stderr, "test_exists_1: expected true, got false\n");
2287       return -1;
2288     }
2289   }
2290   return 0;
2291 }
2292
2293 static int test_mkdir_p_0 (void)
2294 {
2295   /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */
2296   {
2297     int r;
2298     suppress_error = 0;
2299     r = guestfs_umount_all (g);
2300     if (r == -1)
2301       return -1;
2302   }
2303   {
2304     int r;
2305     suppress_error = 0;
2306     r = guestfs_lvm_remove_all (g);
2307     if (r == -1)
2308       return -1;
2309   }
2310   {
2311     char *lines[] = {
2312       ",",
2313       NULL
2314     };
2315     int r;
2316     suppress_error = 0;
2317     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2318     if (r == -1)
2319       return -1;
2320   }
2321   {
2322     int r;
2323     suppress_error = 0;
2324     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2325     if (r == -1)
2326       return -1;
2327   }
2328   {
2329     int r;
2330     suppress_error = 0;
2331     r = guestfs_mount (g, "/dev/sda1", "/");
2332     if (r == -1)
2333       return -1;
2334   }
2335   /* TestOutputTrue for mkdir_p (0) */
2336   {
2337     int r;
2338     suppress_error = 0;
2339     r = guestfs_mkdir_p (g, "/new/foo/bar");
2340     if (r == -1)
2341       return -1;
2342   }
2343   {
2344     int r;
2345     suppress_error = 0;
2346     r = guestfs_is_dir (g, "/new/foo/bar");
2347     if (r == -1)
2348       return -1;
2349     if (!r) {
2350       fprintf (stderr, "test_mkdir_p_0: expected true, got false\n");
2351       return -1;
2352     }
2353   }
2354   return 0;
2355 }
2356
2357 static int test_mkdir_p_1 (void)
2358 {
2359   /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */
2360   {
2361     int r;
2362     suppress_error = 0;
2363     r = guestfs_umount_all (g);
2364     if (r == -1)
2365       return -1;
2366   }
2367   {
2368     int r;
2369     suppress_error = 0;
2370     r = guestfs_lvm_remove_all (g);
2371     if (r == -1)
2372       return -1;
2373   }
2374   {
2375     char *lines[] = {
2376       ",",
2377       NULL
2378     };
2379     int r;
2380     suppress_error = 0;
2381     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2382     if (r == -1)
2383       return -1;
2384   }
2385   {
2386     int r;
2387     suppress_error = 0;
2388     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2389     if (r == -1)
2390       return -1;
2391   }
2392   {
2393     int r;
2394     suppress_error = 0;
2395     r = guestfs_mount (g, "/dev/sda1", "/");
2396     if (r == -1)
2397       return -1;
2398   }
2399   /* TestOutputTrue for mkdir_p (1) */
2400   {
2401     int r;
2402     suppress_error = 0;
2403     r = guestfs_mkdir_p (g, "/new/foo/bar");
2404     if (r == -1)
2405       return -1;
2406   }
2407   {
2408     int r;
2409     suppress_error = 0;
2410     r = guestfs_is_dir (g, "/new/foo");
2411     if (r == -1)
2412       return -1;
2413     if (!r) {
2414       fprintf (stderr, "test_mkdir_p_1: expected true, got false\n");
2415       return -1;
2416     }
2417   }
2418   return 0;
2419 }
2420
2421 static int test_mkdir_p_2 (void)
2422 {
2423   /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */
2424   {
2425     int r;
2426     suppress_error = 0;
2427     r = guestfs_umount_all (g);
2428     if (r == -1)
2429       return -1;
2430   }
2431   {
2432     int r;
2433     suppress_error = 0;
2434     r = guestfs_lvm_remove_all (g);
2435     if (r == -1)
2436       return -1;
2437   }
2438   {
2439     char *lines[] = {
2440       ",",
2441       NULL
2442     };
2443     int r;
2444     suppress_error = 0;
2445     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2446     if (r == -1)
2447       return -1;
2448   }
2449   {
2450     int r;
2451     suppress_error = 0;
2452     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2453     if (r == -1)
2454       return -1;
2455   }
2456   {
2457     int r;
2458     suppress_error = 0;
2459     r = guestfs_mount (g, "/dev/sda1", "/");
2460     if (r == -1)
2461       return -1;
2462   }
2463   /* TestOutputTrue for mkdir_p (2) */
2464   {
2465     int r;
2466     suppress_error = 0;
2467     r = guestfs_mkdir_p (g, "/new/foo/bar");
2468     if (r == -1)
2469       return -1;
2470   }
2471   {
2472     int r;
2473     suppress_error = 0;
2474     r = guestfs_is_dir (g, "/new");
2475     if (r == -1)
2476       return -1;
2477     if (!r) {
2478       fprintf (stderr, "test_mkdir_p_2: expected true, got false\n");
2479       return -1;
2480     }
2481   }
2482   return 0;
2483 }
2484
2485 static int test_mkdir_0 (void)
2486 {
2487   /* InitBasicFS for mkdir (0): create ext2 on /dev/sda1 */
2488   {
2489     int r;
2490     suppress_error = 0;
2491     r = guestfs_umount_all (g);
2492     if (r == -1)
2493       return -1;
2494   }
2495   {
2496     int r;
2497     suppress_error = 0;
2498     r = guestfs_lvm_remove_all (g);
2499     if (r == -1)
2500       return -1;
2501   }
2502   {
2503     char *lines[] = {
2504       ",",
2505       NULL
2506     };
2507     int r;
2508     suppress_error = 0;
2509     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2510     if (r == -1)
2511       return -1;
2512   }
2513   {
2514     int r;
2515     suppress_error = 0;
2516     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2517     if (r == -1)
2518       return -1;
2519   }
2520   {
2521     int r;
2522     suppress_error = 0;
2523     r = guestfs_mount (g, "/dev/sda1", "/");
2524     if (r == -1)
2525       return -1;
2526   }
2527   /* TestOutputTrue for mkdir (0) */
2528   {
2529     int r;
2530     suppress_error = 0;
2531     r = guestfs_mkdir (g, "/new");
2532     if (r == -1)
2533       return -1;
2534   }
2535   {
2536     int r;
2537     suppress_error = 0;
2538     r = guestfs_is_dir (g, "/new");
2539     if (r == -1)
2540       return -1;
2541     if (!r) {
2542       fprintf (stderr, "test_mkdir_0: expected true, got false\n");
2543       return -1;
2544     }
2545   }
2546   return 0;
2547 }
2548
2549 static int test_mkdir_1 (void)
2550 {
2551   /* InitBasicFS for mkdir (1): create ext2 on /dev/sda1 */
2552   {
2553     int r;
2554     suppress_error = 0;
2555     r = guestfs_umount_all (g);
2556     if (r == -1)
2557       return -1;
2558   }
2559   {
2560     int r;
2561     suppress_error = 0;
2562     r = guestfs_lvm_remove_all (g);
2563     if (r == -1)
2564       return -1;
2565   }
2566   {
2567     char *lines[] = {
2568       ",",
2569       NULL
2570     };
2571     int r;
2572     suppress_error = 0;
2573     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2574     if (r == -1)
2575       return -1;
2576   }
2577   {
2578     int r;
2579     suppress_error = 0;
2580     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2581     if (r == -1)
2582       return -1;
2583   }
2584   {
2585     int r;
2586     suppress_error = 0;
2587     r = guestfs_mount (g, "/dev/sda1", "/");
2588     if (r == -1)
2589       return -1;
2590   }
2591   /* TestLastFail for mkdir (1) */
2592   {
2593     int r;
2594     suppress_error = 1;
2595     r = guestfs_mkdir (g, "/new/foo/bar");
2596     if (r != -1)
2597       return -1;
2598   }
2599   return 0;
2600 }
2601
2602 static int test_rm_rf_0 (void)
2603 {
2604   /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */
2605   {
2606     int r;
2607     suppress_error = 0;
2608     r = guestfs_umount_all (g);
2609     if (r == -1)
2610       return -1;
2611   }
2612   {
2613     int r;
2614     suppress_error = 0;
2615     r = guestfs_lvm_remove_all (g);
2616     if (r == -1)
2617       return -1;
2618   }
2619   {
2620     char *lines[] = {
2621       ",",
2622       NULL
2623     };
2624     int r;
2625     suppress_error = 0;
2626     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2627     if (r == -1)
2628       return -1;
2629   }
2630   {
2631     int r;
2632     suppress_error = 0;
2633     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2634     if (r == -1)
2635       return -1;
2636   }
2637   {
2638     int r;
2639     suppress_error = 0;
2640     r = guestfs_mount (g, "/dev/sda1", "/");
2641     if (r == -1)
2642       return -1;
2643   }
2644   /* TestOutputFalse for rm_rf (0) */
2645   {
2646     int r;
2647     suppress_error = 0;
2648     r = guestfs_mkdir (g, "/new");
2649     if (r == -1)
2650       return -1;
2651   }
2652   {
2653     int r;
2654     suppress_error = 0;
2655     r = guestfs_mkdir (g, "/new/foo");
2656     if (r == -1)
2657       return -1;
2658   }
2659   {
2660     int r;
2661     suppress_error = 0;
2662     r = guestfs_touch (g, "/new/foo/bar");
2663     if (r == -1)
2664       return -1;
2665   }
2666   {
2667     int r;
2668     suppress_error = 0;
2669     r = guestfs_rm_rf (g, "/new");
2670     if (r == -1)
2671       return -1;
2672   }
2673   {
2674     int r;
2675     suppress_error = 0;
2676     r = guestfs_exists (g, "/new");
2677     if (r == -1)
2678       return -1;
2679     if (r) {
2680       fprintf (stderr, "test_rm_rf_0: expected false, got true\n");
2681       return -1;
2682     }
2683   }
2684   return 0;
2685 }
2686
2687 static int test_rmdir_0 (void)
2688 {
2689   /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */
2690   {
2691     int r;
2692     suppress_error = 0;
2693     r = guestfs_umount_all (g);
2694     if (r == -1)
2695       return -1;
2696   }
2697   {
2698     int r;
2699     suppress_error = 0;
2700     r = guestfs_lvm_remove_all (g);
2701     if (r == -1)
2702       return -1;
2703   }
2704   {
2705     char *lines[] = {
2706       ",",
2707       NULL
2708     };
2709     int r;
2710     suppress_error = 0;
2711     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2712     if (r == -1)
2713       return -1;
2714   }
2715   {
2716     int r;
2717     suppress_error = 0;
2718     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2719     if (r == -1)
2720       return -1;
2721   }
2722   {
2723     int r;
2724     suppress_error = 0;
2725     r = guestfs_mount (g, "/dev/sda1", "/");
2726     if (r == -1)
2727       return -1;
2728   }
2729   /* TestRun for rmdir (0) */
2730   {
2731     int r;
2732     suppress_error = 0;
2733     r = guestfs_mkdir (g, "/new");
2734     if (r == -1)
2735       return -1;
2736   }
2737   {
2738     int r;
2739     suppress_error = 0;
2740     r = guestfs_rmdir (g, "/new");
2741     if (r == -1)
2742       return -1;
2743   }
2744   return 0;
2745 }
2746
2747 static int test_rmdir_1 (void)
2748 {
2749   /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */
2750   {
2751     int r;
2752     suppress_error = 0;
2753     r = guestfs_umount_all (g);
2754     if (r == -1)
2755       return -1;
2756   }
2757   {
2758     int r;
2759     suppress_error = 0;
2760     r = guestfs_lvm_remove_all (g);
2761     if (r == -1)
2762       return -1;
2763   }
2764   {
2765     char *lines[] = {
2766       ",",
2767       NULL
2768     };
2769     int r;
2770     suppress_error = 0;
2771     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2772     if (r == -1)
2773       return -1;
2774   }
2775   {
2776     int r;
2777     suppress_error = 0;
2778     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2779     if (r == -1)
2780       return -1;
2781   }
2782   {
2783     int r;
2784     suppress_error = 0;
2785     r = guestfs_mount (g, "/dev/sda1", "/");
2786     if (r == -1)
2787       return -1;
2788   }
2789   /* TestLastFail for rmdir (1) */
2790   {
2791     int r;
2792     suppress_error = 1;
2793     r = guestfs_rmdir (g, "/new");
2794     if (r != -1)
2795       return -1;
2796   }
2797   return 0;
2798 }
2799
2800 static int test_rmdir_2 (void)
2801 {
2802   /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */
2803   {
2804     int r;
2805     suppress_error = 0;
2806     r = guestfs_umount_all (g);
2807     if (r == -1)
2808       return -1;
2809   }
2810   {
2811     int r;
2812     suppress_error = 0;
2813     r = guestfs_lvm_remove_all (g);
2814     if (r == -1)
2815       return -1;
2816   }
2817   {
2818     char *lines[] = {
2819       ",",
2820       NULL
2821     };
2822     int r;
2823     suppress_error = 0;
2824     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2825     if (r == -1)
2826       return -1;
2827   }
2828   {
2829     int r;
2830     suppress_error = 0;
2831     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2832     if (r == -1)
2833       return -1;
2834   }
2835   {
2836     int r;
2837     suppress_error = 0;
2838     r = guestfs_mount (g, "/dev/sda1", "/");
2839     if (r == -1)
2840       return -1;
2841   }
2842   /* TestLastFail for rmdir (2) */
2843   {
2844     int r;
2845     suppress_error = 0;
2846     r = guestfs_touch (g, "/new");
2847     if (r == -1)
2848       return -1;
2849   }
2850   {
2851     int r;
2852     suppress_error = 1;
2853     r = guestfs_rmdir (g, "/new");
2854     if (r != -1)
2855       return -1;
2856   }
2857   return 0;
2858 }
2859
2860 static int test_rm_0 (void)
2861 {
2862   /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */
2863   {
2864     int r;
2865     suppress_error = 0;
2866     r = guestfs_umount_all (g);
2867     if (r == -1)
2868       return -1;
2869   }
2870   {
2871     int r;
2872     suppress_error = 0;
2873     r = guestfs_lvm_remove_all (g);
2874     if (r == -1)
2875       return -1;
2876   }
2877   {
2878     char *lines[] = {
2879       ",",
2880       NULL
2881     };
2882     int r;
2883     suppress_error = 0;
2884     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2885     if (r == -1)
2886       return -1;
2887   }
2888   {
2889     int r;
2890     suppress_error = 0;
2891     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2892     if (r == -1)
2893       return -1;
2894   }
2895   {
2896     int r;
2897     suppress_error = 0;
2898     r = guestfs_mount (g, "/dev/sda1", "/");
2899     if (r == -1)
2900       return -1;
2901   }
2902   /* TestRun for rm (0) */
2903   {
2904     int r;
2905     suppress_error = 0;
2906     r = guestfs_touch (g, "/new");
2907     if (r == -1)
2908       return -1;
2909   }
2910   {
2911     int r;
2912     suppress_error = 0;
2913     r = guestfs_rm (g, "/new");
2914     if (r == -1)
2915       return -1;
2916   }
2917   return 0;
2918 }
2919
2920 static int test_rm_1 (void)
2921 {
2922   /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */
2923   {
2924     int r;
2925     suppress_error = 0;
2926     r = guestfs_umount_all (g);
2927     if (r == -1)
2928       return -1;
2929   }
2930   {
2931     int r;
2932     suppress_error = 0;
2933     r = guestfs_lvm_remove_all (g);
2934     if (r == -1)
2935       return -1;
2936   }
2937   {
2938     char *lines[] = {
2939       ",",
2940       NULL
2941     };
2942     int r;
2943     suppress_error = 0;
2944     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2945     if (r == -1)
2946       return -1;
2947   }
2948   {
2949     int r;
2950     suppress_error = 0;
2951     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2952     if (r == -1)
2953       return -1;
2954   }
2955   {
2956     int r;
2957     suppress_error = 0;
2958     r = guestfs_mount (g, "/dev/sda1", "/");
2959     if (r == -1)
2960       return -1;
2961   }
2962   /* TestLastFail for rm (1) */
2963   {
2964     int r;
2965     suppress_error = 1;
2966     r = guestfs_rm (g, "/new");
2967     if (r != -1)
2968       return -1;
2969   }
2970   return 0;
2971 }
2972
2973 static int test_rm_2 (void)
2974 {
2975   /* InitBasicFS for rm (2): create ext2 on /dev/sda1 */
2976   {
2977     int r;
2978     suppress_error = 0;
2979     r = guestfs_umount_all (g);
2980     if (r == -1)
2981       return -1;
2982   }
2983   {
2984     int r;
2985     suppress_error = 0;
2986     r = guestfs_lvm_remove_all (g);
2987     if (r == -1)
2988       return -1;
2989   }
2990   {
2991     char *lines[] = {
2992       ",",
2993       NULL
2994     };
2995     int r;
2996     suppress_error = 0;
2997     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2998     if (r == -1)
2999       return -1;
3000   }
3001   {
3002     int r;
3003     suppress_error = 0;
3004     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3005     if (r == -1)
3006       return -1;
3007   }
3008   {
3009     int r;
3010     suppress_error = 0;
3011     r = guestfs_mount (g, "/dev/sda1", "/");
3012     if (r == -1)
3013       return -1;
3014   }
3015   /* TestLastFail for rm (2) */
3016   {
3017     int r;
3018     suppress_error = 0;
3019     r = guestfs_mkdir (g, "/new");
3020     if (r == -1)
3021       return -1;
3022   }
3023   {
3024     int r;
3025     suppress_error = 1;
3026     r = guestfs_rm (g, "/new");
3027     if (r != -1)
3028       return -1;
3029   }
3030   return 0;
3031 }
3032
3033 static int test_read_lines_0 (void)
3034 {
3035   /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */
3036   {
3037     int r;
3038     suppress_error = 0;
3039     r = guestfs_umount_all (g);
3040     if (r == -1)
3041       return -1;
3042   }
3043   {
3044     int r;
3045     suppress_error = 0;
3046     r = guestfs_lvm_remove_all (g);
3047     if (r == -1)
3048       return -1;
3049   }
3050   {
3051     char *lines[] = {
3052       ",",
3053       NULL
3054     };
3055     int r;
3056     suppress_error = 0;
3057     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3058     if (r == -1)
3059       return -1;
3060   }
3061   {
3062     int r;
3063     suppress_error = 0;
3064     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3065     if (r == -1)
3066       return -1;
3067   }
3068   {
3069     int r;
3070     suppress_error = 0;
3071     r = guestfs_mount (g, "/dev/sda1", "/");
3072     if (r == -1)
3073       return -1;
3074   }
3075   /* TestOutputList for read_lines (0) */
3076   {
3077     int r;
3078     suppress_error = 0;
3079     r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0);
3080     if (r == -1)
3081       return -1;
3082   }
3083   {
3084     char **r;
3085     int i;
3086     suppress_error = 0;
3087     r = guestfs_read_lines (g, "/new");
3088     if (r == NULL)
3089       return -1;
3090     if (!r[0]) {
3091       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3092       print_strings (r);
3093       return -1;
3094     }
3095     if (strcmp (r[0], "line1") != 0) {
3096       fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]);
3097       return -1;
3098     }
3099     if (!r[1]) {
3100       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3101       print_strings (r);
3102       return -1;
3103     }
3104     if (strcmp (r[1], "line2") != 0) {
3105       fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]);
3106       return -1;
3107     }
3108     if (!r[2]) {
3109       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3110       print_strings (r);
3111       return -1;
3112     }
3113     if (strcmp (r[2], "line3") != 0) {
3114       fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]);
3115       return -1;
3116     }
3117     if (r[3] != NULL) {
3118       fprintf (stderr, "test_read_lines_0: extra elements returned from command\n");
3119       print_strings (r);
3120       return -1;
3121     }
3122     for (i = 0; r[i] != NULL; ++i)
3123       free (r[i]);
3124     free (r);
3125   }
3126   return 0;
3127 }
3128
3129 static int test_read_lines_1 (void)
3130 {
3131   /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */
3132   {
3133     int r;
3134     suppress_error = 0;
3135     r = guestfs_umount_all (g);
3136     if (r == -1)
3137       return -1;
3138   }
3139   {
3140     int r;
3141     suppress_error = 0;
3142     r = guestfs_lvm_remove_all (g);
3143     if (r == -1)
3144       return -1;
3145   }
3146   {
3147     char *lines[] = {
3148       ",",
3149       NULL
3150     };
3151     int r;
3152     suppress_error = 0;
3153     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3154     if (r == -1)
3155       return -1;
3156   }
3157   {
3158     int r;
3159     suppress_error = 0;
3160     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3161     if (r == -1)
3162       return -1;
3163   }
3164   {
3165     int r;
3166     suppress_error = 0;
3167     r = guestfs_mount (g, "/dev/sda1", "/");
3168     if (r == -1)
3169       return -1;
3170   }
3171   /* TestOutputList for read_lines (1) */
3172   {
3173     int r;
3174     suppress_error = 0;
3175     r = guestfs_write_file (g, "/new", "", 0);
3176     if (r == -1)
3177       return -1;
3178   }
3179   {
3180     char **r;
3181     int i;
3182     suppress_error = 0;
3183     r = guestfs_read_lines (g, "/new");
3184     if (r == NULL)
3185       return -1;
3186     if (r[0] != NULL) {
3187       fprintf (stderr, "test_read_lines_1: extra elements returned from command\n");
3188       print_strings (r);
3189       return -1;
3190     }
3191     for (i = 0; r[i] != NULL; ++i)
3192       free (r[i]);
3193     free (r);
3194   }
3195   return 0;
3196 }
3197
3198 static int test_lvs_0 (void)
3199 {
3200   /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */
3201   {
3202     int r;
3203     suppress_error = 0;
3204     r = guestfs_umount_all (g);
3205     if (r == -1)
3206       return -1;
3207   }
3208   {
3209     int r;
3210     suppress_error = 0;
3211     r = guestfs_lvm_remove_all (g);
3212     if (r == -1)
3213       return -1;
3214   }
3215   {
3216     char *lines[] = {
3217       ",",
3218       NULL
3219     };
3220     int r;
3221     suppress_error = 0;
3222     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3223     if (r == -1)
3224       return -1;
3225   }
3226   {
3227     int r;
3228     suppress_error = 0;
3229     r = guestfs_pvcreate (g, "/dev/sda1");
3230     if (r == -1)
3231       return -1;
3232   }
3233   {
3234     char *physvols[] = {
3235       "/dev/sda1",
3236       NULL
3237     };
3238     int r;
3239     suppress_error = 0;
3240     r = guestfs_vgcreate (g, "VG", physvols);
3241     if (r == -1)
3242       return -1;
3243   }
3244   {
3245     int r;
3246     suppress_error = 0;
3247     r = guestfs_lvcreate (g, "LV", "VG", 8);
3248     if (r == -1)
3249       return -1;
3250   }
3251   {
3252     int r;
3253     suppress_error = 0;
3254     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3255     if (r == -1)
3256       return -1;
3257   }
3258   {
3259     int r;
3260     suppress_error = 0;
3261     r = guestfs_mount (g, "/dev/VG/LV", "/");
3262     if (r == -1)
3263       return -1;
3264   }
3265   /* TestOutputList for lvs (0) */
3266   {
3267     char **r;
3268     int i;
3269     suppress_error = 0;
3270     r = guestfs_lvs (g);
3271     if (r == NULL)
3272       return -1;
3273     if (!r[0]) {
3274       fprintf (stderr, "test_lvs_0: short list returned from command\n");
3275       print_strings (r);
3276       return -1;
3277     }
3278     if (strcmp (r[0], "/dev/VG/LV") != 0) {
3279       fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]);
3280       return -1;
3281     }
3282     if (r[1] != NULL) {
3283       fprintf (stderr, "test_lvs_0: extra elements returned from command\n");
3284       print_strings (r);
3285       return -1;
3286     }
3287     for (i = 0; r[i] != NULL; ++i)
3288       free (r[i]);
3289     free (r);
3290   }
3291   return 0;
3292 }
3293
3294 static int test_lvs_1 (void)
3295 {
3296   /* InitEmpty for lvs (1) */
3297   {
3298     int r;
3299     suppress_error = 0;
3300     r = guestfs_umount_all (g);
3301     if (r == -1)
3302       return -1;
3303   }
3304   {
3305     int r;
3306     suppress_error = 0;
3307     r = guestfs_lvm_remove_all (g);
3308     if (r == -1)
3309       return -1;
3310   }
3311   /* TestOutputList for lvs (1) */
3312   {
3313     char *lines[] = {
3314       ",10",
3315       ",20",
3316       ",",
3317       NULL
3318     };
3319     int r;
3320     suppress_error = 0;
3321     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3322     if (r == -1)
3323       return -1;
3324   }
3325   {
3326     int r;
3327     suppress_error = 0;
3328     r = guestfs_pvcreate (g, "/dev/sda1");
3329     if (r == -1)
3330       return -1;
3331   }
3332   {
3333     int r;
3334     suppress_error = 0;
3335     r = guestfs_pvcreate (g, "/dev/sda2");
3336     if (r == -1)
3337       return -1;
3338   }
3339   {
3340     int r;
3341     suppress_error = 0;
3342     r = guestfs_pvcreate (g, "/dev/sda3");
3343     if (r == -1)
3344       return -1;
3345   }
3346   {
3347     char *physvols[] = {
3348       "/dev/sda1",
3349       "/dev/sda2",
3350       NULL
3351     };
3352     int r;
3353     suppress_error = 0;
3354     r = guestfs_vgcreate (g, "VG1", physvols);
3355     if (r == -1)
3356       return -1;
3357   }
3358   {
3359     char *physvols[] = {
3360       "/dev/sda3",
3361       NULL
3362     };
3363     int r;
3364     suppress_error = 0;
3365     r = guestfs_vgcreate (g, "VG2", physvols);
3366     if (r == -1)
3367       return -1;
3368   }
3369   {
3370     int r;
3371     suppress_error = 0;
3372     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
3373     if (r == -1)
3374       return -1;
3375   }
3376   {
3377     int r;
3378     suppress_error = 0;
3379     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
3380     if (r == -1)
3381       return -1;
3382   }
3383   {
3384     int r;
3385     suppress_error = 0;
3386     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
3387     if (r == -1)
3388       return -1;
3389   }
3390   {
3391     char **r;
3392     int i;
3393     suppress_error = 0;
3394     r = guestfs_lvs (g);
3395     if (r == NULL)
3396       return -1;
3397     if (!r[0]) {
3398       fprintf (stderr, "test_lvs_1: short list returned from command\n");
3399       print_strings (r);
3400       return -1;
3401     }
3402     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
3403       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
3404       return -1;
3405     }
3406     if (!r[1]) {
3407       fprintf (stderr, "test_lvs_1: short list returned from command\n");
3408       print_strings (r);
3409       return -1;
3410     }
3411     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
3412       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
3413       return -1;
3414     }
3415     if (!r[2]) {
3416       fprintf (stderr, "test_lvs_1: short list returned from command\n");
3417       print_strings (r);
3418       return -1;
3419     }
3420     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
3421       fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
3422       return -1;
3423     }
3424     if (r[3] != NULL) {
3425       fprintf (stderr, "test_lvs_1: extra elements returned from command\n");
3426       print_strings (r);
3427       return -1;
3428     }
3429     for (i = 0; r[i] != NULL; ++i)
3430       free (r[i]);
3431     free (r);
3432   }
3433   return 0;
3434 }
3435
3436 static int test_vgs_0 (void)
3437 {
3438   /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */
3439   {
3440     int r;
3441     suppress_error = 0;
3442     r = guestfs_umount_all (g);
3443     if (r == -1)
3444       return -1;
3445   }
3446   {
3447     int r;
3448     suppress_error = 0;
3449     r = guestfs_lvm_remove_all (g);
3450     if (r == -1)
3451       return -1;
3452   }
3453   {
3454     char *lines[] = {
3455       ",",
3456       NULL
3457     };
3458     int r;
3459     suppress_error = 0;
3460     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3461     if (r == -1)
3462       return -1;
3463   }
3464   {
3465     int r;
3466     suppress_error = 0;
3467     r = guestfs_pvcreate (g, "/dev/sda1");
3468     if (r == -1)
3469       return -1;
3470   }
3471   {
3472     char *physvols[] = {
3473       "/dev/sda1",
3474       NULL
3475     };
3476     int r;
3477     suppress_error = 0;
3478     r = guestfs_vgcreate (g, "VG", physvols);
3479     if (r == -1)
3480       return -1;
3481   }
3482   {
3483     int r;
3484     suppress_error = 0;
3485     r = guestfs_lvcreate (g, "LV", "VG", 8);
3486     if (r == -1)
3487       return -1;
3488   }
3489   {
3490     int r;
3491     suppress_error = 0;
3492     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3493     if (r == -1)
3494       return -1;
3495   }
3496   {
3497     int r;
3498     suppress_error = 0;
3499     r = guestfs_mount (g, "/dev/VG/LV", "/");
3500     if (r == -1)
3501       return -1;
3502   }
3503   /* TestOutputList for vgs (0) */
3504   {
3505     char **r;
3506     int i;
3507     suppress_error = 0;
3508     r = guestfs_vgs (g);
3509     if (r == NULL)
3510       return -1;
3511     if (!r[0]) {
3512       fprintf (stderr, "test_vgs_0: short list returned from command\n");
3513       print_strings (r);
3514       return -1;
3515     }
3516     if (strcmp (r[0], "VG") != 0) {
3517       fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]);
3518       return -1;
3519     }
3520     if (r[1] != NULL) {
3521       fprintf (stderr, "test_vgs_0: extra elements returned from command\n");
3522       print_strings (r);
3523       return -1;
3524     }
3525     for (i = 0; r[i] != NULL; ++i)
3526       free (r[i]);
3527     free (r);
3528   }
3529   return 0;
3530 }
3531
3532 static int test_vgs_1 (void)
3533 {
3534   /* InitEmpty for vgs (1) */
3535   {
3536     int r;
3537     suppress_error = 0;
3538     r = guestfs_umount_all (g);
3539     if (r == -1)
3540       return -1;
3541   }
3542   {
3543     int r;
3544     suppress_error = 0;
3545     r = guestfs_lvm_remove_all (g);
3546     if (r == -1)
3547       return -1;
3548   }
3549   /* TestOutputList for vgs (1) */
3550   {
3551     char *lines[] = {
3552       ",10",
3553       ",20",
3554       ",",
3555       NULL
3556     };
3557     int r;
3558     suppress_error = 0;
3559     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3560     if (r == -1)
3561       return -1;
3562   }
3563   {
3564     int r;
3565     suppress_error = 0;
3566     r = guestfs_pvcreate (g, "/dev/sda1");
3567     if (r == -1)
3568       return -1;
3569   }
3570   {
3571     int r;
3572     suppress_error = 0;
3573     r = guestfs_pvcreate (g, "/dev/sda2");
3574     if (r == -1)
3575       return -1;
3576   }
3577   {
3578     int r;
3579     suppress_error = 0;
3580     r = guestfs_pvcreate (g, "/dev/sda3");
3581     if (r == -1)
3582       return -1;
3583   }
3584   {
3585     char *physvols[] = {
3586       "/dev/sda1",
3587       "/dev/sda2",
3588       NULL
3589     };
3590     int r;
3591     suppress_error = 0;
3592     r = guestfs_vgcreate (g, "VG1", physvols);
3593     if (r == -1)
3594       return -1;
3595   }
3596   {
3597     char *physvols[] = {
3598       "/dev/sda3",
3599       NULL
3600     };
3601     int r;
3602     suppress_error = 0;
3603     r = guestfs_vgcreate (g, "VG2", physvols);
3604     if (r == -1)
3605       return -1;
3606   }
3607   {
3608     char **r;
3609     int i;
3610     suppress_error = 0;
3611     r = guestfs_vgs (g);
3612     if (r == NULL)
3613       return -1;
3614     if (!r[0]) {
3615       fprintf (stderr, "test_vgs_1: short list returned from command\n");
3616       print_strings (r);
3617       return -1;
3618     }
3619     if (strcmp (r[0], "VG1") != 0) {
3620       fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]);
3621       return -1;
3622     }
3623     if (!r[1]) {
3624       fprintf (stderr, "test_vgs_1: short list returned from command\n");
3625       print_strings (r);
3626       return -1;
3627     }
3628     if (strcmp (r[1], "VG2") != 0) {
3629       fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]);
3630       return -1;
3631     }
3632     if (r[2] != NULL) {
3633       fprintf (stderr, "test_vgs_1: extra elements returned from command\n");
3634       print_strings (r);
3635       return -1;
3636     }
3637     for (i = 0; r[i] != NULL; ++i)
3638       free (r[i]);
3639     free (r);
3640   }
3641   return 0;
3642 }
3643
3644 static int test_pvs_0 (void)
3645 {
3646   /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */
3647   {
3648     int r;
3649     suppress_error = 0;
3650     r = guestfs_umount_all (g);
3651     if (r == -1)
3652       return -1;
3653   }
3654   {
3655     int r;
3656     suppress_error = 0;
3657     r = guestfs_lvm_remove_all (g);
3658     if (r == -1)
3659       return -1;
3660   }
3661   {
3662     char *lines[] = {
3663       ",",
3664       NULL
3665     };
3666     int r;
3667     suppress_error = 0;
3668     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3669     if (r == -1)
3670       return -1;
3671   }
3672   {
3673     int r;
3674     suppress_error = 0;
3675     r = guestfs_pvcreate (g, "/dev/sda1");
3676     if (r == -1)
3677       return -1;
3678   }
3679   {
3680     char *physvols[] = {
3681       "/dev/sda1",
3682       NULL
3683     };
3684     int r;
3685     suppress_error = 0;
3686     r = guestfs_vgcreate (g, "VG", physvols);
3687     if (r == -1)
3688       return -1;
3689   }
3690   {
3691     int r;
3692     suppress_error = 0;
3693     r = guestfs_lvcreate (g, "LV", "VG", 8);
3694     if (r == -1)
3695       return -1;
3696   }
3697   {
3698     int r;
3699     suppress_error = 0;
3700     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3701     if (r == -1)
3702       return -1;
3703   }
3704   {
3705     int r;
3706     suppress_error = 0;
3707     r = guestfs_mount (g, "/dev/VG/LV", "/");
3708     if (r == -1)
3709       return -1;
3710   }
3711   /* TestOutputList for pvs (0) */
3712   {
3713     char **r;
3714     int i;
3715     suppress_error = 0;
3716     r = guestfs_pvs (g);
3717     if (r == NULL)
3718       return -1;
3719     if (!r[0]) {
3720       fprintf (stderr, "test_pvs_0: short list returned from command\n");
3721       print_strings (r);
3722       return -1;
3723     }
3724     if (strcmp (r[0], "/dev/sda1") != 0) {
3725       fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3726       return -1;
3727     }
3728     if (r[1] != NULL) {
3729       fprintf (stderr, "test_pvs_0: extra elements returned from command\n");
3730       print_strings (r);
3731       return -1;
3732     }
3733     for (i = 0; r[i] != NULL; ++i)
3734       free (r[i]);
3735     free (r);
3736   }
3737   return 0;
3738 }
3739
3740 static int test_pvs_1 (void)
3741 {
3742   /* InitEmpty for pvs (1) */
3743   {
3744     int r;
3745     suppress_error = 0;
3746     r = guestfs_umount_all (g);
3747     if (r == -1)
3748       return -1;
3749   }
3750   {
3751     int r;
3752     suppress_error = 0;
3753     r = guestfs_lvm_remove_all (g);
3754     if (r == -1)
3755       return -1;
3756   }
3757   /* TestOutputList for pvs (1) */
3758   {
3759     char *lines[] = {
3760       ",10",
3761       ",20",
3762       ",",
3763       NULL
3764     };
3765     int r;
3766     suppress_error = 0;
3767     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3768     if (r == -1)
3769       return -1;
3770   }
3771   {
3772     int r;
3773     suppress_error = 0;
3774     r = guestfs_pvcreate (g, "/dev/sda1");
3775     if (r == -1)
3776       return -1;
3777   }
3778   {
3779     int r;
3780     suppress_error = 0;
3781     r = guestfs_pvcreate (g, "/dev/sda2");
3782     if (r == -1)
3783       return -1;
3784   }
3785   {
3786     int r;
3787     suppress_error = 0;
3788     r = guestfs_pvcreate (g, "/dev/sda3");
3789     if (r == -1)
3790       return -1;
3791   }
3792   {
3793     char **r;
3794     int i;
3795     suppress_error = 0;
3796     r = guestfs_pvs (g);
3797     if (r == NULL)
3798       return -1;
3799     if (!r[0]) {
3800       fprintf (stderr, "test_pvs_1: short list returned from command\n");
3801       print_strings (r);
3802       return -1;
3803     }
3804     if (strcmp (r[0], "/dev/sda1") != 0) {
3805       fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3806       return -1;
3807     }
3808     if (!r[1]) {
3809       fprintf (stderr, "test_pvs_1: short list returned from command\n");
3810       print_strings (r);
3811       return -1;
3812     }
3813     if (strcmp (r[1], "/dev/sda2") != 0) {
3814       fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3815       return -1;
3816     }
3817     if (!r[2]) {
3818       fprintf (stderr, "test_pvs_1: short list returned from command\n");
3819       print_strings (r);
3820       return -1;
3821     }
3822     if (strcmp (r[2], "/dev/sda3") != 0) {
3823       fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3824       return -1;
3825     }
3826     if (r[3] != NULL) {
3827       fprintf (stderr, "test_pvs_1: extra elements returned from command\n");
3828       print_strings (r);
3829       return -1;
3830     }
3831     for (i = 0; r[i] != NULL; ++i)
3832       free (r[i]);
3833     free (r);
3834   }
3835   return 0;
3836 }
3837
3838 static int test_list_partitions_0 (void)
3839 {
3840   /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */
3841   {
3842     int r;
3843     suppress_error = 0;
3844     r = guestfs_umount_all (g);
3845     if (r == -1)
3846       return -1;
3847   }
3848   {
3849     int r;
3850     suppress_error = 0;
3851     r = guestfs_lvm_remove_all (g);
3852     if (r == -1)
3853       return -1;
3854   }
3855   {
3856     char *lines[] = {
3857       ",",
3858       NULL
3859     };
3860     int r;
3861     suppress_error = 0;
3862     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3863     if (r == -1)
3864       return -1;
3865   }
3866   {
3867     int r;
3868     suppress_error = 0;
3869     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3870     if (r == -1)
3871       return -1;
3872   }
3873   {
3874     int r;
3875     suppress_error = 0;
3876     r = guestfs_mount (g, "/dev/sda1", "/");
3877     if (r == -1)
3878       return -1;
3879   }
3880   /* TestOutputList for list_partitions (0) */
3881   {
3882     char **r;
3883     int i;
3884     suppress_error = 0;
3885     r = guestfs_list_partitions (g);
3886     if (r == NULL)
3887       return -1;
3888     if (!r[0]) {
3889       fprintf (stderr, "test_list_partitions_0: short list returned from command\n");
3890       print_strings (r);
3891       return -1;
3892     }
3893     if (strcmp (r[0], "/dev/sda1") != 0) {
3894       fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3895       return -1;
3896     }
3897     if (r[1] != NULL) {
3898       fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n");
3899       print_strings (r);
3900       return -1;
3901     }
3902     for (i = 0; r[i] != NULL; ++i)
3903       free (r[i]);
3904     free (r);
3905   }
3906   return 0;
3907 }
3908
3909 static int test_list_partitions_1 (void)
3910 {
3911   /* InitEmpty for list_partitions (1) */
3912   {
3913     int r;
3914     suppress_error = 0;
3915     r = guestfs_umount_all (g);
3916     if (r == -1)
3917       return -1;
3918   }
3919   {
3920     int r;
3921     suppress_error = 0;
3922     r = guestfs_lvm_remove_all (g);
3923     if (r == -1)
3924       return -1;
3925   }
3926   /* TestOutputList for list_partitions (1) */
3927   {
3928     char *lines[] = {
3929       ",10",
3930       ",20",
3931       ",",
3932       NULL
3933     };
3934     int r;
3935     suppress_error = 0;
3936     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3937     if (r == -1)
3938       return -1;
3939   }
3940   {
3941     char **r;
3942     int i;
3943     suppress_error = 0;
3944     r = guestfs_list_partitions (g);
3945     if (r == NULL)
3946       return -1;
3947     if (!r[0]) {
3948       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3949       print_strings (r);
3950       return -1;
3951     }
3952     if (strcmp (r[0], "/dev/sda1") != 0) {
3953       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3954       return -1;
3955     }
3956     if (!r[1]) {
3957       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3958       print_strings (r);
3959       return -1;
3960     }
3961     if (strcmp (r[1], "/dev/sda2") != 0) {
3962       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3963       return -1;
3964     }
3965     if (!r[2]) {
3966       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3967       print_strings (r);
3968       return -1;
3969     }
3970     if (strcmp (r[2], "/dev/sda3") != 0) {
3971       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3972       return -1;
3973     }
3974     if (r[3] != NULL) {
3975       fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n");
3976       print_strings (r);
3977       return -1;
3978     }
3979     for (i = 0; r[i] != NULL; ++i)
3980       free (r[i]);
3981     free (r);
3982   }
3983   return 0;
3984 }
3985
3986 static int test_list_devices_0 (void)
3987 {
3988   /* InitEmpty for list_devices (0) */
3989   {
3990     int r;
3991     suppress_error = 0;
3992     r = guestfs_umount_all (g);
3993     if (r == -1)
3994       return -1;
3995   }
3996   {
3997     int r;
3998     suppress_error = 0;
3999     r = guestfs_lvm_remove_all (g);
4000     if (r == -1)
4001       return -1;
4002   }
4003   /* TestOutputList for list_devices (0) */
4004   {
4005     char **r;
4006     int i;
4007     suppress_error = 0;
4008     r = guestfs_list_devices (g);
4009     if (r == NULL)
4010       return -1;
4011     if (!r[0]) {
4012       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4013       print_strings (r);
4014       return -1;
4015     }
4016     if (strcmp (r[0], "/dev/sda") != 0) {
4017       fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]);
4018       return -1;
4019     }
4020     if (!r[1]) {
4021       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4022       print_strings (r);
4023       return -1;
4024     }
4025     if (strcmp (r[1], "/dev/sdb") != 0) {
4026       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]);
4027       return -1;
4028     }
4029     if (!r[2]) {
4030       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4031       print_strings (r);
4032       return -1;
4033     }
4034     if (strcmp (r[2], "/dev/sdc") != 0) {
4035       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]);
4036       return -1;
4037     }
4038     if (r[3] != NULL) {
4039       fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
4040       print_strings (r);
4041       return -1;
4042     }
4043     for (i = 0; r[i] != NULL; ++i)
4044       free (r[i]);
4045     free (r);
4046   }
4047   return 0;
4048 }
4049
4050 static int test_ls_0 (void)
4051 {
4052   /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */
4053   {
4054     int r;
4055     suppress_error = 0;
4056     r = guestfs_umount_all (g);
4057     if (r == -1)
4058       return -1;
4059   }
4060   {
4061     int r;
4062     suppress_error = 0;
4063     r = guestfs_lvm_remove_all (g);
4064     if (r == -1)
4065       return -1;
4066   }
4067   {
4068     char *lines[] = {
4069       ",",
4070       NULL
4071     };
4072     int r;
4073     suppress_error = 0;
4074     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4075     if (r == -1)
4076       return -1;
4077   }
4078   {
4079     int r;
4080     suppress_error = 0;
4081     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4082     if (r == -1)
4083       return -1;
4084   }
4085   {
4086     int r;
4087     suppress_error = 0;
4088     r = guestfs_mount (g, "/dev/sda1", "/");
4089     if (r == -1)
4090       return -1;
4091   }
4092   /* TestOutputList for ls (0) */
4093   {
4094     int r;
4095     suppress_error = 0;
4096     r = guestfs_touch (g, "/new");
4097     if (r == -1)
4098       return -1;
4099   }
4100   {
4101     int r;
4102     suppress_error = 0;
4103     r = guestfs_touch (g, "/newer");
4104     if (r == -1)
4105       return -1;
4106   }
4107   {
4108     int r;
4109     suppress_error = 0;
4110     r = guestfs_touch (g, "/newest");
4111     if (r == -1)
4112       return -1;
4113   }
4114   {
4115     char **r;
4116     int i;
4117     suppress_error = 0;
4118     r = guestfs_ls (g, "/");
4119     if (r == NULL)
4120       return -1;
4121     if (!r[0]) {
4122       fprintf (stderr, "test_ls_0: short list returned from command\n");
4123       print_strings (r);
4124       return -1;
4125     }
4126     if (strcmp (r[0], "lost+found") != 0) {
4127       fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]);
4128       return -1;
4129     }
4130     if (!r[1]) {
4131       fprintf (stderr, "test_ls_0: short list returned from command\n");
4132       print_strings (r);
4133       return -1;
4134     }
4135     if (strcmp (r[1], "new") != 0) {
4136       fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]);
4137       return -1;
4138     }
4139     if (!r[2]) {
4140       fprintf (stderr, "test_ls_0: short list returned from command\n");
4141       print_strings (r);
4142       return -1;
4143     }
4144     if (strcmp (r[2], "newer") != 0) {
4145       fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]);
4146       return -1;
4147     }
4148     if (!r[3]) {
4149       fprintf (stderr, "test_ls_0: short list returned from command\n");
4150       print_strings (r);
4151       return -1;
4152     }
4153     if (strcmp (r[3], "newest") != 0) {
4154       fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]);
4155       return -1;
4156     }
4157     if (r[4] != NULL) {
4158       fprintf (stderr, "test_ls_0: extra elements returned from command\n");
4159       print_strings (r);
4160       return -1;
4161     }
4162     for (i = 0; r[i] != NULL; ++i)
4163       free (r[i]);
4164     free (r);
4165   }
4166   return 0;
4167 }
4168
4169 static int test_cat_0 (void)
4170 {
4171   /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */
4172   {
4173     int r;
4174     suppress_error = 0;
4175     r = guestfs_umount_all (g);
4176     if (r == -1)
4177       return -1;
4178   }
4179   {
4180     int r;
4181     suppress_error = 0;
4182     r = guestfs_lvm_remove_all (g);
4183     if (r == -1)
4184       return -1;
4185   }
4186   {
4187     char *lines[] = {
4188       ",",
4189       NULL
4190     };
4191     int r;
4192     suppress_error = 0;
4193     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4194     if (r == -1)
4195       return -1;
4196   }
4197   {
4198     int r;
4199     suppress_error = 0;
4200     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4201     if (r == -1)
4202       return -1;
4203   }
4204   {
4205     int r;
4206     suppress_error = 0;
4207     r = guestfs_mount (g, "/dev/sda1", "/");
4208     if (r == -1)
4209       return -1;
4210   }
4211   /* TestOutput for cat (0) */
4212   {
4213     int r;
4214     suppress_error = 0;
4215     r = guestfs_write_file (g, "/new", "new file contents", 0);
4216     if (r == -1)
4217       return -1;
4218   }
4219   {
4220     char *r;
4221     suppress_error = 0;
4222     r = guestfs_cat (g, "/new");
4223     if (r == NULL)
4224       return -1;
4225     if (strcmp (r, "new file contents") != 0) {
4226       fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r);
4227       return -1;
4228     }
4229     free (r);
4230   }
4231   return 0;
4232 }
4233
4234 static int test_touch_0 (void)
4235 {
4236   /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */
4237   {
4238     int r;
4239     suppress_error = 0;
4240     r = guestfs_umount_all (g);
4241     if (r == -1)
4242       return -1;
4243   }
4244   {
4245     int r;
4246     suppress_error = 0;
4247     r = guestfs_lvm_remove_all (g);
4248     if (r == -1)
4249       return -1;
4250   }
4251   {
4252     char *lines[] = {
4253       ",",
4254       NULL
4255     };
4256     int r;
4257     suppress_error = 0;
4258     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4259     if (r == -1)
4260       return -1;
4261   }
4262   {
4263     int r;
4264     suppress_error = 0;
4265     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4266     if (r == -1)
4267       return -1;
4268   }
4269   {
4270     int r;
4271     suppress_error = 0;
4272     r = guestfs_mount (g, "/dev/sda1", "/");
4273     if (r == -1)
4274       return -1;
4275   }
4276   /* TestOutputTrue for touch (0) */
4277   {
4278     int r;
4279     suppress_error = 0;
4280     r = guestfs_touch (g, "/new");
4281     if (r == -1)
4282       return -1;
4283   }
4284   {
4285     int r;
4286     suppress_error = 0;
4287     r = guestfs_exists (g, "/new");
4288     if (r == -1)
4289       return -1;
4290     if (!r) {
4291       fprintf (stderr, "test_touch_0: expected true, got false\n");
4292       return -1;
4293     }
4294   }
4295   return 0;
4296 }
4297
4298 static int test_sync_0 (void)
4299 {
4300   /* InitEmpty for sync (0) */
4301   {
4302     int r;
4303     suppress_error = 0;
4304     r = guestfs_umount_all (g);
4305     if (r == -1)
4306       return -1;
4307   }
4308   {
4309     int r;
4310     suppress_error = 0;
4311     r = guestfs_lvm_remove_all (g);
4312     if (r == -1)
4313       return -1;
4314   }
4315   /* TestRun for sync (0) */
4316   {
4317     int r;
4318     suppress_error = 0;
4319     r = guestfs_sync (g);
4320     if (r == -1)
4321       return -1;
4322   }
4323   return 0;
4324 }
4325
4326 static int test_mount_0 (void)
4327 {
4328   /* InitEmpty for mount (0) */
4329   {
4330     int r;
4331     suppress_error = 0;
4332     r = guestfs_umount_all (g);
4333     if (r == -1)
4334       return -1;
4335   }
4336   {
4337     int r;
4338     suppress_error = 0;
4339     r = guestfs_lvm_remove_all (g);
4340     if (r == -1)
4341       return -1;
4342   }
4343   /* TestOutput for mount (0) */
4344   {
4345     char *lines[] = {
4346       ",",
4347       NULL
4348     };
4349     int r;
4350     suppress_error = 0;
4351     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4352     if (r == -1)
4353       return -1;
4354   }
4355   {
4356     int r;
4357     suppress_error = 0;
4358     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4359     if (r == -1)
4360       return -1;
4361   }
4362   {
4363     int r;
4364     suppress_error = 0;
4365     r = guestfs_mount (g, "/dev/sda1", "/");
4366     if (r == -1)
4367       return -1;
4368   }
4369   {
4370     int r;
4371     suppress_error = 0;
4372     r = guestfs_write_file (g, "/new", "new file contents", 0);
4373     if (r == -1)
4374       return -1;
4375   }
4376   {
4377     char *r;
4378     suppress_error = 0;
4379     r = guestfs_cat (g, "/new");
4380     if (r == NULL)
4381       return -1;
4382     if (strcmp (r, "new file contents") != 0) {
4383       fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r);
4384       return -1;
4385     }
4386     free (r);
4387   }
4388   return 0;
4389 }
4390
4391 int main (int argc, char *argv[])
4392 {
4393   char c = 0;
4394   int failed = 0;
4395   const char *srcdir;
4396   int fd;
4397   char buf[256];
4398   int nr_tests, test_num = 0;
4399
4400   no_test_warnings ();
4401
4402   g = guestfs_create ();
4403   if (g == NULL) {
4404     printf ("guestfs_create FAILED\n");
4405     exit (1);
4406   }
4407
4408   guestfs_set_error_handler (g, print_error, NULL);
4409
4410   srcdir = getenv ("srcdir");
4411   if (!srcdir) srcdir = ".";
4412   guestfs_set_path (g, srcdir);
4413
4414   snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
4415   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4416   if (fd == -1) {
4417     perror (buf);
4418     exit (1);
4419   }
4420   if (lseek (fd, 524288000, SEEK_SET) == -1) {
4421     perror ("lseek");
4422     close (fd);
4423     unlink (buf);
4424     exit (1);
4425   }
4426   if (write (fd, &c, 1) == -1) {
4427     perror ("write");
4428     close (fd);
4429     unlink (buf);
4430     exit (1);
4431   }
4432   if (close (fd) == -1) {
4433     perror (buf);
4434     unlink (buf);
4435     exit (1);
4436   }
4437   if (guestfs_add_drive (g, buf) == -1) {
4438     printf ("guestfs_add_drive %s FAILED\n", buf);
4439     exit (1);
4440   }
4441
4442   snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
4443   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4444   if (fd == -1) {
4445     perror (buf);
4446     exit (1);
4447   }
4448   if (lseek (fd, 52428800, SEEK_SET) == -1) {
4449     perror ("lseek");
4450     close (fd);
4451     unlink (buf);
4452     exit (1);
4453   }
4454   if (write (fd, &c, 1) == -1) {
4455     perror ("write");
4456     close (fd);
4457     unlink (buf);
4458     exit (1);
4459   }
4460   if (close (fd) == -1) {
4461     perror (buf);
4462     unlink (buf);
4463     exit (1);
4464   }
4465   if (guestfs_add_drive (g, buf) == -1) {
4466     printf ("guestfs_add_drive %s FAILED\n", buf);
4467     exit (1);
4468   }
4469
4470   snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
4471   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4472   if (fd == -1) {
4473     perror (buf);
4474     exit (1);
4475   }
4476   if (lseek (fd, 10485760, SEEK_SET) == -1) {
4477     perror ("lseek");
4478     close (fd);
4479     unlink (buf);
4480     exit (1);
4481   }
4482   if (write (fd, &c, 1) == -1) {
4483     perror ("write");
4484     close (fd);
4485     unlink (buf);
4486     exit (1);
4487   }
4488   if (close (fd) == -1) {
4489     perror (buf);
4490     unlink (buf);
4491     exit (1);
4492   }
4493   if (guestfs_add_drive (g, buf) == -1) {
4494     printf ("guestfs_add_drive %s FAILED\n", buf);
4495     exit (1);
4496   }
4497
4498   if (guestfs_launch (g) == -1) {
4499     printf ("guestfs_launch FAILED\n");
4500     exit (1);
4501   }
4502   if (guestfs_wait_ready (g) == -1) {
4503     printf ("guestfs_wait_ready FAILED\n");
4504     exit (1);
4505   }
4506
4507   nr_tests = 63;
4508
4509   test_num++;
4510   printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests);
4511   if (test_blockdev_rereadpt_0 () == -1) {
4512     printf ("test_blockdev_rereadpt_0 FAILED\n");
4513     failed++;
4514   }
4515   test_num++;
4516   printf ("%3d/%3d test_blockdev_flushbufs_0\n", test_num, nr_tests);
4517   if (test_blockdev_flushbufs_0 () == -1) {
4518     printf ("test_blockdev_flushbufs_0 FAILED\n");
4519     failed++;
4520   }
4521   test_num++;
4522   printf ("%3d/%3d test_blockdev_getsize64_0\n", test_num, nr_tests);
4523   if (test_blockdev_getsize64_0 () == -1) {
4524     printf ("test_blockdev_getsize64_0 FAILED\n");
4525     failed++;
4526   }
4527   test_num++;
4528   printf ("%3d/%3d test_blockdev_getsz_0\n", test_num, nr_tests);
4529   if (test_blockdev_getsz_0 () == -1) {
4530     printf ("test_blockdev_getsz_0 FAILED\n");
4531     failed++;
4532   }
4533   test_num++;
4534   printf ("%3d/%3d test_blockdev_getbsz_0\n", test_num, nr_tests);
4535   if (test_blockdev_getbsz_0 () == -1) {
4536     printf ("test_blockdev_getbsz_0 FAILED\n");
4537     failed++;
4538   }
4539   test_num++;
4540   printf ("%3d/%3d test_blockdev_getss_0\n", test_num, nr_tests);
4541   if (test_blockdev_getss_0 () == -1) {
4542     printf ("test_blockdev_getss_0 FAILED\n");
4543     failed++;
4544   }
4545   test_num++;
4546   printf ("%3d/%3d test_blockdev_getro_0\n", test_num, nr_tests);
4547   if (test_blockdev_getro_0 () == -1) {
4548     printf ("test_blockdev_getro_0 FAILED\n");
4549     failed++;
4550   }
4551   test_num++;
4552   printf ("%3d/%3d test_blockdev_setrw_0\n", test_num, nr_tests);
4553   if (test_blockdev_setrw_0 () == -1) {
4554     printf ("test_blockdev_setrw_0 FAILED\n");
4555     failed++;
4556   }
4557   test_num++;
4558   printf ("%3d/%3d test_blockdev_setro_0\n", test_num, nr_tests);
4559   if (test_blockdev_setro_0 () == -1) {
4560     printf ("test_blockdev_setro_0 FAILED\n");
4561     failed++;
4562   }
4563   test_num++;
4564   printf ("%3d/%3d test_statvfs_0\n", test_num, nr_tests);
4565   if (test_statvfs_0 () == -1) {
4566     printf ("test_statvfs_0 FAILED\n");
4567     failed++;
4568   }
4569   test_num++;
4570   printf ("%3d/%3d test_lstat_0\n", test_num, nr_tests);
4571   if (test_lstat_0 () == -1) {
4572     printf ("test_lstat_0 FAILED\n");
4573     failed++;
4574   }
4575   test_num++;
4576   printf ("%3d/%3d test_stat_0\n", test_num, nr_tests);
4577   if (test_stat_0 () == -1) {
4578     printf ("test_stat_0 FAILED\n");
4579     failed++;
4580   }
4581   test_num++;
4582   printf ("%3d/%3d test_file_0\n", test_num, nr_tests);
4583   if (test_file_0 () == -1) {
4584     printf ("test_file_0 FAILED\n");
4585     failed++;
4586   }
4587   test_num++;
4588   printf ("%3d/%3d test_file_1\n", test_num, nr_tests);
4589   if (test_file_1 () == -1) {
4590     printf ("test_file_1 FAILED\n");
4591     failed++;
4592   }
4593   test_num++;
4594   printf ("%3d/%3d test_file_2\n", test_num, nr_tests);
4595   if (test_file_2 () == -1) {
4596     printf ("test_file_2 FAILED\n");
4597     failed++;
4598   }
4599   test_num++;
4600   printf ("%3d/%3d test_umount_all_0\n", test_num, nr_tests);
4601   if (test_umount_all_0 () == -1) {
4602     printf ("test_umount_all_0 FAILED\n");
4603     failed++;
4604   }
4605   test_num++;
4606   printf ("%3d/%3d test_mounts_0\n", test_num, nr_tests);
4607   if (test_mounts_0 () == -1) {
4608     printf ("test_mounts_0 FAILED\n");
4609     failed++;
4610   }
4611   test_num++;
4612   printf ("%3d/%3d test_umount_0\n", test_num, nr_tests);
4613   if (test_umount_0 () == -1) {
4614     printf ("test_umount_0 FAILED\n");
4615     failed++;
4616   }
4617   test_num++;
4618   printf ("%3d/%3d test_umount_1\n", test_num, nr_tests);
4619   if (test_umount_1 () == -1) {
4620     printf ("test_umount_1 FAILED\n");
4621     failed++;
4622   }
4623   test_num++;
4624   printf ("%3d/%3d test_write_file_0\n", test_num, nr_tests);
4625   if (test_write_file_0 () == -1) {
4626     printf ("test_write_file_0 FAILED\n");
4627     failed++;
4628   }
4629   test_num++;
4630   printf ("%3d/%3d test_write_file_1\n", test_num, nr_tests);
4631   if (test_write_file_1 () == -1) {
4632     printf ("test_write_file_1 FAILED\n");
4633     failed++;
4634   }
4635   test_num++;
4636   printf ("%3d/%3d test_write_file_2\n", test_num, nr_tests);
4637   if (test_write_file_2 () == -1) {
4638     printf ("test_write_file_2 FAILED\n");
4639     failed++;
4640   }
4641   test_num++;
4642   printf ("%3d/%3d test_write_file_3\n", test_num, nr_tests);
4643   if (test_write_file_3 () == -1) {
4644     printf ("test_write_file_3 FAILED\n");
4645     failed++;
4646   }
4647   test_num++;
4648   printf ("%3d/%3d test_write_file_4\n", test_num, nr_tests);
4649   if (test_write_file_4 () == -1) {
4650     printf ("test_write_file_4 FAILED\n");
4651     failed++;
4652   }
4653   test_num++;
4654   printf ("%3d/%3d test_write_file_5\n", test_num, nr_tests);
4655   if (test_write_file_5 () == -1) {
4656     printf ("test_write_file_5 FAILED\n");
4657     failed++;
4658   }
4659   test_num++;
4660   printf ("%3d/%3d test_mkfs_0\n", test_num, nr_tests);
4661   if (test_mkfs_0 () == -1) {
4662     printf ("test_mkfs_0 FAILED\n");
4663     failed++;
4664   }
4665   test_num++;
4666   printf ("%3d/%3d test_lvcreate_0\n", test_num, nr_tests);
4667   if (test_lvcreate_0 () == -1) {
4668     printf ("test_lvcreate_0 FAILED\n");
4669     failed++;
4670   }
4671   test_num++;
4672   printf ("%3d/%3d test_vgcreate_0\n", test_num, nr_tests);
4673   if (test_vgcreate_0 () == -1) {
4674     printf ("test_vgcreate_0 FAILED\n");
4675     failed++;
4676   }
4677   test_num++;
4678   printf ("%3d/%3d test_pvcreate_0\n", test_num, nr_tests);
4679   if (test_pvcreate_0 () == -1) {
4680     printf ("test_pvcreate_0 FAILED\n");
4681     failed++;
4682   }
4683   test_num++;
4684   printf ("%3d/%3d test_is_dir_0\n", test_num, nr_tests);
4685   if (test_is_dir_0 () == -1) {
4686     printf ("test_is_dir_0 FAILED\n");
4687     failed++;
4688   }
4689   test_num++;
4690   printf ("%3d/%3d test_is_dir_1\n", test_num, nr_tests);
4691   if (test_is_dir_1 () == -1) {
4692     printf ("test_is_dir_1 FAILED\n");
4693     failed++;
4694   }
4695   test_num++;
4696   printf ("%3d/%3d test_is_file_0\n", test_num, nr_tests);
4697   if (test_is_file_0 () == -1) {
4698     printf ("test_is_file_0 FAILED\n");
4699     failed++;
4700   }
4701   test_num++;
4702   printf ("%3d/%3d test_is_file_1\n", test_num, nr_tests);
4703   if (test_is_file_1 () == -1) {
4704     printf ("test_is_file_1 FAILED\n");
4705     failed++;
4706   }
4707   test_num++;
4708   printf ("%3d/%3d test_exists_0\n", test_num, nr_tests);
4709   if (test_exists_0 () == -1) {
4710     printf ("test_exists_0 FAILED\n");
4711     failed++;
4712   }
4713   test_num++;
4714   printf ("%3d/%3d test_exists_1\n", test_num, nr_tests);
4715   if (test_exists_1 () == -1) {
4716     printf ("test_exists_1 FAILED\n");
4717     failed++;
4718   }
4719   test_num++;
4720   printf ("%3d/%3d test_mkdir_p_0\n", test_num, nr_tests);
4721   if (test_mkdir_p_0 () == -1) {
4722     printf ("test_mkdir_p_0 FAILED\n");
4723     failed++;
4724   }
4725   test_num++;
4726   printf ("%3d/%3d test_mkdir_p_1\n", test_num, nr_tests);
4727   if (test_mkdir_p_1 () == -1) {
4728     printf ("test_mkdir_p_1 FAILED\n");
4729     failed++;
4730   }
4731   test_num++;
4732   printf ("%3d/%3d test_mkdir_p_2\n", test_num, nr_tests);
4733   if (test_mkdir_p_2 () == -1) {
4734     printf ("test_mkdir_p_2 FAILED\n");
4735     failed++;
4736   }
4737   test_num++;
4738   printf ("%3d/%3d test_mkdir_0\n", test_num, nr_tests);
4739   if (test_mkdir_0 () == -1) {
4740     printf ("test_mkdir_0 FAILED\n");
4741     failed++;
4742   }
4743   test_num++;
4744   printf ("%3d/%3d test_mkdir_1\n", test_num, nr_tests);
4745   if (test_mkdir_1 () == -1) {
4746     printf ("test_mkdir_1 FAILED\n");
4747     failed++;
4748   }
4749   test_num++;
4750   printf ("%3d/%3d test_rm_rf_0\n", test_num, nr_tests);
4751   if (test_rm_rf_0 () == -1) {
4752     printf ("test_rm_rf_0 FAILED\n");
4753     failed++;
4754   }
4755   test_num++;
4756   printf ("%3d/%3d test_rmdir_0\n", test_num, nr_tests);
4757   if (test_rmdir_0 () == -1) {
4758     printf ("test_rmdir_0 FAILED\n");
4759     failed++;
4760   }
4761   test_num++;
4762   printf ("%3d/%3d test_rmdir_1\n", test_num, nr_tests);
4763   if (test_rmdir_1 () == -1) {
4764     printf ("test_rmdir_1 FAILED\n");
4765     failed++;
4766   }
4767   test_num++;
4768   printf ("%3d/%3d test_rmdir_2\n", test_num, nr_tests);
4769   if (test_rmdir_2 () == -1) {
4770     printf ("test_rmdir_2 FAILED\n");
4771     failed++;
4772   }
4773   test_num++;
4774   printf ("%3d/%3d test_rm_0\n", test_num, nr_tests);
4775   if (test_rm_0 () == -1) {
4776     printf ("test_rm_0 FAILED\n");
4777     failed++;
4778   }
4779   test_num++;
4780   printf ("%3d/%3d test_rm_1\n", test_num, nr_tests);
4781   if (test_rm_1 () == -1) {
4782     printf ("test_rm_1 FAILED\n");
4783     failed++;
4784   }
4785   test_num++;
4786   printf ("%3d/%3d test_rm_2\n", test_num, nr_tests);
4787   if (test_rm_2 () == -1) {
4788     printf ("test_rm_2 FAILED\n");
4789     failed++;
4790   }
4791   test_num++;
4792   printf ("%3d/%3d test_read_lines_0\n", test_num, nr_tests);
4793   if (test_read_lines_0 () == -1) {
4794     printf ("test_read_lines_0 FAILED\n");
4795     failed++;
4796   }
4797   test_num++;
4798   printf ("%3d/%3d test_read_lines_1\n", test_num, nr_tests);
4799   if (test_read_lines_1 () == -1) {
4800     printf ("test_read_lines_1 FAILED\n");
4801     failed++;
4802   }
4803   test_num++;
4804   printf ("%3d/%3d test_lvs_0\n", test_num, nr_tests);
4805   if (test_lvs_0 () == -1) {
4806     printf ("test_lvs_0 FAILED\n");
4807     failed++;
4808   }
4809   test_num++;
4810   printf ("%3d/%3d test_lvs_1\n", test_num, nr_tests);
4811   if (test_lvs_1 () == -1) {
4812     printf ("test_lvs_1 FAILED\n");
4813     failed++;
4814   }
4815   test_num++;
4816   printf ("%3d/%3d test_vgs_0\n", test_num, nr_tests);
4817   if (test_vgs_0 () == -1) {
4818     printf ("test_vgs_0 FAILED\n");
4819     failed++;
4820   }
4821   test_num++;
4822   printf ("%3d/%3d test_vgs_1\n", test_num, nr_tests);
4823   if (test_vgs_1 () == -1) {
4824     printf ("test_vgs_1 FAILED\n");
4825     failed++;
4826   }
4827   test_num++;
4828   printf ("%3d/%3d test_pvs_0\n", test_num, nr_tests);
4829   if (test_pvs_0 () == -1) {
4830     printf ("test_pvs_0 FAILED\n");
4831     failed++;
4832   }
4833   test_num++;
4834   printf ("%3d/%3d test_pvs_1\n", test_num, nr_tests);
4835   if (test_pvs_1 () == -1) {
4836     printf ("test_pvs_1 FAILED\n");
4837     failed++;
4838   }
4839   test_num++;
4840   printf ("%3d/%3d test_list_partitions_0\n", test_num, nr_tests);
4841   if (test_list_partitions_0 () == -1) {
4842     printf ("test_list_partitions_0 FAILED\n");
4843     failed++;
4844   }
4845   test_num++;
4846   printf ("%3d/%3d test_list_partitions_1\n", test_num, nr_tests);
4847   if (test_list_partitions_1 () == -1) {
4848     printf ("test_list_partitions_1 FAILED\n");
4849     failed++;
4850   }
4851   test_num++;
4852   printf ("%3d/%3d test_list_devices_0\n", test_num, nr_tests);
4853   if (test_list_devices_0 () == -1) {
4854     printf ("test_list_devices_0 FAILED\n");
4855     failed++;
4856   }
4857   test_num++;
4858   printf ("%3d/%3d test_ls_0\n", test_num, nr_tests);
4859   if (test_ls_0 () == -1) {
4860     printf ("test_ls_0 FAILED\n");
4861     failed++;
4862   }
4863   test_num++;
4864   printf ("%3d/%3d test_cat_0\n", test_num, nr_tests);
4865   if (test_cat_0 () == -1) {
4866     printf ("test_cat_0 FAILED\n");
4867     failed++;
4868   }
4869   test_num++;
4870   printf ("%3d/%3d test_touch_0\n", test_num, nr_tests);
4871   if (test_touch_0 () == -1) {
4872     printf ("test_touch_0 FAILED\n");
4873     failed++;
4874   }
4875   test_num++;
4876   printf ("%3d/%3d test_sync_0\n", test_num, nr_tests);
4877   if (test_sync_0 () == -1) {
4878     printf ("test_sync_0 FAILED\n");
4879     failed++;
4880   }
4881   test_num++;
4882   printf ("%3d/%3d test_mount_0\n", test_num, nr_tests);
4883   if (test_mount_0 () == -1) {
4884     printf ("test_mount_0 FAILED\n");
4885     failed++;
4886   }
4887
4888   guestfs_close (g);
4889   snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
4890   unlink (buf);
4891   snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
4892   unlink (buf);
4893   snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
4894   unlink (buf);
4895
4896   if (failed > 0) {
4897     printf ("***** %d / %d tests FAILED *****\n", failed, nr_tests);
4898     exit (1);
4899   }
4900
4901   exit (0);
4902 }