f1cf32a6b568956d6b0121d77fa887aa89b86a0d
[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_path\" has no tests\n");
67   fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n");
68   fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n");
69   fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n");
70   fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n");
71   fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n");
72   fprintf (stderr, "warning: \"guestfs_is_ready\" has no tests\n");
73   fprintf (stderr, "warning: \"guestfs_is_config\" has no tests\n");
74   fprintf (stderr, "warning: \"guestfs_is_launching\" has no tests\n");
75   fprintf (stderr, "warning: \"guestfs_is_busy\" has no tests\n");
76   fprintf (stderr, "warning: \"guestfs_get_state\" has no tests\n");
77   fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n");
78   fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n");
79   fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n");
80   fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n");
81   fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n");
82   fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n");
83   fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n");
84   fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n");
85   fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n");
86   fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n");
87   fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n");
88   fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n");
89   fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n");
90   fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n");
91   fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n");
92   fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n");
93   fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n");
94   fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n");
95   fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n");
96   fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n");
97   fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n");
98   fprintf (stderr, "warning: \"guestfs_command\" has no tests\n");
99   fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n");
100   fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
101   fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
102   fprintf (stderr, "warning: \"guestfs_upload\" has no tests\n");
103   fprintf (stderr, "warning: \"guestfs_download\" has no tests\n");
104 }
105
106 static int test_blockdev_rereadpt_0 (void)
107 {
108   /* InitEmpty for blockdev_rereadpt (0) */
109   {
110     int r;
111     suppress_error = 0;
112     r = guestfs_umount_all (g);
113     if (r == -1)
114       return -1;
115   }
116   {
117     int r;
118     suppress_error = 0;
119     r = guestfs_lvm_remove_all (g);
120     if (r == -1)
121       return -1;
122   }
123   /* TestRun for blockdev_rereadpt (0) */
124   {
125     int r;
126     suppress_error = 0;
127     r = guestfs_blockdev_rereadpt (g, "/dev/sda");
128     if (r == -1)
129       return -1;
130   }
131   return 0;
132 }
133
134 static int test_blockdev_flushbufs_0 (void)
135 {
136   /* InitEmpty for blockdev_flushbufs (0) */
137   {
138     int r;
139     suppress_error = 0;
140     r = guestfs_umount_all (g);
141     if (r == -1)
142       return -1;
143   }
144   {
145     int r;
146     suppress_error = 0;
147     r = guestfs_lvm_remove_all (g);
148     if (r == -1)
149       return -1;
150   }
151   /* TestRun for blockdev_flushbufs (0) */
152   {
153     int r;
154     suppress_error = 0;
155     r = guestfs_blockdev_flushbufs (g, "/dev/sda");
156     if (r == -1)
157       return -1;
158   }
159   return 0;
160 }
161
162 static int test_blockdev_getsize64_0 (void)
163 {
164   /* InitEmpty for blockdev_getsize64 (0) */
165   {
166     int r;
167     suppress_error = 0;
168     r = guestfs_umount_all (g);
169     if (r == -1)
170       return -1;
171   }
172   {
173     int r;
174     suppress_error = 0;
175     r = guestfs_lvm_remove_all (g);
176     if (r == -1)
177       return -1;
178   }
179   /* TestOutputInt for blockdev_getsize64 (0) */
180   {
181     int64_t r;
182     suppress_error = 0;
183     r = guestfs_blockdev_getsize64 (g, "/dev/sda");
184     if (r == -1)
185       return -1;
186     if (r != 524288000) {
187       fprintf (stderr, "test_blockdev_getsize64_0: expected 524288000 but got %d\n",               (int) r);
188       return -1;
189     }
190   }
191   return 0;
192 }
193
194 static int test_blockdev_getsz_0 (void)
195 {
196   /* InitEmpty for blockdev_getsz (0) */
197   {
198     int r;
199     suppress_error = 0;
200     r = guestfs_umount_all (g);
201     if (r == -1)
202       return -1;
203   }
204   {
205     int r;
206     suppress_error = 0;
207     r = guestfs_lvm_remove_all (g);
208     if (r == -1)
209       return -1;
210   }
211   /* TestOutputInt for blockdev_getsz (0) */
212   {
213     int64_t r;
214     suppress_error = 0;
215     r = guestfs_blockdev_getsz (g, "/dev/sda");
216     if (r == -1)
217       return -1;
218     if (r != 1024000) {
219       fprintf (stderr, "test_blockdev_getsz_0: expected 1024000 but got %d\n",               (int) r);
220       return -1;
221     }
222   }
223   return 0;
224 }
225
226 static int test_blockdev_getbsz_0 (void)
227 {
228   /* InitEmpty for blockdev_getbsz (0) */
229   {
230     int r;
231     suppress_error = 0;
232     r = guestfs_umount_all (g);
233     if (r == -1)
234       return -1;
235   }
236   {
237     int r;
238     suppress_error = 0;
239     r = guestfs_lvm_remove_all (g);
240     if (r == -1)
241       return -1;
242   }
243   /* TestOutputInt for blockdev_getbsz (0) */
244   {
245     int r;
246     suppress_error = 0;
247     r = guestfs_blockdev_getbsz (g, "/dev/sda");
248     if (r == -1)
249       return -1;
250     if (r != 4096) {
251       fprintf (stderr, "test_blockdev_getbsz_0: expected 4096 but got %d\n",               (int) r);
252       return -1;
253     }
254   }
255   return 0;
256 }
257
258 static int test_blockdev_getss_0 (void)
259 {
260   /* InitEmpty for blockdev_getss (0) */
261   {
262     int r;
263     suppress_error = 0;
264     r = guestfs_umount_all (g);
265     if (r == -1)
266       return -1;
267   }
268   {
269     int r;
270     suppress_error = 0;
271     r = guestfs_lvm_remove_all (g);
272     if (r == -1)
273       return -1;
274   }
275   /* TestOutputInt for blockdev_getss (0) */
276   {
277     int r;
278     suppress_error = 0;
279     r = guestfs_blockdev_getss (g, "/dev/sda");
280     if (r == -1)
281       return -1;
282     if (r != 512) {
283       fprintf (stderr, "test_blockdev_getss_0: expected 512 but got %d\n",               (int) r);
284       return -1;
285     }
286   }
287   return 0;
288 }
289
290 static int test_blockdev_getro_0 (void)
291 {
292   /* InitEmpty for blockdev_getro (0) */
293   {
294     int r;
295     suppress_error = 0;
296     r = guestfs_umount_all (g);
297     if (r == -1)
298       return -1;
299   }
300   {
301     int r;
302     suppress_error = 0;
303     r = guestfs_lvm_remove_all (g);
304     if (r == -1)
305       return -1;
306   }
307   /* TestOutputTrue for blockdev_getro (0) */
308   {
309     int r;
310     suppress_error = 0;
311     r = guestfs_blockdev_setro (g, "/dev/sda");
312     if (r == -1)
313       return -1;
314   }
315   {
316     int r;
317     suppress_error = 0;
318     r = guestfs_blockdev_getro (g, "/dev/sda");
319     if (r == -1)
320       return -1;
321     if (!r) {
322       fprintf (stderr, "test_blockdev_getro_0: expected true, got false\n");
323       return -1;
324     }
325   }
326   return 0;
327 }
328
329 static int test_blockdev_setrw_0 (void)
330 {
331   /* InitEmpty for blockdev_setrw (0) */
332   {
333     int r;
334     suppress_error = 0;
335     r = guestfs_umount_all (g);
336     if (r == -1)
337       return -1;
338   }
339   {
340     int r;
341     suppress_error = 0;
342     r = guestfs_lvm_remove_all (g);
343     if (r == -1)
344       return -1;
345   }
346   /* TestOutputFalse for blockdev_setrw (0) */
347   {
348     int r;
349     suppress_error = 0;
350     r = guestfs_blockdev_setrw (g, "/dev/sda");
351     if (r == -1)
352       return -1;
353   }
354   {
355     int r;
356     suppress_error = 0;
357     r = guestfs_blockdev_getro (g, "/dev/sda");
358     if (r == -1)
359       return -1;
360     if (r) {
361       fprintf (stderr, "test_blockdev_setrw_0: expected false, got true\n");
362       return -1;
363     }
364   }
365   return 0;
366 }
367
368 static int test_blockdev_setro_0 (void)
369 {
370   /* InitEmpty for blockdev_setro (0) */
371   {
372     int r;
373     suppress_error = 0;
374     r = guestfs_umount_all (g);
375     if (r == -1)
376       return -1;
377   }
378   {
379     int r;
380     suppress_error = 0;
381     r = guestfs_lvm_remove_all (g);
382     if (r == -1)
383       return -1;
384   }
385   /* TestOutputTrue for blockdev_setro (0) */
386   {
387     int r;
388     suppress_error = 0;
389     r = guestfs_blockdev_setro (g, "/dev/sda");
390     if (r == -1)
391       return -1;
392   }
393   {
394     int r;
395     suppress_error = 0;
396     r = guestfs_blockdev_getro (g, "/dev/sda");
397     if (r == -1)
398       return -1;
399     if (!r) {
400       fprintf (stderr, "test_blockdev_setro_0: expected true, got false\n");
401       return -1;
402     }
403   }
404   return 0;
405 }
406
407 static int test_statvfs_0 (void)
408 {
409   /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */
410   {
411     int r;
412     suppress_error = 0;
413     r = guestfs_umount_all (g);
414     if (r == -1)
415       return -1;
416   }
417   {
418     int r;
419     suppress_error = 0;
420     r = guestfs_lvm_remove_all (g);
421     if (r == -1)
422       return -1;
423   }
424   {
425     char *lines[] = {
426       ",",
427       NULL
428     };
429     int r;
430     suppress_error = 0;
431     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
432     if (r == -1)
433       return -1;
434   }
435   {
436     int r;
437     suppress_error = 0;
438     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
439     if (r == -1)
440       return -1;
441   }
442   {
443     int r;
444     suppress_error = 0;
445     r = guestfs_mount (g, "/dev/sda1", "/");
446     if (r == -1)
447       return -1;
448   }
449   /* TestOutputStruct for statvfs (0) */
450   {
451     struct guestfs_statvfs *r;
452     suppress_error = 0;
453     r = guestfs_statvfs (g, "/");
454     if (r == NULL)
455       return -1;
456     if (r->bfree != 487702) {
457       fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n",
458                (int) r->bfree);
459       return -1;
460     }
461     if (r->blocks != 490020) {
462       fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n",
463                (int) r->blocks);
464       return -1;
465     }
466     if (r->bsize != 1024) {
467       fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n",
468                (int) r->bsize);
469       return -1;
470     }
471     free (r);
472   }
473   return 0;
474 }
475
476 static int test_lstat_0 (void)
477 {
478   /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */
479   {
480     int r;
481     suppress_error = 0;
482     r = guestfs_umount_all (g);
483     if (r == -1)
484       return -1;
485   }
486   {
487     int r;
488     suppress_error = 0;
489     r = guestfs_lvm_remove_all (g);
490     if (r == -1)
491       return -1;
492   }
493   {
494     char *lines[] = {
495       ",",
496       NULL
497     };
498     int r;
499     suppress_error = 0;
500     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
501     if (r == -1)
502       return -1;
503   }
504   {
505     int r;
506     suppress_error = 0;
507     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
508     if (r == -1)
509       return -1;
510   }
511   {
512     int r;
513     suppress_error = 0;
514     r = guestfs_mount (g, "/dev/sda1", "/");
515     if (r == -1)
516       return -1;
517   }
518   /* TestOutputStruct for lstat (0) */
519   {
520     int r;
521     suppress_error = 0;
522     r = guestfs_touch (g, "/new");
523     if (r == -1)
524       return -1;
525   }
526   {
527     struct guestfs_stat *r;
528     suppress_error = 0;
529     r = guestfs_lstat (g, "/new");
530     if (r == NULL)
531       return -1;
532     if (r->size != 0) {
533       fprintf (stderr, "test_lstat_0: size was %d, expected 0\n",
534                (int) r->size);
535       return -1;
536     }
537     free (r);
538   }
539   return 0;
540 }
541
542 static int test_stat_0 (void)
543 {
544   /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */
545   {
546     int r;
547     suppress_error = 0;
548     r = guestfs_umount_all (g);
549     if (r == -1)
550       return -1;
551   }
552   {
553     int r;
554     suppress_error = 0;
555     r = guestfs_lvm_remove_all (g);
556     if (r == -1)
557       return -1;
558   }
559   {
560     char *lines[] = {
561       ",",
562       NULL
563     };
564     int r;
565     suppress_error = 0;
566     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
567     if (r == -1)
568       return -1;
569   }
570   {
571     int r;
572     suppress_error = 0;
573     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
574     if (r == -1)
575       return -1;
576   }
577   {
578     int r;
579     suppress_error = 0;
580     r = guestfs_mount (g, "/dev/sda1", "/");
581     if (r == -1)
582       return -1;
583   }
584   /* TestOutputStruct for stat (0) */
585   {
586     int r;
587     suppress_error = 0;
588     r = guestfs_touch (g, "/new");
589     if (r == -1)
590       return -1;
591   }
592   {
593     struct guestfs_stat *r;
594     suppress_error = 0;
595     r = guestfs_stat (g, "/new");
596     if (r == NULL)
597       return -1;
598     if (r->size != 0) {
599       fprintf (stderr, "test_stat_0: size was %d, expected 0\n",
600                (int) r->size);
601       return -1;
602     }
603     free (r);
604   }
605   return 0;
606 }
607
608 static int test_file_0 (void)
609 {
610   /* InitBasicFS for file (0): create ext2 on /dev/sda1 */
611   {
612     int r;
613     suppress_error = 0;
614     r = guestfs_umount_all (g);
615     if (r == -1)
616       return -1;
617   }
618   {
619     int r;
620     suppress_error = 0;
621     r = guestfs_lvm_remove_all (g);
622     if (r == -1)
623       return -1;
624   }
625   {
626     char *lines[] = {
627       ",",
628       NULL
629     };
630     int r;
631     suppress_error = 0;
632     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
633     if (r == -1)
634       return -1;
635   }
636   {
637     int r;
638     suppress_error = 0;
639     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
640     if (r == -1)
641       return -1;
642   }
643   {
644     int r;
645     suppress_error = 0;
646     r = guestfs_mount (g, "/dev/sda1", "/");
647     if (r == -1)
648       return -1;
649   }
650   /* TestOutput for file (0) */
651   {
652     int r;
653     suppress_error = 0;
654     r = guestfs_touch (g, "/new");
655     if (r == -1)
656       return -1;
657   }
658   {
659     char *r;
660     suppress_error = 0;
661     r = guestfs_file (g, "/new");
662     if (r == NULL)
663       return -1;
664     if (strcmp (r, "empty") != 0) {
665       fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r);
666       return -1;
667     }
668     free (r);
669   }
670   return 0;
671 }
672
673 static int test_file_1 (void)
674 {
675   /* InitBasicFS for file (1): create ext2 on /dev/sda1 */
676   {
677     int r;
678     suppress_error = 0;
679     r = guestfs_umount_all (g);
680     if (r == -1)
681       return -1;
682   }
683   {
684     int r;
685     suppress_error = 0;
686     r = guestfs_lvm_remove_all (g);
687     if (r == -1)
688       return -1;
689   }
690   {
691     char *lines[] = {
692       ",",
693       NULL
694     };
695     int r;
696     suppress_error = 0;
697     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
698     if (r == -1)
699       return -1;
700   }
701   {
702     int r;
703     suppress_error = 0;
704     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
705     if (r == -1)
706       return -1;
707   }
708   {
709     int r;
710     suppress_error = 0;
711     r = guestfs_mount (g, "/dev/sda1", "/");
712     if (r == -1)
713       return -1;
714   }
715   /* TestOutput for file (1) */
716   {
717     int r;
718     suppress_error = 0;
719     r = guestfs_write_file (g, "/new", "some content\n", 0);
720     if (r == -1)
721       return -1;
722   }
723   {
724     char *r;
725     suppress_error = 0;
726     r = guestfs_file (g, "/new");
727     if (r == NULL)
728       return -1;
729     if (strcmp (r, "ASCII text") != 0) {
730       fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r);
731       return -1;
732     }
733     free (r);
734   }
735   return 0;
736 }
737
738 static int test_file_2 (void)
739 {
740   /* InitBasicFS for file (2): create ext2 on /dev/sda1 */
741   {
742     int r;
743     suppress_error = 0;
744     r = guestfs_umount_all (g);
745     if (r == -1)
746       return -1;
747   }
748   {
749     int r;
750     suppress_error = 0;
751     r = guestfs_lvm_remove_all (g);
752     if (r == -1)
753       return -1;
754   }
755   {
756     char *lines[] = {
757       ",",
758       NULL
759     };
760     int r;
761     suppress_error = 0;
762     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
763     if (r == -1)
764       return -1;
765   }
766   {
767     int r;
768     suppress_error = 0;
769     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
770     if (r == -1)
771       return -1;
772   }
773   {
774     int r;
775     suppress_error = 0;
776     r = guestfs_mount (g, "/dev/sda1", "/");
777     if (r == -1)
778       return -1;
779   }
780   /* TestLastFail for file (2) */
781   {
782     char *r;
783     suppress_error = 1;
784     r = guestfs_file (g, "/nofile");
785     if (r != NULL)
786       return -1;
787     free (r);
788   }
789   return 0;
790 }
791
792 static int test_umount_all_0 (void)
793 {
794   /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */
795   {
796     int r;
797     suppress_error = 0;
798     r = guestfs_umount_all (g);
799     if (r == -1)
800       return -1;
801   }
802   {
803     int r;
804     suppress_error = 0;
805     r = guestfs_lvm_remove_all (g);
806     if (r == -1)
807       return -1;
808   }
809   {
810     char *lines[] = {
811       ",",
812       NULL
813     };
814     int r;
815     suppress_error = 0;
816     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
817     if (r == -1)
818       return -1;
819   }
820   {
821     int r;
822     suppress_error = 0;
823     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
824     if (r == -1)
825       return -1;
826   }
827   {
828     int r;
829     suppress_error = 0;
830     r = guestfs_mount (g, "/dev/sda1", "/");
831     if (r == -1)
832       return -1;
833   }
834   /* TestOutputList for umount_all (0) */
835   {
836     int r;
837     suppress_error = 0;
838     r = guestfs_umount_all (g);
839     if (r == -1)
840       return -1;
841   }
842   {
843     char **r;
844     int i;
845     suppress_error = 0;
846     r = guestfs_mounts (g);
847     if (r == NULL)
848       return -1;
849     if (r[0] != NULL) {
850       fprintf (stderr, "test_umount_all_0: extra elements returned from command\n");
851       print_strings (r);
852       return -1;
853     }
854     for (i = 0; r[i] != NULL; ++i)
855       free (r[i]);
856     free (r);
857   }
858   return 0;
859 }
860
861 static int test_mounts_0 (void)
862 {
863   /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */
864   {
865     int r;
866     suppress_error = 0;
867     r = guestfs_umount_all (g);
868     if (r == -1)
869       return -1;
870   }
871   {
872     int r;
873     suppress_error = 0;
874     r = guestfs_lvm_remove_all (g);
875     if (r == -1)
876       return -1;
877   }
878   {
879     char *lines[] = {
880       ",",
881       NULL
882     };
883     int r;
884     suppress_error = 0;
885     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
886     if (r == -1)
887       return -1;
888   }
889   {
890     int r;
891     suppress_error = 0;
892     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
893     if (r == -1)
894       return -1;
895   }
896   {
897     int r;
898     suppress_error = 0;
899     r = guestfs_mount (g, "/dev/sda1", "/");
900     if (r == -1)
901       return -1;
902   }
903   /* TestOutputList for mounts (0) */
904   {
905     char **r;
906     int i;
907     suppress_error = 0;
908     r = guestfs_mounts (g);
909     if (r == NULL)
910       return -1;
911     if (!r[0]) {
912       fprintf (stderr, "test_mounts_0: short list returned from command\n");
913       print_strings (r);
914       return -1;
915     }
916     if (strcmp (r[0], "/dev/sda1") != 0) {
917       fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
918       return -1;
919     }
920     if (r[1] != NULL) {
921       fprintf (stderr, "test_mounts_0: extra elements returned from command\n");
922       print_strings (r);
923       return -1;
924     }
925     for (i = 0; r[i] != NULL; ++i)
926       free (r[i]);
927     free (r);
928   }
929   return 0;
930 }
931
932 static int test_umount_0 (void)
933 {
934   /* InitEmpty for umount (0) */
935   {
936     int r;
937     suppress_error = 0;
938     r = guestfs_umount_all (g);
939     if (r == -1)
940       return -1;
941   }
942   {
943     int r;
944     suppress_error = 0;
945     r = guestfs_lvm_remove_all (g);
946     if (r == -1)
947       return -1;
948   }
949   /* TestOutputList for umount (0) */
950   {
951     char *lines[] = {
952       ",",
953       NULL
954     };
955     int r;
956     suppress_error = 0;
957     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
958     if (r == -1)
959       return -1;
960   }
961   {
962     int r;
963     suppress_error = 0;
964     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
965     if (r == -1)
966       return -1;
967   }
968   {
969     int r;
970     suppress_error = 0;
971     r = guestfs_mount (g, "/dev/sda1", "/");
972     if (r == -1)
973       return -1;
974   }
975   {
976     char **r;
977     int i;
978     suppress_error = 0;
979     r = guestfs_mounts (g);
980     if (r == NULL)
981       return -1;
982     if (!r[0]) {
983       fprintf (stderr, "test_umount_0: short list returned from command\n");
984       print_strings (r);
985       return -1;
986     }
987     if (strcmp (r[0], "/dev/sda1") != 0) {
988       fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
989       return -1;
990     }
991     if (r[1] != NULL) {
992       fprintf (stderr, "test_umount_0: extra elements returned from command\n");
993       print_strings (r);
994       return -1;
995     }
996     for (i = 0; r[i] != NULL; ++i)
997       free (r[i]);
998     free (r);
999   }
1000   return 0;
1001 }
1002
1003 static int test_umount_1 (void)
1004 {
1005   /* InitEmpty for umount (1) */
1006   {
1007     int r;
1008     suppress_error = 0;
1009     r = guestfs_umount_all (g);
1010     if (r == -1)
1011       return -1;
1012   }
1013   {
1014     int r;
1015     suppress_error = 0;
1016     r = guestfs_lvm_remove_all (g);
1017     if (r == -1)
1018       return -1;
1019   }
1020   /* TestOutputList for umount (1) */
1021   {
1022     char *lines[] = {
1023       ",",
1024       NULL
1025     };
1026     int r;
1027     suppress_error = 0;
1028     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1029     if (r == -1)
1030       return -1;
1031   }
1032   {
1033     int r;
1034     suppress_error = 0;
1035     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1036     if (r == -1)
1037       return -1;
1038   }
1039   {
1040     int r;
1041     suppress_error = 0;
1042     r = guestfs_mount (g, "/dev/sda1", "/");
1043     if (r == -1)
1044       return -1;
1045   }
1046   {
1047     int r;
1048     suppress_error = 0;
1049     r = guestfs_umount (g, "/");
1050     if (r == -1)
1051       return -1;
1052   }
1053   {
1054     char **r;
1055     int i;
1056     suppress_error = 0;
1057     r = guestfs_mounts (g);
1058     if (r == NULL)
1059       return -1;
1060     if (r[0] != NULL) {
1061       fprintf (stderr, "test_umount_1: extra elements returned from command\n");
1062       print_strings (r);
1063       return -1;
1064     }
1065     for (i = 0; r[i] != NULL; ++i)
1066       free (r[i]);
1067     free (r);
1068   }
1069   return 0;
1070 }
1071
1072 static int test_write_file_0 (void)
1073 {
1074   /* InitBasicFS for write_file (0): create ext2 on /dev/sda1 */
1075   {
1076     int r;
1077     suppress_error = 0;
1078     r = guestfs_umount_all (g);
1079     if (r == -1)
1080       return -1;
1081   }
1082   {
1083     int r;
1084     suppress_error = 0;
1085     r = guestfs_lvm_remove_all (g);
1086     if (r == -1)
1087       return -1;
1088   }
1089   {
1090     char *lines[] = {
1091       ",",
1092       NULL
1093     };
1094     int r;
1095     suppress_error = 0;
1096     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1097     if (r == -1)
1098       return -1;
1099   }
1100   {
1101     int r;
1102     suppress_error = 0;
1103     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1104     if (r == -1)
1105       return -1;
1106   }
1107   {
1108     int r;
1109     suppress_error = 0;
1110     r = guestfs_mount (g, "/dev/sda1", "/");
1111     if (r == -1)
1112       return -1;
1113   }
1114   /* TestOutput for write_file (0) */
1115   {
1116     int r;
1117     suppress_error = 0;
1118     r = guestfs_write_file (g, "/new", "new file contents", 0);
1119     if (r == -1)
1120       return -1;
1121   }
1122   {
1123     char *r;
1124     suppress_error = 0;
1125     r = guestfs_cat (g, "/new");
1126     if (r == NULL)
1127       return -1;
1128     if (strcmp (r, "new file contents") != 0) {
1129       fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r);
1130       return -1;
1131     }
1132     free (r);
1133   }
1134   return 0;
1135 }
1136
1137 static int test_write_file_1 (void)
1138 {
1139   /* InitBasicFS for write_file (1): create ext2 on /dev/sda1 */
1140   {
1141     int r;
1142     suppress_error = 0;
1143     r = guestfs_umount_all (g);
1144     if (r == -1)
1145       return -1;
1146   }
1147   {
1148     int r;
1149     suppress_error = 0;
1150     r = guestfs_lvm_remove_all (g);
1151     if (r == -1)
1152       return -1;
1153   }
1154   {
1155     char *lines[] = {
1156       ",",
1157       NULL
1158     };
1159     int r;
1160     suppress_error = 0;
1161     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1162     if (r == -1)
1163       return -1;
1164   }
1165   {
1166     int r;
1167     suppress_error = 0;
1168     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1169     if (r == -1)
1170       return -1;
1171   }
1172   {
1173     int r;
1174     suppress_error = 0;
1175     r = guestfs_mount (g, "/dev/sda1", "/");
1176     if (r == -1)
1177       return -1;
1178   }
1179   /* TestOutput for write_file (1) */
1180   {
1181     int r;
1182     suppress_error = 0;
1183     r = guestfs_write_file (g, "/new", "\nnew file contents\n", 0);
1184     if (r == -1)
1185       return -1;
1186   }
1187   {
1188     char *r;
1189     suppress_error = 0;
1190     r = guestfs_cat (g, "/new");
1191     if (r == NULL)
1192       return -1;
1193     if (strcmp (r, "\nnew file contents\n") != 0) {
1194       fprintf (stderr, "test_write_file_1: expected \"\nnew file contents\n\" but got \"%s\"\n", r);
1195       return -1;
1196     }
1197     free (r);
1198   }
1199   return 0;
1200 }
1201
1202 static int test_write_file_2 (void)
1203 {
1204   /* InitBasicFS for write_file (2): create ext2 on /dev/sda1 */
1205   {
1206     int r;
1207     suppress_error = 0;
1208     r = guestfs_umount_all (g);
1209     if (r == -1)
1210       return -1;
1211   }
1212   {
1213     int r;
1214     suppress_error = 0;
1215     r = guestfs_lvm_remove_all (g);
1216     if (r == -1)
1217       return -1;
1218   }
1219   {
1220     char *lines[] = {
1221       ",",
1222       NULL
1223     };
1224     int r;
1225     suppress_error = 0;
1226     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1227     if (r == -1)
1228       return -1;
1229   }
1230   {
1231     int r;
1232     suppress_error = 0;
1233     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1234     if (r == -1)
1235       return -1;
1236   }
1237   {
1238     int r;
1239     suppress_error = 0;
1240     r = guestfs_mount (g, "/dev/sda1", "/");
1241     if (r == -1)
1242       return -1;
1243   }
1244   /* TestOutput for write_file (2) */
1245   {
1246     int r;
1247     suppress_error = 0;
1248     r = guestfs_write_file (g, "/new", "\n\n", 0);
1249     if (r == -1)
1250       return -1;
1251   }
1252   {
1253     char *r;
1254     suppress_error = 0;
1255     r = guestfs_cat (g, "/new");
1256     if (r == NULL)
1257       return -1;
1258     if (strcmp (r, "\n\n") != 0) {
1259       fprintf (stderr, "test_write_file_2: expected \"\n\n\" but got \"%s\"\n", r);
1260       return -1;
1261     }
1262     free (r);
1263   }
1264   return 0;
1265 }
1266
1267 static int test_write_file_3 (void)
1268 {
1269   /* InitBasicFS for write_file (3): create ext2 on /dev/sda1 */
1270   {
1271     int r;
1272     suppress_error = 0;
1273     r = guestfs_umount_all (g);
1274     if (r == -1)
1275       return -1;
1276   }
1277   {
1278     int r;
1279     suppress_error = 0;
1280     r = guestfs_lvm_remove_all (g);
1281     if (r == -1)
1282       return -1;
1283   }
1284   {
1285     char *lines[] = {
1286       ",",
1287       NULL
1288     };
1289     int r;
1290     suppress_error = 0;
1291     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1292     if (r == -1)
1293       return -1;
1294   }
1295   {
1296     int r;
1297     suppress_error = 0;
1298     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1299     if (r == -1)
1300       return -1;
1301   }
1302   {
1303     int r;
1304     suppress_error = 0;
1305     r = guestfs_mount (g, "/dev/sda1", "/");
1306     if (r == -1)
1307       return -1;
1308   }
1309   /* TestOutput for write_file (3) */
1310   {
1311     int r;
1312     suppress_error = 0;
1313     r = guestfs_write_file (g, "/new", "", 0);
1314     if (r == -1)
1315       return -1;
1316   }
1317   {
1318     char *r;
1319     suppress_error = 0;
1320     r = guestfs_cat (g, "/new");
1321     if (r == NULL)
1322       return -1;
1323     if (strcmp (r, "") != 0) {
1324       fprintf (stderr, "test_write_file_3: expected \"\" but got \"%s\"\n", r);
1325       return -1;
1326     }
1327     free (r);
1328   }
1329   return 0;
1330 }
1331
1332 static int test_write_file_4 (void)
1333 {
1334   /* InitBasicFS for write_file (4): create ext2 on /dev/sda1 */
1335   {
1336     int r;
1337     suppress_error = 0;
1338     r = guestfs_umount_all (g);
1339     if (r == -1)
1340       return -1;
1341   }
1342   {
1343     int r;
1344     suppress_error = 0;
1345     r = guestfs_lvm_remove_all (g);
1346     if (r == -1)
1347       return -1;
1348   }
1349   {
1350     char *lines[] = {
1351       ",",
1352       NULL
1353     };
1354     int r;
1355     suppress_error = 0;
1356     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1357     if (r == -1)
1358       return -1;
1359   }
1360   {
1361     int r;
1362     suppress_error = 0;
1363     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1364     if (r == -1)
1365       return -1;
1366   }
1367   {
1368     int r;
1369     suppress_error = 0;
1370     r = guestfs_mount (g, "/dev/sda1", "/");
1371     if (r == -1)
1372       return -1;
1373   }
1374   /* TestOutput for write_file (4) */
1375   {
1376     int r;
1377     suppress_error = 0;
1378     r = guestfs_write_file (g, "/new", "\n\n\n", 0);
1379     if (r == -1)
1380       return -1;
1381   }
1382   {
1383     char *r;
1384     suppress_error = 0;
1385     r = guestfs_cat (g, "/new");
1386     if (r == NULL)
1387       return -1;
1388     if (strcmp (r, "\n\n\n") != 0) {
1389       fprintf (stderr, "test_write_file_4: expected \"\n\n\n\" but got \"%s\"\n", r);
1390       return -1;
1391     }
1392     free (r);
1393   }
1394   return 0;
1395 }
1396
1397 static int test_write_file_5 (void)
1398 {
1399   /* InitBasicFS for write_file (5): create ext2 on /dev/sda1 */
1400   {
1401     int r;
1402     suppress_error = 0;
1403     r = guestfs_umount_all (g);
1404     if (r == -1)
1405       return -1;
1406   }
1407   {
1408     int r;
1409     suppress_error = 0;
1410     r = guestfs_lvm_remove_all (g);
1411     if (r == -1)
1412       return -1;
1413   }
1414   {
1415     char *lines[] = {
1416       ",",
1417       NULL
1418     };
1419     int r;
1420     suppress_error = 0;
1421     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1422     if (r == -1)
1423       return -1;
1424   }
1425   {
1426     int r;
1427     suppress_error = 0;
1428     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1429     if (r == -1)
1430       return -1;
1431   }
1432   {
1433     int r;
1434     suppress_error = 0;
1435     r = guestfs_mount (g, "/dev/sda1", "/");
1436     if (r == -1)
1437       return -1;
1438   }
1439   /* TestOutput for write_file (5) */
1440   {
1441     int r;
1442     suppress_error = 0;
1443     r = guestfs_write_file (g, "/new", "\n", 0);
1444     if (r == -1)
1445       return -1;
1446   }
1447   {
1448     char *r;
1449     suppress_error = 0;
1450     r = guestfs_cat (g, "/new");
1451     if (r == NULL)
1452       return -1;
1453     if (strcmp (r, "\n") != 0) {
1454       fprintf (stderr, "test_write_file_5: expected \"\n\" but got \"%s\"\n", r);
1455       return -1;
1456     }
1457     free (r);
1458   }
1459   return 0;
1460 }
1461
1462 static int test_mkfs_0 (void)
1463 {
1464   /* InitEmpty for mkfs (0) */
1465   {
1466     int r;
1467     suppress_error = 0;
1468     r = guestfs_umount_all (g);
1469     if (r == -1)
1470       return -1;
1471   }
1472   {
1473     int r;
1474     suppress_error = 0;
1475     r = guestfs_lvm_remove_all (g);
1476     if (r == -1)
1477       return -1;
1478   }
1479   /* TestOutput for mkfs (0) */
1480   {
1481     char *lines[] = {
1482       ",",
1483       NULL
1484     };
1485     int r;
1486     suppress_error = 0;
1487     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1488     if (r == -1)
1489       return -1;
1490   }
1491   {
1492     int r;
1493     suppress_error = 0;
1494     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1495     if (r == -1)
1496       return -1;
1497   }
1498   {
1499     int r;
1500     suppress_error = 0;
1501     r = guestfs_mount (g, "/dev/sda1", "/");
1502     if (r == -1)
1503       return -1;
1504   }
1505   {
1506     int r;
1507     suppress_error = 0;
1508     r = guestfs_write_file (g, "/new", "new file contents", 0);
1509     if (r == -1)
1510       return -1;
1511   }
1512   {
1513     char *r;
1514     suppress_error = 0;
1515     r = guestfs_cat (g, "/new");
1516     if (r == NULL)
1517       return -1;
1518     if (strcmp (r, "new file contents") != 0) {
1519       fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r);
1520       return -1;
1521     }
1522     free (r);
1523   }
1524   return 0;
1525 }
1526
1527 static int test_lvcreate_0 (void)
1528 {
1529   /* InitEmpty for lvcreate (0) */
1530   {
1531     int r;
1532     suppress_error = 0;
1533     r = guestfs_umount_all (g);
1534     if (r == -1)
1535       return -1;
1536   }
1537   {
1538     int r;
1539     suppress_error = 0;
1540     r = guestfs_lvm_remove_all (g);
1541     if (r == -1)
1542       return -1;
1543   }
1544   /* TestOutputList for lvcreate (0) */
1545   {
1546     char *lines[] = {
1547       ",10",
1548       ",20",
1549       ",",
1550       NULL
1551     };
1552     int r;
1553     suppress_error = 0;
1554     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1555     if (r == -1)
1556       return -1;
1557   }
1558   {
1559     int r;
1560     suppress_error = 0;
1561     r = guestfs_pvcreate (g, "/dev/sda1");
1562     if (r == -1)
1563       return -1;
1564   }
1565   {
1566     int r;
1567     suppress_error = 0;
1568     r = guestfs_pvcreate (g, "/dev/sda2");
1569     if (r == -1)
1570       return -1;
1571   }
1572   {
1573     int r;
1574     suppress_error = 0;
1575     r = guestfs_pvcreate (g, "/dev/sda3");
1576     if (r == -1)
1577       return -1;
1578   }
1579   {
1580     char *physvols[] = {
1581       "/dev/sda1",
1582       "/dev/sda2",
1583       NULL
1584     };
1585     int r;
1586     suppress_error = 0;
1587     r = guestfs_vgcreate (g, "VG1", physvols);
1588     if (r == -1)
1589       return -1;
1590   }
1591   {
1592     char *physvols[] = {
1593       "/dev/sda3",
1594       NULL
1595     };
1596     int r;
1597     suppress_error = 0;
1598     r = guestfs_vgcreate (g, "VG2", physvols);
1599     if (r == -1)
1600       return -1;
1601   }
1602   {
1603     int r;
1604     suppress_error = 0;
1605     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
1606     if (r == -1)
1607       return -1;
1608   }
1609   {
1610     int r;
1611     suppress_error = 0;
1612     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
1613     if (r == -1)
1614       return -1;
1615   }
1616   {
1617     int r;
1618     suppress_error = 0;
1619     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
1620     if (r == -1)
1621       return -1;
1622   }
1623   {
1624     int r;
1625     suppress_error = 0;
1626     r = guestfs_lvcreate (g, "LV4", "VG2", 50);
1627     if (r == -1)
1628       return -1;
1629   }
1630   {
1631     int r;
1632     suppress_error = 0;
1633     r = guestfs_lvcreate (g, "LV5", "VG2", 50);
1634     if (r == -1)
1635       return -1;
1636   }
1637   {
1638     char **r;
1639     int i;
1640     suppress_error = 0;
1641     r = guestfs_lvs (g);
1642     if (r == NULL)
1643       return -1;
1644     if (!r[0]) {
1645       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1646       print_strings (r);
1647       return -1;
1648     }
1649     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
1650       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
1651       return -1;
1652     }
1653     if (!r[1]) {
1654       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1655       print_strings (r);
1656       return -1;
1657     }
1658     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
1659       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
1660       return -1;
1661     }
1662     if (!r[2]) {
1663       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1664       print_strings (r);
1665       return -1;
1666     }
1667     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
1668       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
1669       return -1;
1670     }
1671     if (!r[3]) {
1672       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1673       print_strings (r);
1674       return -1;
1675     }
1676     if (strcmp (r[3], "/dev/VG2/LV4") != 0) {
1677       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]);
1678       return -1;
1679     }
1680     if (!r[4]) {
1681       fprintf (stderr, "test_lvcreate_0: short list returned from command\n");
1682       print_strings (r);
1683       return -1;
1684     }
1685     if (strcmp (r[4], "/dev/VG2/LV5") != 0) {
1686       fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]);
1687       return -1;
1688     }
1689     if (r[5] != NULL) {
1690       fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n");
1691       print_strings (r);
1692       return -1;
1693     }
1694     for (i = 0; r[i] != NULL; ++i)
1695       free (r[i]);
1696     free (r);
1697   }
1698   return 0;
1699 }
1700
1701 static int test_vgcreate_0 (void)
1702 {
1703   /* InitEmpty for vgcreate (0) */
1704   {
1705     int r;
1706     suppress_error = 0;
1707     r = guestfs_umount_all (g);
1708     if (r == -1)
1709       return -1;
1710   }
1711   {
1712     int r;
1713     suppress_error = 0;
1714     r = guestfs_lvm_remove_all (g);
1715     if (r == -1)
1716       return -1;
1717   }
1718   /* TestOutputList for vgcreate (0) */
1719   {
1720     char *lines[] = {
1721       ",10",
1722       ",20",
1723       ",",
1724       NULL
1725     };
1726     int r;
1727     suppress_error = 0;
1728     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1729     if (r == -1)
1730       return -1;
1731   }
1732   {
1733     int r;
1734     suppress_error = 0;
1735     r = guestfs_pvcreate (g, "/dev/sda1");
1736     if (r == -1)
1737       return -1;
1738   }
1739   {
1740     int r;
1741     suppress_error = 0;
1742     r = guestfs_pvcreate (g, "/dev/sda2");
1743     if (r == -1)
1744       return -1;
1745   }
1746   {
1747     int r;
1748     suppress_error = 0;
1749     r = guestfs_pvcreate (g, "/dev/sda3");
1750     if (r == -1)
1751       return -1;
1752   }
1753   {
1754     char *physvols[] = {
1755       "/dev/sda1",
1756       "/dev/sda2",
1757       NULL
1758     };
1759     int r;
1760     suppress_error = 0;
1761     r = guestfs_vgcreate (g, "VG1", physvols);
1762     if (r == -1)
1763       return -1;
1764   }
1765   {
1766     char *physvols[] = {
1767       "/dev/sda3",
1768       NULL
1769     };
1770     int r;
1771     suppress_error = 0;
1772     r = guestfs_vgcreate (g, "VG2", physvols);
1773     if (r == -1)
1774       return -1;
1775   }
1776   {
1777     char **r;
1778     int i;
1779     suppress_error = 0;
1780     r = guestfs_vgs (g);
1781     if (r == NULL)
1782       return -1;
1783     if (!r[0]) {
1784       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
1785       print_strings (r);
1786       return -1;
1787     }
1788     if (strcmp (r[0], "VG1") != 0) {
1789       fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]);
1790       return -1;
1791     }
1792     if (!r[1]) {
1793       fprintf (stderr, "test_vgcreate_0: short list returned from command\n");
1794       print_strings (r);
1795       return -1;
1796     }
1797     if (strcmp (r[1], "VG2") != 0) {
1798       fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]);
1799       return -1;
1800     }
1801     if (r[2] != NULL) {
1802       fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n");
1803       print_strings (r);
1804       return -1;
1805     }
1806     for (i = 0; r[i] != NULL; ++i)
1807       free (r[i]);
1808     free (r);
1809   }
1810   return 0;
1811 }
1812
1813 static int test_pvcreate_0 (void)
1814 {
1815   /* InitEmpty for pvcreate (0) */
1816   {
1817     int r;
1818     suppress_error = 0;
1819     r = guestfs_umount_all (g);
1820     if (r == -1)
1821       return -1;
1822   }
1823   {
1824     int r;
1825     suppress_error = 0;
1826     r = guestfs_lvm_remove_all (g);
1827     if (r == -1)
1828       return -1;
1829   }
1830   /* TestOutputList for pvcreate (0) */
1831   {
1832     char *lines[] = {
1833       ",10",
1834       ",20",
1835       ",",
1836       NULL
1837     };
1838     int r;
1839     suppress_error = 0;
1840     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1841     if (r == -1)
1842       return -1;
1843   }
1844   {
1845     int r;
1846     suppress_error = 0;
1847     r = guestfs_pvcreate (g, "/dev/sda1");
1848     if (r == -1)
1849       return -1;
1850   }
1851   {
1852     int r;
1853     suppress_error = 0;
1854     r = guestfs_pvcreate (g, "/dev/sda2");
1855     if (r == -1)
1856       return -1;
1857   }
1858   {
1859     int r;
1860     suppress_error = 0;
1861     r = guestfs_pvcreate (g, "/dev/sda3");
1862     if (r == -1)
1863       return -1;
1864   }
1865   {
1866     char **r;
1867     int i;
1868     suppress_error = 0;
1869     r = guestfs_pvs (g);
1870     if (r == NULL)
1871       return -1;
1872     if (!r[0]) {
1873       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1874       print_strings (r);
1875       return -1;
1876     }
1877     if (strcmp (r[0], "/dev/sda1") != 0) {
1878       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
1879       return -1;
1880     }
1881     if (!r[1]) {
1882       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1883       print_strings (r);
1884       return -1;
1885     }
1886     if (strcmp (r[1], "/dev/sda2") != 0) {
1887       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
1888       return -1;
1889     }
1890     if (!r[2]) {
1891       fprintf (stderr, "test_pvcreate_0: short list returned from command\n");
1892       print_strings (r);
1893       return -1;
1894     }
1895     if (strcmp (r[2], "/dev/sda3") != 0) {
1896       fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
1897       return -1;
1898     }
1899     if (r[3] != NULL) {
1900       fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n");
1901       print_strings (r);
1902       return -1;
1903     }
1904     for (i = 0; r[i] != NULL; ++i)
1905       free (r[i]);
1906     free (r);
1907   }
1908   return 0;
1909 }
1910
1911 static int test_is_dir_0 (void)
1912 {
1913   /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */
1914   {
1915     int r;
1916     suppress_error = 0;
1917     r = guestfs_umount_all (g);
1918     if (r == -1)
1919       return -1;
1920   }
1921   {
1922     int r;
1923     suppress_error = 0;
1924     r = guestfs_lvm_remove_all (g);
1925     if (r == -1)
1926       return -1;
1927   }
1928   {
1929     char *lines[] = {
1930       ",",
1931       NULL
1932     };
1933     int r;
1934     suppress_error = 0;
1935     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
1936     if (r == -1)
1937       return -1;
1938   }
1939   {
1940     int r;
1941     suppress_error = 0;
1942     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
1943     if (r == -1)
1944       return -1;
1945   }
1946   {
1947     int r;
1948     suppress_error = 0;
1949     r = guestfs_mount (g, "/dev/sda1", "/");
1950     if (r == -1)
1951       return -1;
1952   }
1953   /* TestOutputFalse for is_dir (0) */
1954   {
1955     int r;
1956     suppress_error = 0;
1957     r = guestfs_touch (g, "/new");
1958     if (r == -1)
1959       return -1;
1960   }
1961   {
1962     int r;
1963     suppress_error = 0;
1964     r = guestfs_is_dir (g, "/new");
1965     if (r == -1)
1966       return -1;
1967     if (r) {
1968       fprintf (stderr, "test_is_dir_0: expected false, got true\n");
1969       return -1;
1970     }
1971   }
1972   return 0;
1973 }
1974
1975 static int test_is_dir_1 (void)
1976 {
1977   /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */
1978   {
1979     int r;
1980     suppress_error = 0;
1981     r = guestfs_umount_all (g);
1982     if (r == -1)
1983       return -1;
1984   }
1985   {
1986     int r;
1987     suppress_error = 0;
1988     r = guestfs_lvm_remove_all (g);
1989     if (r == -1)
1990       return -1;
1991   }
1992   {
1993     char *lines[] = {
1994       ",",
1995       NULL
1996     };
1997     int r;
1998     suppress_error = 0;
1999     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2000     if (r == -1)
2001       return -1;
2002   }
2003   {
2004     int r;
2005     suppress_error = 0;
2006     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2007     if (r == -1)
2008       return -1;
2009   }
2010   {
2011     int r;
2012     suppress_error = 0;
2013     r = guestfs_mount (g, "/dev/sda1", "/");
2014     if (r == -1)
2015       return -1;
2016   }
2017   /* TestOutputTrue for is_dir (1) */
2018   {
2019     int r;
2020     suppress_error = 0;
2021     r = guestfs_mkdir (g, "/new");
2022     if (r == -1)
2023       return -1;
2024   }
2025   {
2026     int r;
2027     suppress_error = 0;
2028     r = guestfs_is_dir (g, "/new");
2029     if (r == -1)
2030       return -1;
2031     if (!r) {
2032       fprintf (stderr, "test_is_dir_1: expected true, got false\n");
2033       return -1;
2034     }
2035   }
2036   return 0;
2037 }
2038
2039 static int test_is_file_0 (void)
2040 {
2041   /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */
2042   {
2043     int r;
2044     suppress_error = 0;
2045     r = guestfs_umount_all (g);
2046     if (r == -1)
2047       return -1;
2048   }
2049   {
2050     int r;
2051     suppress_error = 0;
2052     r = guestfs_lvm_remove_all (g);
2053     if (r == -1)
2054       return -1;
2055   }
2056   {
2057     char *lines[] = {
2058       ",",
2059       NULL
2060     };
2061     int r;
2062     suppress_error = 0;
2063     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2064     if (r == -1)
2065       return -1;
2066   }
2067   {
2068     int r;
2069     suppress_error = 0;
2070     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2071     if (r == -1)
2072       return -1;
2073   }
2074   {
2075     int r;
2076     suppress_error = 0;
2077     r = guestfs_mount (g, "/dev/sda1", "/");
2078     if (r == -1)
2079       return -1;
2080   }
2081   /* TestOutputTrue for is_file (0) */
2082   {
2083     int r;
2084     suppress_error = 0;
2085     r = guestfs_touch (g, "/new");
2086     if (r == -1)
2087       return -1;
2088   }
2089   {
2090     int r;
2091     suppress_error = 0;
2092     r = guestfs_is_file (g, "/new");
2093     if (r == -1)
2094       return -1;
2095     if (!r) {
2096       fprintf (stderr, "test_is_file_0: expected true, got false\n");
2097       return -1;
2098     }
2099   }
2100   return 0;
2101 }
2102
2103 static int test_is_file_1 (void)
2104 {
2105   /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */
2106   {
2107     int r;
2108     suppress_error = 0;
2109     r = guestfs_umount_all (g);
2110     if (r == -1)
2111       return -1;
2112   }
2113   {
2114     int r;
2115     suppress_error = 0;
2116     r = guestfs_lvm_remove_all (g);
2117     if (r == -1)
2118       return -1;
2119   }
2120   {
2121     char *lines[] = {
2122       ",",
2123       NULL
2124     };
2125     int r;
2126     suppress_error = 0;
2127     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2128     if (r == -1)
2129       return -1;
2130   }
2131   {
2132     int r;
2133     suppress_error = 0;
2134     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2135     if (r == -1)
2136       return -1;
2137   }
2138   {
2139     int r;
2140     suppress_error = 0;
2141     r = guestfs_mount (g, "/dev/sda1", "/");
2142     if (r == -1)
2143       return -1;
2144   }
2145   /* TestOutputFalse for is_file (1) */
2146   {
2147     int r;
2148     suppress_error = 0;
2149     r = guestfs_mkdir (g, "/new");
2150     if (r == -1)
2151       return -1;
2152   }
2153   {
2154     int r;
2155     suppress_error = 0;
2156     r = guestfs_is_file (g, "/new");
2157     if (r == -1)
2158       return -1;
2159     if (r) {
2160       fprintf (stderr, "test_is_file_1: expected false, got true\n");
2161       return -1;
2162     }
2163   }
2164   return 0;
2165 }
2166
2167 static int test_exists_0 (void)
2168 {
2169   /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */
2170   {
2171     int r;
2172     suppress_error = 0;
2173     r = guestfs_umount_all (g);
2174     if (r == -1)
2175       return -1;
2176   }
2177   {
2178     int r;
2179     suppress_error = 0;
2180     r = guestfs_lvm_remove_all (g);
2181     if (r == -1)
2182       return -1;
2183   }
2184   {
2185     char *lines[] = {
2186       ",",
2187       NULL
2188     };
2189     int r;
2190     suppress_error = 0;
2191     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2192     if (r == -1)
2193       return -1;
2194   }
2195   {
2196     int r;
2197     suppress_error = 0;
2198     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2199     if (r == -1)
2200       return -1;
2201   }
2202   {
2203     int r;
2204     suppress_error = 0;
2205     r = guestfs_mount (g, "/dev/sda1", "/");
2206     if (r == -1)
2207       return -1;
2208   }
2209   /* TestOutputTrue for exists (0) */
2210   {
2211     int r;
2212     suppress_error = 0;
2213     r = guestfs_touch (g, "/new");
2214     if (r == -1)
2215       return -1;
2216   }
2217   {
2218     int r;
2219     suppress_error = 0;
2220     r = guestfs_exists (g, "/new");
2221     if (r == -1)
2222       return -1;
2223     if (!r) {
2224       fprintf (stderr, "test_exists_0: expected true, got false\n");
2225       return -1;
2226     }
2227   }
2228   return 0;
2229 }
2230
2231 static int test_exists_1 (void)
2232 {
2233   /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */
2234   {
2235     int r;
2236     suppress_error = 0;
2237     r = guestfs_umount_all (g);
2238     if (r == -1)
2239       return -1;
2240   }
2241   {
2242     int r;
2243     suppress_error = 0;
2244     r = guestfs_lvm_remove_all (g);
2245     if (r == -1)
2246       return -1;
2247   }
2248   {
2249     char *lines[] = {
2250       ",",
2251       NULL
2252     };
2253     int r;
2254     suppress_error = 0;
2255     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2256     if (r == -1)
2257       return -1;
2258   }
2259   {
2260     int r;
2261     suppress_error = 0;
2262     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2263     if (r == -1)
2264       return -1;
2265   }
2266   {
2267     int r;
2268     suppress_error = 0;
2269     r = guestfs_mount (g, "/dev/sda1", "/");
2270     if (r == -1)
2271       return -1;
2272   }
2273   /* TestOutputTrue for exists (1) */
2274   {
2275     int r;
2276     suppress_error = 0;
2277     r = guestfs_mkdir (g, "/new");
2278     if (r == -1)
2279       return -1;
2280   }
2281   {
2282     int r;
2283     suppress_error = 0;
2284     r = guestfs_exists (g, "/new");
2285     if (r == -1)
2286       return -1;
2287     if (!r) {
2288       fprintf (stderr, "test_exists_1: expected true, got false\n");
2289       return -1;
2290     }
2291   }
2292   return 0;
2293 }
2294
2295 static int test_mkdir_p_0 (void)
2296 {
2297   /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */
2298   {
2299     int r;
2300     suppress_error = 0;
2301     r = guestfs_umount_all (g);
2302     if (r == -1)
2303       return -1;
2304   }
2305   {
2306     int r;
2307     suppress_error = 0;
2308     r = guestfs_lvm_remove_all (g);
2309     if (r == -1)
2310       return -1;
2311   }
2312   {
2313     char *lines[] = {
2314       ",",
2315       NULL
2316     };
2317     int r;
2318     suppress_error = 0;
2319     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2320     if (r == -1)
2321       return -1;
2322   }
2323   {
2324     int r;
2325     suppress_error = 0;
2326     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2327     if (r == -1)
2328       return -1;
2329   }
2330   {
2331     int r;
2332     suppress_error = 0;
2333     r = guestfs_mount (g, "/dev/sda1", "/");
2334     if (r == -1)
2335       return -1;
2336   }
2337   /* TestOutputTrue for mkdir_p (0) */
2338   {
2339     int r;
2340     suppress_error = 0;
2341     r = guestfs_mkdir_p (g, "/new/foo/bar");
2342     if (r == -1)
2343       return -1;
2344   }
2345   {
2346     int r;
2347     suppress_error = 0;
2348     r = guestfs_is_dir (g, "/new/foo/bar");
2349     if (r == -1)
2350       return -1;
2351     if (!r) {
2352       fprintf (stderr, "test_mkdir_p_0: expected true, got false\n");
2353       return -1;
2354     }
2355   }
2356   return 0;
2357 }
2358
2359 static int test_mkdir_p_1 (void)
2360 {
2361   /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */
2362   {
2363     int r;
2364     suppress_error = 0;
2365     r = guestfs_umount_all (g);
2366     if (r == -1)
2367       return -1;
2368   }
2369   {
2370     int r;
2371     suppress_error = 0;
2372     r = guestfs_lvm_remove_all (g);
2373     if (r == -1)
2374       return -1;
2375   }
2376   {
2377     char *lines[] = {
2378       ",",
2379       NULL
2380     };
2381     int r;
2382     suppress_error = 0;
2383     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2384     if (r == -1)
2385       return -1;
2386   }
2387   {
2388     int r;
2389     suppress_error = 0;
2390     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2391     if (r == -1)
2392       return -1;
2393   }
2394   {
2395     int r;
2396     suppress_error = 0;
2397     r = guestfs_mount (g, "/dev/sda1", "/");
2398     if (r == -1)
2399       return -1;
2400   }
2401   /* TestOutputTrue for mkdir_p (1) */
2402   {
2403     int r;
2404     suppress_error = 0;
2405     r = guestfs_mkdir_p (g, "/new/foo/bar");
2406     if (r == -1)
2407       return -1;
2408   }
2409   {
2410     int r;
2411     suppress_error = 0;
2412     r = guestfs_is_dir (g, "/new/foo");
2413     if (r == -1)
2414       return -1;
2415     if (!r) {
2416       fprintf (stderr, "test_mkdir_p_1: expected true, got false\n");
2417       return -1;
2418     }
2419   }
2420   return 0;
2421 }
2422
2423 static int test_mkdir_p_2 (void)
2424 {
2425   /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */
2426   {
2427     int r;
2428     suppress_error = 0;
2429     r = guestfs_umount_all (g);
2430     if (r == -1)
2431       return -1;
2432   }
2433   {
2434     int r;
2435     suppress_error = 0;
2436     r = guestfs_lvm_remove_all (g);
2437     if (r == -1)
2438       return -1;
2439   }
2440   {
2441     char *lines[] = {
2442       ",",
2443       NULL
2444     };
2445     int r;
2446     suppress_error = 0;
2447     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2448     if (r == -1)
2449       return -1;
2450   }
2451   {
2452     int r;
2453     suppress_error = 0;
2454     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2455     if (r == -1)
2456       return -1;
2457   }
2458   {
2459     int r;
2460     suppress_error = 0;
2461     r = guestfs_mount (g, "/dev/sda1", "/");
2462     if (r == -1)
2463       return -1;
2464   }
2465   /* TestOutputTrue for mkdir_p (2) */
2466   {
2467     int r;
2468     suppress_error = 0;
2469     r = guestfs_mkdir_p (g, "/new/foo/bar");
2470     if (r == -1)
2471       return -1;
2472   }
2473   {
2474     int r;
2475     suppress_error = 0;
2476     r = guestfs_is_dir (g, "/new");
2477     if (r == -1)
2478       return -1;
2479     if (!r) {
2480       fprintf (stderr, "test_mkdir_p_2: expected true, got false\n");
2481       return -1;
2482     }
2483   }
2484   return 0;
2485 }
2486
2487 static int test_mkdir_0 (void)
2488 {
2489   /* InitBasicFS for mkdir (0): create ext2 on /dev/sda1 */
2490   {
2491     int r;
2492     suppress_error = 0;
2493     r = guestfs_umount_all (g);
2494     if (r == -1)
2495       return -1;
2496   }
2497   {
2498     int r;
2499     suppress_error = 0;
2500     r = guestfs_lvm_remove_all (g);
2501     if (r == -1)
2502       return -1;
2503   }
2504   {
2505     char *lines[] = {
2506       ",",
2507       NULL
2508     };
2509     int r;
2510     suppress_error = 0;
2511     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2512     if (r == -1)
2513       return -1;
2514   }
2515   {
2516     int r;
2517     suppress_error = 0;
2518     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2519     if (r == -1)
2520       return -1;
2521   }
2522   {
2523     int r;
2524     suppress_error = 0;
2525     r = guestfs_mount (g, "/dev/sda1", "/");
2526     if (r == -1)
2527       return -1;
2528   }
2529   /* TestOutputTrue for mkdir (0) */
2530   {
2531     int r;
2532     suppress_error = 0;
2533     r = guestfs_mkdir (g, "/new");
2534     if (r == -1)
2535       return -1;
2536   }
2537   {
2538     int r;
2539     suppress_error = 0;
2540     r = guestfs_is_dir (g, "/new");
2541     if (r == -1)
2542       return -1;
2543     if (!r) {
2544       fprintf (stderr, "test_mkdir_0: expected true, got false\n");
2545       return -1;
2546     }
2547   }
2548   return 0;
2549 }
2550
2551 static int test_mkdir_1 (void)
2552 {
2553   /* InitBasicFS for mkdir (1): create ext2 on /dev/sda1 */
2554   {
2555     int r;
2556     suppress_error = 0;
2557     r = guestfs_umount_all (g);
2558     if (r == -1)
2559       return -1;
2560   }
2561   {
2562     int r;
2563     suppress_error = 0;
2564     r = guestfs_lvm_remove_all (g);
2565     if (r == -1)
2566       return -1;
2567   }
2568   {
2569     char *lines[] = {
2570       ",",
2571       NULL
2572     };
2573     int r;
2574     suppress_error = 0;
2575     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2576     if (r == -1)
2577       return -1;
2578   }
2579   {
2580     int r;
2581     suppress_error = 0;
2582     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2583     if (r == -1)
2584       return -1;
2585   }
2586   {
2587     int r;
2588     suppress_error = 0;
2589     r = guestfs_mount (g, "/dev/sda1", "/");
2590     if (r == -1)
2591       return -1;
2592   }
2593   /* TestLastFail for mkdir (1) */
2594   {
2595     int r;
2596     suppress_error = 1;
2597     r = guestfs_mkdir (g, "/new/foo/bar");
2598     if (r != -1)
2599       return -1;
2600   }
2601   return 0;
2602 }
2603
2604 static int test_rm_rf_0 (void)
2605 {
2606   /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */
2607   {
2608     int r;
2609     suppress_error = 0;
2610     r = guestfs_umount_all (g);
2611     if (r == -1)
2612       return -1;
2613   }
2614   {
2615     int r;
2616     suppress_error = 0;
2617     r = guestfs_lvm_remove_all (g);
2618     if (r == -1)
2619       return -1;
2620   }
2621   {
2622     char *lines[] = {
2623       ",",
2624       NULL
2625     };
2626     int r;
2627     suppress_error = 0;
2628     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2629     if (r == -1)
2630       return -1;
2631   }
2632   {
2633     int r;
2634     suppress_error = 0;
2635     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2636     if (r == -1)
2637       return -1;
2638   }
2639   {
2640     int r;
2641     suppress_error = 0;
2642     r = guestfs_mount (g, "/dev/sda1", "/");
2643     if (r == -1)
2644       return -1;
2645   }
2646   /* TestOutputFalse for rm_rf (0) */
2647   {
2648     int r;
2649     suppress_error = 0;
2650     r = guestfs_mkdir (g, "/new");
2651     if (r == -1)
2652       return -1;
2653   }
2654   {
2655     int r;
2656     suppress_error = 0;
2657     r = guestfs_mkdir (g, "/new/foo");
2658     if (r == -1)
2659       return -1;
2660   }
2661   {
2662     int r;
2663     suppress_error = 0;
2664     r = guestfs_touch (g, "/new/foo/bar");
2665     if (r == -1)
2666       return -1;
2667   }
2668   {
2669     int r;
2670     suppress_error = 0;
2671     r = guestfs_rm_rf (g, "/new");
2672     if (r == -1)
2673       return -1;
2674   }
2675   {
2676     int r;
2677     suppress_error = 0;
2678     r = guestfs_exists (g, "/new");
2679     if (r == -1)
2680       return -1;
2681     if (r) {
2682       fprintf (stderr, "test_rm_rf_0: expected false, got true\n");
2683       return -1;
2684     }
2685   }
2686   return 0;
2687 }
2688
2689 static int test_rmdir_0 (void)
2690 {
2691   /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */
2692   {
2693     int r;
2694     suppress_error = 0;
2695     r = guestfs_umount_all (g);
2696     if (r == -1)
2697       return -1;
2698   }
2699   {
2700     int r;
2701     suppress_error = 0;
2702     r = guestfs_lvm_remove_all (g);
2703     if (r == -1)
2704       return -1;
2705   }
2706   {
2707     char *lines[] = {
2708       ",",
2709       NULL
2710     };
2711     int r;
2712     suppress_error = 0;
2713     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2714     if (r == -1)
2715       return -1;
2716   }
2717   {
2718     int r;
2719     suppress_error = 0;
2720     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2721     if (r == -1)
2722       return -1;
2723   }
2724   {
2725     int r;
2726     suppress_error = 0;
2727     r = guestfs_mount (g, "/dev/sda1", "/");
2728     if (r == -1)
2729       return -1;
2730   }
2731   /* TestRun for rmdir (0) */
2732   {
2733     int r;
2734     suppress_error = 0;
2735     r = guestfs_mkdir (g, "/new");
2736     if (r == -1)
2737       return -1;
2738   }
2739   {
2740     int r;
2741     suppress_error = 0;
2742     r = guestfs_rmdir (g, "/new");
2743     if (r == -1)
2744       return -1;
2745   }
2746   return 0;
2747 }
2748
2749 static int test_rmdir_1 (void)
2750 {
2751   /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */
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   {
2767     char *lines[] = {
2768       ",",
2769       NULL
2770     };
2771     int r;
2772     suppress_error = 0;
2773     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2774     if (r == -1)
2775       return -1;
2776   }
2777   {
2778     int r;
2779     suppress_error = 0;
2780     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2781     if (r == -1)
2782       return -1;
2783   }
2784   {
2785     int r;
2786     suppress_error = 0;
2787     r = guestfs_mount (g, "/dev/sda1", "/");
2788     if (r == -1)
2789       return -1;
2790   }
2791   /* TestLastFail for rmdir (1) */
2792   {
2793     int r;
2794     suppress_error = 1;
2795     r = guestfs_rmdir (g, "/new");
2796     if (r != -1)
2797       return -1;
2798   }
2799   return 0;
2800 }
2801
2802 static int test_rmdir_2 (void)
2803 {
2804   /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */
2805   {
2806     int r;
2807     suppress_error = 0;
2808     r = guestfs_umount_all (g);
2809     if (r == -1)
2810       return -1;
2811   }
2812   {
2813     int r;
2814     suppress_error = 0;
2815     r = guestfs_lvm_remove_all (g);
2816     if (r == -1)
2817       return -1;
2818   }
2819   {
2820     char *lines[] = {
2821       ",",
2822       NULL
2823     };
2824     int r;
2825     suppress_error = 0;
2826     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2827     if (r == -1)
2828       return -1;
2829   }
2830   {
2831     int r;
2832     suppress_error = 0;
2833     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2834     if (r == -1)
2835       return -1;
2836   }
2837   {
2838     int r;
2839     suppress_error = 0;
2840     r = guestfs_mount (g, "/dev/sda1", "/");
2841     if (r == -1)
2842       return -1;
2843   }
2844   /* TestLastFail for rmdir (2) */
2845   {
2846     int r;
2847     suppress_error = 0;
2848     r = guestfs_touch (g, "/new");
2849     if (r == -1)
2850       return -1;
2851   }
2852   {
2853     int r;
2854     suppress_error = 1;
2855     r = guestfs_rmdir (g, "/new");
2856     if (r != -1)
2857       return -1;
2858   }
2859   return 0;
2860 }
2861
2862 static int test_rm_0 (void)
2863 {
2864   /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */
2865   {
2866     int r;
2867     suppress_error = 0;
2868     r = guestfs_umount_all (g);
2869     if (r == -1)
2870       return -1;
2871   }
2872   {
2873     int r;
2874     suppress_error = 0;
2875     r = guestfs_lvm_remove_all (g);
2876     if (r == -1)
2877       return -1;
2878   }
2879   {
2880     char *lines[] = {
2881       ",",
2882       NULL
2883     };
2884     int r;
2885     suppress_error = 0;
2886     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2887     if (r == -1)
2888       return -1;
2889   }
2890   {
2891     int r;
2892     suppress_error = 0;
2893     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2894     if (r == -1)
2895       return -1;
2896   }
2897   {
2898     int r;
2899     suppress_error = 0;
2900     r = guestfs_mount (g, "/dev/sda1", "/");
2901     if (r == -1)
2902       return -1;
2903   }
2904   /* TestRun for rm (0) */
2905   {
2906     int r;
2907     suppress_error = 0;
2908     r = guestfs_touch (g, "/new");
2909     if (r == -1)
2910       return -1;
2911   }
2912   {
2913     int r;
2914     suppress_error = 0;
2915     r = guestfs_rm (g, "/new");
2916     if (r == -1)
2917       return -1;
2918   }
2919   return 0;
2920 }
2921
2922 static int test_rm_1 (void)
2923 {
2924   /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */
2925   {
2926     int r;
2927     suppress_error = 0;
2928     r = guestfs_umount_all (g);
2929     if (r == -1)
2930       return -1;
2931   }
2932   {
2933     int r;
2934     suppress_error = 0;
2935     r = guestfs_lvm_remove_all (g);
2936     if (r == -1)
2937       return -1;
2938   }
2939   {
2940     char *lines[] = {
2941       ",",
2942       NULL
2943     };
2944     int r;
2945     suppress_error = 0;
2946     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
2947     if (r == -1)
2948       return -1;
2949   }
2950   {
2951     int r;
2952     suppress_error = 0;
2953     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
2954     if (r == -1)
2955       return -1;
2956   }
2957   {
2958     int r;
2959     suppress_error = 0;
2960     r = guestfs_mount (g, "/dev/sda1", "/");
2961     if (r == -1)
2962       return -1;
2963   }
2964   /* TestLastFail for rm (1) */
2965   {
2966     int r;
2967     suppress_error = 1;
2968     r = guestfs_rm (g, "/new");
2969     if (r != -1)
2970       return -1;
2971   }
2972   return 0;
2973 }
2974
2975 static int test_rm_2 (void)
2976 {
2977   /* InitBasicFS for rm (2): 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   /* TestLastFail for rm (2) */
3018   {
3019     int r;
3020     suppress_error = 0;
3021     r = guestfs_mkdir (g, "/new");
3022     if (r == -1)
3023       return -1;
3024   }
3025   {
3026     int r;
3027     suppress_error = 1;
3028     r = guestfs_rm (g, "/new");
3029     if (r != -1)
3030       return -1;
3031   }
3032   return 0;
3033 }
3034
3035 static int test_read_lines_0 (void)
3036 {
3037   /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */
3038   {
3039     int r;
3040     suppress_error = 0;
3041     r = guestfs_umount_all (g);
3042     if (r == -1)
3043       return -1;
3044   }
3045   {
3046     int r;
3047     suppress_error = 0;
3048     r = guestfs_lvm_remove_all (g);
3049     if (r == -1)
3050       return -1;
3051   }
3052   {
3053     char *lines[] = {
3054       ",",
3055       NULL
3056     };
3057     int r;
3058     suppress_error = 0;
3059     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3060     if (r == -1)
3061       return -1;
3062   }
3063   {
3064     int r;
3065     suppress_error = 0;
3066     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3067     if (r == -1)
3068       return -1;
3069   }
3070   {
3071     int r;
3072     suppress_error = 0;
3073     r = guestfs_mount (g, "/dev/sda1", "/");
3074     if (r == -1)
3075       return -1;
3076   }
3077   /* TestOutputList for read_lines (0) */
3078   {
3079     int r;
3080     suppress_error = 0;
3081     r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0);
3082     if (r == -1)
3083       return -1;
3084   }
3085   {
3086     char **r;
3087     int i;
3088     suppress_error = 0;
3089     r = guestfs_read_lines (g, "/new");
3090     if (r == NULL)
3091       return -1;
3092     if (!r[0]) {
3093       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3094       print_strings (r);
3095       return -1;
3096     }
3097     if (strcmp (r[0], "line1") != 0) {
3098       fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]);
3099       return -1;
3100     }
3101     if (!r[1]) {
3102       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3103       print_strings (r);
3104       return -1;
3105     }
3106     if (strcmp (r[1], "line2") != 0) {
3107       fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]);
3108       return -1;
3109     }
3110     if (!r[2]) {
3111       fprintf (stderr, "test_read_lines_0: short list returned from command\n");
3112       print_strings (r);
3113       return -1;
3114     }
3115     if (strcmp (r[2], "line3") != 0) {
3116       fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]);
3117       return -1;
3118     }
3119     if (r[3] != NULL) {
3120       fprintf (stderr, "test_read_lines_0: extra elements returned from command\n");
3121       print_strings (r);
3122       return -1;
3123     }
3124     for (i = 0; r[i] != NULL; ++i)
3125       free (r[i]);
3126     free (r);
3127   }
3128   return 0;
3129 }
3130
3131 static int test_read_lines_1 (void)
3132 {
3133   /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */
3134   {
3135     int r;
3136     suppress_error = 0;
3137     r = guestfs_umount_all (g);
3138     if (r == -1)
3139       return -1;
3140   }
3141   {
3142     int r;
3143     suppress_error = 0;
3144     r = guestfs_lvm_remove_all (g);
3145     if (r == -1)
3146       return -1;
3147   }
3148   {
3149     char *lines[] = {
3150       ",",
3151       NULL
3152     };
3153     int r;
3154     suppress_error = 0;
3155     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3156     if (r == -1)
3157       return -1;
3158   }
3159   {
3160     int r;
3161     suppress_error = 0;
3162     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3163     if (r == -1)
3164       return -1;
3165   }
3166   {
3167     int r;
3168     suppress_error = 0;
3169     r = guestfs_mount (g, "/dev/sda1", "/");
3170     if (r == -1)
3171       return -1;
3172   }
3173   /* TestOutputList for read_lines (1) */
3174   {
3175     int r;
3176     suppress_error = 0;
3177     r = guestfs_write_file (g, "/new", "", 0);
3178     if (r == -1)
3179       return -1;
3180   }
3181   {
3182     char **r;
3183     int i;
3184     suppress_error = 0;
3185     r = guestfs_read_lines (g, "/new");
3186     if (r == NULL)
3187       return -1;
3188     if (r[0] != NULL) {
3189       fprintf (stderr, "test_read_lines_1: extra elements returned from command\n");
3190       print_strings (r);
3191       return -1;
3192     }
3193     for (i = 0; r[i] != NULL; ++i)
3194       free (r[i]);
3195     free (r);
3196   }
3197   return 0;
3198 }
3199
3200 static int test_lvs_0 (void)
3201 {
3202   /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */
3203   {
3204     int r;
3205     suppress_error = 0;
3206     r = guestfs_umount_all (g);
3207     if (r == -1)
3208       return -1;
3209   }
3210   {
3211     int r;
3212     suppress_error = 0;
3213     r = guestfs_lvm_remove_all (g);
3214     if (r == -1)
3215       return -1;
3216   }
3217   {
3218     char *lines[] = {
3219       ",",
3220       NULL
3221     };
3222     int r;
3223     suppress_error = 0;
3224     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3225     if (r == -1)
3226       return -1;
3227   }
3228   {
3229     int r;
3230     suppress_error = 0;
3231     r = guestfs_pvcreate (g, "/dev/sda1");
3232     if (r == -1)
3233       return -1;
3234   }
3235   {
3236     char *physvols[] = {
3237       "/dev/sda1",
3238       NULL
3239     };
3240     int r;
3241     suppress_error = 0;
3242     r = guestfs_vgcreate (g, "VG", physvols);
3243     if (r == -1)
3244       return -1;
3245   }
3246   {
3247     int r;
3248     suppress_error = 0;
3249     r = guestfs_lvcreate (g, "LV", "VG", 8);
3250     if (r == -1)
3251       return -1;
3252   }
3253   {
3254     int r;
3255     suppress_error = 0;
3256     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3257     if (r == -1)
3258       return -1;
3259   }
3260   {
3261     int r;
3262     suppress_error = 0;
3263     r = guestfs_mount (g, "/dev/VG/LV", "/");
3264     if (r == -1)
3265       return -1;
3266   }
3267   /* TestOutputList for lvs (0) */
3268   {
3269     char **r;
3270     int i;
3271     suppress_error = 0;
3272     r = guestfs_lvs (g);
3273     if (r == NULL)
3274       return -1;
3275     if (!r[0]) {
3276       fprintf (stderr, "test_lvs_0: short list returned from command\n");
3277       print_strings (r);
3278       return -1;
3279     }
3280     if (strcmp (r[0], "/dev/VG/LV") != 0) {
3281       fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]);
3282       return -1;
3283     }
3284     if (r[1] != NULL) {
3285       fprintf (stderr, "test_lvs_0: extra elements returned from command\n");
3286       print_strings (r);
3287       return -1;
3288     }
3289     for (i = 0; r[i] != NULL; ++i)
3290       free (r[i]);
3291     free (r);
3292   }
3293   return 0;
3294 }
3295
3296 static int test_lvs_1 (void)
3297 {
3298   /* InitEmpty for lvs (1) */
3299   {
3300     int r;
3301     suppress_error = 0;
3302     r = guestfs_umount_all (g);
3303     if (r == -1)
3304       return -1;
3305   }
3306   {
3307     int r;
3308     suppress_error = 0;
3309     r = guestfs_lvm_remove_all (g);
3310     if (r == -1)
3311       return -1;
3312   }
3313   /* TestOutputList for lvs (1) */
3314   {
3315     char *lines[] = {
3316       ",10",
3317       ",20",
3318       ",",
3319       NULL
3320     };
3321     int r;
3322     suppress_error = 0;
3323     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3324     if (r == -1)
3325       return -1;
3326   }
3327   {
3328     int r;
3329     suppress_error = 0;
3330     r = guestfs_pvcreate (g, "/dev/sda1");
3331     if (r == -1)
3332       return -1;
3333   }
3334   {
3335     int r;
3336     suppress_error = 0;
3337     r = guestfs_pvcreate (g, "/dev/sda2");
3338     if (r == -1)
3339       return -1;
3340   }
3341   {
3342     int r;
3343     suppress_error = 0;
3344     r = guestfs_pvcreate (g, "/dev/sda3");
3345     if (r == -1)
3346       return -1;
3347   }
3348   {
3349     char *physvols[] = {
3350       "/dev/sda1",
3351       "/dev/sda2",
3352       NULL
3353     };
3354     int r;
3355     suppress_error = 0;
3356     r = guestfs_vgcreate (g, "VG1", physvols);
3357     if (r == -1)
3358       return -1;
3359   }
3360   {
3361     char *physvols[] = {
3362       "/dev/sda3",
3363       NULL
3364     };
3365     int r;
3366     suppress_error = 0;
3367     r = guestfs_vgcreate (g, "VG2", physvols);
3368     if (r == -1)
3369       return -1;
3370   }
3371   {
3372     int r;
3373     suppress_error = 0;
3374     r = guestfs_lvcreate (g, "LV1", "VG1", 50);
3375     if (r == -1)
3376       return -1;
3377   }
3378   {
3379     int r;
3380     suppress_error = 0;
3381     r = guestfs_lvcreate (g, "LV2", "VG1", 50);
3382     if (r == -1)
3383       return -1;
3384   }
3385   {
3386     int r;
3387     suppress_error = 0;
3388     r = guestfs_lvcreate (g, "LV3", "VG2", 50);
3389     if (r == -1)
3390       return -1;
3391   }
3392   {
3393     char **r;
3394     int i;
3395     suppress_error = 0;
3396     r = guestfs_lvs (g);
3397     if (r == NULL)
3398       return -1;
3399     if (!r[0]) {
3400       fprintf (stderr, "test_lvs_1: short list returned from command\n");
3401       print_strings (r);
3402       return -1;
3403     }
3404     if (strcmp (r[0], "/dev/VG1/LV1") != 0) {
3405       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]);
3406       return -1;
3407     }
3408     if (!r[1]) {
3409       fprintf (stderr, "test_lvs_1: short list returned from command\n");
3410       print_strings (r);
3411       return -1;
3412     }
3413     if (strcmp (r[1], "/dev/VG1/LV2") != 0) {
3414       fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]);
3415       return -1;
3416     }
3417     if (!r[2]) {
3418       fprintf (stderr, "test_lvs_1: short list returned from command\n");
3419       print_strings (r);
3420       return -1;
3421     }
3422     if (strcmp (r[2], "/dev/VG2/LV3") != 0) {
3423       fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]);
3424       return -1;
3425     }
3426     if (r[3] != NULL) {
3427       fprintf (stderr, "test_lvs_1: extra elements returned from command\n");
3428       print_strings (r);
3429       return -1;
3430     }
3431     for (i = 0; r[i] != NULL; ++i)
3432       free (r[i]);
3433     free (r);
3434   }
3435   return 0;
3436 }
3437
3438 static int test_vgs_0 (void)
3439 {
3440   /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */
3441   {
3442     int r;
3443     suppress_error = 0;
3444     r = guestfs_umount_all (g);
3445     if (r == -1)
3446       return -1;
3447   }
3448   {
3449     int r;
3450     suppress_error = 0;
3451     r = guestfs_lvm_remove_all (g);
3452     if (r == -1)
3453       return -1;
3454   }
3455   {
3456     char *lines[] = {
3457       ",",
3458       NULL
3459     };
3460     int r;
3461     suppress_error = 0;
3462     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3463     if (r == -1)
3464       return -1;
3465   }
3466   {
3467     int r;
3468     suppress_error = 0;
3469     r = guestfs_pvcreate (g, "/dev/sda1");
3470     if (r == -1)
3471       return -1;
3472   }
3473   {
3474     char *physvols[] = {
3475       "/dev/sda1",
3476       NULL
3477     };
3478     int r;
3479     suppress_error = 0;
3480     r = guestfs_vgcreate (g, "VG", physvols);
3481     if (r == -1)
3482       return -1;
3483   }
3484   {
3485     int r;
3486     suppress_error = 0;
3487     r = guestfs_lvcreate (g, "LV", "VG", 8);
3488     if (r == -1)
3489       return -1;
3490   }
3491   {
3492     int r;
3493     suppress_error = 0;
3494     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3495     if (r == -1)
3496       return -1;
3497   }
3498   {
3499     int r;
3500     suppress_error = 0;
3501     r = guestfs_mount (g, "/dev/VG/LV", "/");
3502     if (r == -1)
3503       return -1;
3504   }
3505   /* TestOutputList for vgs (0) */
3506   {
3507     char **r;
3508     int i;
3509     suppress_error = 0;
3510     r = guestfs_vgs (g);
3511     if (r == NULL)
3512       return -1;
3513     if (!r[0]) {
3514       fprintf (stderr, "test_vgs_0: short list returned from command\n");
3515       print_strings (r);
3516       return -1;
3517     }
3518     if (strcmp (r[0], "VG") != 0) {
3519       fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]);
3520       return -1;
3521     }
3522     if (r[1] != NULL) {
3523       fprintf (stderr, "test_vgs_0: extra elements returned from command\n");
3524       print_strings (r);
3525       return -1;
3526     }
3527     for (i = 0; r[i] != NULL; ++i)
3528       free (r[i]);
3529     free (r);
3530   }
3531   return 0;
3532 }
3533
3534 static int test_vgs_1 (void)
3535 {
3536   /* InitEmpty for vgs (1) */
3537   {
3538     int r;
3539     suppress_error = 0;
3540     r = guestfs_umount_all (g);
3541     if (r == -1)
3542       return -1;
3543   }
3544   {
3545     int r;
3546     suppress_error = 0;
3547     r = guestfs_lvm_remove_all (g);
3548     if (r == -1)
3549       return -1;
3550   }
3551   /* TestOutputList for vgs (1) */
3552   {
3553     char *lines[] = {
3554       ",10",
3555       ",20",
3556       ",",
3557       NULL
3558     };
3559     int r;
3560     suppress_error = 0;
3561     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3562     if (r == -1)
3563       return -1;
3564   }
3565   {
3566     int r;
3567     suppress_error = 0;
3568     r = guestfs_pvcreate (g, "/dev/sda1");
3569     if (r == -1)
3570       return -1;
3571   }
3572   {
3573     int r;
3574     suppress_error = 0;
3575     r = guestfs_pvcreate (g, "/dev/sda2");
3576     if (r == -1)
3577       return -1;
3578   }
3579   {
3580     int r;
3581     suppress_error = 0;
3582     r = guestfs_pvcreate (g, "/dev/sda3");
3583     if (r == -1)
3584       return -1;
3585   }
3586   {
3587     char *physvols[] = {
3588       "/dev/sda1",
3589       "/dev/sda2",
3590       NULL
3591     };
3592     int r;
3593     suppress_error = 0;
3594     r = guestfs_vgcreate (g, "VG1", physvols);
3595     if (r == -1)
3596       return -1;
3597   }
3598   {
3599     char *physvols[] = {
3600       "/dev/sda3",
3601       NULL
3602     };
3603     int r;
3604     suppress_error = 0;
3605     r = guestfs_vgcreate (g, "VG2", physvols);
3606     if (r == -1)
3607       return -1;
3608   }
3609   {
3610     char **r;
3611     int i;
3612     suppress_error = 0;
3613     r = guestfs_vgs (g);
3614     if (r == NULL)
3615       return -1;
3616     if (!r[0]) {
3617       fprintf (stderr, "test_vgs_1: short list returned from command\n");
3618       print_strings (r);
3619       return -1;
3620     }
3621     if (strcmp (r[0], "VG1") != 0) {
3622       fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]);
3623       return -1;
3624     }
3625     if (!r[1]) {
3626       fprintf (stderr, "test_vgs_1: short list returned from command\n");
3627       print_strings (r);
3628       return -1;
3629     }
3630     if (strcmp (r[1], "VG2") != 0) {
3631       fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]);
3632       return -1;
3633     }
3634     if (r[2] != NULL) {
3635       fprintf (stderr, "test_vgs_1: extra elements returned from command\n");
3636       print_strings (r);
3637       return -1;
3638     }
3639     for (i = 0; r[i] != NULL; ++i)
3640       free (r[i]);
3641     free (r);
3642   }
3643   return 0;
3644 }
3645
3646 static int test_pvs_0 (void)
3647 {
3648   /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */
3649   {
3650     int r;
3651     suppress_error = 0;
3652     r = guestfs_umount_all (g);
3653     if (r == -1)
3654       return -1;
3655   }
3656   {
3657     int r;
3658     suppress_error = 0;
3659     r = guestfs_lvm_remove_all (g);
3660     if (r == -1)
3661       return -1;
3662   }
3663   {
3664     char *lines[] = {
3665       ",",
3666       NULL
3667     };
3668     int r;
3669     suppress_error = 0;
3670     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3671     if (r == -1)
3672       return -1;
3673   }
3674   {
3675     int r;
3676     suppress_error = 0;
3677     r = guestfs_pvcreate (g, "/dev/sda1");
3678     if (r == -1)
3679       return -1;
3680   }
3681   {
3682     char *physvols[] = {
3683       "/dev/sda1",
3684       NULL
3685     };
3686     int r;
3687     suppress_error = 0;
3688     r = guestfs_vgcreate (g, "VG", physvols);
3689     if (r == -1)
3690       return -1;
3691   }
3692   {
3693     int r;
3694     suppress_error = 0;
3695     r = guestfs_lvcreate (g, "LV", "VG", 8);
3696     if (r == -1)
3697       return -1;
3698   }
3699   {
3700     int r;
3701     suppress_error = 0;
3702     r = guestfs_mkfs (g, "ext2", "/dev/VG/LV");
3703     if (r == -1)
3704       return -1;
3705   }
3706   {
3707     int r;
3708     suppress_error = 0;
3709     r = guestfs_mount (g, "/dev/VG/LV", "/");
3710     if (r == -1)
3711       return -1;
3712   }
3713   /* TestOutputList for pvs (0) */
3714   {
3715     char **r;
3716     int i;
3717     suppress_error = 0;
3718     r = guestfs_pvs (g);
3719     if (r == NULL)
3720       return -1;
3721     if (!r[0]) {
3722       fprintf (stderr, "test_pvs_0: short list returned from command\n");
3723       print_strings (r);
3724       return -1;
3725     }
3726     if (strcmp (r[0], "/dev/sda1") != 0) {
3727       fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3728       return -1;
3729     }
3730     if (r[1] != NULL) {
3731       fprintf (stderr, "test_pvs_0: extra elements returned from command\n");
3732       print_strings (r);
3733       return -1;
3734     }
3735     for (i = 0; r[i] != NULL; ++i)
3736       free (r[i]);
3737     free (r);
3738   }
3739   return 0;
3740 }
3741
3742 static int test_pvs_1 (void)
3743 {
3744   /* InitEmpty for pvs (1) */
3745   {
3746     int r;
3747     suppress_error = 0;
3748     r = guestfs_umount_all (g);
3749     if (r == -1)
3750       return -1;
3751   }
3752   {
3753     int r;
3754     suppress_error = 0;
3755     r = guestfs_lvm_remove_all (g);
3756     if (r == -1)
3757       return -1;
3758   }
3759   /* TestOutputList for pvs (1) */
3760   {
3761     char *lines[] = {
3762       ",10",
3763       ",20",
3764       ",",
3765       NULL
3766     };
3767     int r;
3768     suppress_error = 0;
3769     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3770     if (r == -1)
3771       return -1;
3772   }
3773   {
3774     int r;
3775     suppress_error = 0;
3776     r = guestfs_pvcreate (g, "/dev/sda1");
3777     if (r == -1)
3778       return -1;
3779   }
3780   {
3781     int r;
3782     suppress_error = 0;
3783     r = guestfs_pvcreate (g, "/dev/sda2");
3784     if (r == -1)
3785       return -1;
3786   }
3787   {
3788     int r;
3789     suppress_error = 0;
3790     r = guestfs_pvcreate (g, "/dev/sda3");
3791     if (r == -1)
3792       return -1;
3793   }
3794   {
3795     char **r;
3796     int i;
3797     suppress_error = 0;
3798     r = guestfs_pvs (g);
3799     if (r == NULL)
3800       return -1;
3801     if (!r[0]) {
3802       fprintf (stderr, "test_pvs_1: short list returned from command\n");
3803       print_strings (r);
3804       return -1;
3805     }
3806     if (strcmp (r[0], "/dev/sda1") != 0) {
3807       fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3808       return -1;
3809     }
3810     if (!r[1]) {
3811       fprintf (stderr, "test_pvs_1: short list returned from command\n");
3812       print_strings (r);
3813       return -1;
3814     }
3815     if (strcmp (r[1], "/dev/sda2") != 0) {
3816       fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3817       return -1;
3818     }
3819     if (!r[2]) {
3820       fprintf (stderr, "test_pvs_1: short list returned from command\n");
3821       print_strings (r);
3822       return -1;
3823     }
3824     if (strcmp (r[2], "/dev/sda3") != 0) {
3825       fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3826       return -1;
3827     }
3828     if (r[3] != NULL) {
3829       fprintf (stderr, "test_pvs_1: extra elements returned from command\n");
3830       print_strings (r);
3831       return -1;
3832     }
3833     for (i = 0; r[i] != NULL; ++i)
3834       free (r[i]);
3835     free (r);
3836   }
3837   return 0;
3838 }
3839
3840 static int test_list_partitions_0 (void)
3841 {
3842   /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */
3843   {
3844     int r;
3845     suppress_error = 0;
3846     r = guestfs_umount_all (g);
3847     if (r == -1)
3848       return -1;
3849   }
3850   {
3851     int r;
3852     suppress_error = 0;
3853     r = guestfs_lvm_remove_all (g);
3854     if (r == -1)
3855       return -1;
3856   }
3857   {
3858     char *lines[] = {
3859       ",",
3860       NULL
3861     };
3862     int r;
3863     suppress_error = 0;
3864     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3865     if (r == -1)
3866       return -1;
3867   }
3868   {
3869     int r;
3870     suppress_error = 0;
3871     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
3872     if (r == -1)
3873       return -1;
3874   }
3875   {
3876     int r;
3877     suppress_error = 0;
3878     r = guestfs_mount (g, "/dev/sda1", "/");
3879     if (r == -1)
3880       return -1;
3881   }
3882   /* TestOutputList for list_partitions (0) */
3883   {
3884     char **r;
3885     int i;
3886     suppress_error = 0;
3887     r = guestfs_list_partitions (g);
3888     if (r == NULL)
3889       return -1;
3890     if (!r[0]) {
3891       fprintf (stderr, "test_list_partitions_0: short list returned from command\n");
3892       print_strings (r);
3893       return -1;
3894     }
3895     if (strcmp (r[0], "/dev/sda1") != 0) {
3896       fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3897       return -1;
3898     }
3899     if (r[1] != NULL) {
3900       fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n");
3901       print_strings (r);
3902       return -1;
3903     }
3904     for (i = 0; r[i] != NULL; ++i)
3905       free (r[i]);
3906     free (r);
3907   }
3908   return 0;
3909 }
3910
3911 static int test_list_partitions_1 (void)
3912 {
3913   /* InitEmpty for list_partitions (1) */
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   /* TestOutputList for list_partitions (1) */
3929   {
3930     char *lines[] = {
3931       ",10",
3932       ",20",
3933       ",",
3934       NULL
3935     };
3936     int r;
3937     suppress_error = 0;
3938     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
3939     if (r == -1)
3940       return -1;
3941   }
3942   {
3943     char **r;
3944     int i;
3945     suppress_error = 0;
3946     r = guestfs_list_partitions (g);
3947     if (r == NULL)
3948       return -1;
3949     if (!r[0]) {
3950       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3951       print_strings (r);
3952       return -1;
3953     }
3954     if (strcmp (r[0], "/dev/sda1") != 0) {
3955       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]);
3956       return -1;
3957     }
3958     if (!r[1]) {
3959       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3960       print_strings (r);
3961       return -1;
3962     }
3963     if (strcmp (r[1], "/dev/sda2") != 0) {
3964       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]);
3965       return -1;
3966     }
3967     if (!r[2]) {
3968       fprintf (stderr, "test_list_partitions_1: short list returned from command\n");
3969       print_strings (r);
3970       return -1;
3971     }
3972     if (strcmp (r[2], "/dev/sda3") != 0) {
3973       fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]);
3974       return -1;
3975     }
3976     if (r[3] != NULL) {
3977       fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n");
3978       print_strings (r);
3979       return -1;
3980     }
3981     for (i = 0; r[i] != NULL; ++i)
3982       free (r[i]);
3983     free (r);
3984   }
3985   return 0;
3986 }
3987
3988 static int test_list_devices_0 (void)
3989 {
3990   /* InitEmpty for list_devices (0) */
3991   {
3992     int r;
3993     suppress_error = 0;
3994     r = guestfs_umount_all (g);
3995     if (r == -1)
3996       return -1;
3997   }
3998   {
3999     int r;
4000     suppress_error = 0;
4001     r = guestfs_lvm_remove_all (g);
4002     if (r == -1)
4003       return -1;
4004   }
4005   /* TestOutputList for list_devices (0) */
4006   {
4007     char **r;
4008     int i;
4009     suppress_error = 0;
4010     r = guestfs_list_devices (g);
4011     if (r == NULL)
4012       return -1;
4013     if (!r[0]) {
4014       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4015       print_strings (r);
4016       return -1;
4017     }
4018     if (strcmp (r[0], "/dev/sda") != 0) {
4019       fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]);
4020       return -1;
4021     }
4022     if (!r[1]) {
4023       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4024       print_strings (r);
4025       return -1;
4026     }
4027     if (strcmp (r[1], "/dev/sdb") != 0) {
4028       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]);
4029       return -1;
4030     }
4031     if (!r[2]) {
4032       fprintf (stderr, "test_list_devices_0: short list returned from command\n");
4033       print_strings (r);
4034       return -1;
4035     }
4036     if (strcmp (r[2], "/dev/sdc") != 0) {
4037       fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]);
4038       return -1;
4039     }
4040     if (r[3] != NULL) {
4041       fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
4042       print_strings (r);
4043       return -1;
4044     }
4045     for (i = 0; r[i] != NULL; ++i)
4046       free (r[i]);
4047     free (r);
4048   }
4049   return 0;
4050 }
4051
4052 static int test_ls_0 (void)
4053 {
4054   /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */
4055   {
4056     int r;
4057     suppress_error = 0;
4058     r = guestfs_umount_all (g);
4059     if (r == -1)
4060       return -1;
4061   }
4062   {
4063     int r;
4064     suppress_error = 0;
4065     r = guestfs_lvm_remove_all (g);
4066     if (r == -1)
4067       return -1;
4068   }
4069   {
4070     char *lines[] = {
4071       ",",
4072       NULL
4073     };
4074     int r;
4075     suppress_error = 0;
4076     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4077     if (r == -1)
4078       return -1;
4079   }
4080   {
4081     int r;
4082     suppress_error = 0;
4083     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4084     if (r == -1)
4085       return -1;
4086   }
4087   {
4088     int r;
4089     suppress_error = 0;
4090     r = guestfs_mount (g, "/dev/sda1", "/");
4091     if (r == -1)
4092       return -1;
4093   }
4094   /* TestOutputList for ls (0) */
4095   {
4096     int r;
4097     suppress_error = 0;
4098     r = guestfs_touch (g, "/new");
4099     if (r == -1)
4100       return -1;
4101   }
4102   {
4103     int r;
4104     suppress_error = 0;
4105     r = guestfs_touch (g, "/newer");
4106     if (r == -1)
4107       return -1;
4108   }
4109   {
4110     int r;
4111     suppress_error = 0;
4112     r = guestfs_touch (g, "/newest");
4113     if (r == -1)
4114       return -1;
4115   }
4116   {
4117     char **r;
4118     int i;
4119     suppress_error = 0;
4120     r = guestfs_ls (g, "/");
4121     if (r == NULL)
4122       return -1;
4123     if (!r[0]) {
4124       fprintf (stderr, "test_ls_0: short list returned from command\n");
4125       print_strings (r);
4126       return -1;
4127     }
4128     if (strcmp (r[0], "lost+found") != 0) {
4129       fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]);
4130       return -1;
4131     }
4132     if (!r[1]) {
4133       fprintf (stderr, "test_ls_0: short list returned from command\n");
4134       print_strings (r);
4135       return -1;
4136     }
4137     if (strcmp (r[1], "new") != 0) {
4138       fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]);
4139       return -1;
4140     }
4141     if (!r[2]) {
4142       fprintf (stderr, "test_ls_0: short list returned from command\n");
4143       print_strings (r);
4144       return -1;
4145     }
4146     if (strcmp (r[2], "newer") != 0) {
4147       fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]);
4148       return -1;
4149     }
4150     if (!r[3]) {
4151       fprintf (stderr, "test_ls_0: short list returned from command\n");
4152       print_strings (r);
4153       return -1;
4154     }
4155     if (strcmp (r[3], "newest") != 0) {
4156       fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]);
4157       return -1;
4158     }
4159     if (r[4] != NULL) {
4160       fprintf (stderr, "test_ls_0: extra elements returned from command\n");
4161       print_strings (r);
4162       return -1;
4163     }
4164     for (i = 0; r[i] != NULL; ++i)
4165       free (r[i]);
4166     free (r);
4167   }
4168   return 0;
4169 }
4170
4171 static int test_cat_0 (void)
4172 {
4173   /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */
4174   {
4175     int r;
4176     suppress_error = 0;
4177     r = guestfs_umount_all (g);
4178     if (r == -1)
4179       return -1;
4180   }
4181   {
4182     int r;
4183     suppress_error = 0;
4184     r = guestfs_lvm_remove_all (g);
4185     if (r == -1)
4186       return -1;
4187   }
4188   {
4189     char *lines[] = {
4190       ",",
4191       NULL
4192     };
4193     int r;
4194     suppress_error = 0;
4195     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4196     if (r == -1)
4197       return -1;
4198   }
4199   {
4200     int r;
4201     suppress_error = 0;
4202     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4203     if (r == -1)
4204       return -1;
4205   }
4206   {
4207     int r;
4208     suppress_error = 0;
4209     r = guestfs_mount (g, "/dev/sda1", "/");
4210     if (r == -1)
4211       return -1;
4212   }
4213   /* TestOutput for cat (0) */
4214   {
4215     int r;
4216     suppress_error = 0;
4217     r = guestfs_write_file (g, "/new", "new file contents", 0);
4218     if (r == -1)
4219       return -1;
4220   }
4221   {
4222     char *r;
4223     suppress_error = 0;
4224     r = guestfs_cat (g, "/new");
4225     if (r == NULL)
4226       return -1;
4227     if (strcmp (r, "new file contents") != 0) {
4228       fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r);
4229       return -1;
4230     }
4231     free (r);
4232   }
4233   return 0;
4234 }
4235
4236 static int test_touch_0 (void)
4237 {
4238   /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */
4239   {
4240     int r;
4241     suppress_error = 0;
4242     r = guestfs_umount_all (g);
4243     if (r == -1)
4244       return -1;
4245   }
4246   {
4247     int r;
4248     suppress_error = 0;
4249     r = guestfs_lvm_remove_all (g);
4250     if (r == -1)
4251       return -1;
4252   }
4253   {
4254     char *lines[] = {
4255       ",",
4256       NULL
4257     };
4258     int r;
4259     suppress_error = 0;
4260     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4261     if (r == -1)
4262       return -1;
4263   }
4264   {
4265     int r;
4266     suppress_error = 0;
4267     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4268     if (r == -1)
4269       return -1;
4270   }
4271   {
4272     int r;
4273     suppress_error = 0;
4274     r = guestfs_mount (g, "/dev/sda1", "/");
4275     if (r == -1)
4276       return -1;
4277   }
4278   /* TestOutputTrue for touch (0) */
4279   {
4280     int r;
4281     suppress_error = 0;
4282     r = guestfs_touch (g, "/new");
4283     if (r == -1)
4284       return -1;
4285   }
4286   {
4287     int r;
4288     suppress_error = 0;
4289     r = guestfs_exists (g, "/new");
4290     if (r == -1)
4291       return -1;
4292     if (!r) {
4293       fprintf (stderr, "test_touch_0: expected true, got false\n");
4294       return -1;
4295     }
4296   }
4297   return 0;
4298 }
4299
4300 static int test_sync_0 (void)
4301 {
4302   /* InitEmpty for sync (0) */
4303   {
4304     int r;
4305     suppress_error = 0;
4306     r = guestfs_umount_all (g);
4307     if (r == -1)
4308       return -1;
4309   }
4310   {
4311     int r;
4312     suppress_error = 0;
4313     r = guestfs_lvm_remove_all (g);
4314     if (r == -1)
4315       return -1;
4316   }
4317   /* TestRun for sync (0) */
4318   {
4319     int r;
4320     suppress_error = 0;
4321     r = guestfs_sync (g);
4322     if (r == -1)
4323       return -1;
4324   }
4325   return 0;
4326 }
4327
4328 static int test_mount_0 (void)
4329 {
4330   /* InitEmpty for mount (0) */
4331   {
4332     int r;
4333     suppress_error = 0;
4334     r = guestfs_umount_all (g);
4335     if (r == -1)
4336       return -1;
4337   }
4338   {
4339     int r;
4340     suppress_error = 0;
4341     r = guestfs_lvm_remove_all (g);
4342     if (r == -1)
4343       return -1;
4344   }
4345   /* TestOutput for mount (0) */
4346   {
4347     char *lines[] = {
4348       ",",
4349       NULL
4350     };
4351     int r;
4352     suppress_error = 0;
4353     r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines);
4354     if (r == -1)
4355       return -1;
4356   }
4357   {
4358     int r;
4359     suppress_error = 0;
4360     r = guestfs_mkfs (g, "ext2", "/dev/sda1");
4361     if (r == -1)
4362       return -1;
4363   }
4364   {
4365     int r;
4366     suppress_error = 0;
4367     r = guestfs_mount (g, "/dev/sda1", "/");
4368     if (r == -1)
4369       return -1;
4370   }
4371   {
4372     int r;
4373     suppress_error = 0;
4374     r = guestfs_write_file (g, "/new", "new file contents", 0);
4375     if (r == -1)
4376       return -1;
4377   }
4378   {
4379     char *r;
4380     suppress_error = 0;
4381     r = guestfs_cat (g, "/new");
4382     if (r == NULL)
4383       return -1;
4384     if (strcmp (r, "new file contents") != 0) {
4385       fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r);
4386       return -1;
4387     }
4388     free (r);
4389   }
4390   return 0;
4391 }
4392
4393 int main (int argc, char *argv[])
4394 {
4395   char c = 0;
4396   int failed = 0;
4397   const char *srcdir;
4398   int fd;
4399   char buf[256];
4400   int nr_tests, test_num = 0;
4401
4402   no_test_warnings ();
4403
4404   g = guestfs_create ();
4405   if (g == NULL) {
4406     printf ("guestfs_create FAILED\n");
4407     exit (1);
4408   }
4409
4410   guestfs_set_error_handler (g, print_error, NULL);
4411
4412   srcdir = getenv ("srcdir");
4413   if (!srcdir) srcdir = ".";
4414   guestfs_set_path (g, srcdir);
4415
4416   snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
4417   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4418   if (fd == -1) {
4419     perror (buf);
4420     exit (1);
4421   }
4422   if (lseek (fd, 524288000, SEEK_SET) == -1) {
4423     perror ("lseek");
4424     close (fd);
4425     unlink (buf);
4426     exit (1);
4427   }
4428   if (write (fd, &c, 1) == -1) {
4429     perror ("write");
4430     close (fd);
4431     unlink (buf);
4432     exit (1);
4433   }
4434   if (close (fd) == -1) {
4435     perror (buf);
4436     unlink (buf);
4437     exit (1);
4438   }
4439   if (guestfs_add_drive (g, buf) == -1) {
4440     printf ("guestfs_add_drive %s FAILED\n", buf);
4441     exit (1);
4442   }
4443
4444   snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
4445   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4446   if (fd == -1) {
4447     perror (buf);
4448     exit (1);
4449   }
4450   if (lseek (fd, 52428800, SEEK_SET) == -1) {
4451     perror ("lseek");
4452     close (fd);
4453     unlink (buf);
4454     exit (1);
4455   }
4456   if (write (fd, &c, 1) == -1) {
4457     perror ("write");
4458     close (fd);
4459     unlink (buf);
4460     exit (1);
4461   }
4462   if (close (fd) == -1) {
4463     perror (buf);
4464     unlink (buf);
4465     exit (1);
4466   }
4467   if (guestfs_add_drive (g, buf) == -1) {
4468     printf ("guestfs_add_drive %s FAILED\n", buf);
4469     exit (1);
4470   }
4471
4472   snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
4473   fd = open (buf, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666);
4474   if (fd == -1) {
4475     perror (buf);
4476     exit (1);
4477   }
4478   if (lseek (fd, 10485760, SEEK_SET) == -1) {
4479     perror ("lseek");
4480     close (fd);
4481     unlink (buf);
4482     exit (1);
4483   }
4484   if (write (fd, &c, 1) == -1) {
4485     perror ("write");
4486     close (fd);
4487     unlink (buf);
4488     exit (1);
4489   }
4490   if (close (fd) == -1) {
4491     perror (buf);
4492     unlink (buf);
4493     exit (1);
4494   }
4495   if (guestfs_add_drive (g, buf) == -1) {
4496     printf ("guestfs_add_drive %s FAILED\n", buf);
4497     exit (1);
4498   }
4499
4500   if (guestfs_launch (g) == -1) {
4501     printf ("guestfs_launch FAILED\n");
4502     exit (1);
4503   }
4504   if (guestfs_wait_ready (g) == -1) {
4505     printf ("guestfs_wait_ready FAILED\n");
4506     exit (1);
4507   }
4508
4509   nr_tests = 63;
4510
4511   test_num++;
4512   printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests);
4513   if (test_blockdev_rereadpt_0 () == -1) {
4514     printf ("test_blockdev_rereadpt_0 FAILED\n");
4515     failed++;
4516   }
4517   test_num++;
4518   printf ("%3d/%3d test_blockdev_flushbufs_0\n", test_num, nr_tests);
4519   if (test_blockdev_flushbufs_0 () == -1) {
4520     printf ("test_blockdev_flushbufs_0 FAILED\n");
4521     failed++;
4522   }
4523   test_num++;
4524   printf ("%3d/%3d test_blockdev_getsize64_0\n", test_num, nr_tests);
4525   if (test_blockdev_getsize64_0 () == -1) {
4526     printf ("test_blockdev_getsize64_0 FAILED\n");
4527     failed++;
4528   }
4529   test_num++;
4530   printf ("%3d/%3d test_blockdev_getsz_0\n", test_num, nr_tests);
4531   if (test_blockdev_getsz_0 () == -1) {
4532     printf ("test_blockdev_getsz_0 FAILED\n");
4533     failed++;
4534   }
4535   test_num++;
4536   printf ("%3d/%3d test_blockdev_getbsz_0\n", test_num, nr_tests);
4537   if (test_blockdev_getbsz_0 () == -1) {
4538     printf ("test_blockdev_getbsz_0 FAILED\n");
4539     failed++;
4540   }
4541   test_num++;
4542   printf ("%3d/%3d test_blockdev_getss_0\n", test_num, nr_tests);
4543   if (test_blockdev_getss_0 () == -1) {
4544     printf ("test_blockdev_getss_0 FAILED\n");
4545     failed++;
4546   }
4547   test_num++;
4548   printf ("%3d/%3d test_blockdev_getro_0\n", test_num, nr_tests);
4549   if (test_blockdev_getro_0 () == -1) {
4550     printf ("test_blockdev_getro_0 FAILED\n");
4551     failed++;
4552   }
4553   test_num++;
4554   printf ("%3d/%3d test_blockdev_setrw_0\n", test_num, nr_tests);
4555   if (test_blockdev_setrw_0 () == -1) {
4556     printf ("test_blockdev_setrw_0 FAILED\n");
4557     failed++;
4558   }
4559   test_num++;
4560   printf ("%3d/%3d test_blockdev_setro_0\n", test_num, nr_tests);
4561   if (test_blockdev_setro_0 () == -1) {
4562     printf ("test_blockdev_setro_0 FAILED\n");
4563     failed++;
4564   }
4565   test_num++;
4566   printf ("%3d/%3d test_statvfs_0\n", test_num, nr_tests);
4567   if (test_statvfs_0 () == -1) {
4568     printf ("test_statvfs_0 FAILED\n");
4569     failed++;
4570   }
4571   test_num++;
4572   printf ("%3d/%3d test_lstat_0\n", test_num, nr_tests);
4573   if (test_lstat_0 () == -1) {
4574     printf ("test_lstat_0 FAILED\n");
4575     failed++;
4576   }
4577   test_num++;
4578   printf ("%3d/%3d test_stat_0\n", test_num, nr_tests);
4579   if (test_stat_0 () == -1) {
4580     printf ("test_stat_0 FAILED\n");
4581     failed++;
4582   }
4583   test_num++;
4584   printf ("%3d/%3d test_file_0\n", test_num, nr_tests);
4585   if (test_file_0 () == -1) {
4586     printf ("test_file_0 FAILED\n");
4587     failed++;
4588   }
4589   test_num++;
4590   printf ("%3d/%3d test_file_1\n", test_num, nr_tests);
4591   if (test_file_1 () == -1) {
4592     printf ("test_file_1 FAILED\n");
4593     failed++;
4594   }
4595   test_num++;
4596   printf ("%3d/%3d test_file_2\n", test_num, nr_tests);
4597   if (test_file_2 () == -1) {
4598     printf ("test_file_2 FAILED\n");
4599     failed++;
4600   }
4601   test_num++;
4602   printf ("%3d/%3d test_umount_all_0\n", test_num, nr_tests);
4603   if (test_umount_all_0 () == -1) {
4604     printf ("test_umount_all_0 FAILED\n");
4605     failed++;
4606   }
4607   test_num++;
4608   printf ("%3d/%3d test_mounts_0\n", test_num, nr_tests);
4609   if (test_mounts_0 () == -1) {
4610     printf ("test_mounts_0 FAILED\n");
4611     failed++;
4612   }
4613   test_num++;
4614   printf ("%3d/%3d test_umount_0\n", test_num, nr_tests);
4615   if (test_umount_0 () == -1) {
4616     printf ("test_umount_0 FAILED\n");
4617     failed++;
4618   }
4619   test_num++;
4620   printf ("%3d/%3d test_umount_1\n", test_num, nr_tests);
4621   if (test_umount_1 () == -1) {
4622     printf ("test_umount_1 FAILED\n");
4623     failed++;
4624   }
4625   test_num++;
4626   printf ("%3d/%3d test_write_file_0\n", test_num, nr_tests);
4627   if (test_write_file_0 () == -1) {
4628     printf ("test_write_file_0 FAILED\n");
4629     failed++;
4630   }
4631   test_num++;
4632   printf ("%3d/%3d test_write_file_1\n", test_num, nr_tests);
4633   if (test_write_file_1 () == -1) {
4634     printf ("test_write_file_1 FAILED\n");
4635     failed++;
4636   }
4637   test_num++;
4638   printf ("%3d/%3d test_write_file_2\n", test_num, nr_tests);
4639   if (test_write_file_2 () == -1) {
4640     printf ("test_write_file_2 FAILED\n");
4641     failed++;
4642   }
4643   test_num++;
4644   printf ("%3d/%3d test_write_file_3\n", test_num, nr_tests);
4645   if (test_write_file_3 () == -1) {
4646     printf ("test_write_file_3 FAILED\n");
4647     failed++;
4648   }
4649   test_num++;
4650   printf ("%3d/%3d test_write_file_4\n", test_num, nr_tests);
4651   if (test_write_file_4 () == -1) {
4652     printf ("test_write_file_4 FAILED\n");
4653     failed++;
4654   }
4655   test_num++;
4656   printf ("%3d/%3d test_write_file_5\n", test_num, nr_tests);
4657   if (test_write_file_5 () == -1) {
4658     printf ("test_write_file_5 FAILED\n");
4659     failed++;
4660   }
4661   test_num++;
4662   printf ("%3d/%3d test_mkfs_0\n", test_num, nr_tests);
4663   if (test_mkfs_0 () == -1) {
4664     printf ("test_mkfs_0 FAILED\n");
4665     failed++;
4666   }
4667   test_num++;
4668   printf ("%3d/%3d test_lvcreate_0\n", test_num, nr_tests);
4669   if (test_lvcreate_0 () == -1) {
4670     printf ("test_lvcreate_0 FAILED\n");
4671     failed++;
4672   }
4673   test_num++;
4674   printf ("%3d/%3d test_vgcreate_0\n", test_num, nr_tests);
4675   if (test_vgcreate_0 () == -1) {
4676     printf ("test_vgcreate_0 FAILED\n");
4677     failed++;
4678   }
4679   test_num++;
4680   printf ("%3d/%3d test_pvcreate_0\n", test_num, nr_tests);
4681   if (test_pvcreate_0 () == -1) {
4682     printf ("test_pvcreate_0 FAILED\n");
4683     failed++;
4684   }
4685   test_num++;
4686   printf ("%3d/%3d test_is_dir_0\n", test_num, nr_tests);
4687   if (test_is_dir_0 () == -1) {
4688     printf ("test_is_dir_0 FAILED\n");
4689     failed++;
4690   }
4691   test_num++;
4692   printf ("%3d/%3d test_is_dir_1\n", test_num, nr_tests);
4693   if (test_is_dir_1 () == -1) {
4694     printf ("test_is_dir_1 FAILED\n");
4695     failed++;
4696   }
4697   test_num++;
4698   printf ("%3d/%3d test_is_file_0\n", test_num, nr_tests);
4699   if (test_is_file_0 () == -1) {
4700     printf ("test_is_file_0 FAILED\n");
4701     failed++;
4702   }
4703   test_num++;
4704   printf ("%3d/%3d test_is_file_1\n", test_num, nr_tests);
4705   if (test_is_file_1 () == -1) {
4706     printf ("test_is_file_1 FAILED\n");
4707     failed++;
4708   }
4709   test_num++;
4710   printf ("%3d/%3d test_exists_0\n", test_num, nr_tests);
4711   if (test_exists_0 () == -1) {
4712     printf ("test_exists_0 FAILED\n");
4713     failed++;
4714   }
4715   test_num++;
4716   printf ("%3d/%3d test_exists_1\n", test_num, nr_tests);
4717   if (test_exists_1 () == -1) {
4718     printf ("test_exists_1 FAILED\n");
4719     failed++;
4720   }
4721   test_num++;
4722   printf ("%3d/%3d test_mkdir_p_0\n", test_num, nr_tests);
4723   if (test_mkdir_p_0 () == -1) {
4724     printf ("test_mkdir_p_0 FAILED\n");
4725     failed++;
4726   }
4727   test_num++;
4728   printf ("%3d/%3d test_mkdir_p_1\n", test_num, nr_tests);
4729   if (test_mkdir_p_1 () == -1) {
4730     printf ("test_mkdir_p_1 FAILED\n");
4731     failed++;
4732   }
4733   test_num++;
4734   printf ("%3d/%3d test_mkdir_p_2\n", test_num, nr_tests);
4735   if (test_mkdir_p_2 () == -1) {
4736     printf ("test_mkdir_p_2 FAILED\n");
4737     failed++;
4738   }
4739   test_num++;
4740   printf ("%3d/%3d test_mkdir_0\n", test_num, nr_tests);
4741   if (test_mkdir_0 () == -1) {
4742     printf ("test_mkdir_0 FAILED\n");
4743     failed++;
4744   }
4745   test_num++;
4746   printf ("%3d/%3d test_mkdir_1\n", test_num, nr_tests);
4747   if (test_mkdir_1 () == -1) {
4748     printf ("test_mkdir_1 FAILED\n");
4749     failed++;
4750   }
4751   test_num++;
4752   printf ("%3d/%3d test_rm_rf_0\n", test_num, nr_tests);
4753   if (test_rm_rf_0 () == -1) {
4754     printf ("test_rm_rf_0 FAILED\n");
4755     failed++;
4756   }
4757   test_num++;
4758   printf ("%3d/%3d test_rmdir_0\n", test_num, nr_tests);
4759   if (test_rmdir_0 () == -1) {
4760     printf ("test_rmdir_0 FAILED\n");
4761     failed++;
4762   }
4763   test_num++;
4764   printf ("%3d/%3d test_rmdir_1\n", test_num, nr_tests);
4765   if (test_rmdir_1 () == -1) {
4766     printf ("test_rmdir_1 FAILED\n");
4767     failed++;
4768   }
4769   test_num++;
4770   printf ("%3d/%3d test_rmdir_2\n", test_num, nr_tests);
4771   if (test_rmdir_2 () == -1) {
4772     printf ("test_rmdir_2 FAILED\n");
4773     failed++;
4774   }
4775   test_num++;
4776   printf ("%3d/%3d test_rm_0\n", test_num, nr_tests);
4777   if (test_rm_0 () == -1) {
4778     printf ("test_rm_0 FAILED\n");
4779     failed++;
4780   }
4781   test_num++;
4782   printf ("%3d/%3d test_rm_1\n", test_num, nr_tests);
4783   if (test_rm_1 () == -1) {
4784     printf ("test_rm_1 FAILED\n");
4785     failed++;
4786   }
4787   test_num++;
4788   printf ("%3d/%3d test_rm_2\n", test_num, nr_tests);
4789   if (test_rm_2 () == -1) {
4790     printf ("test_rm_2 FAILED\n");
4791     failed++;
4792   }
4793   test_num++;
4794   printf ("%3d/%3d test_read_lines_0\n", test_num, nr_tests);
4795   if (test_read_lines_0 () == -1) {
4796     printf ("test_read_lines_0 FAILED\n");
4797     failed++;
4798   }
4799   test_num++;
4800   printf ("%3d/%3d test_read_lines_1\n", test_num, nr_tests);
4801   if (test_read_lines_1 () == -1) {
4802     printf ("test_read_lines_1 FAILED\n");
4803     failed++;
4804   }
4805   test_num++;
4806   printf ("%3d/%3d test_lvs_0\n", test_num, nr_tests);
4807   if (test_lvs_0 () == -1) {
4808     printf ("test_lvs_0 FAILED\n");
4809     failed++;
4810   }
4811   test_num++;
4812   printf ("%3d/%3d test_lvs_1\n", test_num, nr_tests);
4813   if (test_lvs_1 () == -1) {
4814     printf ("test_lvs_1 FAILED\n");
4815     failed++;
4816   }
4817   test_num++;
4818   printf ("%3d/%3d test_vgs_0\n", test_num, nr_tests);
4819   if (test_vgs_0 () == -1) {
4820     printf ("test_vgs_0 FAILED\n");
4821     failed++;
4822   }
4823   test_num++;
4824   printf ("%3d/%3d test_vgs_1\n", test_num, nr_tests);
4825   if (test_vgs_1 () == -1) {
4826     printf ("test_vgs_1 FAILED\n");
4827     failed++;
4828   }
4829   test_num++;
4830   printf ("%3d/%3d test_pvs_0\n", test_num, nr_tests);
4831   if (test_pvs_0 () == -1) {
4832     printf ("test_pvs_0 FAILED\n");
4833     failed++;
4834   }
4835   test_num++;
4836   printf ("%3d/%3d test_pvs_1\n", test_num, nr_tests);
4837   if (test_pvs_1 () == -1) {
4838     printf ("test_pvs_1 FAILED\n");
4839     failed++;
4840   }
4841   test_num++;
4842   printf ("%3d/%3d test_list_partitions_0\n", test_num, nr_tests);
4843   if (test_list_partitions_0 () == -1) {
4844     printf ("test_list_partitions_0 FAILED\n");
4845     failed++;
4846   }
4847   test_num++;
4848   printf ("%3d/%3d test_list_partitions_1\n", test_num, nr_tests);
4849   if (test_list_partitions_1 () == -1) {
4850     printf ("test_list_partitions_1 FAILED\n");
4851     failed++;
4852   }
4853   test_num++;
4854   printf ("%3d/%3d test_list_devices_0\n", test_num, nr_tests);
4855   if (test_list_devices_0 () == -1) {
4856     printf ("test_list_devices_0 FAILED\n");
4857     failed++;
4858   }
4859   test_num++;
4860   printf ("%3d/%3d test_ls_0\n", test_num, nr_tests);
4861   if (test_ls_0 () == -1) {
4862     printf ("test_ls_0 FAILED\n");
4863     failed++;
4864   }
4865   test_num++;
4866   printf ("%3d/%3d test_cat_0\n", test_num, nr_tests);
4867   if (test_cat_0 () == -1) {
4868     printf ("test_cat_0 FAILED\n");
4869     failed++;
4870   }
4871   test_num++;
4872   printf ("%3d/%3d test_touch_0\n", test_num, nr_tests);
4873   if (test_touch_0 () == -1) {
4874     printf ("test_touch_0 FAILED\n");
4875     failed++;
4876   }
4877   test_num++;
4878   printf ("%3d/%3d test_sync_0\n", test_num, nr_tests);
4879   if (test_sync_0 () == -1) {
4880     printf ("test_sync_0 FAILED\n");
4881     failed++;
4882   }
4883   test_num++;
4884   printf ("%3d/%3d test_mount_0\n", test_num, nr_tests);
4885   if (test_mount_0 () == -1) {
4886     printf ("test_mount_0 FAILED\n");
4887     failed++;
4888   }
4889
4890   guestfs_close (g);
4891   snprintf (buf, sizeof buf, "%s/test1.img", srcdir);
4892   unlink (buf);
4893   snprintf (buf, sizeof buf, "%s/test2.img", srcdir);
4894   unlink (buf);
4895   snprintf (buf, sizeof buf, "%s/test3.img", srcdir);
4896   unlink (buf);
4897
4898   if (failed > 0) {
4899     printf ("***** %d / %d tests FAILED *****\n", failed, nr_tests);
4900     exit (1);
4901   }
4902
4903   exit (0);
4904 }