X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=tests.c;h=aef5dd091da8a469986ff50566b6107da7d45043;hb=e038597ebd1e43c83a8ddde21c4f1898eb7a9a98;hp=3e0fbd3dfe361cc320cedb4c6a0d725feaf8a36f;hpb=b4d2a01828e5de85e5eee3631f7fe3925a0312ca;p=libguestfs.git diff --git a/tests.c b/tests.c index 3e0fbd3..aef5dd0 100644 --- a/tests.c +++ b/tests.c @@ -45,9 +45,57 @@ static void print_strings (char * const * const argv) 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: \"launch\" has no tests\n"); + fprintf (stderr, "warning: \"wait_ready\" has no tests\n"); + fprintf (stderr, "warning: \"kill_subprocess\" has no tests\n"); + fprintf (stderr, "warning: \"add_drive\" has no tests\n"); + fprintf (stderr, "warning: \"add_cdrom\" has no tests\n"); + fprintf (stderr, "warning: \"config\" has no tests\n"); + fprintf (stderr, "warning: \"set_path\" has no tests\n"); + fprintf (stderr, "warning: \"get_path\" has no tests\n"); + fprintf (stderr, "warning: \"set_autosync\" has no tests\n"); + fprintf (stderr, "warning: \"get_autosync\" has no tests\n"); + fprintf (stderr, "warning: \"set_verbose\" has no tests\n"); + fprintf (stderr, "warning: \"get_verbose\" has no tests\n"); + fprintf (stderr, "warning: \"ll\" has no tests\n"); + fprintf (stderr, "warning: \"pvs_full\" has no tests\n"); + fprintf (stderr, "warning: \"vgs_full\" has no tests\n"); + fprintf (stderr, "warning: \"lvs_full\" has no tests\n"); + fprintf (stderr, "warning: \"aug_init\" has no tests\n"); + fprintf (stderr, "warning: \"aug_close\" has no tests\n"); + fprintf (stderr, "warning: \"aug_defvar\" has no tests\n"); + fprintf (stderr, "warning: \"aug_defnode\" has no tests\n"); + fprintf (stderr, "warning: \"aug_get\" has no tests\n"); + fprintf (stderr, "warning: \"aug_set\" has no tests\n"); + fprintf (stderr, "warning: \"aug_insert\" has no tests\n"); + fprintf (stderr, "warning: \"aug_rm\" has no tests\n"); + fprintf (stderr, "warning: \"aug_mv\" has no tests\n"); + fprintf (stderr, "warning: \"aug_match\" has no tests\n"); + fprintf (stderr, "warning: \"aug_save\" has no tests\n"); + fprintf (stderr, "warning: \"aug_load\" has no tests\n"); + fprintf (stderr, "warning: \"aug_ls\" has no tests\n"); + fprintf (stderr, "warning: \"chmod\" has no tests\n"); + fprintf (stderr, "warning: \"chown\" has no tests\n"); + fprintf (stderr, "warning: \"sfdisk\" has no tests\n"); + fprintf (stderr, "warning: \"lvm_remove_all\" has no tests\n"); + fprintf (stderr, "warning: \"command\" has no tests\n"); + fprintf (stderr, "warning: \"command_lines\" has no tests\n"); + fprintf (stderr, "warning: \"tune2fs_l\" has no tests\n"); +} + static int test_mount_0 (void) { - /* InitNone for mount (0) */ + /* InitEmpty for mount (0) */ { int r; suppress_error = 0; @@ -112,7 +160,7 @@ static int test_mount_0 (void) static int test_sync_0 (void) { - /* InitNone for sync (0) */ + /* InitEmpty for sync (0) */ { int r; suppress_error = 0; @@ -140,7 +188,7 @@ static int test_sync_0 (void) static int test_touch_0 (void) { - /* InitEmpty for touch (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -204,7 +252,7 @@ static int test_touch_0 (void) static int test_cat_0 (void) { - /* InitEmpty for cat (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -269,7 +317,7 @@ static int test_cat_0 (void) static int test_ls_0 (void) { - /* InitEmpty for ls (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -388,7 +436,7 @@ static int test_ls_0 (void) static int test_list_devices_0 (void) { - /* InitNone for list_devices (0) */ + /* InitEmpty for list_devices (0) */ { int r; suppress_error = 0; @@ -452,7 +500,7 @@ static int test_list_devices_0 (void) static int test_list_partitions_0 (void) { - /* InitEmpty for list_partitions (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -523,7 +571,7 @@ static int test_list_partitions_0 (void) static int test_list_partitions_1 (void) { - /* InitNone for list_partitions (1) */ + /* InitEmpty for list_partitions (1) */ { int r; suppress_error = 0; @@ -600,7 +648,7 @@ static int test_list_partitions_1 (void) static int test_pvs_0 (void) { - /* InitEmptyLVM for pvs (0): create ext2 on /dev/VG/LV */ + /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */ { int r; suppress_error = 0; @@ -696,7 +744,7 @@ static int test_pvs_0 (void) static int test_pvs_1 (void) { - /* InitNone for pvs (1) */ + /* InitEmpty for pvs (1) */ { int r; suppress_error = 0; @@ -794,7 +842,7 @@ static int test_pvs_1 (void) static int test_vgs_0 (void) { - /* InitEmptyLVM for vgs (0): create ext2 on /dev/VG/LV */ + /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */ { int r; suppress_error = 0; @@ -890,7 +938,7 @@ static int test_vgs_0 (void) static int test_vgs_1 (void) { - /* InitNone for vgs (1) */ + /* InitEmpty for vgs (1) */ { int r; suppress_error = 0; @@ -1002,7 +1050,7 @@ static int test_vgs_1 (void) static int test_lvs_0 (void) { - /* InitEmptyLVM for lvs (0): create ext2 on /dev/VG/LV */ + /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */ { int r; suppress_error = 0; @@ -1098,7 +1146,7 @@ static int test_lvs_0 (void) static int test_lvs_1 (void) { - /* InitNone for lvs (1) */ + /* InitEmpty for lvs (1) */ { int r; suppress_error = 0; @@ -1238,291 +1286,9 @@ static int test_lvs_1 (void) return 0; } -static int test_pvs_full_0 (void) -{ - /* InitEmptyLVM for pvs_full (0): create ext2 on /dev/VG/LV */ - { - 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 *lines[] = { - ",", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV", "VG", 8); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mount (g, "/dev/VG/LV", "/"); - if (r == -1) - return -1; - } - /* TestOutputLength for pvs_full (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - int j; - for (j = 0; j < 1; ++j) - if (r[j] == NULL) { - fprintf (stderr, "test_pvs_full_0: short list returned\n"); - print_strings (r); - return -1; - } - if (r[j] != NULL) { - fprintf (stderr, "test_pvs_full_0: long list returned\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_vgs_full_0 (void) -{ - /* InitEmptyLVM for vgs_full (0): create ext2 on /dev/VG/LV */ - { - 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 *lines[] = { - ",", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV", "VG", 8); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mount (g, "/dev/VG/LV", "/"); - if (r == -1) - return -1; - } - /* TestOutputLength for vgs_full (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - int j; - for (j = 0; j < 1; ++j) - if (r[j] == NULL) { - fprintf (stderr, "test_vgs_full_0: short list returned\n"); - print_strings (r); - return -1; - } - if (r[j] != NULL) { - fprintf (stderr, "test_vgs_full_0: long list returned\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - -static int test_lvs_full_0 (void) -{ - /* InitEmptyLVM for lvs_full (0): create ext2 on /dev/VG/LV */ - { - 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 *lines[] = { - ",", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV", "VG", 8); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mount (g, "/dev/VG/LV", "/"); - if (r == -1) - return -1; - } - /* TestOutputLength for lvs_full (0) */ - { - char **r; - int i; - suppress_error = 0; - r = guestfs_pvs (g); - if (r == NULL) - return -1; - int j; - for (j = 0; j < 1; ++j) - if (r[j] == NULL) { - fprintf (stderr, "test_lvs_full_0: short list returned\n"); - print_strings (r); - return -1; - } - if (r[j] != NULL) { - fprintf (stderr, "test_lvs_full_0: long list returned\n"); - print_strings (r); - return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); - } - return 0; -} - static int test_read_lines_0 (void) { - /* InitEmpty for read_lines (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1618,7 +1384,7 @@ static int test_read_lines_0 (void) static int test_read_lines_1 (void) { - /* InitEmpty for read_lines (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1687,7 +1453,7 @@ static int test_read_lines_1 (void) static int test_rm_0 (void) { - /* InitEmpty for rm (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1747,7 +1513,7 @@ static int test_rm_0 (void) static int test_rm_1 (void) { - /* InitEmpty for rm (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1800,7 +1566,7 @@ static int test_rm_1 (void) static int test_rm_2 (void) { - /* InitEmpty for rm (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1860,7 +1626,7 @@ static int test_rm_2 (void) static int test_rmdir_0 (void) { - /* InitEmpty for rmdir (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1920,7 +1686,7 @@ static int test_rmdir_0 (void) static int test_rmdir_1 (void) { - /* InitEmpty for rmdir (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1973,7 +1739,7 @@ static int test_rmdir_1 (void) static int test_rmdir_2 (void) { - /* InitEmpty for rmdir (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2033,7 +1799,7 @@ static int test_rmdir_2 (void) static int test_rm_rf_0 (void) { - /* InitEmpty for rm_rf (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2118,7 +1884,7 @@ static int test_rm_rf_0 (void) static int test_mkdir_0 (void) { - /* InitEmpty for mkdir (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2182,7 +1948,7 @@ static int test_mkdir_0 (void) static int test_mkdir_1 (void) { - /* InitEmpty for mkdir (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2235,7 +2001,7 @@ static int test_mkdir_1 (void) static int test_mkdir_p_0 (void) { - /* InitEmpty for mkdir_p (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2299,7 +2065,7 @@ static int test_mkdir_p_0 (void) static int test_mkdir_p_1 (void) { - /* InitEmpty for mkdir_p (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2363,7 +2129,7 @@ static int test_mkdir_p_1 (void) static int test_mkdir_p_2 (void) { - /* InitEmpty for mkdir_p (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2427,7 +2193,7 @@ static int test_mkdir_p_2 (void) static int test_exists_0 (void) { - /* InitEmpty for exists (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2491,7 +2257,7 @@ static int test_exists_0 (void) static int test_exists_1 (void) { - /* InitEmpty for exists (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2555,7 +2321,7 @@ static int test_exists_1 (void) static int test_is_file_0 (void) { - /* InitEmpty for is_file (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2619,7 +2385,7 @@ static int test_is_file_0 (void) static int test_is_file_1 (void) { - /* InitEmpty for is_file (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2683,7 +2449,7 @@ static int test_is_file_1 (void) static int test_is_dir_0 (void) { - /* InitEmpty for is_dir (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2747,7 +2513,7 @@ static int test_is_dir_0 (void) static int test_is_dir_1 (void) { - /* InitEmpty for is_dir (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2811,7 +2577,7 @@ static int test_is_dir_1 (void) static int test_pvcreate_0 (void) { - /* InitNone for pvcreate (0) */ + /* InitEmpty for pvcreate (0) */ { int r; suppress_error = 0; @@ -2909,7 +2675,7 @@ static int test_pvcreate_0 (void) static int test_vgcreate_0 (void) { - /* InitNone for vgcreate (0) */ + /* InitEmpty for vgcreate (0) */ { int r; suppress_error = 0; @@ -3021,7 +2787,7 @@ static int test_vgcreate_0 (void) static int test_lvcreate_0 (void) { - /* InitNone for lvcreate (0) */ + /* InitEmpty for lvcreate (0) */ { int r; suppress_error = 0; @@ -3195,7 +2961,7 @@ static int test_lvcreate_0 (void) static int test_mkfs_0 (void) { - /* InitNone for mkfs (0) */ + /* InitEmpty for mkfs (0) */ { int r; suppress_error = 0; @@ -3260,7 +3026,7 @@ static int test_mkfs_0 (void) static int test_write_file_0 (void) { - /* InitNone for write_file (0) */ + /* InitEmpty for write_file (0) */ { int r; suppress_error = 0; @@ -3325,7 +3091,7 @@ static int test_write_file_0 (void) static int test_umount_0 (void) { - /* InitNone for umount (0) */ + /* InitEmpty for umount (0) */ { int r; suppress_error = 0; @@ -3396,7 +3162,7 @@ static int test_umount_0 (void) static int test_umount_1 (void) { - /* InitNone for umount (1) */ + /* InitEmpty for umount (1) */ { int r; suppress_error = 0; @@ -3465,7 +3231,7 @@ static int test_umount_1 (void) static int test_mounts_0 (void) { - /* InitEmpty for mounts (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -3536,7 +3302,7 @@ static int test_mounts_0 (void) static int test_umount_all_0 (void) { - /* InitEmpty for umount_all (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -3603,13 +3369,401 @@ static int test_umount_all_0 (void) return 0; } -int main (int argc, char *argv[]) +static int test_file_0 (void) { - char c = 0; - int failed = 0; + /* InitBasicFS for file (0): create ext2 on /dev/sda1 */ + { + 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 *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutput for file (0) */ + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/new"); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_file (g, "/new"); + if (r == NULL) + return -1; + if (strcmp (r, "empty") != 0) { + fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_file_1 (void) +{ + /* InitBasicFS for file (1): create ext2 on /dev/sda1 */ + { + 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 *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutput for file (1) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/new", "some content\n", 0); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_file (g, "/new"); + if (r == NULL) + return -1; + if (strcmp (r, "ASCII text") != 0) { + fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_file_2 (void) +{ + /* InitBasicFS for file (2): create ext2 on /dev/sda1 */ + { + 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 *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestLastFail for file (2) */ + { + char *r; + suppress_error = 1; + r = guestfs_file (g, "/nofile"); + if (r != NULL) + return -1; + free (r); + } + return 0; +} + +static int test_stat_0 (void) +{ + /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */ + { + 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 *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputStruct for stat (0) */ + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/new"); + if (r == -1) + return -1; + } + { + struct guestfs_stat *r; + suppress_error = 0; + r = guestfs_stat (g, "/new"); + if (r == NULL) + return -1; + if (r->size != 0) { + fprintf (stderr, "test_stat_0: size was %d, expected 0\n", + (int) r->size); + return -1; + } + free (r); + } + return 0; +} + +static int test_lstat_0 (void) +{ + /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */ + { + 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 *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputStruct for lstat (0) */ + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/new"); + if (r == -1) + return -1; + } + { + struct guestfs_stat *r; + suppress_error = 0; + r = guestfs_lstat (g, "/new"); + if (r == NULL) + return -1; + if (r->size != 0) { + fprintf (stderr, "test_lstat_0: size was %d, expected 0\n", + (int) r->size); + return -1; + } + free (r); + } + return 0; +} + +static int test_statvfs_0 (void) +{ + /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */ + { + 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 *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputStruct for statvfs (0) */ + { + struct guestfs_statvfs *r; + suppress_error = 0; + r = guestfs_statvfs (g, "/"); + if (r == NULL) + return -1; + if (r->bfree != 487702) { + fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n", + (int) r->bfree); + return -1; + } + if (r->blocks != 490020) { + fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n", + (int) r->blocks); + return -1; + } + if (r->bsize != 1024) { + fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n", + (int) r->bsize); + return -1; + } + free (r); + } + return 0; +} + +int main (int argc, char *argv[]) +{ + char c = 0; + int failed = 0; const char *srcdir; int fd; char buf[256]; + int nr_tests; + + no_test_warnings (); g = guestfs_create (); if (g == NULL) { @@ -3716,236 +3870,252 @@ int main (int argc, char *argv[]) exit (1); } - printf (" 1/ 46 test_mount_0\n"); + nr_tests = 49; + printf (" 1/%3d test_mount_0\n", nr_tests); if (test_mount_0 () == -1) { printf ("test_mount_0 FAILED\n"); failed++; } - printf (" 2/ 46 test_sync_0\n"); + printf (" 2/%3d test_sync_0\n", nr_tests); if (test_sync_0 () == -1) { printf ("test_sync_0 FAILED\n"); failed++; } - printf (" 3/ 46 test_touch_0\n"); + printf (" 3/%3d test_touch_0\n", nr_tests); if (test_touch_0 () == -1) { printf ("test_touch_0 FAILED\n"); failed++; } - printf (" 4/ 46 test_cat_0\n"); + printf (" 4/%3d test_cat_0\n", nr_tests); if (test_cat_0 () == -1) { printf ("test_cat_0 FAILED\n"); failed++; } - printf (" 5/ 46 test_ls_0\n"); + printf (" 5/%3d test_ls_0\n", nr_tests); if (test_ls_0 () == -1) { printf ("test_ls_0 FAILED\n"); failed++; } - printf (" 6/ 46 test_list_devices_0\n"); + printf (" 6/%3d test_list_devices_0\n", nr_tests); if (test_list_devices_0 () == -1) { printf ("test_list_devices_0 FAILED\n"); failed++; } - printf (" 7/ 46 test_list_partitions_0\n"); + printf (" 7/%3d test_list_partitions_0\n", nr_tests); if (test_list_partitions_0 () == -1) { printf ("test_list_partitions_0 FAILED\n"); failed++; } - printf (" 8/ 46 test_list_partitions_1\n"); + printf (" 8/%3d test_list_partitions_1\n", nr_tests); if (test_list_partitions_1 () == -1) { printf ("test_list_partitions_1 FAILED\n"); failed++; } - printf (" 9/ 46 test_pvs_0\n"); + printf (" 9/%3d test_pvs_0\n", nr_tests); if (test_pvs_0 () == -1) { printf ("test_pvs_0 FAILED\n"); failed++; } - printf (" 10/ 46 test_pvs_1\n"); + printf (" 10/%3d test_pvs_1\n", nr_tests); if (test_pvs_1 () == -1) { printf ("test_pvs_1 FAILED\n"); failed++; } - printf (" 11/ 46 test_vgs_0\n"); + printf (" 11/%3d test_vgs_0\n", nr_tests); if (test_vgs_0 () == -1) { printf ("test_vgs_0 FAILED\n"); failed++; } - printf (" 12/ 46 test_vgs_1\n"); + printf (" 12/%3d test_vgs_1\n", nr_tests); if (test_vgs_1 () == -1) { printf ("test_vgs_1 FAILED\n"); failed++; } - printf (" 13/ 46 test_lvs_0\n"); + printf (" 13/%3d test_lvs_0\n", nr_tests); if (test_lvs_0 () == -1) { printf ("test_lvs_0 FAILED\n"); failed++; } - printf (" 14/ 46 test_lvs_1\n"); + printf (" 14/%3d test_lvs_1\n", nr_tests); if (test_lvs_1 () == -1) { printf ("test_lvs_1 FAILED\n"); failed++; } - printf (" 15/ 46 test_pvs_full_0\n"); - if (test_pvs_full_0 () == -1) { - printf ("test_pvs_full_0 FAILED\n"); - failed++; - } - printf (" 16/ 46 test_vgs_full_0\n"); - if (test_vgs_full_0 () == -1) { - printf ("test_vgs_full_0 FAILED\n"); - failed++; - } - printf (" 17/ 46 test_lvs_full_0\n"); - if (test_lvs_full_0 () == -1) { - printf ("test_lvs_full_0 FAILED\n"); - failed++; - } - printf (" 18/ 46 test_read_lines_0\n"); + printf (" 15/%3d test_read_lines_0\n", nr_tests); if (test_read_lines_0 () == -1) { printf ("test_read_lines_0 FAILED\n"); failed++; } - printf (" 19/ 46 test_read_lines_1\n"); + printf (" 16/%3d test_read_lines_1\n", nr_tests); if (test_read_lines_1 () == -1) { printf ("test_read_lines_1 FAILED\n"); failed++; } - printf (" 20/ 46 test_rm_0\n"); + printf (" 17/%3d test_rm_0\n", nr_tests); if (test_rm_0 () == -1) { printf ("test_rm_0 FAILED\n"); failed++; } - printf (" 21/ 46 test_rm_1\n"); + printf (" 18/%3d test_rm_1\n", nr_tests); if (test_rm_1 () == -1) { printf ("test_rm_1 FAILED\n"); failed++; } - printf (" 22/ 46 test_rm_2\n"); + printf (" 19/%3d test_rm_2\n", nr_tests); if (test_rm_2 () == -1) { printf ("test_rm_2 FAILED\n"); failed++; } - printf (" 23/ 46 test_rmdir_0\n"); + printf (" 20/%3d test_rmdir_0\n", nr_tests); if (test_rmdir_0 () == -1) { printf ("test_rmdir_0 FAILED\n"); failed++; } - printf (" 24/ 46 test_rmdir_1\n"); + printf (" 21/%3d test_rmdir_1\n", nr_tests); if (test_rmdir_1 () == -1) { printf ("test_rmdir_1 FAILED\n"); failed++; } - printf (" 25/ 46 test_rmdir_2\n"); + printf (" 22/%3d test_rmdir_2\n", nr_tests); if (test_rmdir_2 () == -1) { printf ("test_rmdir_2 FAILED\n"); failed++; } - printf (" 26/ 46 test_rm_rf_0\n"); + printf (" 23/%3d test_rm_rf_0\n", nr_tests); if (test_rm_rf_0 () == -1) { printf ("test_rm_rf_0 FAILED\n"); failed++; } - printf (" 27/ 46 test_mkdir_0\n"); + printf (" 24/%3d test_mkdir_0\n", nr_tests); if (test_mkdir_0 () == -1) { printf ("test_mkdir_0 FAILED\n"); failed++; } - printf (" 28/ 46 test_mkdir_1\n"); + printf (" 25/%3d test_mkdir_1\n", nr_tests); if (test_mkdir_1 () == -1) { printf ("test_mkdir_1 FAILED\n"); failed++; } - printf (" 29/ 46 test_mkdir_p_0\n"); + printf (" 26/%3d test_mkdir_p_0\n", nr_tests); if (test_mkdir_p_0 () == -1) { printf ("test_mkdir_p_0 FAILED\n"); failed++; } - printf (" 30/ 46 test_mkdir_p_1\n"); + printf (" 27/%3d test_mkdir_p_1\n", nr_tests); if (test_mkdir_p_1 () == -1) { printf ("test_mkdir_p_1 FAILED\n"); failed++; } - printf (" 31/ 46 test_mkdir_p_2\n"); + printf (" 28/%3d test_mkdir_p_2\n", nr_tests); if (test_mkdir_p_2 () == -1) { printf ("test_mkdir_p_2 FAILED\n"); failed++; } - printf (" 32/ 46 test_exists_0\n"); + printf (" 29/%3d test_exists_0\n", nr_tests); if (test_exists_0 () == -1) { printf ("test_exists_0 FAILED\n"); failed++; } - printf (" 33/ 46 test_exists_1\n"); + printf (" 30/%3d test_exists_1\n", nr_tests); if (test_exists_1 () == -1) { printf ("test_exists_1 FAILED\n"); failed++; } - printf (" 34/ 46 test_is_file_0\n"); + printf (" 31/%3d test_is_file_0\n", nr_tests); if (test_is_file_0 () == -1) { printf ("test_is_file_0 FAILED\n"); failed++; } - printf (" 35/ 46 test_is_file_1\n"); + printf (" 32/%3d test_is_file_1\n", nr_tests); if (test_is_file_1 () == -1) { printf ("test_is_file_1 FAILED\n"); failed++; } - printf (" 36/ 46 test_is_dir_0\n"); + printf (" 33/%3d test_is_dir_0\n", nr_tests); if (test_is_dir_0 () == -1) { printf ("test_is_dir_0 FAILED\n"); failed++; } - printf (" 37/ 46 test_is_dir_1\n"); + printf (" 34/%3d test_is_dir_1\n", nr_tests); if (test_is_dir_1 () == -1) { printf ("test_is_dir_1 FAILED\n"); failed++; } - printf (" 38/ 46 test_pvcreate_0\n"); + printf (" 35/%3d test_pvcreate_0\n", nr_tests); if (test_pvcreate_0 () == -1) { printf ("test_pvcreate_0 FAILED\n"); failed++; } - printf (" 39/ 46 test_vgcreate_0\n"); + printf (" 36/%3d test_vgcreate_0\n", nr_tests); if (test_vgcreate_0 () == -1) { printf ("test_vgcreate_0 FAILED\n"); failed++; } - printf (" 40/ 46 test_lvcreate_0\n"); + printf (" 37/%3d test_lvcreate_0\n", nr_tests); if (test_lvcreate_0 () == -1) { printf ("test_lvcreate_0 FAILED\n"); failed++; } - printf (" 41/ 46 test_mkfs_0\n"); + printf (" 38/%3d test_mkfs_0\n", nr_tests); if (test_mkfs_0 () == -1) { printf ("test_mkfs_0 FAILED\n"); failed++; } - printf (" 42/ 46 test_write_file_0\n"); + printf (" 39/%3d test_write_file_0\n", nr_tests); if (test_write_file_0 () == -1) { printf ("test_write_file_0 FAILED\n"); failed++; } - printf (" 43/ 46 test_umount_0\n"); + printf (" 40/%3d test_umount_0\n", nr_tests); if (test_umount_0 () == -1) { printf ("test_umount_0 FAILED\n"); failed++; } - printf (" 44/ 46 test_umount_1\n"); + printf (" 41/%3d test_umount_1\n", nr_tests); if (test_umount_1 () == -1) { printf ("test_umount_1 FAILED\n"); failed++; } - printf (" 45/ 46 test_mounts_0\n"); + printf (" 42/%3d test_mounts_0\n", nr_tests); if (test_mounts_0 () == -1) { printf ("test_mounts_0 FAILED\n"); failed++; } - printf (" 46/ 46 test_umount_all_0\n"); + printf (" 43/%3d test_umount_all_0\n", nr_tests); if (test_umount_all_0 () == -1) { printf ("test_umount_all_0 FAILED\n"); failed++; } + printf (" 44/%3d test_file_0\n", nr_tests); + if (test_file_0 () == -1) { + printf ("test_file_0 FAILED\n"); + failed++; + } + printf (" 45/%3d test_file_1\n", nr_tests); + if (test_file_1 () == -1) { + printf ("test_file_1 FAILED\n"); + failed++; + } + printf (" 46/%3d test_file_2\n", nr_tests); + if (test_file_2 () == -1) { + printf ("test_file_2 FAILED\n"); + failed++; + } + printf (" 47/%3d test_stat_0\n", nr_tests); + if (test_stat_0 () == -1) { + printf ("test_stat_0 FAILED\n"); + failed++; + } + printf (" 48/%3d test_lstat_0\n", nr_tests); + if (test_lstat_0 () == -1) { + printf ("test_lstat_0 FAILED\n"); + failed++; + } + printf (" 49/%3d test_statvfs_0\n", nr_tests); + if (test_statvfs_0 () == -1) { + printf ("test_statvfs_0 FAILED\n"); + failed++; + } guestfs_close (g); snprintf (buf, sizeof buf, "%s/test1.img", srcdir); @@ -3956,7 +4126,7 @@ int main (int argc, char *argv[]) unlink (buf); if (failed > 0) { - printf ("***** %d / 46 tests FAILED *****\n", failed); + printf ("***** %d / %d tests FAILED *****\n", failed, nr_tests); exit (1); }