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