X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=capitests%2Ftests.c;fp=capitests%2Ftests.c;h=6e31c401de995a09b4dd05ec560c5c71d10b3fb2;hp=08f64ee1eadd674e68dae1a9ce9c188ae5f1c301;hb=e492608f2f3809a824cb70ee03ff305964b69dd7;hpb=9a92446bcad09b492dee42dd5950bac67073fbea diff --git a/capitests/tests.c b/capitests/tests.c index 08f64ee..6e31c40 100644 --- a/capitests/tests.c +++ b/capitests/tests.c @@ -155,6 +155,105 @@ static void no_test_warnings (void) fprintf (stderr, "warning: \"guestfs_df_h\" has no tests\n"); } +static int test_du_0_skip (void) +{ + const char *str; + + str = getenv ("TEST_ONLY"); + if (str) + return strstr (str, "du") == NULL; + str = getenv ("SKIP_TEST_DU_0"); + if (str && strcmp (str, "1") == 0) return 1; + str = getenv ("SKIP_TEST_DU"); + if (str && strcmp (str, "1") == 0) return 1; + return 0; +} + +static int test_du_0 (void) +{ + if (test_du_0_skip ()) { + printf ("%s skipped (reason: environment variable set)\n", "test_du_0"); + return 0; + } + + /* InitBasicFS for test_du_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; + } + /* TestOutputInt for du (0) */ + { + char path[] = "/p"; + int r; + suppress_error = 0; + r = guestfs_mkdir (g, path); + if (r == -1) + return -1; + } + { + char path[] = "/p"; + int64_t r; + suppress_error = 0; + r = guestfs_du (g, path); + if (r == -1) + return -1; + if (r != 1) { + fprintf (stderr, "test_du_0: expected 1 but got %d\n", (int) r); + return -1; + } + } + return 0; +} + static int test_tail_n_0_skip (void) { const char *str; @@ -18509,9 +18608,15 @@ int main (int argc, char *argv[]) /* Cancel previous alarm. */ alarm (0); - nr_tests = 164; + nr_tests = 165; test_num++; + printf ("%3d/%3d test_du_0\n", test_num, nr_tests); + if (test_du_0 () == -1) { + printf ("test_du_0 FAILED\n"); + failed++; + } + test_num++; printf ("%3d/%3d test_tail_n_0\n", test_num, nr_tests); if (test_tail_n_0 () == -1) { printf ("test_tail_n_0 FAILED\n");