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