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