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