+static void print_error (guestfs_h *g, void *data, const char *msg)
+{
+ if (!suppress_error)
+ fprintf (stderr, "%s\n", msg);
+}
+
+static void print_strings (char * const * const argv)
+{
+ int argc;
+
+ for (argc = 0; argv[argc] != NULL; ++argc)
+ printf ("\t%s\n", argv[argc]);
+}
+
+/*
+static void print_table (char * const * const argv)
+{
+ int i;
+
+ for (i = 0; argv[i] != NULL; i += 2)
+ printf ("%s: %s\n", argv[i], argv[i+1]);
+}
+*/
+
+static void no_test_warnings (void)
+{
+ fprintf (stderr, "warning: \"guestfs_test0\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rint\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rinterr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rint64\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rint64err\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rbool\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rboolerr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rconststring\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rconststringerr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstring\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstringerr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstringlist\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstringlisterr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rintbool\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rintboolerr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rpvlist\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rpvlisterr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rvglist\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rvglisterr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rlvlist\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rlvlisterr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstat\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstaterr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstatvfs\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rstatvfserr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rhashtable\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_test0rhashtableerr\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_launch\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_wait_ready\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_kill_subprocess\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_add_drive_ro\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_config\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_qemu\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_qemu\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_append\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_append\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_is_ready\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_is_config\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_is_launching\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_is_busy\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_state\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_busy\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_set_ready\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_end_busy\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_tar_out\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_tgz_out\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_mount_options\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_mount_vfs\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_debug\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_e2label\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_pvresize\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sfdisk_N\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sfdisk_l\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sfdisk_kernel_geometry\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sfdisk_disk_geometry\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_vg_activate_all\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_vg_activate\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_resize2fs\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_e2fsck_f\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sh\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_sh_lines\" has no tests\n");
+}
+
+static int test_glob_expand_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_GLOB_EXPAND_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_GLOB_EXPAND");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_glob_expand_0 (void)
+{
+ if (test_glob_expand_0_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_glob_expand_0");
+ return 0;
+ }
+
+ /* InitBasicFS for test_glob_expand_0: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for glob_expand (0) */
+ {
+ char path[] = "/a/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir_p (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/d";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/e";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char pattern[] = "/a/b/c/*";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_glob_expand_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/d";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_0: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_glob_expand_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/e";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_0: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (r[2] != NULL) {
+ fprintf (stderr, "test_glob_expand_0: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
+static int test_glob_expand_1_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_GLOB_EXPAND_1");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_GLOB_EXPAND");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_glob_expand_1 (void)
+{
+ if (test_glob_expand_1_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_glob_expand_1");
+ return 0;
+ }
+
+ /* InitBasicFS for test_glob_expand_1: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for glob_expand (1) */
+ {
+ char path[] = "/a/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir_p (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/d";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/e";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char pattern[] = "/a/*/c/*";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_glob_expand_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/d";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_1: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_glob_expand_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/e";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_1: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (r[2] != NULL) {
+ fprintf (stderr, "test_glob_expand_1: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
+static int test_glob_expand_2_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_GLOB_EXPAND_2");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_GLOB_EXPAND");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_glob_expand_2 (void)
+{
+ if (test_glob_expand_2_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_glob_expand_2");
+ return 0;
+ }
+
+ /* InitBasicFS for test_glob_expand_2: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for glob_expand (2) */
+ {
+ char path[] = "/a/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir_p (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/d";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/e";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char pattern[] = "/a/*/x/*";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL)
+ return -1;
+ if (r[0] != NULL) {
+ fprintf (stderr, "test_glob_expand_2: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
+static int test_ntfs_3g_probe_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_NTFS_3G_PROBE_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_NTFS_3G_PROBE");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_ntfs_3g_probe_0 (void)
+{
+ if (test_ntfs_3g_probe_0_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_ntfs_3g_probe_0");
+ return 0;
+ }
+
+ /* InitNone|InitEmpty for test_ntfs_3g_probe_0 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputInt for ntfs_3g_probe (0) */
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ntfs";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_ntfs_3g_probe (g, 1, device);
+ if (r == -1)
+ return -1;
+ if (r != 0) {
+ fprintf (stderr, "test_ntfs_3g_probe_0: expected 0 but got %d\n", (int) r);
+ return -1;
+ }
+ }
+ return 0;
+}