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