378f3af3f56966a8a2fa8f5473a623e7a7526ae5
[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_qemu\" has no tests\n");
67   fprintf (stderr, "warning: \"guestfs_get_qemu\" has no tests\n");
68   fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n");
69   fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n");
70   fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n");
71   fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n");
72   fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n");
73   fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n");
74   fprintf (stderr, "warning: \"guestfs_is_ready\" has no tests\n");
75   fprintf (stderr, "warning: \"guestfs_is_config\" has no tests\n");
76   fprintf (stderr, "warning: \"guestfs_is_launching\" has no tests\n");
77   fprintf (stderr, "warning: \"guestfs_is_busy\" has no tests\n");
78   fprintf (stderr, "warning: \"guestfs_get_state\" has no tests\n");
79   fprintf (stderr, "warning: \"guestfs_set_busy\" has no tests\n");
80   fprintf (stderr, "warning: \"guestfs_set_ready\" has no tests\n");
81   fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n");
82   fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n");
83   fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n");
84   fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n");
85   fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n");
86   fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n");
87   fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n");
88   fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n");
89   fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n");
90   fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n");
91   fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n");
92   fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n");
93   fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n");
94   fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n");
95   fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n");
96   fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n");
97   fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n");
98   fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n");
99   fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n");
100   fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n");
101   fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n");
102   fprintf (stderr, "warning: \"guestfs_command\" has no tests\n");
103   fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n");
104   fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
105   fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
106   fprintf (stderr, "warning: \"guestfs_tar_out\" has no tests\n");
107   fprintf (stderr, "warning: \"guestfs_tgz_out\" has no tests\n");
108   fprintf (stderr, "warning: \"guestfs_mount_options\" has no tests\n");
109   fprintf (stderr, "warning: \"guestfs_mount_vfs\" has no tests\n");
110   fprintf (stderr, "warning: \"guestfs_debug\" has no tests\n");
111 }
112
113 static int test_pvremove_0 (void)
114 {
115   /* InitEmpty for pvremove (0) */
116   {
117     int r;
118     suppress_error = 0;
119     r = guestfs_umount_all (g);
120     if (r == -1)
121       return -1;
122   }
123   {
124     int r;
125     suppress_error = 0;
126     r = guestfs_lvm_remove_all (g);
127     if (r == -1)
128       return -1;
129   }
130   /* TestOutputList for pvremove (0) */
131   {
132     int r;
133     suppress_error = 0;
134     r = guestfs_pvcreate (g, "/dev/sda");
135     if (r == -1)
136       return -1;
137   }
138   {
139     char *physvols[] = {
140       "/dev/sda",
141       NULL
142     };
143     int r;
144     suppress_error = 0;
145     r = guestfs_vgcreate (g, "VG", physvols);
146     if (r == -1)
147       return -1;
148   }
149   {
150     int r;
151     suppress_error = 0;
152     r = guestfs_lvcreate (g, "LV1", "VG", 50);
153     if (r == -1)
154       return -1;
155   }
156   {
157     int r;
158     suppress_error = 0;
159     r = guestfs_lvcreate (g, "LV2", "VG", 50);
160     if (r == -1)
161       return -1;
162   }
163   {
164     int r;
165     suppress_error = 0;
166     r = guestfs_vgremove (g, "VG");
167     if (r == -1)
168       return -1;
169   }
170   {
171     int r;
172     suppress_error = 0;
173     r = guestfs_pvremove (g, "/dev/sda");
174     if (r == -1)
175       return -1;
176   }
177   {
178     char **r;
179     int i;
180     suppress_error = 0;
181     r = guestfs_lvs (g);
182     if (r == NULL)
183       return -1;
184     if (r[0] != NULL) {
185       fprintf (stderr, "test_pvremove_0: extra elements returned from command\n");
186       print_strings (r);
187       return -1;
188     }
189     for (i = 0; r[i] != NULL; ++i)
190       free (r[i]);
191     free (r);
192   }
193   return 0;
194 }
195
196 static int test_pvremove_1 (void)
197 {
198   /* InitEmpty for pvremove (1) */
199   {
200     int r;
201     suppress_error = 0;
202     r = guestfs_umount_all (g);
203     if (r == -1)
204       return -1;
205   }
206   {
207     int r;
208     suppress_error = 0;
209     r = guestfs_lvm_remove_all (g);
210     if (r == -1)
211       return -1;
212   }
213   /* TestOutputList for pvremove (1) */
214   {
215     int r;
216     suppress_error = 0;
217     r = guestfs_pvcreate (g, "/dev/sda");
218     if (r == -1)
219       return -1;
220   }
221   {
222     char *physvols[] = {
223       "/dev/sda",
224       NULL
225     };
226     int r;
227     suppress_error = 0;
228     r = guestfs_vgcreate (g, "VG", physvols);
229     if (r == -1)
230       return -1;
231   }
232   {
233     int r;
234     suppress_error = 0;
235     r = guestfs_lvcreate (g, "LV1", "VG", 50);
236     if (r == -1)
237       return -1;
238   }
239   {
240     int r;
241     suppress_error = 0;
242     r = guestfs_lvcreate (g, "LV2", "VG", 50);
243     if (r == -1)
244       return -1;
245   }
246   {
247     int r;
248     suppress_error = 0;
249     r = guestfs_vgremove (g, "VG");
250     if (r == -1)
251       return -1;
252   }
253   {
254     int r;
255     suppress_error = 0;
256     r = guestfs_pvremove (g, "/dev/sda");
257     if (r == -1)
258       return -1;
259   }
260   {
261     char **r;
262     int i;
263     suppress_error = 0;
264     r = guestfs_vgs (g);
265     if (r == NULL)
266       return -1;
267     if (r[0] != NULL) {
268       fprintf (stderr, "test_pvremove_1: extra elements returned from command\n");
269       print_strings (r);
270       return -1;
271     }
272     for (i = 0; r[i] != NULL; ++i)
273       free (r[i]);
274     free (r);
275   }
276   return 0;
277 }
278
279 static int test_pvremove_2 (void)
280 {
281   /* InitEmpty for pvremove (2) */
282   {
283     int r;
284     suppress_error = 0;
285     r = guestfs_umount_all (g);
286     if (r == -1)
287       return -1;
288   }
289   {
290     int r;
291     suppress_error = 0;
292     r = guestfs_lvm_remove_all (g);
293     if (r == -1)
294       return -1;
295   }
296   /* TestOutputList for pvremove (2) */
297   {
298     int r;
299     suppress_error = 0;
300     r = guestfs_pvcreate (g, "/dev/sda");
301     if (r == -1)
302       return -1;
303   }
304   {
305     char *physvols[] = {
306       "/dev/sda",
307       NULL
308     };
309     int r;
310     suppress_error = 0;
311     r = guestfs_vgcreate (g, "VG", physvols);
312     if (r == -1)
313       return -1;
314   }
315   {
316     int r;
317     suppress_error = 0;
318     r = guestfs_lvcreate (g, "LV1", "VG", 50);
319     if (r == -1)
320       return -1;
321   }
322   {
323     int r;
324     suppress_error = 0;
325     r = guestfs_lvcreate (g, "LV2", "VG", 50);
326     if (r == -1)
327       return -1;
328   }
329   {
330     int r;
331     suppress_error = 0;
332     r = guestfs_vgremove (g, "VG");
333     if (r == -1)
334       return -1;
335   }
336   {
337     int r;
338     suppress_error = 0;
339     r = guestfs_pvremove (g, "/dev/sda");
340     if (r == -1)
341       return -1;
342   }
343   {
344     char **r;
345     int i;
346     suppress_error = 0;
347     r = guestfs_pvs (g);
348     if (r == NULL)
349       return -1;
350     if (r[0] != NULL) {
351       fprintf (stderr, "test_pvremove_2: extra elements returned from command\n");
352       print_strings (r);
353       return -1;
354     }
355     for (i = 0; r[i] != NULL; ++i)
356       free (r[i]);
357     free (r);
358   }
359   return 0;
360 }
361
362 static int test_vgremove_0 (void)
363 {
364   /* InitEmpty for vgremove (0) */
365   {
366     int r;
367     suppress_error = 0;
368     r = guestfs_umount_all (g);
369     if (r == -1)
370       return -1;
371   }
372   {
373     int r;
374     suppress_error = 0;
375     r = guestfs_lvm_remove_all (g);
376     if (r == -1)
377       return -1;
378   }
379   /* TestOutputList for vgremove (0) */
380   {
381     int r;
382     suppress_error = 0;
383     r = guestfs_pvcreate (g, "/dev/sda");
384     if (r == -1)
385       return -1;
386   }
387   {
388     char *physvols[] = {
389       "/dev/sda",
390       NULL
391     };
392     int r;
393     suppress_error = 0;
394     r = guestfs_vgcreate (g, "VG", physvols);
395     if (r == -1)
396       return -1;
397   }
398   {
399     int r;
400     suppress_error = 0;
401     r = guestfs_lvcreate (g, "LV1", "VG", 50);
402     if (r == -1)
403       return -1;
404   }
405   {
406     int r;
407     suppress_error = 0;
408     r = guestfs_lvcreate (g, "LV2", "VG", 50);
409     if (r == -1)
410       return -1;
411   }
412   {
413     int r;
414     suppress_error = 0;
415     r = guestfs_vgremove (g, "VG");
416     if (r == -1)
417       return -1;
418   }
419   {
420     char **r;
421     int i;
422     suppress_error = 0;
423     r = guestfs_lvs (g);
424     if (r == NULL)
425       return -1;
426     if (r[0] != NULL) {
427       fprintf (stderr, "test_vgremove_0: extra elements returned from command\n");
428       print_strings (r);
429       return -1;
430     }
431     for (i = 0; r[i] != NULL; ++i)
432       free (r[i]);
433     free (r);
434   }
435   return 0;
436 }
437
438 static int test_vgremove_1 (void)
439 {
440   /* InitEmpty for vgremove (1) */
441   {
442     int r;
443     suppress_error = 0;
444     r = guestfs_umount_all (g);
445     if (r == -1)
446       return -1;
447   }
448   {
449     int r;
450     suppress_error = 0;
451     r = guestfs_lvm_remove_all (g);
452     if (r == -1)
453       return -1;
454   }
455   /* TestOutputList for vgremove (1) */
456   {
457     int r;
458     suppress_error = 0;
459     r = guestfs_pvcreate (g, "/dev/sda");
460     if (r == -1)
461       return -1;
462   }
463   {
464     char *physvols[] = {
465       "/dev/sda",
466       NULL
467     };
468     int r;
469     suppress_error = 0;
470     r = guestfs_vgcreate (g, "VG", physvols);
471     if (r == -1)
472       return -1;
473   }
474   {
475     int r;
476     suppress_error = 0;
477     r = guestfs_lvcreate (g, "LV1", "VG", 50);
478     if (r == -1)
479       return -1;
480   }
481   {
482     int r;
483     suppress_error = 0;
484     r = guestfs_lvcreate (g, "LV2", "VG", 50);
485     if (r == -1)
486       return -1;
487   }
488   {
489     int r;
490     suppress_error = 0;
491     r = guestfs_vgremove (g, "VG");
492     if (r == -1)
493       return -1;
494   }
495   {
496     char **r;
497     int i;
498     suppress_error = 0;
499     r = guestfs_vgs (g);
500     if (r == NULL)
501       return -1;
502     if (r[0] != NULL) {
503       fprintf (stderr, "test_vgremove_1: extra elements returned from command\n");
504       print_strings (r);
505       return -1;
506     }
507     for (i = 0; r[i] != NULL; ++i)
508       free (r[i]);
509     free (r);
510   }
511   return 0;
512 }
513
514 static int test_lvremove_0 (void)
515 {
516   /* InitEmpty for lvremove (0) */
517   {
518     int r;
519     suppress_error = 0;
520     r = guestfs_umount_all (g);
521     if (r == -1)
522       return -1;
523   }
524   {
525     int r;
526     suppress_error = 0;
527     r = guestfs_lvm_remove_all (g);
528     if (r == -1)
529       return -1;
530   }
531   /* TestOutputList for lvremove (0) */
532   {
533     int r;
534     suppress_error = 0;
535     r = guestfs_pvcreate (g, "/dev/sda");
536     if (r == -1)
537       return -1;
538   }
539   {
540     char *physvols[] = {
541       "/dev/sda",
542       NULL
543     };
544     int r;
545     suppress_error = 0;
546     r = guestfs_vgcreate (g, "VG", physvols);
547     if (r == -1)
548       return -1;
549   }
550   {
551     int r;
552     suppress_error = 0;
553     r = guestfs_lvcreate (g, "LV1", "VG", 50);
554     if (r == -1)
555       return -1;
556   }
557   {
558     int r;
559     suppress_error = 0;
560     r = guestfs_lvcreate (g, "LV2", "VG", 50);
561     if (r == -1)
562       return -1;
563   }
564   {
565     int r;
566     suppress_error = 0;
567     r = guestfs_lvremove (g, "/dev/VG/LV1");
568     if (r == -1)
569       return -1;
570   }
571   {
572     char **r;
573     int i;
574     suppress_error = 0;
575     r = guestfs_lvs (g);
576     if (r == NULL)
577       return -1;
578     if (!r[0]) {
579       fprintf (stderr, "test_lvremove_0: short list returned from command\n");
580       print_strings (r);
581       return -1;
582     }
583     if (strcmp (r[0], "/dev/VG/LV2") != 0) {
584       fprintf (stderr, "test_lvremove_0: expected \"/dev/VG/LV2\" but got \"%s\"\n", r[0]);
585       return -1;
586     }
587     if (r[1] != NULL) {
588       fprintf (stderr, "test_lvremove_0: extra elements returned from command\n");
589       print_strings (r);
590       return -1;
591     }
592     for (i = 0; r[i] != NULL; ++i)
593       free (r[i]);
594     free (r);
595   }
596   return 0;
597 }
598
599 static int test_lvremove_1 (void)
600 {
601   /* InitEmpty for lvremove (1) */
602   {
603     int r;
604     suppress_error = 0;
605     r = guestfs_umount_all (g);
606     if (r == -1)
607       return -1;
608   }
609   {
610     int r;
611     suppress_error = 0;
612     r = guestfs_lvm_remove_all (g);
613     if (r == -1)
614       return -1;
615   }
616   /* TestOutputList for lvremove (1) */
617   {
618     int r;
619     suppress_error = 0;
620     r = guestfs_pvcreate (g, "/dev/sda");
621     if (r == -1)
622       return -1;
623   }
624   {
625     char *physvols[] = {
626       "/dev/sda",
627       NULL
628     };
629     int r;
630     suppress_error = 0;
631     r = guestfs_vgcreate (g, "VG", physvols);
632     if (r == -1)
633       return -1;
634   }
635   {
636     int r;
637     suppress_error = 0;
638     r = guestfs_lvcreate (g, "LV1", "VG", 50);
639     if (r == -1)
640       return -1;
641   }
642   {
643     int r;
644     suppress_error = 0;
645     r = guestfs_lvcreate (g, "LV2", "VG", 50);
646     if (r == -1)
647       return -1;
648   }
649   {
650     int r;
651     suppress_error = 0;
652     r = guestfs_lvremove (g, "/dev/VG");
653     if (r == -1)
654       return -1;
655   }
656   {
657     char **r;
658     int i;
659     suppress_error = 0;
660     r = guestfs_lvs (g);
661     if (r == NULL)
662       return -1;
663     if (r[0] != NULL) {
664       fprintf (stderr, "test_lvremove_1: extra elements returned from command\n");
665       print_strings (r);
666       return -1;
667     }
668     for (i = 0; r[i] != NULL; ++i)
669       free (r[i]);
670     free (r);
671   }
672   return 0;
673 }
674
675 static int test_lvremove_2 (void)
676 {
677   /* InitEmpty for lvremove (2) */
678   {
679     int r;
680     suppress_error = 0;
681     r = guestfs_umount_all (g);
682     if (r == -1)
683       return -1;
684   }
685   {
686     int r;
687     suppress_error = 0;
688     r = guestfs_lvm_remove_all (g);
689     if (r == -1)
690       return -1;
691   }
692   /* TestOutputList for lvremove (2) */
693   {
694     int r;
695     suppress_error = 0;
696     r = guestfs_pvcreate (g, "/dev/sda");
697     if (r == -1)
698       return -1;
699   }
700   {
701     char *physvols[] = {
702       "/dev/sda",
703       NULL
704     };
705     int r;
706     suppress_error = 0;
707     r = guestfs_vgcreate (g, "VG", physvols);
708     if (r == -1)
709       return -1;
710   }
711   {
712     int r;
713     suppress_error = 0;
714     r = guestfs_lvcreate (g, "LV1", "VG", 50);
715     if (r == -1)
716       return -1;
717   }
718   {
719     int r;
720     suppress_error = 0;
721     r = guestfs_lvcreate (g, "LV2", "VG", 50);
722     if (r == -1)
723       return -1;
724   }
725   {
726     int r;
727     suppress_error = 0;
728     r = guestfs_lvremove (g, "/dev/VG");
729     if (r == -1)
730       return -1;
731   }
732   {
733     char **r;
734     int i;
735     suppress_error = 0;
736     r = guestfs_vgs (g);
737     if (r == NULL)
738       return -1;
739     if (!r[0]) {
740       fprintf (stderr, "test_lvremove_2: short list returned from command\n");
741       print_strings (r);
742       return -1;
743     }
744     if (strcmp (r[0], "VG") != 0) {
745       fprintf (stderr, "test_lvremove_2: expected \"VG\" but got \"%s\"\n", r[0]);
746       return -1;
747     }
748     if (r[1] != NULL) {
749       fprintf (stderr, "test_lvremove_2: extra elements returned from command\n");
750       print_strings (r);
751       return -1;
752     }
753     for (i = 0; r[i] != NULL; ++i)
754       free (r[i]);
755     free (r);
756   }
757   return 0;
758 }
759
760 static int test_mount_ro_0 (void)
761 {
762   /* InitBasicFS for mount_ro (0): create ext2 on /dev/sda1 */
763   {
764     int r;
765     suppress_error = 0;
766     r = guestfs_umount_all (g);
767     if (r == -1)
768       return -1;
769   }
770   {
771     int r;
772     suppress_error = 0;
773     r = guestfs_lvm_remove_all (g);
774     if (r == -1)
775       return -1;
776   }
777   {
778     char *lines[] = {
779       ",",
780       NULL
781     };
782     int r;
783     suppress_error = 0;
784     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
785     if (r == -1)
786       return -1;
787   }
788   {
789     int r;
790     suppress_error = 0;
791     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
792     if (r == -1)
793       return -1;
794   }
795   {
796     int r;
797     suppress_error = 0;
798     r = guestfs_mount (g, "/dev/sda1", "/");
799     if (r == -1)
800       return -1;
801   }
802   /* TestLastFail for mount_ro (0) */
803   {
804     int r;
805     suppress_error = 0;
806     r = guestfs_umount (g, "/");
807     if (r == -1)
808       return -1;
809   }
810   {
811     int r;
812     suppress_error = 0;
813     r = guestfs_mount_ro (g, "/dev/sda1", "/");
814     if (r == -1)
815       return -1;
816   }
817   {
818     int r;
819     suppress_error = 1;
820     r = guestfs_touch (g, "/new");
821     if (r != -1)
822       return -1;
823   }
824   return 0;
825 }
826
827 static int test_mount_ro_1 (void)
828 {
829   /* InitBasicFS for mount_ro (1): create ext2 on /dev/sda1 */
830   {
831     int r;
832     suppress_error = 0;
833     r = guestfs_umount_all (g);
834     if (r == -1)
835       return -1;
836   }
837   {
838     int r;
839     suppress_error = 0;
840     r = guestfs_lvm_remove_all (g);
841     if (r == -1)
842       return -1;
843   }
844   {
845     char *lines[] = {
846       ",",
847       NULL
848     };
849     int r;
850     suppress_error = 0;
851     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
852     if (r == -1)
853       return -1;
854   }
855   {
856     int r;
857     suppress_error = 0;
858     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
859     if (r == -1)
860       return -1;
861   }
862   {
863     int r;
864     suppress_error = 0;
865     r = guestfs_mount (g, "/dev/sda1", "/");
866     if (r == -1)
867       return -1;
868   }
869   /* TestOutput for mount_ro (1) */
870   {
871     int r;
872     suppress_error = 0;
873     r = guestfs_write_file (g, "/new", "data", 0);
874     if (r == -1)
875       return -1;
876   }
877   {
878     int r;
879     suppress_error = 0;
880     r = guestfs_umount (g, "/");
881     if (r == -1)
882       return -1;
883   }
884   {
885     int r;
886     suppress_error = 0;
887     r = guestfs_mount_ro (g, "/dev/sda1", "/");
888     if (r == -1)
889       return -1;
890   }
891   {
892     char *r;
893     suppress_error = 0;
894     r = guestfs_cat (g, "/new");
895     if (r == NULL)
896       return -1;
897     if (strcmp (r, "data") != 0) {
898       fprintf (stderr, "test_mount_ro_1: expected \"data\" but got \"%s\"\n", r);
899       return -1;
900     }
901     free (r);
902   }
903   return 0;
904 }
905
906 static int test_tgz_in_0 (void)
907 {
908   /* InitBasicFS for tgz_in (0): create ext2 on /dev/sda1 */
909   {
910     int r;
911     suppress_error = 0;
912     r = guestfs_umount_all (g);
913     if (r == -1)
914       return -1;
915   }
916   {
917     int r;
918     suppress_error = 0;
919     r = guestfs_lvm_remove_all (g);
920     if (r == -1)
921       return -1;
922   }
923   {
924     char *lines[] = {
925       ",",
926       NULL
927     };
928     int r;
929     suppress_error = 0;
930     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
931     if (r == -1)
932       return -1;
933   }
934   {
935     int r;
936     suppress_error = 0;
937     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
938     if (r == -1)
939       return -1;
940   }
941   {
942     int r;
943     suppress_error = 0;
944     r = guestfs_mount (g, "/dev/sda1", "/");
945     if (r == -1)
946       return -1;
947   }
948   /* TestOutput for tgz_in (0) */
949   {
950     int r;
951     suppress_error = 0;
952     r = guestfs_tgz_in (g, "images/helloworld.tar.gz", "/");
953     if (r == -1)
954       return -1;
955   }
956   {
957     char *r;
958     suppress_error = 0;
959     r = guestfs_cat (g, "/hello");
960     if (r == NULL)
961       return -1;
962     if (strcmp (r, "hello\n") != 0) {
963       fprintf (stderr, "test_tgz_in_0: expected \"hello\n\" but got \"%s\"\n", r);
964       return -1;
965     }
966     free (r);
967   }
968   return 0;
969 }
970
971 static int test_tar_in_0 (void)
972 {
973   /* InitBasicFS for tar_in (0): create ext2 on /dev/sda1 */
974   {
975     int r;
976     suppress_error = 0;
977     r = guestfs_umount_all (g);
978     if (r == -1)
979       return -1;
980   }
981   {
982     int r;
983     suppress_error = 0;
984     r = guestfs_lvm_remove_all (g);
985     if (r == -1)
986       return -1;
987   }
988   {
989     char *lines[] = {
990       ",",
991       NULL
992     };
993     int r;
994     suppress_error = 0;
995     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
996     if (r == -1)
997       return -1;
998   }
999   {
1000     int r;
1001     suppress_error = 0;
1002     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1003     if (r == -1)
1004       return -1;
1005   }
1006   {
1007     int r;
1008     suppress_error = 0;
1009     r = guestfs_mount (g, "/dev/sda1", "/");
1010     if (r == -1)
1011       return -1;
1012   }
1013   /* TestOutput for tar_in (0) */
1014   {
1015     int r;
1016     suppress_error = 0;
1017     r = guestfs_tar_in (g, "images/helloworld.tar", "/");
1018     if (r == -1)
1019       return -1;
1020   }
1021   {
1022     char *r;
1023     suppress_error = 0;
1024     r = guestfs_cat (g, "/hello");
1025     if (r == NULL)
1026       return -1;
1027     if (strcmp (r, "hello\n") != 0) {
1028       fprintf (stderr, "test_tar_in_0: expected \"hello\n\" but got \"%s\"\n", r);
1029       return -1;
1030     }
1031     free (r);
1032   }
1033   return 0;
1034 }
1035
1036 static int test_checksum_0 (void)
1037 {
1038   /* InitBasicFS for checksum (0): create ext2 on /dev/sda1 */
1039   {
1040     int r;
1041     suppress_error = 0;
1042     r = guestfs_umount_all (g);
1043     if (r == -1)
1044       return -1;
1045   }
1046   {
1047     int r;
1048     suppress_error = 0;
1049     r = guestfs_lvm_remove_all (g);
1050     if (r == -1)
1051       return -1;
1052   }
1053   {
1054     char *lines[] = {
1055       ",",
1056       NULL
1057     };
1058     int r;
1059     suppress_error = 0;
1060     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1061     if (r == -1)
1062       return -1;
1063   }
1064   {
1065     int r;
1066     suppress_error = 0;
1067     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1068     if (r == -1)
1069       return -1;
1070   }
1071   {
1072     int r;
1073     suppress_error = 0;
1074     r = guestfs_mount (g, "/dev/sda1", "/");
1075     if (r == -1)
1076       return -1;
1077   }
1078   /* TestOutput for checksum (0) */
1079   {
1080     int r;
1081     suppress_error = 0;
1082     r = guestfs_write_file (g, "/new", "test\n", 0);
1083     if (r == -1)
1084       return -1;
1085   }
1086   {
1087     char *r;
1088     suppress_error = 0;
1089     r = guestfs_checksum (g, "crc", "/new");
1090     if (r == NULL)
1091       return -1;
1092     if (strcmp (r, "935282863") != 0) {
1093       fprintf (stderr, "test_checksum_0: expected \"935282863\" but got \"%s\"\n", r);
1094       return -1;
1095     }
1096     free (r);
1097   }
1098   return 0;
1099 }
1100
1101 static int test_checksum_1 (void)
1102 {
1103   /* InitBasicFS for checksum (1): create ext2 on /dev/sda1 */
1104   {
1105     int r;
1106     suppress_error = 0;
1107     r = guestfs_umount_all (g);
1108     if (r == -1)
1109       return -1;
1110   }
1111   {
1112     int r;
1113     suppress_error = 0;
1114     r = guestfs_lvm_remove_all (g);
1115     if (r == -1)
1116       return -1;
1117   }
1118   {
1119     char *lines[] = {
1120       ",",
1121       NULL
1122     };
1123     int r;
1124     suppress_error = 0;
1125     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1126     if (r == -1)
1127       return -1;
1128   }
1129   {
1130     int r;
1131     suppress_error = 0;
1132     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1133     if (r == -1)
1134       return -1;
1135   }
1136   {
1137     int r;
1138     suppress_error = 0;
1139     r = guestfs_mount (g, "/dev/sda1", "/");
1140     if (r == -1)
1141       return -1;
1142   }
1143   /* TestLastFail for checksum (1) */
1144   {
1145     char *r;
1146     suppress_error = 1;
1147     r = guestfs_checksum (g, "crc", "/new");
1148     if (r != NULL)
1149       return -1;
1150     free (r);
1151   }
1152   return 0;
1153 }
1154
1155 static int test_checksum_2 (void)
1156 {
1157   /* InitBasicFS for checksum (2): create ext2 on /dev/sda1 */
1158   {
1159     int r;
1160     suppress_error = 0;
1161     r = guestfs_umount_all (g);
1162     if (r == -1)
1163       return -1;
1164   }
1165   {
1166     int r;
1167     suppress_error = 0;
1168     r = guestfs_lvm_remove_all (g);
1169     if (r == -1)
1170       return -1;
1171   }
1172   {
1173     char *lines[] = {
1174       ",",
1175       NULL
1176     };
1177     int r;
1178     suppress_error = 0;
1179     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1180     if (r == -1)
1181       return -1;
1182   }
1183   {
1184     int r;
1185     suppress_error = 0;
1186     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1187     if (r == -1)
1188       return -1;
1189   }
1190   {
1191     int r;
1192     suppress_error = 0;
1193     r = guestfs_mount (g, "/dev/sda1", "/");
1194     if (r == -1)
1195       return -1;
1196   }
1197   /* TestOutput for checksum (2) */
1198   {
1199     int r;
1200     suppress_error = 0;
1201     r = guestfs_write_file (g, "/new", "test\n", 0);
1202     if (r == -1)
1203       return -1;
1204   }
1205   {
1206     char *r;
1207     suppress_error = 0;
1208     r = guestfs_checksum (g, "md5", "/new");
1209     if (r == NULL)
1210       return -1;
1211     if (strcmp (r, "d8e8fca2dc0f896fd7cb4cb0031ba249") != 0) {
1212       fprintf (stderr, "test_checksum_2: expected \"d8e8fca2dc0f896fd7cb4cb0031ba249\" but got \"%s\"\n", r);
1213       return -1;
1214     }
1215     free (r);
1216   }
1217   return 0;
1218 }
1219
1220 static int test_checksum_3 (void)
1221 {
1222   /* InitBasicFS for checksum (3): create ext2 on /dev/sda1 */
1223   {
1224     int r;
1225     suppress_error = 0;
1226     r = guestfs_umount_all (g);
1227     if (r == -1)
1228       return -1;
1229   }
1230   {
1231     int r;
1232     suppress_error = 0;
1233     r = guestfs_lvm_remove_all (g);
1234     if (r == -1)
1235       return -1;
1236   }
1237   {
1238     char *lines[] = {
1239       ",",
1240       NULL
1241     };
1242     int r;
1243     suppress_error = 0;
1244     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1245     if (r == -1)
1246       return -1;
1247   }
1248   {
1249     int r;
1250     suppress_error = 0;
1251     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1252     if (r == -1)
1253       return -1;
1254   }
1255   {
1256     int r;
1257     suppress_error = 0;
1258     r = guestfs_mount (g, "/dev/sda1", "/");
1259     if (r == -1)
1260       return -1;
1261   }
1262   /* TestOutput for checksum (3) */
1263   {
1264     int r;
1265     suppress_error = 0;
1266     r = guestfs_write_file (g, "/new", "test\n", 0);
1267     if (r == -1)
1268       return -1;
1269   }
1270   {
1271     char *r;
1272     suppress_error = 0;
1273     r = guestfs_checksum (g, "sha1", "/new");
1274     if (r == NULL)
1275       return -1;
1276     if (strcmp (r, "4e1243bd22c66e76c2ba9eddc1f91394e57f9f83") != 0) {
1277       fprintf (stderr, "test_checksum_3: expected \"4e1243bd22c66e76c2ba9eddc1f91394e57f9f83\" but got \"%s\"\n", r);
1278       return -1;
1279     }
1280     free (r);
1281   }
1282   return 0;
1283 }
1284
1285 static int test_checksum_4 (void)
1286 {
1287   /* InitBasicFS for checksum (4): create ext2 on /dev/sda1 */
1288   {
1289     int r;
1290     suppress_error = 0;
1291     r = guestfs_umount_all (g);
1292     if (r == -1)
1293       return -1;
1294   }
1295   {
1296     int r;
1297     suppress_error = 0;
1298     r = guestfs_lvm_remove_all (g);
1299     if (r == -1)
1300       return -1;
1301   }
1302   {
1303     char *lines[] = {
1304       ",",
1305       NULL
1306     };
1307     int r;
1308     suppress_error = 0;
1309     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1310     if (r == -1)
1311       return -1;
1312   }
1313   {
1314     int r;
1315     suppress_error = 0;
1316     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1317     if (r == -1)
1318       return -1;
1319   }
1320   {
1321     int r;
1322     suppress_error = 0;
1323     r = guestfs_mount (g, "/dev/sda1", "/");
1324     if (r == -1)
1325       return -1;
1326   }
1327   /* TestOutput for checksum (4) */
1328   {
1329     int r;
1330     suppress_error = 0;
1331     r = guestfs_write_file (g, "/new", "test\n", 0);
1332     if (r == -1)
1333       return -1;
1334   }
1335   {
1336     char *r;
1337     suppress_error = 0;
1338     r = guestfs_checksum (g, "sha224", "/new");
1339     if (r == NULL)
1340       return -1;
1341     if (strcmp (r, "52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec") != 0) {
1342       fprintf (stderr, "test_checksum_4: expected \"52f1bf093f4b7588726035c176c0cdb4376cfea53819f1395ac9e6ec\" but got \"%s\"\n", r);
1343       return -1;
1344     }
1345     free (r);
1346   }
1347   return 0;
1348 }
1349
1350 static int test_checksum_5 (void)
1351 {
1352   /* InitBasicFS for checksum (5): create ext2 on /dev/sda1 */
1353   {
1354     int r;
1355     suppress_error = 0;
1356     r = guestfs_umount_all (g);
1357     if (r == -1)
1358       return -1;
1359   }
1360   {
1361     int r;
1362     suppress_error = 0;
1363     r = guestfs_lvm_remove_all (g);
1364     if (r == -1)
1365       return -1;
1366   }
1367   {
1368     char *lines[] = {
1369       ",",
1370       NULL
1371     };
1372     int r;
1373     suppress_error = 0;
1374     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1375     if (r == -1)
1376       return -1;
1377   }
1378   {
1379     int r;
1380     suppress_error = 0;
1381     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1382     if (r == -1)
1383       return -1;
1384   }
1385   {
1386     int r;
1387     suppress_error = 0;
1388     r = guestfs_mount (g, "/dev/sda1", "/");
1389     if (r == -1)
1390       return -1;
1391   }
1392   /* TestOutput for checksum (5) */
1393   {
1394     int r;
1395     suppress_error = 0;
1396     r = guestfs_write_file (g, "/new", "test\n", 0);
1397     if (r == -1)
1398       return -1;
1399   }
1400   {
1401     char *r;
1402     suppress_error = 0;
1403     r = guestfs_checksum (g, "sha256", "/new");
1404     if (r == NULL)
1405       return -1;
1406     if (strcmp (r, "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2") != 0) {
1407       fprintf (stderr, "test_checksum_5: expected \"f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2\" but got \"%s\"\n", r);
1408       return -1;
1409     }
1410     free (r);
1411   }
1412   return 0;
1413 }
1414
1415 static int test_checksum_6 (void)
1416 {
1417   /* InitBasicFS for checksum (6): create ext2 on /dev/sda1 */
1418   {
1419     int r;
1420     suppress_error = 0;
1421     r = guestfs_umount_all (g);
1422     if (r == -1)
1423       return -1;
1424   }
1425   {
1426     int r;
1427     suppress_error = 0;
1428     r = guestfs_lvm_remove_all (g);
1429     if (r == -1)
1430       return -1;
1431   }
1432   {
1433     char *lines[] = {
1434       ",",
1435       NULL
1436     };
1437     int r;
1438     suppress_error = 0;
1439     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1440     if (r == -1)
1441       return -1;
1442   }
1443   {
1444     int r;
1445     suppress_error = 0;
1446     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1447     if (r == -1)
1448       return -1;
1449   }
1450   {
1451     int r;
1452     suppress_error = 0;
1453     r = guestfs_mount (g, "/dev/sda1", "/");
1454     if (r == -1)
1455       return -1;
1456   }
1457   /* TestOutput for checksum (6) */
1458   {
1459     int r;
1460     suppress_error = 0;
1461     r = guestfs_write_file (g, "/new", "test\n", 0);
1462     if (r == -1)
1463       return -1;
1464   }
1465   {
1466     char *r;
1467     suppress_error = 0;
1468     r = guestfs_checksum (g, "sha384", "/new");
1469     if (r == NULL)
1470       return -1;
1471     if (strcmp (r, "109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d") != 0) {
1472       fprintf (stderr, "test_checksum_6: expected \"109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d\" but got \"%s\"\n", r);
1473       return -1;
1474     }
1475     free (r);
1476   }
1477   return 0;
1478 }
1479
1480 static int test_checksum_7 (void)
1481 {
1482   /* InitBasicFS for checksum (7): create ext2 on /dev/sda1 */
1483   {
1484     int r;
1485     suppress_error = 0;
1486     r = guestfs_umount_all (g);
1487     if (r == -1)
1488       return -1;
1489   }
1490   {
1491     int r;
1492     suppress_error = 0;
1493     r = guestfs_lvm_remove_all (g);
1494     if (r == -1)
1495       return -1;
1496   }
1497   {
1498     char *lines[] = {
1499       ",",
1500       NULL
1501     };
1502     int r;
1503     suppress_error = 0;
1504     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1505     if (r == -1)
1506       return -1;
1507   }
1508   {
1509     int r;
1510     suppress_error = 0;
1511     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1512     if (r == -1)
1513       return -1;
1514   }
1515   {
1516     int r;
1517     suppress_error = 0;
1518     r = guestfs_mount (g, "/dev/sda1", "/");
1519     if (r == -1)
1520       return -1;
1521   }
1522   /* TestOutput for checksum (7) */
1523   {
1524     int r;
1525     suppress_error = 0;
1526     r = guestfs_write_file (g, "/new", "test\n", 0);
1527     if (r == -1)
1528       return -1;
1529   }
1530   {
1531     char *r;
1532     suppress_error = 0;
1533     r = guestfs_checksum (g, "sha512", "/new");
1534     if (r == NULL)
1535       return -1;
1536     if (strcmp (r, "0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123") != 0) {
1537       fprintf (stderr, "test_checksum_7: expected \"0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123\" but got \"%s\"\n", r);
1538       return -1;
1539     }
1540     free (r);
1541   }
1542   return 0;
1543 }
1544
1545 static int test_download_0 (void)
1546 {
1547   /* InitBasicFS for download (0): create ext2 on /dev/sda1 */
1548   {
1549     int r;
1550     suppress_error = 0;
1551     r = guestfs_umount_all (g);
1552     if (r == -1)
1553       return -1;
1554   }
1555   {
1556     int r;
1557     suppress_error = 0;
1558     r = guestfs_lvm_remove_all (g);
1559     if (r == -1)
1560       return -1;
1561   }
1562   {
1563     char *lines[] = {
1564       ",",
1565       NULL
1566     };
1567     int r;
1568     suppress_error = 0;
1569     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1570     if (r == -1)
1571       return -1;
1572   }
1573   {
1574     int r;
1575     suppress_error = 0;
1576     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1577     if (r == -1)
1578       return -1;
1579   }
1580   {
1581     int r;
1582     suppress_error = 0;
1583     r = guestfs_mount (g, "/dev/sda1", "/");
1584     if (r == -1)
1585       return -1;
1586   }
1587   /* TestOutput for download (0) */
1588   {
1589     int r;
1590     suppress_error = 0;
1591     r = guestfs_upload (g, "COPYING.LIB", "/COPYING.LIB");
1592     if (r == -1)
1593       return -1;
1594   }
1595   {
1596     int r;
1597     suppress_error = 0;
1598     r = guestfs_download (g, "/COPYING.LIB", "testdownload.tmp");
1599     if (r == -1)
1600       return -1;
1601   }
1602   {
1603     int r;
1604     suppress_error = 0;
1605     r = guestfs_upload (g, "testdownload.tmp", "/upload");
1606     if (r == -1)
1607       return -1;
1608   }
1609   {
1610     char *r;
1611     suppress_error = 0;
1612     r = guestfs_checksum (g, "md5", "/upload");
1613     if (r == NULL)
1614       return -1;
1615     if (strcmp (r, "e3eda01d9815f8d24aae2dbd89b68b06") != 0) {
1616       fprintf (stderr, "test_download_0: expected \"e3eda01d9815f8d24aae2dbd89b68b06\" but got \"%s\"\n", r);
1617       return -1;
1618     }
1619     free (r);
1620   }
1621   return 0;
1622 }
1623
1624 static int test_upload_0 (void)
1625 {
1626   /* InitBasicFS for upload (0): create ext2 on /dev/sda1 */
1627   {
1628     int r;
1629     suppress_error = 0;
1630     r = guestfs_umount_all (g);
1631     if (r == -1)
1632       return -1;
1633   }
1634   {
1635     int r;
1636     suppress_error = 0;
1637     r = guestfs_lvm_remove_all (g);
1638     if (r == -1)
1639       return -1;
1640   }
1641   {
1642     char *lines[] = {
1643       ",",
1644       NULL
1645     };
1646     int r;
1647     suppress_error = 0;
1648     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1649     if (r == -1)
1650       return -1;
1651   }
1652   {
1653     int r;
1654     suppress_error = 0;
1655     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1656     if (r == -1)
1657       return -1;
1658   }
1659   {
1660     int r;
1661     suppress_error = 0;
1662     r = guestfs_mount (g, "/dev/sda1", "/");
1663     if (r == -1)
1664       return -1;
1665   }
1666   /* TestOutput for upload (0) */
1667   {
1668     int r;
1669     suppress_error = 0;
1670     r = guestfs_upload (g, "COPYING.LIB", "/COPYING.LIB");
1671     if (r == -1)
1672       return -1;
1673   }
1674   {
1675     char *r;
1676     suppress_error = 0;
1677     r = guestfs_checksum (g, "md5", "/COPYING.LIB");
1678     if (r == NULL)
1679       return -1;
1680     if (strcmp (r, "e3eda01d9815f8d24aae2dbd89b68b06") != 0) {
1681       fprintf (stderr, "test_upload_0: expected \"e3eda01d9815f8d24aae2dbd89b68b06\" but got \"%s\"\n", r);
1682       return -1;
1683     }
1684     free (r);
1685   }
1686   return 0;
1687 }
1688
1689 static int test_blockdev_rereadpt_0 (void)
1690 {
1691   /* InitEmpty for blockdev_rereadpt (0) */
1692   {
1693     int r;
1694     suppress_error = 0;
1695     r = guestfs_umount_all (g);
1696     if (r == -1)
1697       return -1;
1698   }
1699   {
1700     int r;
1701     suppress_error = 0;
1702     r = guestfs_lvm_remove_all (g);
1703     if (r == -1)
1704       return -1;
1705   }
1706   /* TestRun for blockdev_rereadpt (0) */
1707   {
1708     int r;
1709     suppress_error = 0;
1710     r = guestfs_blockdev_rereadpt (g, "/dev/sda");
1711     if (r == -1)
1712       return -1;
1713   }
1714   return 0;
1715 }
1716
1717 static int test_blockdev_flushbufs_0 (void)
1718 {
1719   /* InitEmpty for blockdev_flushbufs (0) */
1720   {
1721     int r;
1722     suppress_error = 0;
1723     r = guestfs_umount_all (g);
1724     if (r == -1)
1725       return -1;
1726   }
1727   {
1728     int r;
1729     suppress_error = 0;
1730     r = guestfs_lvm_remove_all (g);
1731     if (r == -1)
1732       return -1;
1733   }
1734   /* TestRun for blockdev_flushbufs (0) */
1735   {
1736     int r;
1737     suppress_error = 0;
1738     r = guestfs_blockdev_flushbufs (g, "/dev/sda");
1739     if (r == -1)
1740       return -1;
1741   }
1742   return 0;
1743 }
1744
1745 static int test_blockdev_getsize64_0 (void)
1746 {
1747   /* InitEmpty for blockdev_getsize64 (0) */
1748   {
1749     int r;
1750     suppress_error = 0;
1751     r = guestfs_umount_all (g);
1752     if (r == -1)
1753       return -1;
1754   }
1755   {
1756     int r;
1757     suppress_error = 0;
1758     r = guestfs_lvm_remove_all (g);
1759     if (r == -1)
1760       return -1;
1761   }
1762   /* TestOutputInt for blockdev_getsize64 (0) */
1763   {
1764     int64_t r;
1765     suppress_error = 0;
1766     r = guestfs_blockdev_getsize64 (g, "/dev/sda");
1767     if (r == -1)
1768       return -1;
1769     if (r != 524288000) {
1770       fprintf (stderr, "test_blockdev_getsize64_0: expected 524288000 but got %d\n",               (int) r);
1771       return -1;
1772     }
1773   }
1774   return 0;
1775 }
1776
1777 static int test_blockdev_getsz_0 (void)
1778 {
1779   /* InitEmpty for blockdev_getsz (0) */
1780   {
1781     int r;
1782     suppress_error = 0;
1783     r = guestfs_umount_all (g);
1784     if (r == -1)
1785       return -1;
1786   }
1787   {
1788     int r;
1789     suppress_error = 0;
1790     r = guestfs_lvm_remove_all (g);
1791     if (r == -1)
1792       return -1;
1793   }
1794   /* TestOutputInt for blockdev_getsz (0) */
1795   {
1796     int64_t r;
1797     suppress_error = 0;
1798     r = guestfs_blockdev_getsz (g, "/dev/sda");
1799     if (r == -1)
1800       return -1;
1801     if (r != 1024000) {
1802       fprintf (stderr, "test_blockdev_getsz_0: expected 1024000 but got %d\n",               (int) r);
1803       return -1;
1804     }
1805   }
1806   return 0;
1807 }
1808
1809 static int test_blockdev_getbsz_0 (void)
1810 {
1811   /* InitEmpty for blockdev_getbsz (0) */
1812   {
1813     int r;
1814     suppress_error = 0;
1815     r = guestfs_umount_all (g);
1816     if (r == -1)
1817       return -1;
1818   }
1819   {
1820     int r;
1821     suppress_error = 0;
1822     r = guestfs_lvm_remove_all (g);
1823     if (r == -1)
1824       return -1;
1825   }
1826   /* TestOutputInt for blockdev_getbsz (0) */
1827   {
1828     int r;
1829     suppress_error = 0;
1830     r = guestfs_blockdev_getbsz (g, "/dev/sda");
1831     if (r == -1)
1832       return -1;
1833     if (r != 4096) {
1834       fprintf (stderr, "test_blockdev_getbsz_0: expected 4096 but got %d\n",               (int) r);
1835       return -1;
1836     }
1837   }
1838   return 0;
1839 }
1840
1841 static int test_blockdev_getss_0 (void)
1842 {
1843   /* InitEmpty for blockdev_getss (0) */
1844   {
1845     int r;
1846     suppress_error = 0;
1847     r = guestfs_umount_all (g);
1848     if (r == -1)
1849       return -1;
1850   }
1851   {
1852     int r;
1853     suppress_error = 0;
1854     r = guestfs_lvm_remove_all (g);
1855     if (r == -1)
1856       return -1;
1857   }
1858   /* TestOutputInt for blockdev_getss (0) */
1859   {
1860     int r;
1861     suppress_error = 0;
1862     r = guestfs_blockdev_getss (g, "/dev/sda");
1863     if (r == -1)
1864       return -1;
1865     if (r != 512) {
1866       fprintf (stderr, "test_blockdev_getss_0: expected 512 but got %d\n",               (int) r);
1867       return -1;
1868     }
1869   }
1870   return 0;
1871 }
1872
1873 static int test_blockdev_getro_0 (void)
1874 {
1875   /* InitEmpty for blockdev_getro (0) */
1876   {
1877     int r;
1878     suppress_error = 0;
1879     r = guestfs_umount_all (g);
1880     if (r == -1)
1881       return -1;
1882   }
1883   {
1884     int r;
1885     suppress_error = 0;
1886     r = guestfs_lvm_remove_all (g);
1887     if (r == -1)
1888       return -1;
1889   }
1890   /* TestOutputTrue for blockdev_getro (0) */
1891   {
1892     int r;
1893     suppress_error = 0;
1894     r = guestfs_blockdev_setro (g, "/dev/sda");
1895     if (r == -1)
1896       return -1;
1897   }
1898   {
1899     int r;
1900     suppress_error = 0;
1901     r = guestfs_blockdev_getro (g, "/dev/sda");
1902     if (r == -1)
1903       return -1;
1904     if (!r) {
1905       fprintf (stderr, "test_blockdev_getro_0: expected true, got false\n");
1906       return -1;
1907     }
1908   }
1909   return 0;
1910 }
1911
1912 static int test_blockdev_setrw_0 (void)
1913 {
1914   /* InitEmpty for blockdev_setrw (0) */
1915   {
1916     int r;
1917     suppress_error = 0;
1918     r = guestfs_umount_all (g);
1919     if (r == -1)
1920       return -1;
1921   }
1922   {
1923     int r;
1924     suppress_error = 0;
1925     r = guestfs_lvm_remove_all (g);
1926     if (r == -1)
1927       return -1;
1928   }
1929   /* TestOutputFalse for blockdev_setrw (0) */
1930   {
1931     int r;
1932     suppress_error = 0;
1933     r = guestfs_blockdev_setrw (g, "/dev/sda");
1934     if (r == -1)
1935       return -1;
1936   }
1937   {
1938     int r;
1939     suppress_error = 0;
1940     r = guestfs_blockdev_getro (g, "/dev/sda");
1941     if (r == -1)
1942       return -1;
1943     if (r) {
1944       fprintf (stderr, "test_blockdev_setrw_0: expected false, got true\n");
1945       return -1;
1946     }
1947   }
1948   return 0;
1949 }
1950
1951 static int test_blockdev_setro_0 (void)
1952 {
1953   /* InitEmpty for blockdev_setro (0) */
1954   {
1955     int r;
1956     suppress_error = 0;
1957     r = guestfs_umount_all (g);
1958     if (r == -1)
1959       return -1;
1960   }
1961   {
1962     int r;
1963     suppress_error = 0;
1964     r = guestfs_lvm_remove_all (g);
1965     if (r == -1)
1966       return -1;
1967   }
1968   /* TestOutputTrue for blockdev_setro (0) */
1969   {
1970     int r;
1971     suppress_error = 0;
1972     r = guestfs_blockdev_setro (g, "/dev/sda");
1973     if (r == -1)
1974       return -1;
1975   }
1976   {
1977     int r;
1978     suppress_error = 0;
1979     r = guestfs_blockdev_getro (g, "/dev/sda");
1980     if (r == -1)
1981       return -1;
1982     if (!r) {
1983       fprintf (stderr, "test_blockdev_setro_0: expected true, got false\n");
1984       return -1;
1985     }
1986   }
1987   return 0;
1988 }
1989
1990 static int test_statvfs_0 (void)
1991 {
1992   /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */
1993   {
1994     int r;
1995     suppress_error = 0;
1996     r = guestfs_umount_all (g);
1997     if (r == -1)
1998       return -1;
1999   }
2000   {
2001     int r;
2002     suppress_error = 0;
2003     r = guestfs_lvm_remove_all (g);
2004     if (r == -1)
2005       return -1;
2006   }
2007   {
2008     char *lines[] = {
2009       ",",
2010       NULL
2011     };
2012     int r;
2013     suppress_error = 0;
2014     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2015     if (r == -1)
2016       return -1;
2017   }
2018   {
2019     int r;
2020     suppress_error = 0;
2021     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2022     if (r == -1)
2023       return -1;
2024   }
2025   {
2026     int r;
2027     suppress_error = 0;
2028     r = guestfs_mount (g, "/dev/sda1", "/");
2029     if (r == -1)
2030       return -1;
2031   }
2032   /* TestOutputStruct for statvfs (0) */
2033   {
2034     struct guestfs_statvfs *r;
2035     suppress_error = 0;
2036     r = guestfs_statvfs (g, "/");
2037     if (r == NULL)
2038       return -1;
2039     if (r->bfree != 487702) {
2040       fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n",
2041                (int) r->bfree);
2042       return -1;
2043     }
2044     if (r->blocks != 490020) {
2045       fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n",
2046                (int) r->blocks);
2047       return -1;
2048     }
2049     if (r->bsize != 1024) {
2050       fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n",
2051                (int) r->bsize);
2052       return -1;
2053     }
2054     free (r);
2055   }
2056   return 0;
2057 }
2058
2059 static int test_lstat_0 (void)
2060 {
2061   /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */
2062   {
2063     int r;
2064     suppress_error = 0;
2065     r = guestfs_umount_all (g);
2066     if (r == -1)
2067       return -1;
2068   }
2069   {
2070     int r;
2071     suppress_error = 0;
2072     r = guestfs_lvm_remove_all (g);
2073     if (r == -1)
2074       return -1;
2075   }
2076   {
2077     char *lines[] = {
2078       ",",
2079       NULL
2080     };
2081     int r;
2082     suppress_error = 0;
2083     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2084     if (r == -1)
2085       return -1;
2086   }
2087   {
2088     int r;
2089     suppress_error = 0;
2090     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2091     if (r == -1)
2092       return -1;
2093   }
2094   {
2095     int r;
2096     suppress_error = 0;
2097     r = guestfs_mount (g, "/dev/sda1", "/");
2098     if (r == -1)
2099       return -1;
2100   }
2101   /* TestOutputStruct for lstat (0) */
2102   {
2103     int r;
2104     suppress_error = 0;
2105     r = guestfs_touch (g, "/new");
2106     if (r == -1)
2107       return -1;
2108   }
2109   {
2110     struct guestfs_stat *r;
2111     suppress_error = 0;
2112     r = guestfs_lstat (g, "/new");
2113     if (r == NULL)
2114       return -1;
2115     if (r->size != 0) {
2116       fprintf (stderr, "test_lstat_0: size was %d, expected 0\n",
2117                (int) r->size);
2118       return -1;
2119     }
2120     free (r);
2121   }
2122   return 0;
2123 }
2124
2125 static int test_stat_0 (void)
2126 {
2127   /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */
2128   {
2129     int r;
2130     suppress_error = 0;
2131     r = guestfs_umount_all (g);
2132     if (r == -1)
2133       return -1;
2134   }
2135   {
2136     int r;
2137     suppress_error = 0;
2138     r = guestfs_lvm_remove_all (g);
2139     if (r == -1)
2140       return -1;
2141   }
2142   {
2143     char *lines[] = {
2144       ",",
2145       NULL
2146     };
2147     int r;
2148     suppress_error = 0;
2149     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2150     if (r == -1)
2151       return -1;
2152   }
2153   {
2154     int r;
2155     suppress_error = 0;
2156     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2157     if (r == -1)
2158       return -1;
2159   }
2160   {
2161     int r;
2162     suppress_error = 0;
2163     r = guestfs_mount (g, "/dev/sda1", "/");
2164     if (r == -1)
2165       return -1;
2166   }
2167   /* TestOutputStruct for stat (0) */
2168   {
2169     int r;
2170     suppress_error = 0;
2171     r = guestfs_touch (g, "/new");
2172     if (r == -1)
2173       return -1;
2174   }
2175   {
2176     struct guestfs_stat *r;
2177     suppress_error = 0;
2178     r = guestfs_stat (g, "/new");
2179     if (r == NULL)
2180       return -1;
2181     if (r->size != 0) {
2182       fprintf (stderr, "test_stat_0: size was %d, expected 0\n",
2183                (int) r->size);
2184       return -1;
2185     }
2186     free (r);
2187   }
2188   return 0;
2189 }
2190
2191 static int test_file_0 (void)
2192 {
2193   /* InitBasicFS for file (0): create ext2 on /dev/sda1 */
2194   {
2195     int r;
2196     suppress_error = 0;
2197     r = guestfs_umount_all (g);
2198     if (r == -1)
2199       return -1;
2200   }
2201   {
2202     int r;
2203     suppress_error = 0;
2204     r = guestfs_lvm_remove_all (g);
2205     if (r == -1)
2206       return -1;
2207   }
2208   {
2209     char *lines[] = {
2210       ",",
2211       NULL
2212     };
2213     int r;
2214     suppress_error = 0;
2215     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2216     if (r == -1)
2217       return -1;
2218   }
2219   {
2220     int r;
2221     suppress_error = 0;
2222     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2223     if (r == -1)
2224       return -1;
2225   }
2226   {
2227     int r;
2228     suppress_error = 0;
2229     r = guestfs_mount (g, "/dev/sda1", "/");
2230     if (r == -1)
2231       return -1;
2232   }
2233   /* TestOutput for file (0) */
2234   {
2235     int r;
2236     suppress_error = 0;
2237     r = guestfs_touch (g, "/new");
2238     if (r == -1)
2239       return -1;
2240   }
2241   {
2242     char *r;
2243     suppress_error = 0;
2244     r = guestfs_file (g, "/new");
2245     if (r == NULL)
2246       return -1;
2247     if (strcmp (r, "empty") != 0) {
2248       fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r);
2249       return -1;
2250     }
2251     free (r);
2252   }
2253   return 0;
2254 }
2255
2256 static int test_file_1 (void)
2257 {
2258   /* InitBasicFS for file (1): create ext2 on /dev/sda1 */
2259   {
2260     int r;
2261     suppress_error = 0;
2262     r = guestfs_umount_all (g);
2263     if (r == -1)
2264       return -1;
2265   }
2266   {
2267     int r;
2268     suppress_error = 0;
2269     r = guestfs_lvm_remove_all (g);
2270     if (r == -1)
2271       return -1;
2272   }
2273   {
2274     char *lines[] = {
2275       ",",
2276       NULL
2277     };
2278     int r;
2279     suppress_error = 0;
2280     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2281     if (r == -1)
2282       return -1;
2283   }
2284   {
2285     int r;
2286     suppress_error = 0;
2287     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2288     if (r == -1)
2289       return -1;
2290   }
2291   {
2292     int r;
2293     suppress_error = 0;
2294     r = guestfs_mount (g, "/dev/sda1", "/");
2295     if (r == -1)
2296       return -1;
2297   }
2298   /* TestOutput for file (1) */
2299   {
2300     int r;
2301     suppress_error = 0;
2302     r = guestfs_write_file (g, "/new", "some content\n", 0);
2303     if (r == -1)
2304       return -1;
2305   }
2306   {
2307     char *r;
2308     suppress_error = 0;
2309     r = guestfs_file (g, "/new");
2310     if (r == NULL)
2311       return -1;
2312     if (strcmp (r, "ASCII text") != 0) {
2313       fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r);
2314       return -1;
2315     }
2316     free (r);
2317   }
2318   return 0;
2319 }
2320
2321 static int test_file_2 (void)
2322 {
2323   /* InitBasicFS for file (2): create ext2 on /dev/sda1 */
2324   {
2325     int r;
2326     suppress_error = 0;
2327     r = guestfs_umount_all (g);
2328     if (r == -1)
2329       return -1;
2330   }
2331   {
2332     int r;
2333     suppress_error = 0;
2334     r = guestfs_lvm_remove_all (g);
2335     if (r == -1)
2336       return -1;
2337   }
2338   {
2339     char *lines[] = {
2340       ",",
2341       NULL
2342     };
2343     int r;
2344     suppress_error = 0;
2345     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2346     if (r == -1)
2347       return -1;
2348   }
2349   {
2350     int r;
2351     suppress_error = 0;
2352     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2353     if (r == -1)
2354       return -1;
2355   }
2356   {
2357     int r;
2358     suppress_error = 0;
2359     r = guestfs_mount (g, "/dev/sda1", "/");
2360     if (r == -1)
2361       return -1;
2362   }
2363   /* TestLastFail for file (2) */
2364   {
2365     char *r;
2366     suppress_error = 1;
2367     r = guestfs_file (g, "/nofile");
2368     if (r != NULL)
2369       return -1;
2370     free (r);
2371   }
2372   return 0;
2373 }
2374
2375 static int test_umount_all_0 (void)
2376 {
2377   /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */
2378   {
2379     int r;
2380     suppress_error = 0;
2381     r = guestfs_umount_all (g);
2382     if (r == -1)
2383       return -1;
2384   }
2385   {
2386     int r;
2387     suppress_error = 0;
2388     r = guestfs_lvm_remove_all (g);
2389     if (r == -1)
2390       return -1;
2391   }
2392   {
2393     char *lines[] = {
2394       ",",
2395       NULL
2396     };
2397     int r;
2398     suppress_error = 0;
2399     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2400     if (r == -1)
2401       return -1;
2402   }
2403   {
2404     int r;
2405     suppress_error = 0;
2406     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2407     if (r == -1)
2408       return -1;
2409   }
2410   {
2411     int r;
2412     suppress_error = 0;
2413     r = guestfs_mount (g, "/dev/sda1", "/");
2414     if (r == -1)
2415       return -1;
2416   }
2417   /* TestOutputList for umount_all (0) */
2418   {
2419     int r;
2420     suppress_error = 0;
2421     r = guestfs_umount_all (g);
2422     if (r == -1)
2423       return -1;
2424   }
2425   {
2426     char **r;
2427     int i;
2428     suppress_error = 0;
2429     r = guestfs_mounts (g);
2430     if (r == NULL)
2431       return -1;
2432     if (r[0] != NULL) {
2433       fprintf (stderr, "test_umount_all_0: extra elements returned from command\n");
2434       print_strings (r);
2435       return -1;
2436     }
2437     for (i = 0; r[i] != NULL; ++i)
2438       free (r[i]);
2439     free (r);
2440   }
2441   return 0;
2442 }
2443
2444 static int test_mounts_0 (void)
2445 {
2446   /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */
2447   {
2448     int r;
2449     suppress_error = 0;
2450     r = guestfs_umount_all (g);
2451     if (r == -1)
2452       return -1;
2453   }
2454   {
2455     int r;
2456     suppress_error = 0;
2457     r = guestfs_lvm_remove_all (g);
2458     if (r == -1)
2459       return -1;
2460   }
2461   {
2462     char *lines[] = {
2463       ",",
2464       NULL
2465     };
2466     int r;
2467     suppress_error = 0;
2468     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2469     if (r == -1)
2470       return -1;
2471   }
2472   {
2473     int r;
2474     suppress_error = 0;
2475     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2476     if (r == -1)
2477       return -1;
2478   }
2479   {
2480     int r;
2481     suppress_error = 0;
2482     r = guestfs_mount (g, "/dev/sda1", "/");
2483     if (r == -1)
2484       return -1;
2485   }
2486   /* TestOutputList for mounts (0) */
2487   {
2488     char **r;
2489     int i;
2490     suppress_error = 0;
2491     r = guestfs_mounts (g);
2492     if (r == NULL)
2493       return -1;
2494     if (!r[0]) {
2495       fprintf (stderr, "test_mounts_0: short list returned from command\n");
2496       print_strings (r);
2497       return -1;
2498     }
2499     if (strcmp (r[0], "/dev/sda1") != 0) {
2500       fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
2501       return -1;
2502     }
2503     if (r[1] != NULL) {
2504       fprintf (stderr, "test_mounts_0: extra elements returned from command\n");
2505       print_strings (r);
2506       return -1;
2507     }
2508     for (i = 0; r[i] != NULL; ++i)
2509       free (r[i]);
2510     free (r);
2511   }
2512   return 0;
2513 }
2514
2515 static int test_umount_0 (void)
2516 {
2517   /* InitEmpty for umount (0) */
2518   {
2519     int r;
2520     suppress_error = 0;
2521     r = guestfs_umount_all (g);
2522     if (r == -1)
2523       return -1;
2524   }
2525   {
2526     int r;
2527     suppress_error = 0;
2528     r = guestfs_lvm_remove_all (g);
2529     if (r == -1)
2530       return -1;
2531   }
2532   /* TestOutputList for umount (0) */
2533   {
2534     char *lines[] = {
2535       ",",
2536       NULL
2537     };
2538     int r;
2539     suppress_error = 0;
2540     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2541     if (r == -1)
2542       return -1;
2543   }
2544   {
2545     int r;
2546     suppress_error = 0;
2547     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2548     if (r == -1)
2549       return -1;
2550   }
2551   {
2552     int r;
2553     suppress_error = 0;
2554     r = guestfs_mount (g, "/dev/sda1", "/");
2555     if (r == -1)
2556       return -1;
2557   }
2558   {
2559     char **r;
2560     int i;
2561     suppress_error = 0;
2562     r = guestfs_mounts (g);
2563     if (r == NULL)
2564       return -1;
2565     if (!r[0]) {
2566       fprintf (stderr, "test_umount_0: short list returned from command\n");
2567       print_strings (r);
2568       return -1;
2569     }
2570     if (strcmp (r[0], "/dev/sda1") != 0) {
2571       fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
2572       return -1;
2573     }
2574     if (r[1] != NULL) {
2575       fprintf (stderr, "test_umount_0: extra elements returned from command\n");
2576       print_strings (r);
2577       return -1;
2578     }
2579     for (i = 0; r[i] != NULL; ++i)
2580       free (r[i]);
2581     free (r);
2582   }
2583   return 0;
2584 }
2585
2586 static int test_umount_1 (void)
2587 {
2588   /* InitEmpty for umount (1) */
2589   {
2590     int r;
2591     suppress_error = 0;
2592     r = guestfs_umount_all (g);
2593     if (r == -1)
2594       return -1;
2595   }
2596   {
2597     int r;
2598     suppress_error = 0;
2599     r = guestfs_lvm_remove_all (g);
2600     if (r == -1)
2601       return -1;
2602   }
2603   /* TestOutputList for umount (1) */
2604   {
2605     char *lines[] = {
2606       ",",
2607       NULL
2608     };
2609     int r;
2610     suppress_error = 0;
2611     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2612     if (r == -1)
2613       return -1;
2614   }
2615   {
2616     int r;
2617     suppress_error = 0;
2618     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2619     if (r == -1)
2620       return -1;
2621   }
2622   {
2623     int r;
2624     suppress_error = 0;
2625     r = guestfs_mount (g, "/dev/sda1", "/");
2626     if (r == -1)
2627       return -1;
2628   }
2629   {
2630     int r;
2631     suppress_error = 0;
2632     r = guestfs_umount (g, "/");
2633     if (r == -1)
2634       return -1;
2635   }
2636   {
2637     char **r;
2638     int i;
2639     suppress_error = 0;
2640     r = guestfs_mounts (g);
2641     if (r == NULL)
2642       return -1;
2643     if (r[0] != NULL) {
2644       fprintf (stderr, "test_umount_1: extra elements returned from command\n");
2645       print_strings (r);
2646       return -1;
2647     }
2648     for (i = 0; r[i] != NULL; ++i)
2649       free (r[i]);
2650     free (r);
2651   }
2652   return 0;
2653 }
2654
2655 static int test_write_file_0 (void)
2656 {
2657   /* InitBasicFS for write_file (0): create ext2 on /dev/sda1 */
2658   {
2659     int r;
2660     suppress_error = 0;
2661     r = guestfs_umount_all (g);
2662     if (r == -1)
2663       return -1;
2664   }
2665   {
2666     int r;
2667     suppress_error = 0;
2668     r = guestfs_lvm_remove_all (g);
2669     if (r == -1)
2670       return -1;
2671   }
2672   {
2673     char *lines[] = {
2674       ",",
2675       NULL
2676     };
2677     int r;
2678     suppress_error = 0;
2679     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2680     if (r == -1)
2681       return -1;
2682   }
2683   {
2684     int r;
2685     suppress_error = 0;
2686     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2687     if (r == -1)
2688       return -1;
2689   }
2690   {
2691     int r;
2692     suppress_error = 0;
2693     r = guestfs_mount (g, "/dev/sda1", "/");
2694     if (r == -1)
2695       return -1;
2696   }
2697   /* TestOutput for write_file (0) */
2698   {
2699     int r;
2700     suppress_error = 0;
2701     r = guestfs_write_file (g, "/new", "new file contents", 0);
2702     if (r == -1)
2703       return -1;
2704   }
2705   {
2706     char *r;
2707     suppress_error = 0;
2708     r = guestfs_cat (g, "/new");
2709     if (r == NULL)
2710       return -1;
2711     if (strcmp (r, "new file contents") != 0) {
2712       fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r);
2713       return -1;
2714     }
2715     free (r);
2716   }
2717   return 0;
2718 }
2719
2720 static int test_write_file_1 (void)
2721 {
2722   /* InitBasicFS for write_file (1): create ext2 on /dev/sda1 */
2723   {
2724     int r;
2725     suppress_error = 0;
2726     r = guestfs_umount_all (g);
2727     if (r == -1)
2728       return -1;
2729   }
2730   {
2731     int r;
2732     suppress_error = 0;
2733     r = guestfs_lvm_remove_all (g);
2734     if (r == -1)
2735       return -1;
2736   }
2737   {
2738     char *lines[] = {
2739       ",",
2740       NULL
2741     };
2742     int r;
2743     suppress_error = 0;
2744     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2745     if (r == -1)
2746       return -1;
2747   }
2748   {
2749     int r;
2750     suppress_error = 0;
2751     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2752     if (r == -1)
2753       return -1;
2754   }
2755   {
2756     int r;
2757     suppress_error = 0;
2758     r = guestfs_mount (g, "/dev/sda1", "/");
2759     if (r == -1)
2760       return -1;
2761   }
2762   /* TestOutput for write_file (1) */
2763   {
2764     int r;
2765     suppress_error = 0;
2766     r = guestfs_write_file (g, "/new", "\nnew file contents\n", 0);
2767     if (r == -1)
2768       return -1;
2769   }
2770   {
2771     char *r;
2772     suppress_error = 0;
2773     r = guestfs_cat (g, "/new");
2774     if (r == NULL)
2775       return -1;
2776     if (strcmp (r, "\nnew file contents\n") != 0) {
2777       fprintf (stderr, "test_write_file_1: expected \"\nnew file contents\n\" but got \"%s\"\n", r);
2778       return -1;
2779     }
2780     free (r);
2781   }
2782   return 0;
2783 }
2784
2785 static int test_write_file_2 (void)
2786 {
2787   /* InitBasicFS for write_file (2): create ext2 on /dev/sda1 */
2788   {
2789     int r;
2790     suppress_error = 0;
2791     r = guestfs_umount_all (g);
2792     if (r == -1)
2793       return -1;
2794   }
2795   {
2796     int r;
2797     suppress_error = 0;
2798     r = guestfs_lvm_remove_all (g);
2799     if (r == -1)
2800       return -1;
2801   }
2802   {
2803     char *lines[] = {
2804       ",",
2805       NULL
2806     };
2807     int r;
2808     suppress_error = 0;
2809     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2810     if (r == -1)
2811       return -1;
2812   }
2813   {
2814     int r;
2815     suppress_error = 0;
2816     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2817     if (r == -1)
2818       return -1;
2819   }
2820   {
2821     int r;
2822     suppress_error = 0;
2823     r = guestfs_mount (g, "/dev/sda1", "/");
2824     if (r == -1)
2825       return -1;
2826   }
2827   /* TestOutput for write_file (2) */
2828   {
2829     int r;
2830     suppress_error = 0;
2831     r = guestfs_write_file (g, "/new", "\n\n", 0);
2832     if (r == -1)
2833       return -1;
2834   }
2835   {
2836     char *r;
2837     suppress_error = 0;
2838     r = guestfs_cat (g, "/new");
2839     if (r == NULL)
2840       return -1;
2841     if (strcmp (r, "\n\n") != 0) {
2842       fprintf (stderr, "test_write_file_2: expected \"\n\n\" but got \"%s\"\n", r);
2843       return -1;
2844     }
2845     free (r);
2846   }
2847   return 0;
2848 }
2849
2850 static int test_write_file_3 (void)
2851 {
2852   /* InitBasicFS for write_file (3): create ext2 on /dev/sda1 */
2853   {
2854     int r;
2855     suppress_error = 0;
2856     r = guestfs_umount_all (g);
2857     if (r == -1)
2858       return -1;
2859   }
2860   {
2861     int r;
2862     suppress_error = 0;
2863     r = guestfs_lvm_remove_all (g);
2864     if (r == -1)
2865       return -1;
2866   }
2867   {
2868     char *lines[] = {
2869       ",",
2870       NULL
2871     };
2872     int r;
2873     suppress_error = 0;
2874     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2875     if (r == -1)
2876       return -1;
2877   }
2878   {
2879     int r;
2880     suppress_error = 0;
2881     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2882     if (r == -1)
2883       return -1;
2884   }
2885   {
2886     int r;
2887     suppress_error = 0;
2888     r = guestfs_mount (g, "/dev/sda1", "/");
2889     if (r == -1)
2890       return -1;
2891   }
2892   /* TestOutput for write_file (3) */
2893   {
2894     int r;
2895     suppress_error = 0;
2896     r = guestfs_write_file (g, "/new", "", 0);
2897     if (r == -1)
2898       return -1;
2899   }
2900   {
2901     char *r;
2902     suppress_error = 0;
2903     r = guestfs_cat (g, "/new");
2904     if (r == NULL)
2905       return -1;
2906     if (strcmp (r, "") != 0) {
2907       fprintf (stderr, "test_write_file_3: expected \"\" but got \"%s\"\n", r);
2908       return -1;
2909     }
2910     free (r);
2911   }
2912   return 0;
2913 }
2914
2915 static int test_write_file_4 (void)
2916 {
2917   /* InitBasicFS for write_file (4): create ext2 on /dev/sda1 */
2918   {
2919     int r;
2920     suppress_error = 0;
2921     r = guestfs_umount_all (g);
2922     if (r == -1)
2923       return -1;
2924   }
2925   {
2926     int r;
2927     suppress_error = 0;
2928     r = guestfs_lvm_remove_all (g);
2929     if (r == -1)
2930       return -1;
2931   }
2932   {
2933     char *lines[] = {
2934       ",",
2935       NULL
2936     };
2937     int r;
2938     suppress_error = 0;
2939     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2940     if (r == -1)
2941       return -1;
2942   }
2943   {
2944     int r;
2945     suppress_error = 0;
2946     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2947     if (r == -1)
2948       return -1;
2949   }
2950   {
2951     int r;
2952     suppress_error = 0;
2953     r = guestfs_mount (g, "/dev/sda1", "/");
2954     if (r == -1)
2955       return -1;
2956   }
2957   /* TestOutput for write_file (4) */
2958   {
2959     int r;
2960     suppress_error = 0;
2961     r = guestfs_write_file (g, "/new", "\n\n\n", 0);
2962     if (r == -1)
2963       return -1;
2964   }
2965   {
2966     char *r;
2967     suppress_error = 0;
2968     r = guestfs_cat (g, "/new");
2969     if (r == NULL)
2970       return -1;
2971     if (strcmp (r, "\n\n\n") != 0) {
2972       fprintf (stderr, "test_write_file_4: expected \"\n\n\n\" but got \"%s\"\n", r);
2973       return -1;
2974     }
2975     free (r);
2976   }
2977   return 0;
2978 }
2979
2980 static int test_write_file_5 (void)
2981 {
2982   /* InitBasicFS for write_file (5): create ext2 on /dev/sda1 */
2983   {
2984     int r;
2985     suppress_error = 0;
2986     r = guestfs_umount_all (g);
2987     if (r == -1)
2988       return -1;
2989   }
2990   {
2991     int r;
2992     suppress_error = 0;
2993     r = guestfs_lvm_remove_all (g);
2994     if (r == -1)
2995       return -1;
2996   }
2997   {
2998     char *lines[] = {
2999       ",",
3000       NULL
3001     };
3002     int r;
3003     suppress_error = 0;
3004     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3005     if (r == -1)
3006       return -1;
3007   }
3008   {
3009     int r;
3010     suppress_error = 0;
3011     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3012     if (r == -1)
3013       return -1;
3014   }
3015   {
3016     int r;
3017     suppress_error = 0;
3018     r = guestfs_mount (g, "/dev/sda1", "/");
3019     if (r == -1)
3020       return -1;
3021   }
3022   /* TestOutput for write_file (5) */
3023   {
3024     int r;
3025     suppress_error = 0;
3026     r = guestfs_write_file (g, "/new", "\n", 0);
3027     if (r == -1)
3028       return -1;
3029   }
3030   {
3031     char *r;
3032     suppress_error = 0;
3033     r = guestfs_cat (g, "/new");
3034     if (r == NULL)
3035       return -1;
3036     if (strcmp (r, "\n") != 0) {
3037       fprintf (stderr, "test_write_file_5: expected \"\n\" but got \"%s\"\n", r);
3038       return -1;
3039     }
3040     free (r);
3041   }
3042   return 0;
3043 }
3044
3045 static int test_mkfs_0 (void)
3046 {
3047   /* InitEmpty for mkfs (0) */
3048   {
3049     int r;
3050     suppress_error = 0;
3051     r = guestfs_umount_all (g);
3052     if (r == -1)
3053       return -1;
3054   }
3055   {
3056     int r;
3057     suppress_error = 0;
3058     r = guestfs_lvm_remove_all (g);
3059     if (r == -1)
3060       return -1;
3061   }
3062   /* TestOutput for mkfs (0) */
3063   {
3064     char *lines[] = {
3065       ",",
3066       NULL
3067     };
3068     int r;
3069     suppress_error = 0;
3070     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3071     if (r == -1)
3072       return -1;
3073   }
3074   {
3075     int r;
3076     suppress_error = 0;
3077     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3078     if (r == -1)
3079       return -1;
3080   }
3081   {
3082     int r;
3083     suppress_error = 0;
3084     r = guestfs_mount (g, "/dev/sda1", "/");
3085     if (r == -1)
3086       return -1;
3087   }
3088   {
3089     int r;
3090     suppress_error = 0;
3091     r = guestfs_write_file (g, "/new", "new file contents", 0);
3092     if (r == -1)
3093       return -1;
3094   }
3095   {
3096     char *r;
3097     suppress_error = 0;
3098     r = guestfs_cat (g, "/new");
3099     if (r == NULL)
3100       return -1;
3101     if (strcmp (r, "new file contents") != 0) {
3102       fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r);
3103       return -1;
3104     }
3105     free (r);
3106   }
3107   return 0;
3108 }
3109
3110 static int test_lvcreate_0 (void)
3111 {
3112   /* InitEmpty for lvcreate (0) */
3113   {
3114     int r;
3115     suppress_error = 0;
3116     r = guestfs_umount_all (g);
3117     if (r == -1)
3118       return -1;
3119   }
3120   {
3121     int r;
3122     suppress_error = 0;
3123     r = guestfs_lvm_remove_all (g);
3124     if (r == -1)
3125       return -1;
3126   }
3127   /* TestOutputList for lvcreate (0) */
3128   {
3129     char *lines[] = {
3130       ",10",
3131       ",20",
3132       ",",
3133       NULL
3134     };
3135     int r;
3136     suppress_error = 0;
3137     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3138     if (r == -1)
3139       return -1;
3140   }
3141   {
3142     int r;
3143     suppress_error = 0;
3144     r = guestfs_pvcreate (g, "/dev/sda1");
3145     if (r == -1)
3146       return -1;
3147   }
3148   {
3149     int r;
3150     suppress_error = 0;
3151     r = guestfs_pvcreate (g, "/dev/sda2");
3152     if (r == -1)
3153       return -1;
3154   }
3155   {
3156     int r;
3157     suppress_error = 0;
3158     r = guestfs_pvcreate (g, "/dev/sda3");
3159     if (r == -1)
3160       return -1;
3161   }
3162   {
3163     char *physvols[] = {
3164       "/dev/sda1",
3165       "/dev/sda2",
3166       NULL
3167     };
3168     int r;
3169     suppress_error = 0;
3170     r = guestfs_vgcreate (g, "VG1", physvols);
3171     if (r == -1)
3172       return -1;
3173   }
3174   {
3175     char *physvols[] = {
3176       "/dev/sda3",
3177       NULL
3178     };
3179     int r;
3180     suppress_error = 0;
3181     r = guestfs_vgcreate (g, "VG2", physvols);
3182     if (r == -1)
3183       return -1;
3184   }
3185   {
3186     int r;
3187     suppress_error = 0;
3188     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
3189     if (r == -1)
3190       return -1;
3191   }
3192   {
3193     int r;
3194     suppress_error = 0;
3195     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
3196     if (r == -1)
3197       return -1;
3198   }
3199   {
3200     int r;
3201     suppress_error = 0;
3202     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
3203     if (r == -1)
3204       return -1;
3205   }
3206   {
3207     int r;
3208     suppress_error = 0;
3209     r = guestfs_lvcreate (g, "LV4", "VG2", 50);
3210     if (r == -1)
3211       return -1;
3212   }
3213   {
3214     int r;
3215     suppress_error = 0;
3216     r = guestfs_lvcreate (g, "LV5", "VG2", 50);
3217     if (r == -1)
3218       return -1;
3219   }
3220   {
3221     char **r;
3222     int i;
3223     suppress_error = 0;
3224     r = guestfs_lvs (g);
3225     if (r == NULL)
3226       return -1;
3227     if (!r[0]) {
3228       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3229       print_strings (r);
3230       return -1;
3231     }
3232     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
3233       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
3234       return -1;
3235     }
3236     if (!r[1]) {
3237       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3238       print_strings (r);
3239       return -1;
3240     }
3241     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
3242       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
3243       return -1;
3244     }
3245     if (!r[2]) {
3246       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3247       print_strings (r);
3248       return -1;
3249     }
3250     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
3251       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
3252       return -1;
3253     }
3254     if (!r[3]) {
3255       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3256       print_strings (r);
3257       return -1;
3258     }
3259     if (strcmp (r[3], "/dev/VG2/LV4") != 0) {
3260       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]);
3261       return -1;
3262     }
3263     if (!r[4]) {
3264       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
3265       print_strings (r);
3266       return -1;
3267     }
3268     if (strcmp (r[4], "/dev/VG2/LV5") != 0) {
3269       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]);
3270       return -1;
3271     }
3272     if (r[5] != NULL) {
3273       fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n");
3274       print_strings (r);
3275       return -1;
3276     }
3277     for (i = 0; r[i] != NULL; ++i)
3278       free (r[i]);
3279     free (r);
3280   }
3281   return 0;
3282 }
3283
3284 static int test_vgcreate_0 (void)
3285 {
3286   /* InitEmpty for vgcreate (0) */
3287   {
3288     int r;
3289     suppress_error = 0;
3290     r = guestfs_umount_all (g);
3291     if (r == -1)
3292       return -1;
3293   }
3294   {
3295     int r;
3296     suppress_error = 0;
3297     r = guestfs_lvm_remove_all (g);
3298     if (r == -1)
3299       return -1;
3300   }
3301   /* TestOutputList for vgcreate (0) */
3302   {
3303     char *lines[] = {
3304       ",10",
3305       ",20",
3306       ",",
3307       NULL
3308     };
3309     int r;
3310     suppress_error = 0;
3311     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3312     if (r == -1)
3313       return -1;
3314   }
3315   {
3316     int r;
3317     suppress_error = 0;
3318     r = guestfs_pvcreate (g, "/dev/sda1");
3319     if (r == -1)
3320       return -1;
3321   }
3322   {
3323     int r;
3324     suppress_error = 0;
3325     r = guestfs_pvcreate (g, "/dev/sda2");
3326     if (r == -1)
3327       return -1;
3328   }
3329   {
3330     int r;
3331     suppress_error = 0;
3332     r = guestfs_pvcreate (g, "/dev/sda3");
3333     if (r == -1)
3334       return -1;
3335   }
3336   {
3337     char *physvols[] = {
3338       "/dev/sda1",
3339       "/dev/sda2",
3340       NULL
3341     };
3342     int r;
3343     suppress_error = 0;
3344     r = guestfs_vgcreate (g, "VG1", physvols);
3345     if (r == -1)
3346       return -1;
3347   }
3348   {
3349     char *physvols[] = {
3350       "/dev/sda3",
3351       NULL
3352     };
3353     int r;
3354     suppress_error = 0;
3355     r = guestfs_vgcreate (g, "VG2", physvols);
3356     if (r == -1)
3357       return -1;
3358   }
3359   {
3360     char **r;
3361     int i;
3362     suppress_error = 0;
3363     r = guestfs_vgs (g);
3364     if (r == NULL)
3365       return -1;
3366     if (!r[0]) {
3367       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
3368       print_strings (r);
3369       return -1;
3370     }
3371     if (strcmp (r[0], "VG1") != 0) {
3372       fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]);
3373       return -1;
3374     }
3375     if (!r[1]) {
3376       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
3377       print_strings (r);
3378       return -1;
3379     }
3380     if (strcmp (r[1], "VG2") != 0) {
3381       fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]);
3382       return -1;
3383     }
3384     if (r[2] != NULL) {
3385       fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n");
3386       print_strings (r);
3387       return -1;
3388     }
3389     for (i = 0; r[i] != NULL; ++i)
3390       free (r[i]);
3391     free (r);
3392   }
3393   return 0;
3394 }
3395
3396 static int test_pvcreate_0 (void)
3397 {
3398   /* InitEmpty for pvcreate (0) */
3399   {
3400     int r;
3401     suppress_error = 0;
3402     r = guestfs_umount_all (g);
3403     if (r == -1)
3404       return -1;
3405   }
3406   {
3407     int r;
3408     suppress_error = 0;
3409     r = guestfs_lvm_remove_all (g);
3410     if (r == -1)
3411       return -1;
3412   }
3413   /* TestOutputList for pvcreate (0) */
3414   {
3415     char *lines[] = {
3416       ",10",
3417       ",20",
3418       ",",
3419       NULL
3420     };
3421     int r;
3422     suppress_error = 0;
3423     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3424     if (r == -1)
3425       return -1;
3426   }
3427   {
3428     int r;
3429     suppress_error = 0;
3430     r = guestfs_pvcreate (g, "/dev/sda1");
3431     if (r == -1)
3432       return -1;
3433   }
3434   {
3435     int r;
3436     suppress_error = 0;
3437     r = guestfs_pvcreate (g, "/dev/sda2");
3438     if (r == -1)
3439       return -1;
3440   }
3441   {
3442     int r;
3443     suppress_error = 0;
3444     r = guestfs_pvcreate (g, "/dev/sda3");
3445     if (r == -1)
3446       return -1;
3447   }
3448   {
3449     char **r;
3450     int i;
3451     suppress_error = 0;
3452     r = guestfs_pvs (g);
3453     if (r == NULL)
3454       return -1;
3455     if (!r[0]) {
3456       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
3457       print_strings (r);
3458       return -1;
3459     }
3460     if (strcmp (r[0], "/dev/sda1") != 0) {
3461       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3462       return -1;
3463     }
3464     if (!r[1]) {
3465       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
3466       print_strings (r);
3467       return -1;
3468     }
3469     if (strcmp (r[1], "/dev/sda2") != 0) {
3470       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3471       return -1;
3472     }
3473     if (!r[2]) {
3474       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
3475       print_strings (r);
3476       return -1;
3477     }
3478     if (strcmp (r[2], "/dev/sda3") != 0) {
3479       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3480       return -1;
3481     }
3482     if (r[3] != NULL) {
3483       fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n");
3484       print_strings (r);
3485       return -1;
3486     }
3487     for (i = 0; r[i] != NULL; ++i)
3488       free (r[i]);
3489     free (r);
3490   }
3491   return 0;
3492 }
3493
3494 static int test_is_dir_0 (void)
3495 {
3496   /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */
3497   {
3498     int r;
3499     suppress_error = 0;
3500     r = guestfs_umount_all (g);
3501     if (r == -1)
3502       return -1;
3503   }
3504   {
3505     int r;
3506     suppress_error = 0;
3507     r = guestfs_lvm_remove_all (g);
3508     if (r == -1)
3509       return -1;
3510   }
3511   {
3512     char *lines[] = {
3513       ",",
3514       NULL
3515     };
3516     int r;
3517     suppress_error = 0;
3518     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3519     if (r == -1)
3520       return -1;
3521   }
3522   {
3523     int r;
3524     suppress_error = 0;
3525     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3526     if (r == -1)
3527       return -1;
3528   }
3529   {
3530     int r;
3531     suppress_error = 0;
3532     r = guestfs_mount (g, "/dev/sda1", "/");
3533     if (r == -1)
3534       return -1;
3535   }
3536   /* TestOutputFalse for is_dir (0) */
3537   {
3538     int r;
3539     suppress_error = 0;
3540     r = guestfs_touch (g, "/new");
3541     if (r == -1)
3542       return -1;
3543   }
3544   {
3545     int r;
3546     suppress_error = 0;
3547     r = guestfs_is_dir (g, "/new");
3548     if (r == -1)
3549       return -1;
3550     if (r) {
3551       fprintf (stderr, "test_is_dir_0: expected false, got true\n");
3552       return -1;
3553     }
3554   }
3555   return 0;
3556 }
3557
3558 static int test_is_dir_1 (void)
3559 {
3560   /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */
3561   {
3562     int r;
3563     suppress_error = 0;
3564     r = guestfs_umount_all (g);
3565     if (r == -1)
3566       return -1;
3567   }
3568   {
3569     int r;
3570     suppress_error = 0;
3571     r = guestfs_lvm_remove_all (g);
3572     if (r == -1)
3573       return -1;
3574   }
3575   {
3576     char *lines[] = {
3577       ",",
3578       NULL
3579     };
3580     int r;
3581     suppress_error = 0;
3582     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3583     if (r == -1)
3584       return -1;
3585   }
3586   {
3587     int r;
3588     suppress_error = 0;
3589     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3590     if (r == -1)
3591       return -1;
3592   }
3593   {
3594     int r;
3595     suppress_error = 0;
3596     r = guestfs_mount (g, "/dev/sda1", "/");
3597     if (r == -1)
3598       return -1;
3599   }
3600   /* TestOutputTrue for is_dir (1) */
3601   {
3602     int r;
3603     suppress_error = 0;
3604     r = guestfs_mkdir (g, "/new");
3605     if (r == -1)
3606       return -1;
3607   }
3608   {
3609     int r;
3610     suppress_error = 0;
3611     r = guestfs_is_dir (g, "/new");
3612     if (r == -1)
3613       return -1;
3614     if (!r) {
3615       fprintf (stderr, "test_is_dir_1: expected true, got false\n");
3616       return -1;
3617     }
3618   }
3619   return 0;
3620 }
3621
3622 static int test_is_file_0 (void)
3623 {
3624   /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */
3625   {
3626     int r;
3627     suppress_error = 0;
3628     r = guestfs_umount_all (g);
3629     if (r == -1)
3630       return -1;
3631   }
3632   {
3633     int r;
3634     suppress_error = 0;
3635     r = guestfs_lvm_remove_all (g);
3636     if (r == -1)
3637       return -1;
3638   }
3639   {
3640     char *lines[] = {
3641       ",",
3642       NULL
3643     };
3644     int r;
3645     suppress_error = 0;
3646     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3647     if (r == -1)
3648       return -1;
3649   }
3650   {
3651     int r;
3652     suppress_error = 0;
3653     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3654     if (r == -1)
3655       return -1;
3656   }
3657   {
3658     int r;
3659     suppress_error = 0;
3660     r = guestfs_mount (g, "/dev/sda1", "/");
3661     if (r == -1)
3662       return -1;
3663   }
3664   /* TestOutputTrue for is_file (0) */
3665   {
3666     int r;
3667     suppress_error = 0;
3668     r = guestfs_touch (g, "/new");
3669     if (r == -1)
3670       return -1;
3671   }
3672   {
3673     int r;
3674     suppress_error = 0;
3675     r = guestfs_is_file (g, "/new");
3676     if (r == -1)
3677       return -1;
3678     if (!r) {
3679       fprintf (stderr, "test_is_file_0: expected true, got false\n");
3680       return -1;
3681     }
3682   }
3683   return 0;
3684 }
3685
3686 static int test_is_file_1 (void)
3687 {
3688   /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */
3689   {
3690     int r;
3691     suppress_error = 0;
3692     r = guestfs_umount_all (g);
3693     if (r == -1)
3694       return -1;
3695   }
3696   {
3697     int r;
3698     suppress_error = 0;
3699     r = guestfs_lvm_remove_all (g);
3700     if (r == -1)
3701       return -1;
3702   }
3703   {
3704     char *lines[] = {
3705       ",",
3706       NULL
3707     };
3708     int r;
3709     suppress_error = 0;
3710     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3711     if (r == -1)
3712       return -1;
3713   }
3714   {
3715     int r;
3716     suppress_error = 0;
3717     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3718     if (r == -1)
3719       return -1;
3720   }
3721   {
3722     int r;
3723     suppress_error = 0;
3724     r = guestfs_mount (g, "/dev/sda1", "/");
3725     if (r == -1)
3726       return -1;
3727   }
3728   /* TestOutputFalse for is_file (1) */
3729   {
3730     int r;
3731     suppress_error = 0;
3732     r = guestfs_mkdir (g, "/new");
3733     if (r == -1)
3734       return -1;
3735   }
3736   {
3737     int r;
3738     suppress_error = 0;
3739     r = guestfs_is_file (g, "/new");
3740     if (r == -1)
3741       return -1;
3742     if (r) {
3743       fprintf (stderr, "test_is_file_1: expected false, got true\n");
3744       return -1;
3745     }
3746   }
3747   return 0;
3748 }
3749
3750 static int test_exists_0 (void)
3751 {
3752   /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */
3753   {
3754     int r;
3755     suppress_error = 0;
3756     r = guestfs_umount_all (g);
3757     if (r == -1)
3758       return -1;
3759   }
3760   {
3761     int r;
3762     suppress_error = 0;
3763     r = guestfs_lvm_remove_all (g);
3764     if (r == -1)
3765       return -1;
3766   }
3767   {
3768     char *lines[] = {
3769       ",",
3770       NULL
3771     };
3772     int r;
3773     suppress_error = 0;
3774     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3775     if (r == -1)
3776       return -1;
3777   }
3778   {
3779     int r;
3780     suppress_error = 0;
3781     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3782     if (r == -1)
3783       return -1;
3784   }
3785   {
3786     int r;
3787     suppress_error = 0;
3788     r = guestfs_mount (g, "/dev/sda1", "/");
3789     if (r == -1)
3790       return -1;
3791   }
3792   /* TestOutputTrue for exists (0) */
3793   {
3794     int r;
3795     suppress_error = 0;
3796     r = guestfs_touch (g, "/new");
3797     if (r == -1)
3798       return -1;
3799   }
3800   {
3801     int r;
3802     suppress_error = 0;
3803     r = guestfs_exists (g, "/new");
3804     if (r == -1)
3805       return -1;
3806     if (!r) {
3807       fprintf (stderr, "test_exists_0: expected true, got false\n");
3808       return -1;
3809     }
3810   }
3811   return 0;
3812 }
3813
3814 static int test_exists_1 (void)
3815 {
3816   /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */
3817   {
3818     int r;
3819     suppress_error = 0;
3820     r = guestfs_umount_all (g);
3821     if (r == -1)
3822       return -1;
3823   }
3824   {
3825     int r;
3826     suppress_error = 0;
3827     r = guestfs_lvm_remove_all (g);
3828     if (r == -1)
3829       return -1;
3830   }
3831   {
3832     char *lines[] = {
3833       ",",
3834       NULL
3835     };
3836     int r;
3837     suppress_error = 0;
3838     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3839     if (r == -1)
3840       return -1;
3841   }
3842   {
3843     int r;
3844     suppress_error = 0;
3845     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3846     if (r == -1)
3847       return -1;
3848   }
3849   {
3850     int r;
3851     suppress_error = 0;
3852     r = guestfs_mount (g, "/dev/sda1", "/");
3853     if (r == -1)
3854       return -1;
3855   }
3856   /* TestOutputTrue for exists (1) */
3857   {
3858     int r;
3859     suppress_error = 0;
3860     r = guestfs_mkdir (g, "/new");
3861     if (r == -1)
3862       return -1;
3863   }
3864   {
3865     int r;
3866     suppress_error = 0;
3867     r = guestfs_exists (g, "/new");
3868     if (r == -1)
3869       return -1;
3870     if (!r) {
3871       fprintf (stderr, "test_exists_1: expected true, got false\n");
3872       return -1;
3873     }
3874   }
3875   return 0;
3876 }
3877
3878 static int test_mkdir_p_0 (void)
3879 {
3880   /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */
3881   {
3882     int r;
3883     suppress_error = 0;
3884     r = guestfs_umount_all (g);
3885     if (r == -1)
3886       return -1;
3887   }
3888   {
3889     int r;
3890     suppress_error = 0;
3891     r = guestfs_lvm_remove_all (g);
3892     if (r == -1)
3893       return -1;
3894   }
3895   {
3896     char *lines[] = {
3897       ",",
3898       NULL
3899     };
3900     int r;
3901     suppress_error = 0;
3902     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3903     if (r == -1)
3904       return -1;
3905   }
3906   {
3907     int r;
3908     suppress_error = 0;
3909     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3910     if (r == -1)
3911       return -1;
3912   }
3913   {
3914     int r;
3915     suppress_error = 0;
3916     r = guestfs_mount (g, "/dev/sda1", "/");
3917     if (r == -1)
3918       return -1;
3919   }
3920   /* TestOutputTrue for mkdir_p (0) */
3921   {
3922     int r;
3923     suppress_error = 0;
3924     r = guestfs_mkdir_p (g, "/new/foo/bar");
3925     if (r == -1)
3926       return -1;
3927   }
3928   {
3929     int r;
3930     suppress_error = 0;
3931     r = guestfs_is_dir (g, "/new/foo/bar");
3932     if (r == -1)
3933       return -1;
3934     if (!r) {
3935       fprintf (stderr, "test_mkdir_p_0: expected true, got false\n");
3936       return -1;
3937     }
3938   }
3939   return 0;
3940 }
3941
3942 static int test_mkdir_p_1 (void)
3943 {
3944   /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */
3945   {
3946     int r;
3947     suppress_error = 0;
3948     r = guestfs_umount_all (g);
3949     if (r == -1)
3950       return -1;
3951   }
3952   {
3953     int r;
3954     suppress_error = 0;
3955     r = guestfs_lvm_remove_all (g);
3956     if (r == -1)
3957       return -1;
3958   }
3959   {
3960     char *lines[] = {
3961       ",",
3962       NULL
3963     };
3964     int r;
3965     suppress_error = 0;
3966     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3967     if (r == -1)
3968       return -1;
3969   }
3970   {
3971     int r;
3972     suppress_error = 0;
3973     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3974     if (r == -1)
3975       return -1;
3976   }
3977   {
3978     int r;
3979     suppress_error = 0;
3980     r = guestfs_mount (g, "/dev/sda1", "/");
3981     if (r == -1)
3982       return -1;
3983   }
3984   /* TestOutputTrue for mkdir_p (1) */
3985   {
3986     int r;
3987     suppress_error = 0;
3988     r = guestfs_mkdir_p (g, "/new/foo/bar");
3989     if (r == -1)
3990       return -1;
3991   }
3992   {
3993     int r;
3994     suppress_error = 0;
3995     r = guestfs_is_dir (g, "/new/foo");
3996     if (r == -1)
3997       return -1;
3998     if (!r) {
3999       fprintf (stderr, "test_mkdir_p_1: expected true, got false\n");
4000       return -1;
4001     }
4002   }
4003   return 0;
4004 }
4005
4006 static int test_mkdir_p_2 (void)
4007 {
4008   /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */
4009   {
4010     int r;
4011     suppress_error = 0;
4012     r = guestfs_umount_all (g);
4013     if (r == -1)
4014       return -1;
4015   }
4016   {
4017     int r;
4018     suppress_error = 0;
4019     r = guestfs_lvm_remove_all (g);
4020     if (r == -1)
4021       return -1;
4022   }
4023   {
4024     char *lines[] = {
4025       ",",
4026       NULL
4027     };
4028     int r;
4029     suppress_error = 0;
4030     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4031     if (r == -1)
4032       return -1;
4033   }
4034   {
4035     int r;
4036     suppress_error = 0;
4037     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4038     if (r == -1)
4039       return -1;
4040   }
4041   {
4042     int r;
4043     suppress_error = 0;
4044     r = guestfs_mount (g, "/dev/sda1", "/");
4045     if (r == -1)
4046       return -1;
4047   }
4048   /* TestOutputTrue for mkdir_p (2) */
4049   {
4050     int r;
4051     suppress_error = 0;
4052     r = guestfs_mkdir_p (g, "/new/foo/bar");
4053     if (r == -1)
4054       return -1;
4055   }
4056   {
4057     int r;
4058     suppress_error = 0;
4059     r = guestfs_is_dir (g, "/new");
4060     if (r == -1)
4061       return -1;
4062     if (!r) {
4063       fprintf (stderr, "test_mkdir_p_2: expected true, got false\n");
4064       return -1;
4065     }
4066   }
4067   return 0;
4068 }
4069
4070 static int test_mkdir_0 (void)
4071 {
4072   /* InitBasicFS for mkdir (0): create ext2 on /dev/sda1 */
4073   {
4074     int r;
4075     suppress_error = 0;
4076     r = guestfs_umount_all (g);
4077     if (r == -1)
4078       return -1;
4079   }
4080   {
4081     int r;
4082     suppress_error = 0;
4083     r = guestfs_lvm_remove_all (g);
4084     if (r == -1)
4085       return -1;
4086   }
4087   {
4088     char *lines[] = {
4089       ",",
4090       NULL
4091     };
4092     int r;
4093     suppress_error = 0;
4094     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4095     if (r == -1)
4096       return -1;
4097   }
4098   {
4099     int r;
4100     suppress_error = 0;
4101     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4102     if (r == -1)
4103       return -1;
4104   }
4105   {
4106     int r;
4107     suppress_error = 0;
4108     r = guestfs_mount (g, "/dev/sda1", "/");
4109     if (r == -1)
4110       return -1;
4111   }
4112   /* TestOutputTrue for mkdir (0) */
4113   {
4114     int r;
4115     suppress_error = 0;
4116     r = guestfs_mkdir (g, "/new");
4117     if (r == -1)
4118       return -1;
4119   }
4120   {
4121     int r;
4122     suppress_error = 0;
4123     r = guestfs_is_dir (g, "/new");
4124     if (r == -1)
4125       return -1;
4126     if (!r) {
4127       fprintf (stderr, "test_mkdir_0: expected true, got false\n");
4128       return -1;
4129     }
4130   }
4131   return 0;
4132 }
4133
4134 static int test_mkdir_1 (void)
4135 {
4136   /* InitBasicFS for mkdir (1): create ext2 on /dev/sda1 */
4137   {
4138     int r;
4139     suppress_error = 0;
4140     r = guestfs_umount_all (g);
4141     if (r == -1)
4142       return -1;
4143   }
4144   {
4145     int r;
4146     suppress_error = 0;
4147     r = guestfs_lvm_remove_all (g);
4148     if (r == -1)
4149       return -1;
4150   }
4151   {
4152     char *lines[] = {
4153       ",",
4154       NULL
4155     };
4156     int r;
4157     suppress_error = 0;
4158     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4159     if (r == -1)
4160       return -1;
4161   }
4162   {
4163     int r;
4164     suppress_error = 0;
4165     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4166     if (r == -1)
4167       return -1;
4168   }
4169   {
4170     int r;
4171     suppress_error = 0;
4172     r = guestfs_mount (g, "/dev/sda1", "/");
4173     if (r == -1)
4174       return -1;
4175   }
4176   /* TestLastFail for mkdir (1) */
4177   {
4178     int r;
4179     suppress_error = 1;
4180     r = guestfs_mkdir (g, "/new/foo/bar");
4181     if (r != -1)
4182       return -1;
4183   }
4184   return 0;
4185 }
4186
4187 static int test_rm_rf_0 (void)
4188 {
4189   /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */
4190   {
4191     int r;
4192     suppress_error = 0;
4193     r = guestfs_umount_all (g);
4194     if (r == -1)
4195       return -1;
4196   }
4197   {
4198     int r;
4199     suppress_error = 0;
4200     r = guestfs_lvm_remove_all (g);
4201     if (r == -1)
4202       return -1;
4203   }
4204   {
4205     char *lines[] = {
4206       ",",
4207       NULL
4208     };
4209     int r;
4210     suppress_error = 0;
4211     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4212     if (r == -1)
4213       return -1;
4214   }
4215   {
4216     int r;
4217     suppress_error = 0;
4218     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4219     if (r == -1)
4220       return -1;
4221   }
4222   {
4223     int r;
4224     suppress_error = 0;
4225     r = guestfs_mount (g, "/dev/sda1", "/");
4226     if (r == -1)
4227       return -1;
4228   }
4229   /* TestOutputFalse for rm_rf (0) */
4230   {
4231     int r;
4232     suppress_error = 0;
4233     r = guestfs_mkdir (g, "/new");
4234     if (r == -1)
4235       return -1;
4236   }
4237   {
4238     int r;
4239     suppress_error = 0;
4240     r = guestfs_mkdir (g, "/new/foo");
4241     if (r == -1)
4242       return -1;
4243   }
4244   {
4245     int r;
4246     suppress_error = 0;
4247     r = guestfs_touch (g, "/new/foo/bar");
4248     if (r == -1)
4249       return -1;
4250   }
4251   {
4252     int r;
4253     suppress_error = 0;
4254     r = guestfs_rm_rf (g, "/new");
4255     if (r == -1)
4256       return -1;
4257   }
4258   {
4259     int r;
4260     suppress_error = 0;
4261     r = guestfs_exists (g, "/new");
4262     if (r == -1)
4263       return -1;
4264     if (r) {
4265       fprintf (stderr, "test_rm_rf_0: expected false, got true\n");
4266       return -1;
4267     }
4268   }
4269   return 0;
4270 }
4271
4272 static int test_rmdir_0 (void)
4273 {
4274   /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */
4275   {
4276     int r;
4277     suppress_error = 0;
4278     r = guestfs_umount_all (g);
4279     if (r == -1)
4280       return -1;
4281   }
4282   {
4283     int r;
4284     suppress_error = 0;
4285     r = guestfs_lvm_remove_all (g);
4286     if (r == -1)
4287       return -1;
4288   }
4289   {
4290     char *lines[] = {
4291       ",",
4292       NULL
4293     };
4294     int r;
4295     suppress_error = 0;
4296     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4297     if (r == -1)
4298       return -1;
4299   }
4300   {
4301     int r;
4302     suppress_error = 0;
4303     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4304     if (r == -1)
4305       return -1;
4306   }
4307   {
4308     int r;
4309     suppress_error = 0;
4310     r = guestfs_mount (g, "/dev/sda1", "/");
4311     if (r == -1)
4312       return -1;
4313   }
4314   /* TestRun for rmdir (0) */
4315   {
4316     int r;
4317     suppress_error = 0;
4318     r = guestfs_mkdir (g, "/new");
4319     if (r == -1)
4320       return -1;
4321   }
4322   {
4323     int r;
4324     suppress_error = 0;
4325     r = guestfs_rmdir (g, "/new");
4326     if (r == -1)
4327       return -1;
4328   }
4329   return 0;
4330 }
4331
4332 static int test_rmdir_1 (void)
4333 {
4334   /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */
4335   {
4336     int r;
4337     suppress_error = 0;
4338     r = guestfs_umount_all (g);
4339     if (r == -1)
4340       return -1;
4341   }
4342   {
4343     int r;
4344     suppress_error = 0;
4345     r = guestfs_lvm_remove_all (g);
4346     if (r == -1)
4347       return -1;
4348   }
4349   {
4350     char *lines[] = {
4351       ",",
4352       NULL
4353     };
4354     int r;
4355     suppress_error = 0;
4356     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4357     if (r == -1)
4358       return -1;
4359   }
4360   {
4361     int r;
4362     suppress_error = 0;
4363     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4364     if (r == -1)
4365       return -1;
4366   }
4367   {
4368     int r;
4369     suppress_error = 0;
4370     r = guestfs_mount (g, "/dev/sda1", "/");
4371     if (r == -1)
4372       return -1;
4373   }
4374   /* TestLastFail for rmdir (1) */
4375   {
4376     int r;
4377     suppress_error = 1;
4378     r = guestfs_rmdir (g, "/new");
4379     if (r != -1)
4380       return -1;
4381   }
4382   return 0;
4383 }
4384
4385 static int test_rmdir_2 (void)
4386 {
4387   /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */
4388   {
4389     int r;
4390     suppress_error = 0;
4391     r = guestfs_umount_all (g);
4392     if (r == -1)
4393       return -1;
4394   }
4395   {
4396     int r;
4397     suppress_error = 0;
4398     r = guestfs_lvm_remove_all (g);
4399     if (r == -1)
4400       return -1;
4401   }
4402   {
4403     char *lines[] = {
4404       ",",
4405       NULL
4406     };
4407     int r;
4408     suppress_error = 0;
4409     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4410     if (r == -1)
4411       return -1;
4412   }
4413   {
4414     int r;
4415     suppress_error = 0;
4416     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4417     if (r == -1)
4418       return -1;
4419   }
4420   {
4421     int r;
4422     suppress_error = 0;
4423     r = guestfs_mount (g, "/dev/sda1", "/");
4424     if (r == -1)
4425       return -1;
4426   }
4427   /* TestLastFail for rmdir (2) */
4428   {
4429     int r;
4430     suppress_error = 0;
4431     r = guestfs_touch (g, "/new");
4432     if (r == -1)
4433       return -1;
4434   }
4435   {
4436     int r;
4437     suppress_error = 1;
4438     r = guestfs_rmdir (g, "/new");
4439     if (r != -1)
4440       return -1;
4441   }
4442   return 0;
4443 }
4444
4445 static int test_rm_0 (void)
4446 {
4447   /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */
4448   {
4449     int r;
4450     suppress_error = 0;
4451     r = guestfs_umount_all (g);
4452     if (r == -1)
4453       return -1;
4454   }
4455   {
4456     int r;
4457     suppress_error = 0;
4458     r = guestfs_lvm_remove_all (g);
4459     if (r == -1)
4460       return -1;
4461   }
4462   {
4463     char *lines[] = {
4464       ",",
4465       NULL
4466     };
4467     int r;
4468     suppress_error = 0;
4469     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4470     if (r == -1)
4471       return -1;
4472   }
4473   {
4474     int r;
4475     suppress_error = 0;
4476     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4477     if (r == -1)
4478       return -1;
4479   }
4480   {
4481     int r;
4482     suppress_error = 0;
4483     r = guestfs_mount (g, "/dev/sda1", "/");
4484     if (r == -1)
4485       return -1;
4486   }
4487   /* TestRun for rm (0) */
4488   {
4489     int r;
4490     suppress_error = 0;
4491     r = guestfs_touch (g, "/new");
4492     if (r == -1)
4493       return -1;
4494   }
4495   {
4496     int r;
4497     suppress_error = 0;
4498     r = guestfs_rm (g, "/new");
4499     if (r == -1)
4500       return -1;
4501   }
4502   return 0;
4503 }
4504
4505 static int test_rm_1 (void)
4506 {
4507   /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */
4508   {
4509     int r;
4510     suppress_error = 0;
4511     r = guestfs_umount_all (g);
4512     if (r == -1)
4513       return -1;
4514   }
4515   {
4516     int r;
4517     suppress_error = 0;
4518     r = guestfs_lvm_remove_all (g);
4519     if (r == -1)
4520       return -1;
4521   }
4522   {
4523     char *lines[] = {
4524       ",",
4525       NULL
4526     };
4527     int r;
4528     suppress_error = 0;
4529     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4530     if (r == -1)
4531       return -1;
4532   }
4533   {
4534     int r;
4535     suppress_error = 0;
4536     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4537     if (r == -1)
4538       return -1;
4539   }
4540   {
4541     int r;
4542     suppress_error = 0;
4543     r = guestfs_mount (g, "/dev/sda1", "/");
4544     if (r == -1)
4545       return -1;
4546   }
4547   /* TestLastFail for rm (1) */
4548   {
4549     int r;
4550     suppress_error = 1;
4551     r = guestfs_rm (g, "/new");
4552     if (r != -1)
4553       return -1;
4554   }
4555   return 0;
4556 }
4557
4558 static int test_rm_2 (void)
4559 {
4560   /* InitBasicFS for rm (2): create ext2 on /dev/sda1 */
4561   {
4562     int r;
4563     suppress_error = 0;
4564     r = guestfs_umount_all (g);
4565     if (r == -1)
4566       return -1;
4567   }
4568   {
4569     int r;
4570     suppress_error = 0;
4571     r = guestfs_lvm_remove_all (g);
4572     if (r == -1)
4573       return -1;
4574   }
4575   {
4576     char *lines[] = {
4577       ",",
4578       NULL
4579     };
4580     int r;
4581     suppress_error = 0;
4582     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4583     if (r == -1)
4584       return -1;
4585   }
4586   {
4587     int r;
4588     suppress_error = 0;
4589     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4590     if (r == -1)
4591       return -1;
4592   }
4593   {
4594     int r;
4595     suppress_error = 0;
4596     r = guestfs_mount (g, "/dev/sda1", "/");
4597     if (r == -1)
4598       return -1;
4599   }
4600   /* TestLastFail for rm (2) */
4601   {
4602     int r;
4603     suppress_error = 0;
4604     r = guestfs_mkdir (g, "/new");
4605     if (r == -1)
4606       return -1;
4607   }
4608   {
4609     int r;
4610     suppress_error = 1;
4611     r = guestfs_rm (g, "/new");
4612     if (r != -1)
4613       return -1;
4614   }
4615   return 0;
4616 }
4617
4618 static int test_read_lines_0 (void)
4619 {
4620   /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */
4621   {
4622     int r;
4623     suppress_error = 0;
4624     r = guestfs_umount_all (g);
4625     if (r == -1)
4626       return -1;
4627   }
4628   {
4629     int r;
4630     suppress_error = 0;
4631     r = guestfs_lvm_remove_all (g);
4632     if (r == -1)
4633       return -1;
4634   }
4635   {
4636     char *lines[] = {
4637       ",",
4638       NULL
4639     };
4640     int r;
4641     suppress_error = 0;
4642     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4643     if (r == -1)
4644       return -1;
4645   }
4646   {
4647     int r;
4648     suppress_error = 0;
4649     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4650     if (r == -1)
4651       return -1;
4652   }
4653   {
4654     int r;
4655     suppress_error = 0;
4656     r = guestfs_mount (g, "/dev/sda1", "/");
4657     if (r == -1)
4658       return -1;
4659   }
4660   /* TestOutputList for read_lines (0) */
4661   {
4662     int r;
4663     suppress_error = 0;
4664     r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0);
4665     if (r == -1)
4666       return -1;
4667   }
4668   {
4669     char **r;
4670     int i;
4671     suppress_error = 0;
4672     r = guestfs_read_lines (g, "/new");
4673     if (r == NULL)
4674       return -1;
4675     if (!r[0]) {
4676       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
4677       print_strings (r);
4678       return -1;
4679     }
4680     if (strcmp (r[0], "line1") != 0) {
4681       fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]);
4682       return -1;
4683     }
4684     if (!r[1]) {
4685       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
4686       print_strings (r);
4687       return -1;
4688     }
4689     if (strcmp (r[1], "line2") != 0) {
4690       fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]);
4691       return -1;
4692     }
4693     if (!r[2]) {
4694       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
4695       print_strings (r);
4696       return -1;
4697     }
4698     if (strcmp (r[2], "line3") != 0) {
4699       fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]);
4700       return -1;
4701     }
4702     if (r[3] != NULL) {
4703       fprintf (stderr, "test_read_lines_0: extra elements returned from command\n");
4704       print_strings (r);
4705       return -1;
4706     }
4707     for (i = 0; r[i] != NULL; ++i)
4708       free (r[i]);
4709     free (r);
4710   }
4711   return 0;
4712 }
4713
4714 static int test_read_lines_1 (void)
4715 {
4716   /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */
4717   {
4718     int r;
4719     suppress_error = 0;
4720     r = guestfs_umount_all (g);
4721     if (r == -1)
4722       return -1;
4723   }
4724   {
4725     int r;
4726     suppress_error = 0;
4727     r = guestfs_lvm_remove_all (g);
4728     if (r == -1)
4729       return -1;
4730   }
4731   {
4732     char *lines[] = {
4733       ",",
4734       NULL
4735     };
4736     int r;
4737     suppress_error = 0;
4738     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4739     if (r == -1)
4740       return -1;
4741   }
4742   {
4743     int r;
4744     suppress_error = 0;
4745     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4746     if (r == -1)
4747       return -1;
4748   }
4749   {
4750     int r;
4751     suppress_error = 0;
4752     r = guestfs_mount (g, "/dev/sda1", "/");
4753     if (r == -1)
4754       return -1;
4755   }
4756   /* TestOutputList for read_lines (1) */
4757   {
4758     int r;
4759     suppress_error = 0;
4760     r = guestfs_write_file (g, "/new", "", 0);
4761     if (r == -1)
4762       return -1;
4763   }
4764   {
4765     char **r;
4766     int i;
4767     suppress_error = 0;
4768     r = guestfs_read_lines (g, "/new");
4769     if (r == NULL)
4770       return -1;
4771     if (r[0] != NULL) {
4772       fprintf (stderr, "test_read_lines_1: extra elements returned from command\n");
4773       print_strings (r);
4774       return -1;
4775     }
4776     for (i = 0; r[i] != NULL; ++i)
4777       free (r[i]);
4778     free (r);
4779   }
4780   return 0;
4781 }
4782
4783 static int test_lvs_0 (void)
4784 {
4785   /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */
4786   {
4787     int r;
4788     suppress_error = 0;
4789     r = guestfs_umount_all (g);
4790     if (r == -1)
4791       return -1;
4792   }
4793   {
4794     int r;
4795     suppress_error = 0;
4796     r = guestfs_lvm_remove_all (g);
4797     if (r == -1)
4798       return -1;
4799   }
4800   {
4801     char *lines[] = {
4802       ",",
4803       NULL
4804     };
4805     int r;
4806     suppress_error = 0;
4807     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4808     if (r == -1)
4809       return -1;
4810   }
4811   {
4812     int r;
4813     suppress_error = 0;
4814     r = guestfs_pvcreate (g, "/dev/sda1");
4815     if (r == -1)
4816       return -1;
4817   }
4818   {
4819     char *physvols[] = {
4820       "/dev/sda1",
4821       NULL
4822     };
4823     int r;
4824     suppress_error = 0;
4825     r = guestfs_vgcreate (g, "VG", physvols);
4826     if (r == -1)
4827       return -1;
4828   }
4829   {
4830     int r;
4831     suppress_error = 0;
4832     r = guestfs_lvcreate (g, "LV", "VG", 8);
4833     if (r == -1)
4834       return -1;
4835   }
4836   {
4837     int r;
4838     suppress_error = 0;
4839     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
4840     if (r == -1)
4841       return -1;
4842   }
4843   {
4844     int r;
4845     suppress_error = 0;
4846     r = guestfs_mount (g, "/dev/VG/LV", "/");
4847     if (r == -1)
4848       return -1;
4849   }
4850   /* TestOutputList for lvs (0) */
4851   {
4852     char **r;
4853     int i;
4854     suppress_error = 0;
4855     r = guestfs_lvs (g);
4856     if (r == NULL)
4857       return -1;
4858     if (!r[0]) {
4859       fprintf (stderr, "test_lvs_0: short list returned from command\n");
4860       print_strings (r);
4861       return -1;
4862     }
4863     if (strcmp (r[0], "/dev/VG/LV") != 0) {
4864       fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]);
4865       return -1;
4866     }
4867     if (r[1] != NULL) {
4868       fprintf (stderr, "test_lvs_0: extra elements returned from command\n");
4869       print_strings (r);
4870       return -1;
4871     }
4872     for (i = 0; r[i] != NULL; ++i)
4873       free (r[i]);
4874     free (r);
4875   }
4876   return 0;
4877 }
4878
4879 static int test_lvs_1 (void)
4880 {
4881   /* InitEmpty for lvs (1) */
4882   {
4883     int r;
4884     suppress_error = 0;
4885     r = guestfs_umount_all (g);
4886     if (r == -1)
4887       return -1;
4888   }
4889   {
4890     int r;
4891     suppress_error = 0;
4892     r = guestfs_lvm_remove_all (g);
4893     if (r == -1)
4894       return -1;
4895   }
4896   /* TestOutputList for lvs (1) */
4897   {
4898     char *lines[] = {
4899       ",10",
4900       ",20",
4901       ",",
4902       NULL
4903     };
4904     int r;
4905     suppress_error = 0;
4906     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4907     if (r == -1)
4908       return -1;
4909   }
4910   {
4911     int r;
4912     suppress_error = 0;
4913     r = guestfs_pvcreate (g, "/dev/sda1");
4914     if (r == -1)
4915       return -1;
4916   }
4917   {
4918     int r;
4919     suppress_error = 0;
4920     r = guestfs_pvcreate (g, "/dev/sda2");
4921     if (r == -1)
4922       return -1;
4923   }
4924   {
4925     int r;
4926     suppress_error = 0;
4927     r = guestfs_pvcreate (g, "/dev/sda3");
4928     if (r == -1)
4929       return -1;
4930   }
4931   {
4932     char *physvols[] = {
4933       "/dev/sda1",
4934       "/dev/sda2",
4935       NULL
4936     };
4937     int r;
4938     suppress_error = 0;
4939     r = guestfs_vgcreate (g, "VG1", physvols);
4940     if (r == -1)
4941       return -1;
4942   }
4943   {
4944     char *physvols[] = {
4945       "/dev/sda3",
4946       NULL
4947     };
4948     int r;
4949     suppress_error = 0;
4950     r = guestfs_vgcreate (g, "VG2", physvols);
4951     if (r == -1)
4952       return -1;
4953   }
4954   {
4955     int r;
4956     suppress_error = 0;
4957     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
4958     if (r == -1)
4959       return -1;
4960   }
4961   {
4962     int r;
4963     suppress_error = 0;
4964     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
4965     if (r == -1)
4966       return -1;
4967   }
4968   {
4969     int r;
4970     suppress_error = 0;
4971     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
4972     if (r == -1)
4973       return -1;
4974   }
4975   {
4976     char **r;
4977     int i;
4978     suppress_error = 0;
4979     r = guestfs_lvs (g);
4980     if (r == NULL)
4981       return -1;
4982     if (!r[0]) {
4983       fprintf (stderr, "test_lvs_1: short list returned from command\n");
4984       print_strings (r);
4985       return -1;
4986     }
4987     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
4988       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
4989       return -1;
4990     }
4991     if (!r[1]) {
4992       fprintf (stderr, "test_lvs_1: short list returned from command\n");
4993       print_strings (r);
4994       return -1;
4995     }
4996     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
4997       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
4998       return -1;
4999     }
5000     if (!r[2]) {
5001       fprintf (stderr, "test_lvs_1: short list returned from command\n");
5002       print_strings (r);
5003       return -1;
5004     }
5005     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
5006       fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
5007       return -1;
5008     }
5009     if (r[3] != NULL) {
5010       fprintf (stderr, "test_lvs_1: extra elements returned from command\n");
5011       print_strings (r);
5012       return -1;
5013     }
5014     for (i = 0; r[i] != NULL; ++i)
5015       free (r[i]);
5016     free (r);
5017   }
5018   return 0;
5019 }
5020
5021 static int test_vgs_0 (void)
5022 {
5023   /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */
5024   {
5025     int r;
5026     suppress_error = 0;
5027     r = guestfs_umount_all (g);
5028     if (r == -1)
5029       return -1;
5030   }
5031   {
5032     int r;
5033     suppress_error = 0;
5034     r = guestfs_lvm_remove_all (g);
5035     if (r == -1)
5036       return -1;
5037   }
5038   {
5039     char *lines[] = {
5040       ",",
5041       NULL
5042     };
5043     int r;
5044     suppress_error = 0;
5045     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5046     if (r == -1)
5047       return -1;
5048   }
5049   {
5050     int r;
5051     suppress_error = 0;
5052     r = guestfs_pvcreate (g, "/dev/sda1");
5053     if (r == -1)
5054       return -1;
5055   }
5056   {
5057     char *physvols[] = {
5058       "/dev/sda1",
5059       NULL
5060     };
5061     int r;
5062     suppress_error = 0;
5063     r = guestfs_vgcreate (g, "VG", physvols);
5064     if (r == -1)
5065       return -1;
5066   }
5067   {
5068     int r;
5069     suppress_error = 0;
5070     r = guestfs_lvcreate (g, "LV", "VG", 8);
5071     if (r == -1)
5072       return -1;
5073   }
5074   {
5075     int r;
5076     suppress_error = 0;
5077     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
5078     if (r == -1)
5079       return -1;
5080   }
5081   {
5082     int r;
5083     suppress_error = 0;
5084     r = guestfs_mount (g, "/dev/VG/LV", "/");
5085     if (r == -1)
5086       return -1;
5087   }
5088   /* TestOutputList for vgs (0) */
5089   {
5090     char **r;
5091     int i;
5092     suppress_error = 0;
5093     r = guestfs_vgs (g);
5094     if (r == NULL)
5095       return -1;
5096     if (!r[0]) {
5097       fprintf (stderr, "test_vgs_0: short list returned from command\n");
5098       print_strings (r);
5099       return -1;
5100     }
5101     if (strcmp (r[0], "VG") != 0) {
5102       fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]);
5103       return -1;
5104     }
5105     if (r[1] != NULL) {
5106       fprintf (stderr, "test_vgs_0: extra elements returned from command\n");
5107       print_strings (r);
5108       return -1;
5109     }
5110     for (i = 0; r[i] != NULL; ++i)
5111       free (r[i]);
5112     free (r);
5113   }
5114   return 0;
5115 }
5116
5117 static int test_vgs_1 (void)
5118 {
5119   /* InitEmpty for vgs (1) */
5120   {
5121     int r;
5122     suppress_error = 0;
5123     r = guestfs_umount_all (g);
5124     if (r == -1)
5125       return -1;
5126   }
5127   {
5128     int r;
5129     suppress_error = 0;
5130     r = guestfs_lvm_remove_all (g);
5131     if (r == -1)
5132       return -1;
5133   }
5134   /* TestOutputList for vgs (1) */
5135   {
5136     char *lines[] = {
5137       ",10",
5138       ",20",
5139       ",",
5140       NULL
5141     };
5142     int r;
5143     suppress_error = 0;
5144     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5145     if (r == -1)
5146       return -1;
5147   }
5148   {
5149     int r;
5150     suppress_error = 0;
5151     r = guestfs_pvcreate (g, "/dev/sda1");
5152     if (r == -1)
5153       return -1;
5154   }
5155   {
5156     int r;
5157     suppress_error = 0;
5158     r = guestfs_pvcreate (g, "/dev/sda2");
5159     if (r == -1)
5160       return -1;
5161   }
5162   {
5163     int r;
5164     suppress_error = 0;
5165     r = guestfs_pvcreate (g, "/dev/sda3");
5166     if (r == -1)
5167       return -1;
5168   }
5169   {
5170     char *physvols[] = {
5171       "/dev/sda1",
5172       "/dev/sda2",
5173       NULL
5174     };
5175     int r;
5176     suppress_error = 0;
5177     r = guestfs_vgcreate (g, "VG1", physvols);
5178     if (r == -1)
5179       return -1;
5180   }
5181   {
5182     char *physvols[] = {
5183       "/dev/sda3",
5184       NULL
5185     };
5186     int r;
5187     suppress_error = 0;
5188     r = guestfs_vgcreate (g, "VG2", physvols);
5189     if (r == -1)
5190       return -1;
5191   }
5192   {
5193     char **r;
5194     int i;
5195     suppress_error = 0;
5196     r = guestfs_vgs (g);
5197     if (r == NULL)
5198       return -1;
5199     if (!r[0]) {
5200       fprintf (stderr, "test_vgs_1: short list returned from command\n");
5201       print_strings (r);
5202       return -1;
5203     }
5204     if (strcmp (r[0], "VG1") != 0) {
5205       fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]);
5206       return -1;
5207     }
5208     if (!r[1]) {
5209       fprintf (stderr, "test_vgs_1: short list returned from command\n");
5210       print_strings (r);
5211       return -1;
5212     }
5213     if (strcmp (r[1], "VG2") != 0) {
5214       fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]);
5215       return -1;
5216     }
5217     if (r[2] != NULL) {
5218       fprintf (stderr, "test_vgs_1: extra elements returned from command\n");
5219       print_strings (r);
5220       return -1;
5221     }
5222     for (i = 0; r[i] != NULL; ++i)
5223       free (r[i]);
5224     free (r);
5225   }
5226   return 0;
5227 }
5228
5229 static int test_pvs_0 (void)
5230 {
5231   /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */
5232   {
5233     int r;
5234     suppress_error = 0;
5235     r = guestfs_umount_all (g);
5236     if (r == -1)
5237       return -1;
5238   }
5239   {
5240     int r;
5241     suppress_error = 0;
5242     r = guestfs_lvm_remove_all (g);
5243     if (r == -1)
5244       return -1;
5245   }
5246   {
5247     char *lines[] = {
5248       ",",
5249       NULL
5250     };
5251     int r;
5252     suppress_error = 0;
5253     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5254     if (r == -1)
5255       return -1;
5256   }
5257   {
5258     int r;
5259     suppress_error = 0;
5260     r = guestfs_pvcreate (g, "/dev/sda1");
5261     if (r == -1)
5262       return -1;
5263   }
5264   {
5265     char *physvols[] = {
5266       "/dev/sda1",
5267       NULL
5268     };
5269     int r;
5270     suppress_error = 0;
5271     r = guestfs_vgcreate (g, "VG", physvols);
5272     if (r == -1)
5273       return -1;
5274   }
5275   {
5276     int r;
5277     suppress_error = 0;
5278     r = guestfs_lvcreate (g, "LV", "VG", 8);
5279     if (r == -1)
5280       return -1;
5281   }
5282   {
5283     int r;
5284     suppress_error = 0;
5285     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
5286     if (r == -1)
5287       return -1;
5288   }
5289   {
5290     int r;
5291     suppress_error = 0;
5292     r = guestfs_mount (g, "/dev/VG/LV", "/");
5293     if (r == -1)
5294       return -1;
5295   }
5296   /* TestOutputList for pvs (0) */
5297   {
5298     char **r;
5299     int i;
5300     suppress_error = 0;
5301     r = guestfs_pvs (g);
5302     if (r == NULL)
5303       return -1;
5304     if (!r[0]) {
5305       fprintf (stderr, "test_pvs_0: short list returned from command\n");
5306       print_strings (r);
5307       return -1;
5308     }
5309     if (strcmp (r[0], "/dev/sda1") != 0) {
5310       fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
5311       return -1;
5312     }
5313     if (r[1] != NULL) {
5314       fprintf (stderr, "test_pvs_0: extra elements returned from command\n");
5315       print_strings (r);
5316       return -1;
5317     }
5318     for (i = 0; r[i] != NULL; ++i)
5319       free (r[i]);
5320     free (r);
5321   }
5322   return 0;
5323 }
5324
5325 static int test_pvs_1 (void)
5326 {
5327   /* InitEmpty for pvs (1) */
5328   {
5329     int r;
5330     suppress_error = 0;
5331     r = guestfs_umount_all (g);
5332     if (r == -1)
5333       return -1;
5334   }
5335   {
5336     int r;
5337     suppress_error = 0;
5338     r = guestfs_lvm_remove_all (g);
5339     if (r == -1)
5340       return -1;
5341   }
5342   /* TestOutputList for pvs (1) */
5343   {
5344     char *lines[] = {
5345       ",10",
5346       ",20",
5347       ",",
5348       NULL
5349     };
5350     int r;
5351     suppress_error = 0;
5352     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5353     if (r == -1)
5354       return -1;
5355   }
5356   {
5357     int r;
5358     suppress_error = 0;
5359     r = guestfs_pvcreate (g, "/dev/sda1");
5360     if (r == -1)
5361       return -1;
5362   }
5363   {
5364     int r;
5365     suppress_error = 0;
5366     r = guestfs_pvcreate (g, "/dev/sda2");
5367     if (r == -1)
5368       return -1;
5369   }
5370   {
5371     int r;
5372     suppress_error = 0;
5373     r = guestfs_pvcreate (g, "/dev/sda3");
5374     if (r == -1)
5375       return -1;
5376   }
5377   {
5378     char **r;
5379     int i;
5380     suppress_error = 0;
5381     r = guestfs_pvs (g);
5382     if (r == NULL)
5383       return -1;
5384     if (!r[0]) {
5385       fprintf (stderr, "test_pvs_1: short list returned from command\n");
5386       print_strings (r);
5387       return -1;
5388     }
5389     if (strcmp (r[0], "/dev/sda1") != 0) {
5390       fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
5391       return -1;
5392     }
5393     if (!r[1]) {
5394       fprintf (stderr, "test_pvs_1: short list returned from command\n");
5395       print_strings (r);
5396       return -1;
5397     }
5398     if (strcmp (r[1], "/dev/sda2") != 0) {
5399       fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
5400       return -1;
5401     }
5402     if (!r[2]) {
5403       fprintf (stderr, "test_pvs_1: short list returned from command\n");
5404       print_strings (r);
5405       return -1;
5406     }
5407     if (strcmp (r[2], "/dev/sda3") != 0) {
5408       fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
5409       return -1;
5410     }
5411     if (r[3] != NULL) {
5412       fprintf (stderr, "test_pvs_1: extra elements returned from command\n");
5413       print_strings (r);
5414       return -1;
5415     }
5416     for (i = 0; r[i] != NULL; ++i)
5417       free (r[i]);
5418     free (r);
5419   }
5420   return 0;
5421 }
5422
5423 static int test_list_partitions_0 (void)
5424 {
5425   /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */
5426   {
5427     int r;
5428     suppress_error = 0;
5429     r = guestfs_umount_all (g);
5430     if (r == -1)
5431       return -1;
5432   }
5433   {
5434     int r;
5435     suppress_error = 0;
5436     r = guestfs_lvm_remove_all (g);
5437     if (r == -1)
5438       return -1;
5439   }
5440   {
5441     char *lines[] = {
5442       ",",
5443       NULL
5444     };
5445     int r;
5446     suppress_error = 0;
5447     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5448     if (r == -1)
5449       return -1;
5450   }
5451   {
5452     int r;
5453     suppress_error = 0;
5454     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
5455     if (r == -1)
5456       return -1;
5457   }
5458   {
5459     int r;
5460     suppress_error = 0;
5461     r = guestfs_mount (g, "/dev/sda1", "/");
5462     if (r == -1)
5463       return -1;
5464   }
5465   /* TestOutputList for list_partitions (0) */
5466   {
5467     char **r;
5468     int i;
5469     suppress_error = 0;
5470     r = guestfs_list_partitions (g);
5471     if (r == NULL)
5472       return -1;
5473     if (!r[0]) {
5474       fprintf (stderr, "test_list_partitions_0: short list returned from command\n");
5475       print_strings (r);
5476       return -1;
5477     }
5478     if (strcmp (r[0], "/dev/sda1") != 0) {
5479       fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
5480       return -1;
5481     }
5482     if (r[1] != NULL) {
5483       fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n");
5484       print_strings (r);
5485       return -1;
5486     }
5487     for (i = 0; r[i] != NULL; ++i)
5488       free (r[i]);
5489     free (r);
5490   }
5491   return 0;
5492 }
5493
5494 static int test_list_partitions_1 (void)
5495 {
5496   /* InitEmpty for list_partitions (1) */
5497   {
5498     int r;
5499     suppress_error = 0;
5500     r = guestfs_umount_all (g);
5501     if (r == -1)
5502       return -1;
5503   }
5504   {
5505     int r;
5506     suppress_error = 0;
5507     r = guestfs_lvm_remove_all (g);
5508     if (r == -1)
5509       return -1;
5510   }
5511   /* TestOutputList for list_partitions (1) */
5512   {
5513     char *lines[] = {
5514       ",10",
5515       ",20",
5516       ",",
5517       NULL
5518     };
5519     int r;
5520     suppress_error = 0;
5521     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5522     if (r == -1)
5523       return -1;
5524   }
5525   {
5526     char **r;
5527     int i;
5528     suppress_error = 0;
5529     r = guestfs_list_partitions (g);
5530     if (r == NULL)
5531       return -1;
5532     if (!r[0]) {
5533       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
5534       print_strings (r);
5535       return -1;
5536     }
5537     if (strcmp (r[0], "/dev/sda1") != 0) {
5538       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
5539       return -1;
5540     }
5541     if (!r[1]) {
5542       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
5543       print_strings (r);
5544       return -1;
5545     }
5546     if (strcmp (r[1], "/dev/sda2") != 0) {
5547       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
5548       return -1;
5549     }
5550     if (!r[2]) {
5551       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
5552       print_strings (r);
5553       return -1;
5554     }
5555     if (strcmp (r[2], "/dev/sda3") != 0) {
5556       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
5557       return -1;
5558     }
5559     if (r[3] != NULL) {
5560       fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n");
5561       print_strings (r);
5562       return -1;
5563     }
5564     for (i = 0; r[i] != NULL; ++i)
5565       free (r[i]);
5566     free (r);
5567   }
5568   return 0;
5569 }
5570
5571 static int test_list_devices_0 (void)
5572 {
5573   /* InitEmpty for list_devices (0) */
5574   {
5575     int r;
5576     suppress_error = 0;
5577     r = guestfs_umount_all (g);
5578     if (r == -1)
5579       return -1;
5580   }
5581   {
5582     int r;
5583     suppress_error = 0;
5584     r = guestfs_lvm_remove_all (g);
5585     if (r == -1)
5586       return -1;
5587   }
5588   /* TestOutputList for list_devices (0) */
5589   {
5590     char **r;
5591     int i;
5592     suppress_error = 0;
5593     r = guestfs_list_devices (g);
5594     if (r == NULL)
5595       return -1;
5596     if (!r[0]) {
5597       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
5598       print_strings (r);
5599       return -1;
5600     }
5601     if (strcmp (r[0], "/dev/sda") != 0) {
5602       fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]);
5603       return -1;
5604     }
5605     if (!r[1]) {
5606       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
5607       print_strings (r);
5608       return -1;
5609     }
5610     if (strcmp (r[1], "/dev/sdb") != 0) {
5611       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]);
5612       return -1;
5613     }
5614     if (!r[2]) {
5615       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
5616       print_strings (r);
5617       return -1;
5618     }
5619     if (strcmp (r[2], "/dev/sdc") != 0) {
5620       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]);
5621       return -1;
5622     }
5623     if (r[3] != NULL) {
5624       fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
5625       print_strings (r);
5626       return -1;
5627     }
5628     for (i = 0; r[i] != NULL; ++i)
5629       free (r[i]);
5630     free (r);
5631   }
5632   return 0;
5633 }
5634
5635 static int test_ls_0 (void)
5636 {
5637   /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */
5638   {
5639     int r;
5640     suppress_error = 0;
5641     r = guestfs_umount_all (g);
5642     if (r == -1)
5643       return -1;
5644   }
5645   {
5646     int r;
5647     suppress_error = 0;
5648     r = guestfs_lvm_remove_all (g);
5649     if (r == -1)
5650       return -1;
5651   }
5652   {
5653     char *lines[] = {
5654       ",",
5655       NULL
5656     };
5657     int r;
5658     suppress_error = 0;
5659     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5660     if (r == -1)
5661       return -1;
5662   }
5663   {
5664     int r;
5665     suppress_error = 0;
5666     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
5667     if (r == -1)
5668       return -1;
5669   }
5670   {
5671     int r;
5672     suppress_error = 0;
5673     r = guestfs_mount (g, "/dev/sda1", "/");
5674     if (r == -1)
5675       return -1;
5676   }
5677   /* TestOutputList for ls (0) */
5678   {
5679     int r;
5680     suppress_error = 0;
5681     r = guestfs_touch (g, "/new");
5682     if (r == -1)
5683       return -1;
5684   }
5685   {
5686     int r;
5687     suppress_error = 0;
5688     r = guestfs_touch (g, "/newer");
5689     if (r == -1)
5690       return -1;
5691   }
5692   {
5693     int r;
5694     suppress_error = 0;
5695     r = guestfs_touch (g, "/newest");
5696     if (r == -1)
5697       return -1;
5698   }
5699   {
5700     char **r;
5701     int i;
5702     suppress_error = 0;
5703     r = guestfs_ls (g, "/");
5704     if (r == NULL)
5705       return -1;
5706     if (!r[0]) {
5707       fprintf (stderr, "test_ls_0: short list returned from command\n");
5708       print_strings (r);
5709       return -1;
5710     }
5711     if (strcmp (r[0], "lost+found") != 0) {
5712       fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]);
5713       return -1;
5714     }
5715     if (!r[1]) {
5716       fprintf (stderr, "test_ls_0: short list returned from command\n");
5717       print_strings (r);
5718       return -1;
5719     }
5720     if (strcmp (r[1], "new") != 0) {
5721       fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]);
5722       return -1;
5723     }
5724     if (!r[2]) {
5725       fprintf (stderr, "test_ls_0: short list returned from command\n");
5726       print_strings (r);
5727       return -1;
5728     }
5729     if (strcmp (r[2], "newer") != 0) {
5730       fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]);
5731       return -1;
5732     }
5733     if (!r[3]) {
5734       fprintf (stderr, "test_ls_0: short list returned from command\n");
5735       print_strings (r);
5736       return -1;
5737     }
5738     if (strcmp (r[3], "newest") != 0) {
5739       fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]);
5740       return -1;
5741     }
5742     if (r[4] != NULL) {
5743       fprintf (stderr, "test_ls_0: extra elements returned from command\n");
5744       print_strings (r);
5745       return -1;
5746     }
5747     for (i = 0; r[i] != NULL; ++i)
5748       free (r[i]);
5749     free (r);
5750   }
5751   return 0;
5752 }
5753
5754 static int test_cat_0 (void)
5755 {
5756   /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */
5757   {
5758     int r;
5759     suppress_error = 0;
5760     r = guestfs_umount_all (g);
5761     if (r == -1)
5762       return -1;
5763   }
5764   {
5765     int r;
5766     suppress_error = 0;
5767     r = guestfs_lvm_remove_all (g);
5768     if (r == -1)
5769       return -1;
5770   }
5771   {
5772     char *lines[] = {
5773       ",",
5774       NULL
5775     };
5776     int r;
5777     suppress_error = 0;
5778     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5779     if (r == -1)
5780       return -1;
5781   }
5782   {
5783     int r;
5784     suppress_error = 0;
5785     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
5786     if (r == -1)
5787       return -1;
5788   }
5789   {
5790     int r;
5791     suppress_error = 0;
5792     r = guestfs_mount (g, "/dev/sda1", "/");
5793     if (r == -1)
5794       return -1;
5795   }
5796   /* TestOutput for cat (0) */
5797   {
5798     int r;
5799     suppress_error = 0;
5800     r = guestfs_write_file (g, "/new", "new file contents", 0);
5801     if (r == -1)
5802       return -1;
5803   }
5804   {
5805     char *r;
5806     suppress_error = 0;
5807     r = guestfs_cat (g, "/new");
5808     if (r == NULL)
5809       return -1;
5810     if (strcmp (r, "new file contents") != 0) {
5811       fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r);
5812       return -1;
5813     }
5814     free (r);
5815   }
5816   return 0;
5817 }
5818
5819 static int test_touch_0 (void)
5820 {
5821   /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */
5822   {
5823     int r;
5824     suppress_error = 0;
5825     r = guestfs_umount_all (g);
5826     if (r == -1)
5827       return -1;
5828   }
5829   {
5830     int r;
5831     suppress_error = 0;
5832     r = guestfs_lvm_remove_all (g);
5833     if (r == -1)
5834       return -1;
5835   }
5836   {
5837     char *lines[] = {
5838       ",",
5839       NULL
5840     };
5841     int r;
5842     suppress_error = 0;
5843     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5844     if (r == -1)
5845       return -1;
5846   }
5847   {
5848     int r;
5849     suppress_error = 0;
5850     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
5851     if (r == -1)
5852       return -1;
5853   }
5854   {
5855     int r;
5856     suppress_error = 0;
5857     r = guestfs_mount (g, "/dev/sda1", "/");
5858     if (r == -1)
5859       return -1;
5860   }
5861   /* TestOutputTrue for touch (0) */
5862   {
5863     int r;
5864     suppress_error = 0;
5865     r = guestfs_touch (g, "/new");
5866     if (r == -1)
5867       return -1;
5868   }
5869   {
5870     int r;
5871     suppress_error = 0;
5872     r = guestfs_exists (g, "/new");
5873     if (r == -1)
5874       return -1;
5875     if (!r) {
5876       fprintf (stderr, "test_touch_0: expected true, got false\n");
5877       return -1;
5878     }
5879   }
5880   return 0;
5881 }
5882
5883 static int test_sync_0 (void)
5884 {
5885   /* InitEmpty for sync (0) */
5886   {
5887     int r;
5888     suppress_error = 0;
5889     r = guestfs_umount_all (g);
5890     if (r == -1)
5891       return -1;
5892   }
5893   {
5894     int r;
5895     suppress_error = 0;
5896     r = guestfs_lvm_remove_all (g);
5897     if (r == -1)
5898       return -1;
5899   }
5900   /* TestRun for sync (0) */
5901   {
5902     int r;
5903     suppress_error = 0;
5904     r = guestfs_sync (g);
5905     if (r == -1)
5906       return -1;
5907   }
5908   return 0;
5909 }
5910
5911 static int test_mount_0 (void)
5912 {
5913   /* InitEmpty for mount (0) */
5914   {
5915     int r;
5916     suppress_error = 0;
5917     r = guestfs_umount_all (g);
5918     if (r == -1)
5919       return -1;
5920   }
5921   {
5922     int r;
5923     suppress_error = 0;
5924     r = guestfs_lvm_remove_all (g);
5925     if (r == -1)
5926       return -1;
5927   }
5928   /* TestOutput for mount (0) */
5929   {
5930     char *lines[] = {
5931       ",",
5932       NULL
5933     };
5934     int r;
5935     suppress_error = 0;
5936     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
5937     if (r == -1)
5938       return -1;
5939   }
5940   {
5941     int r;
5942     suppress_error = 0;
5943     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
5944     if (r == -1)
5945       return -1;
5946   }
5947   {
5948     int r;
5949     suppress_error = 0;
5950     r = guestfs_mount (g, "/dev/sda1", "/");
5951     if (r == -1)
5952       return -1;
5953   }
5954   {
5955     int r;
5956     suppress_error = 0;
5957     r = guestfs_write_file (g, "/new", "new file contents", 0);
5958     if (r == -1)
5959       return -1;
5960   }
5961   {
5962     char *r;
5963     suppress_error = 0;
5964     r = guestfs_cat (g, "/new");
5965     if (r == NULL)
5966       return -1;
5967     if (strcmp (r, "new file contents") != 0) {
5968       fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r);
5969       return -1;
5970     }
5971     free (r);
5972   }
5973   return 0;
5974 }
5975
5976 int main (int argc, char *argv[])
5977 {
5978   char c = 0;
5979   int failed = 0;
5980   const char *srcdir;
5981   const char *filename;
5982   int fd;
5983   int nr_tests, test_num = 0;
5984
5985   no_test_warnings ();
5986
5987   g = guestfs_create ();
5988   if (g == NULL) {
5989     printf ("guestfs_create FAILED\n");
5990     exit (1);
5991   }
5992
5993   guestfs_set_error_handler (g, print_error, NULL);
5994
5995   srcdir = getenv ("srcdir");
5996   if (!srcdir) srcdir = ".";
5997   chdir (srcdir);
5998   guestfs_set_path (g, ".");
5999
6000   filename = "test1.img";
6001   fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
6002   if (fd == -1) {
6003     perror (filename);
6004     exit (1);
6005   }
6006   if (lseek (fd, 524288000, SEEK_SET) == -1) {
6007     perror ("lseek");
6008     close (fd);
6009     unlink (filename);
6010     exit (1);
6011   }
6012   if (write (fd, &c, 1) == -1) {
6013     perror ("write");
6014     close (fd);
6015     unlink (filename);
6016     exit (1);
6017   }
6018   if (close (fd) == -1) {
6019     perror (filename);
6020     unlink (filename);
6021     exit (1);
6022   }
6023   if (guestfs_add_drive (g, filename) == -1) {
6024     printf ("guestfs_add_drive %s FAILED\n", filename);
6025     exit (1);
6026   }
6027
6028   filename = "test2.img";
6029   fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
6030   if (fd == -1) {
6031     perror (filename);
6032     exit (1);
6033   }
6034   if (lseek (fd, 52428800, SEEK_SET) == -1) {
6035     perror ("lseek");
6036     close (fd);
6037     unlink (filename);
6038     exit (1);
6039   }
6040   if (write (fd, &c, 1) == -1) {
6041     perror ("write");
6042     close (fd);
6043     unlink (filename);
6044     exit (1);
6045   }
6046   if (close (fd) == -1) {
6047     perror (filename);
6048     unlink (filename);
6049     exit (1);
6050   }
6051   if (guestfs_add_drive (g, filename) == -1) {
6052     printf ("guestfs_add_drive %s FAILED\n", filename);
6053     exit (1);
6054   }
6055
6056   filename = "test3.img";
6057   fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
6058   if (fd == -1) {
6059     perror (filename);
6060     exit (1);
6061   }
6062   if (lseek (fd, 10485760, SEEK_SET) == -1) {
6063     perror ("lseek");
6064     close (fd);
6065     unlink (filename);
6066     exit (1);
6067   }
6068   if (write (fd, &c, 1) == -1) {
6069     perror ("write");
6070     close (fd);
6071     unlink (filename);
6072     exit (1);
6073   }
6074   if (close (fd) == -1) {
6075     perror (filename);
6076     unlink (filename);
6077     exit (1);
6078   }
6079   if (guestfs_add_drive (g, filename) == -1) {
6080     printf ("guestfs_add_drive %s FAILED\n", filename);
6081     exit (1);
6082   }
6083
6084   if (guestfs_launch (g) == -1) {
6085     printf ("guestfs_launch FAILED\n");
6086     exit (1);
6087   }
6088   if (guestfs_wait_ready (g) == -1) {
6089     printf ("guestfs_wait_ready FAILED\n");
6090     exit (1);
6091   }
6092
6093   nr_tests = 85;
6094
6095   test_num++;
6096   printf ("%3d/%3d test_pvremove_0\n", test_num, nr_tests);
6097   if (test_pvremove_0 () == -1) {
6098     printf ("test_pvremove_0 FAILED\n");
6099     failed++;
6100   }
6101   test_num++;
6102   printf ("%3d/%3d test_pvremove_1\n", test_num, nr_tests);
6103   if (test_pvremove_1 () == -1) {
6104     printf ("test_pvremove_1 FAILED\n");
6105     failed++;
6106   }
6107   test_num++;
6108   printf ("%3d/%3d test_pvremove_2\n", test_num, nr_tests);
6109   if (test_pvremove_2 () == -1) {
6110     printf ("test_pvremove_2 FAILED\n");
6111     failed++;
6112   }
6113   test_num++;
6114   printf ("%3d/%3d test_vgremove_0\n", test_num, nr_tests);
6115   if (test_vgremove_0 () == -1) {
6116     printf ("test_vgremove_0 FAILED\n");
6117     failed++;
6118   }
6119   test_num++;
6120   printf ("%3d/%3d test_vgremove_1\n", test_num, nr_tests);
6121   if (test_vgremove_1 () == -1) {
6122     printf ("test_vgremove_1 FAILED\n");
6123     failed++;
6124   }
6125   test_num++;
6126   printf ("%3d/%3d test_lvremove_0\n", test_num, nr_tests);
6127   if (test_lvremove_0 () == -1) {
6128     printf ("test_lvremove_0 FAILED\n");
6129     failed++;
6130   }
6131   test_num++;
6132   printf ("%3d/%3d test_lvremove_1\n", test_num, nr_tests);
6133   if (test_lvremove_1 () == -1) {
6134     printf ("test_lvremove_1 FAILED\n");
6135     failed++;
6136   }
6137   test_num++;
6138   printf ("%3d/%3d test_lvremove_2\n", test_num, nr_tests);
6139   if (test_lvremove_2 () == -1) {
6140     printf ("test_lvremove_2 FAILED\n");
6141     failed++;
6142   }
6143   test_num++;
6144   printf ("%3d/%3d test_mount_ro_0\n", test_num, nr_tests);
6145   if (test_mount_ro_0 () == -1) {
6146     printf ("test_mount_ro_0 FAILED\n");
6147     failed++;
6148   }
6149   test_num++;
6150   printf ("%3d/%3d test_mount_ro_1\n", test_num, nr_tests);
6151   if (test_mount_ro_1 () == -1) {
6152     printf ("test_mount_ro_1 FAILED\n");
6153     failed++;
6154   }
6155   test_num++;
6156   printf ("%3d/%3d test_tgz_in_0\n", test_num, nr_tests);
6157   if (test_tgz_in_0 () == -1) {
6158     printf ("test_tgz_in_0 FAILED\n");
6159     failed++;
6160   }
6161   test_num++;
6162   printf ("%3d/%3d test_tar_in_0\n", test_num, nr_tests);
6163   if (test_tar_in_0 () == -1) {
6164     printf ("test_tar_in_0 FAILED\n");
6165     failed++;
6166   }
6167   test_num++;
6168   printf ("%3d/%3d test_checksum_0\n", test_num, nr_tests);
6169   if (test_checksum_0 () == -1) {
6170     printf ("test_checksum_0 FAILED\n");
6171     failed++;
6172   }
6173   test_num++;
6174   printf ("%3d/%3d test_checksum_1\n", test_num, nr_tests);
6175   if (test_checksum_1 () == -1) {
6176     printf ("test_checksum_1 FAILED\n");
6177     failed++;
6178   }
6179   test_num++;
6180   printf ("%3d/%3d test_checksum_2\n", test_num, nr_tests);
6181   if (test_checksum_2 () == -1) {
6182     printf ("test_checksum_2 FAILED\n");
6183     failed++;
6184   }
6185   test_num++;
6186   printf ("%3d/%3d test_checksum_3\n", test_num, nr_tests);
6187   if (test_checksum_3 () == -1) {
6188     printf ("test_checksum_3 FAILED\n");
6189     failed++;
6190   }
6191   test_num++;
6192   printf ("%3d/%3d test_checksum_4\n", test_num, nr_tests);
6193   if (test_checksum_4 () == -1) {
6194     printf ("test_checksum_4 FAILED\n");
6195     failed++;
6196   }
6197   test_num++;
6198   printf ("%3d/%3d test_checksum_5\n", test_num, nr_tests);
6199   if (test_checksum_5 () == -1) {
6200     printf ("test_checksum_5 FAILED\n");
6201     failed++;
6202   }
6203   test_num++;
6204   printf ("%3d/%3d test_checksum_6\n", test_num, nr_tests);
6205   if (test_checksum_6 () == -1) {
6206     printf ("test_checksum_6 FAILED\n");
6207     failed++;
6208   }
6209   test_num++;
6210   printf ("%3d/%3d test_checksum_7\n", test_num, nr_tests);
6211   if (test_checksum_7 () == -1) {
6212     printf ("test_checksum_7 FAILED\n");
6213     failed++;
6214   }
6215   test_num++;
6216   printf ("%3d/%3d test_download_0\n", test_num, nr_tests);
6217   if (test_download_0 () == -1) {
6218     printf ("test_download_0 FAILED\n");
6219     failed++;
6220   }
6221   test_num++;
6222   printf ("%3d/%3d test_upload_0\n", test_num, nr_tests);
6223   if (test_upload_0 () == -1) {
6224     printf ("test_upload_0 FAILED\n");
6225     failed++;
6226   }
6227   test_num++;
6228   printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests);
6229   if (test_blockdev_rereadpt_0 () == -1) {
6230     printf ("test_blockdev_rereadpt_0 FAILED\n");
6231     failed++;
6232   }
6233   test_num++;
6234   printf ("%3d/%3d test_blockdev_flushbufs_0\n", test_num, nr_tests);
6235   if (test_blockdev_flushbufs_0 () == -1) {
6236     printf ("test_blockdev_flushbufs_0 FAILED\n");
6237     failed++;
6238   }
6239   test_num++;
6240   printf ("%3d/%3d test_blockdev_getsize64_0\n", test_num, nr_tests);
6241   if (test_blockdev_getsize64_0 () == -1) {
6242     printf ("test_blockdev_getsize64_0 FAILED\n");
6243     failed++;
6244   }
6245   test_num++;
6246   printf ("%3d/%3d test_blockdev_getsz_0\n", test_num, nr_tests);
6247   if (test_blockdev_getsz_0 () == -1) {
6248     printf ("test_blockdev_getsz_0 FAILED\n");
6249     failed++;
6250   }
6251   test_num++;
6252   printf ("%3d/%3d test_blockdev_getbsz_0\n", test_num, nr_tests);
6253   if (test_blockdev_getbsz_0 () == -1) {
6254     printf ("test_blockdev_getbsz_0 FAILED\n");
6255     failed++;
6256   }
6257   test_num++;
6258   printf ("%3d/%3d test_blockdev_getss_0\n", test_num, nr_tests);
6259   if (test_blockdev_getss_0 () == -1) {
6260     printf ("test_blockdev_getss_0 FAILED\n");
6261     failed++;
6262   }
6263   test_num++;
6264   printf ("%3d/%3d test_blockdev_getro_0\n", test_num, nr_tests);
6265   if (test_blockdev_getro_0 () == -1) {
6266     printf ("test_blockdev_getro_0 FAILED\n");
6267     failed++;
6268   }
6269   test_num++;
6270   printf ("%3d/%3d test_blockdev_setrw_0\n", test_num, nr_tests);
6271   if (test_blockdev_setrw_0 () == -1) {
6272     printf ("test_blockdev_setrw_0 FAILED\n");
6273     failed++;
6274   }
6275   test_num++;
6276   printf ("%3d/%3d test_blockdev_setro_0\n", test_num, nr_tests);
6277   if (test_blockdev_setro_0 () == -1) {
6278     printf ("test_blockdev_setro_0 FAILED\n");
6279     failed++;
6280   }
6281   test_num++;
6282   printf ("%3d/%3d test_statvfs_0\n", test_num, nr_tests);
6283   if (test_statvfs_0 () == -1) {
6284     printf ("test_statvfs_0 FAILED\n");
6285     failed++;
6286   }
6287   test_num++;
6288   printf ("%3d/%3d test_lstat_0\n", test_num, nr_tests);
6289   if (test_lstat_0 () == -1) {
6290     printf ("test_lstat_0 FAILED\n");
6291     failed++;
6292   }
6293   test_num++;
6294   printf ("%3d/%3d test_stat_0\n", test_num, nr_tests);
6295   if (test_stat_0 () == -1) {
6296     printf ("test_stat_0 FAILED\n");
6297     failed++;
6298   }
6299   test_num++;
6300   printf ("%3d/%3d test_file_0\n", test_num, nr_tests);
6301   if (test_file_0 () == -1) {
6302     printf ("test_file_0 FAILED\n");
6303     failed++;
6304   }
6305   test_num++;
6306   printf ("%3d/%3d test_file_1\n", test_num, nr_tests);
6307   if (test_file_1 () == -1) {
6308     printf ("test_file_1 FAILED\n");
6309     failed++;
6310   }
6311   test_num++;
6312   printf ("%3d/%3d test_file_2\n", test_num, nr_tests);
6313   if (test_file_2 () == -1) {
6314     printf ("test_file_2 FAILED\n");
6315     failed++;
6316   }
6317   test_num++;
6318   printf ("%3d/%3d test_umount_all_0\n", test_num, nr_tests);
6319   if (test_umount_all_0 () == -1) {
6320     printf ("test_umount_all_0 FAILED\n");
6321     failed++;
6322   }
6323   test_num++;
6324   printf ("%3d/%3d test_mounts_0\n", test_num, nr_tests);
6325   if (test_mounts_0 () == -1) {
6326     printf ("test_mounts_0 FAILED\n");
6327     failed++;
6328   }
6329   test_num++;
6330   printf ("%3d/%3d test_umount_0\n", test_num, nr_tests);
6331   if (test_umount_0 () == -1) {
6332     printf ("test_umount_0 FAILED\n");
6333     failed++;
6334   }
6335   test_num++;
6336   printf ("%3d/%3d test_umount_1\n", test_num, nr_tests);
6337   if (test_umount_1 () == -1) {
6338     printf ("test_umount_1 FAILED\n");
6339     failed++;
6340   }
6341   test_num++;
6342   printf ("%3d/%3d test_write_file_0\n", test_num, nr_tests);
6343   if (test_write_file_0 () == -1) {
6344     printf ("test_write_file_0 FAILED\n");
6345     failed++;
6346   }
6347   test_num++;
6348   printf ("%3d/%3d test_write_file_1\n", test_num, nr_tests);
6349   if (test_write_file_1 () == -1) {
6350     printf ("test_write_file_1 FAILED\n");
6351     failed++;
6352   }
6353   test_num++;
6354   printf ("%3d/%3d test_write_file_2\n", test_num, nr_tests);
6355   if (test_write_file_2 () == -1) {
6356     printf ("test_write_file_2 FAILED\n");
6357     failed++;
6358   }
6359   test_num++;
6360   printf ("%3d/%3d test_write_file_3\n", test_num, nr_tests);
6361   if (test_write_file_3 () == -1) {
6362     printf ("test_write_file_3 FAILED\n");
6363     failed++;
6364   }
6365   test_num++;
6366   printf ("%3d/%3d test_write_file_4\n", test_num, nr_tests);
6367   if (test_write_file_4 () == -1) {
6368     printf ("test_write_file_4 FAILED\n");
6369     failed++;
6370   }
6371   test_num++;
6372   printf ("%3d/%3d test_write_file_5\n", test_num, nr_tests);
6373   if (test_write_file_5 () == -1) {
6374     printf ("test_write_file_5 FAILED\n");
6375     failed++;
6376   }
6377   test_num++;
6378   printf ("%3d/%3d test_mkfs_0\n", test_num, nr_tests);
6379   if (test_mkfs_0 () == -1) {
6380     printf ("test_mkfs_0 FAILED\n");
6381     failed++;
6382   }
6383   test_num++;
6384   printf ("%3d/%3d test_lvcreate_0\n", test_num, nr_tests);
6385   if (test_lvcreate_0 () == -1) {
6386     printf ("test_lvcreate_0 FAILED\n");
6387     failed++;
6388   }
6389   test_num++;
6390   printf ("%3d/%3d test_vgcreate_0\n", test_num, nr_tests);
6391   if (test_vgcreate_0 () == -1) {
6392     printf ("test_vgcreate_0 FAILED\n");
6393     failed++;
6394   }
6395   test_num++;
6396   printf ("%3d/%3d test_pvcreate_0\n", test_num, nr_tests);
6397   if (test_pvcreate_0 () == -1) {
6398     printf ("test_pvcreate_0 FAILED\n");
6399     failed++;
6400   }
6401   test_num++;
6402   printf ("%3d/%3d test_is_dir_0\n", test_num, nr_tests);
6403   if (test_is_dir_0 () == -1) {
6404     printf ("test_is_dir_0 FAILED\n");
6405     failed++;
6406   }
6407   test_num++;
6408   printf ("%3d/%3d test_is_dir_1\n", test_num, nr_tests);
6409   if (test_is_dir_1 () == -1) {
6410     printf ("test_is_dir_1 FAILED\n");
6411     failed++;
6412   }
6413   test_num++;
6414   printf ("%3d/%3d test_is_file_0\n", test_num, nr_tests);
6415   if (test_is_file_0 () == -1) {
6416     printf ("test_is_file_0 FAILED\n");
6417     failed++;
6418   }
6419   test_num++;
6420   printf ("%3d/%3d test_is_file_1\n", test_num, nr_tests);
6421   if (test_is_file_1 () == -1) {
6422     printf ("test_is_file_1 FAILED\n");
6423     failed++;
6424   }
6425   test_num++;
6426   printf ("%3d/%3d test_exists_0\n", test_num, nr_tests);
6427   if (test_exists_0 () == -1) {
6428     printf ("test_exists_0 FAILED\n");
6429     failed++;
6430   }
6431   test_num++;
6432   printf ("%3d/%3d test_exists_1\n", test_num, nr_tests);
6433   if (test_exists_1 () == -1) {
6434     printf ("test_exists_1 FAILED\n");
6435     failed++;
6436   }
6437   test_num++;
6438   printf ("%3d/%3d test_mkdir_p_0\n", test_num, nr_tests);
6439   if (test_mkdir_p_0 () == -1) {
6440     printf ("test_mkdir_p_0 FAILED\n");
6441     failed++;
6442   }
6443   test_num++;
6444   printf ("%3d/%3d test_mkdir_p_1\n", test_num, nr_tests);
6445   if (test_mkdir_p_1 () == -1) {
6446     printf ("test_mkdir_p_1 FAILED\n");
6447     failed++;
6448   }
6449   test_num++;
6450   printf ("%3d/%3d test_mkdir_p_2\n", test_num, nr_tests);
6451   if (test_mkdir_p_2 () == -1) {
6452     printf ("test_mkdir_p_2 FAILED\n");
6453     failed++;
6454   }
6455   test_num++;
6456   printf ("%3d/%3d test_mkdir_0\n", test_num, nr_tests);
6457   if (test_mkdir_0 () == -1) {
6458     printf ("test_mkdir_0 FAILED\n");
6459     failed++;
6460   }
6461   test_num++;
6462   printf ("%3d/%3d test_mkdir_1\n", test_num, nr_tests);
6463   if (test_mkdir_1 () == -1) {
6464     printf ("test_mkdir_1 FAILED\n");
6465     failed++;
6466   }
6467   test_num++;
6468   printf ("%3d/%3d test_rm_rf_0\n", test_num, nr_tests);
6469   if (test_rm_rf_0 () == -1) {
6470     printf ("test_rm_rf_0 FAILED\n");
6471     failed++;
6472   }
6473   test_num++;
6474   printf ("%3d/%3d test_rmdir_0\n", test_num, nr_tests);
6475   if (test_rmdir_0 () == -1) {
6476     printf ("test_rmdir_0 FAILED\n");
6477     failed++;
6478   }
6479   test_num++;
6480   printf ("%3d/%3d test_rmdir_1\n", test_num, nr_tests);
6481   if (test_rmdir_1 () == -1) {
6482     printf ("test_rmdir_1 FAILED\n");
6483     failed++;
6484   }
6485   test_num++;
6486   printf ("%3d/%3d test_rmdir_2\n", test_num, nr_tests);
6487   if (test_rmdir_2 () == -1) {
6488     printf ("test_rmdir_2 FAILED\n");
6489     failed++;
6490   }
6491   test_num++;
6492   printf ("%3d/%3d test_rm_0\n", test_num, nr_tests);
6493   if (test_rm_0 () == -1) {
6494     printf ("test_rm_0 FAILED\n");
6495     failed++;
6496   }
6497   test_num++;
6498   printf ("%3d/%3d test_rm_1\n", test_num, nr_tests);
6499   if (test_rm_1 () == -1) {
6500     printf ("test_rm_1 FAILED\n");
6501     failed++;
6502   }
6503   test_num++;
6504   printf ("%3d/%3d test_rm_2\n", test_num, nr_tests);
6505   if (test_rm_2 () == -1) {
6506     printf ("test_rm_2 FAILED\n");
6507     failed++;
6508   }
6509   test_num++;
6510   printf ("%3d/%3d test_read_lines_0\n", test_num, nr_tests);
6511   if (test_read_lines_0 () == -1) {
6512     printf ("test_read_lines_0 FAILED\n");
6513     failed++;
6514   }
6515   test_num++;
6516   printf ("%3d/%3d test_read_lines_1\n", test_num, nr_tests);
6517   if (test_read_lines_1 () == -1) {
6518     printf ("test_read_lines_1 FAILED\n");
6519     failed++;
6520   }
6521   test_num++;
6522   printf ("%3d/%3d test_lvs_0\n", test_num, nr_tests);
6523   if (test_lvs_0 () == -1) {
6524     printf ("test_lvs_0 FAILED\n");
6525     failed++;
6526   }
6527   test_num++;
6528   printf ("%3d/%3d test_lvs_1\n", test_num, nr_tests);
6529   if (test_lvs_1 () == -1) {
6530     printf ("test_lvs_1 FAILED\n");
6531     failed++;
6532   }
6533   test_num++;
6534   printf ("%3d/%3d test_vgs_0\n", test_num, nr_tests);
6535   if (test_vgs_0 () == -1) {
6536     printf ("test_vgs_0 FAILED\n");
6537     failed++;
6538   }
6539   test_num++;
6540   printf ("%3d/%3d test_vgs_1\n", test_num, nr_tests);
6541   if (test_vgs_1 () == -1) {
6542     printf ("test_vgs_1 FAILED\n");
6543     failed++;
6544   }
6545   test_num++;
6546   printf ("%3d/%3d test_pvs_0\n", test_num, nr_tests);
6547   if (test_pvs_0 () == -1) {
6548     printf ("test_pvs_0 FAILED\n");
6549     failed++;
6550   }
6551   test_num++;
6552   printf ("%3d/%3d test_pvs_1\n", test_num, nr_tests);
6553   if (test_pvs_1 () == -1) {
6554     printf ("test_pvs_1 FAILED\n");
6555     failed++;
6556   }
6557   test_num++;
6558   printf ("%3d/%3d test_list_partitions_0\n", test_num, nr_tests);
6559   if (test_list_partitions_0 () == -1) {
6560     printf ("test_list_partitions_0 FAILED\n");
6561     failed++;
6562   }
6563   test_num++;
6564   printf ("%3d/%3d test_list_partitions_1\n", test_num, nr_tests);
6565   if (test_list_partitions_1 () == -1) {
6566     printf ("test_list_partitions_1 FAILED\n");
6567     failed++;
6568   }
6569   test_num++;
6570   printf ("%3d/%3d test_list_devices_0\n", test_num, nr_tests);
6571   if (test_list_devices_0 () == -1) {
6572     printf ("test_list_devices_0 FAILED\n");
6573     failed++;
6574   }
6575   test_num++;
6576   printf ("%3d/%3d test_ls_0\n", test_num, nr_tests);
6577   if (test_ls_0 () == -1) {
6578     printf ("test_ls_0 FAILED\n");
6579     failed++;
6580   }
6581   test_num++;
6582   printf ("%3d/%3d test_cat_0\n", test_num, nr_tests);
6583   if (test_cat_0 () == -1) {
6584     printf ("test_cat_0 FAILED\n");
6585     failed++;
6586   }
6587   test_num++;
6588   printf ("%3d/%3d test_touch_0\n", test_num, nr_tests);
6589   if (test_touch_0 () == -1) {
6590     printf ("test_touch_0 FAILED\n");
6591     failed++;
6592   }
6593   test_num++;
6594   printf ("%3d/%3d test_sync_0\n", test_num, nr_tests);
6595   if (test_sync_0 () == -1) {
6596     printf ("test_sync_0 FAILED\n");
6597     failed++;
6598   }
6599   test_num++;
6600   printf ("%3d/%3d test_mount_0\n", test_num, nr_tests);
6601   if (test_mount_0 () == -1) {
6602     printf ("test_mount_0 FAILED\n");
6603     failed++;
6604   }
6605
6606   guestfs_close (g);
6607   unlink ("test1.img");
6608   unlink ("test2.img");
6609   unlink ("test3.img");
6610
6611   if (failed > 0) {
6612     printf ("***** %d / %d tests FAILED *****\n", failed, nr_tests);
6613     exit (1);
6614   }
6615
6616   exit (0);
6617 }