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