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