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