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