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