X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=tests.c;h=d1bccc5870efbc3a39d2f7508d1e1d15a916e92d;hp=dddb9715644b1630f7924c8f6a64c069704cd9b1;hb=4b382eb8110050cb5b769c6f7d79b0b77eb79719;hpb=0703248d233744047515418893dac05ce013a642 diff --git a/tests.c b/tests.c index dddb971..d1bccc5 100644 --- a/tests.c +++ b/tests.c @@ -112,6 +112,873 @@ static void no_test_warnings (void) fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n"); } +static int test_equal_0 (void) +{ + /* InitBasicFS for equal (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; + } + /* TestOutputTrue for equal (0) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/file1", "contents of a file", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_cp (g, "/file1", "/file2"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_equal (g, "/file1", "/file2"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_equal_0: expected true, got false\n"); + return -1; + } + } + return 0; +} + +static int test_equal_1 (void) +{ + /* InitBasicFS for equal (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; + } + /* TestOutputFalse for equal (1) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/file1", "contents of a file", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/file2", "contents of another file", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_equal (g, "/file1", "/file2"); + if (r == -1) + return -1; + if (r) { + fprintf (stderr, "test_equal_1: expected false, got true\n"); + return -1; + } + } + return 0; +} + +static int test_equal_2 (void) +{ + /* InitBasicFS for equal (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 equal (2) */ + { + int r; + suppress_error = 1; + r = guestfs_equal (g, "/file1", "/file2"); + if (r != -1) + return -1; + } + return 0; +} + +static int test_ping_daemon_0 (void) +{ + /* InitEmpty for ping_daemon (0) */ + { + 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; + } + /* TestRun for ping_daemon (0) */ + { + int r; + suppress_error = 0; + r = guestfs_ping_daemon (g); + if (r == -1) + return -1; + } + return 0; +} + +static int test_dmesg_0 (void) +{ + /* InitEmpty for dmesg (0) */ + { + 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; + } + /* TestRun for dmesg (0) */ + { + char *r; + suppress_error = 0; + r = guestfs_dmesg (g); + if (r == NULL) + return -1; + free (r); + } + return 0; +} + +static int test_drop_caches_0 (void) +{ + /* InitEmpty for drop_caches (0) */ + { + 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; + } + /* TestRun for drop_caches (0) */ + { + int r; + suppress_error = 0; + r = guestfs_drop_caches (g, 3); + if (r == -1) + return -1; + } + return 0; +} + +static int test_mv_0 (void) +{ + /* InitBasicFS for mv (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 mv (0) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/old", "file content", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mv (g, "/old", "/new"); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_cat (g, "/new"); + if (r == NULL) + return -1; + if (strcmp (r, "file content") != 0) { + fprintf (stderr, "test_mv_0: expected \"file content\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_mv_1 (void) +{ + /* InitBasicFS for mv (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; + } + /* TestOutputFalse for mv (1) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/old", "file content", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mv (g, "/old", "/new"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_file (g, "/old"); + if (r == -1) + return -1; + if (r) { + fprintf (stderr, "test_mv_1: expected false, got true\n"); + return -1; + } + } + return 0; +} + +static int test_cp_a_0 (void) +{ + /* InitBasicFS for cp_a (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 cp_a (0) */ + { + int r; + suppress_error = 0; + r = guestfs_mkdir (g, "/olddir"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkdir (g, "/newdir"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/olddir/file", "file content", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_cp_a (g, "/olddir", "/newdir"); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_cat (g, "/newdir/olddir/file"); + if (r == NULL) + return -1; + if (strcmp (r, "file content") != 0) { + fprintf (stderr, "test_cp_a_0: expected \"file content\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_cp_0 (void) +{ + /* InitBasicFS for cp (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 cp (0) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/old", "file content", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_cp (g, "/old", "/new"); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_cat (g, "/new"); + if (r == NULL) + return -1; + if (strcmp (r, "file content") != 0) { + fprintf (stderr, "test_cp_0: expected \"file content\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_cp_1 (void) +{ + /* InitBasicFS for cp (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; + } + /* TestOutputTrue for cp (1) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/old", "file content", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_cp (g, "/old", "/new"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_file (g, "/old"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_cp_1: expected true, got false\n"); + return -1; + } + } + return 0; +} + +static int test_cp_2 (void) +{ + /* InitBasicFS for cp (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; + } + /* TestOutput for cp (2) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/old", "file content", 0); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkdir (g, "/dir"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_cp (g, "/old", "/dir/new"); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_cat (g, "/dir/new"); + if (r == NULL) + return -1; + if (strcmp (r, "file content") != 0) { + fprintf (stderr, "test_cp_2: expected \"file content\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_grub_install_0 (void) +{ + /* InitBasicFS for grub_install (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; + } + /* TestOutputTrue for grub_install (0) */ + { + int r; + suppress_error = 0; + r = guestfs_grub_install (g, "/", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_dir (g, "/boot"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_grub_install_0: expected true, got false\n"); + return -1; + } + } + return 0; +} + +static int test_zero_0 (void) +{ + /* InitBasicFS for zero (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 zero (0) */ + { + int r; + suppress_error = 0; + r = guestfs_umount (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_zero (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + char *r; + suppress_error = 0; + r = guestfs_file (g, "/dev/sda1"); + if (r == NULL) + return -1; + if (strcmp (r, "data") != 0) { + fprintf (stderr, "test_zero_0: expected \"data\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + static int test_fsck_0 (void) { /* InitBasicFS for fsck (0): create ext2 on /dev/sda1 */ @@ -154,13 +1021,95 @@ static int test_fsck_0 (void) if (r == -1) return -1; } - /* TestRun for fsck (0) */ + /* TestOutputInt for fsck (0) */ + { + int r; + suppress_error = 0; + r = guestfs_umount (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_fsck (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + if (r != 0) { + fprintf (stderr, "test_fsck_0: expected 0 but got %d\n", (int) r); + return -1; + } + } + return 0; +} + +static int test_fsck_1 (void) +{ + /* InitBasicFS for fsck (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; + } + /* TestOutputInt for fsck (1) */ + { + int r; + suppress_error = 0; + r = guestfs_umount (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_zero (g, "/dev/sda1"); + if (r == -1) + return -1; + } { int r; suppress_error = 0; r = guestfs_fsck (g, "ext2", "/dev/sda1"); if (r == -1) return -1; + if (r != 8) { + fprintf (stderr, "test_fsck_1: expected 8 but got %d\n", (int) r); + return -1; + } } return 0; } @@ -6566,15 +7515,105 @@ int main (int argc, char *argv[]) exit (1); } - nr_tests = 92; + nr_tests = 107; test_num++; + printf ("%3d/%3d test_equal_0\n", test_num, nr_tests); + if (test_equal_0 () == -1) { + printf ("test_equal_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_equal_1\n", test_num, nr_tests); + if (test_equal_1 () == -1) { + printf ("test_equal_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_equal_2\n", test_num, nr_tests); + if (test_equal_2 () == -1) { + printf ("test_equal_2 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_ping_daemon_0\n", test_num, nr_tests); + if (test_ping_daemon_0 () == -1) { + printf ("test_ping_daemon_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_dmesg_0\n", test_num, nr_tests); + if (test_dmesg_0 () == -1) { + printf ("test_dmesg_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_drop_caches_0\n", test_num, nr_tests); + if (test_drop_caches_0 () == -1) { + printf ("test_drop_caches_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_mv_0\n", test_num, nr_tests); + if (test_mv_0 () == -1) { + printf ("test_mv_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_mv_1\n", test_num, nr_tests); + if (test_mv_1 () == -1) { + printf ("test_mv_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_cp_a_0\n", test_num, nr_tests); + if (test_cp_a_0 () == -1) { + printf ("test_cp_a_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_cp_0\n", test_num, nr_tests); + if (test_cp_0 () == -1) { + printf ("test_cp_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_cp_1\n", test_num, nr_tests); + if (test_cp_1 () == -1) { + printf ("test_cp_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_cp_2\n", test_num, nr_tests); + if (test_cp_2 () == -1) { + printf ("test_cp_2 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_grub_install_0\n", test_num, nr_tests); + if (test_grub_install_0 () == -1) { + printf ("test_grub_install_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_zero_0\n", test_num, nr_tests); + if (test_zero_0 () == -1) { + printf ("test_zero_0 FAILED\n"); + failed++; + } + test_num++; printf ("%3d/%3d test_fsck_0\n", test_num, nr_tests); if (test_fsck_0 () == -1) { printf ("test_fsck_0 FAILED\n"); failed++; } test_num++; + printf ("%3d/%3d test_fsck_1\n", test_num, nr_tests); + if (test_fsck_1 () == -1) { + printf ("test_fsck_1 FAILED\n"); + failed++; + } + test_num++; printf ("%3d/%3d test_set_e2uuid_0\n", test_num, nr_tests); if (test_set_e2uuid_0 () == -1) { printf ("test_set_e2uuid_0 FAILED\n");