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