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