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