diff options
Diffstat (limited to 'tests/df')
-rwxr-xr-x | tests/df/df-P.sh | 2 | ||||
-rwxr-xr-x | tests/df/df-output.sh | 4 | ||||
-rwxr-xr-x | tests/df/df-symlink.sh | 4 | ||||
-rwxr-xr-x | tests/df/header.sh | 2 | ||||
-rwxr-xr-x | tests/df/no-mtab-status.sh | 82 | ||||
-rwxr-xr-x | tests/df/over-mount-device.sh | 2 | ||||
-rwxr-xr-x | tests/df/problematic-chars.sh | 2 | ||||
-rwxr-xr-x | tests/df/skip-duplicates.sh | 98 | ||||
-rwxr-xr-x | tests/df/skip-rootfs.sh | 11 | ||||
-rwxr-xr-x | tests/df/total-unprocessed.sh | 2 | ||||
-rwxr-xr-x | tests/df/total-verify.sh | 5 | ||||
-rwxr-xr-x | tests/df/unreadable.sh | 2 |
12 files changed, 159 insertions, 57 deletions
diff --git a/tests/df/df-P.sh b/tests/df/df-P.sh index aff6e1b5..f40da30a 100755 --- a/tests/df/df-P.sh +++ b/tests/df/df-P.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df -P is not affected by BLOCK_SIZE settings -# Copyright (C) 2007-2014 Free Software Foundation, Inc. +# Copyright (C) 2007-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/df-output.sh b/tests/df/df-output.sh index b2715885..d81f0ee4 100755 --- a/tests/df/df-output.sh +++ b/tests/df/df-output.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise df's --output option. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -93,7 +93,7 @@ EOF df -B1K --output=size '.' >out || fail=1 sed -e '1 { - s/ // + s/ *// q }' out > out2 compare exp out2 || fail=1 diff --git a/tests/df/df-symlink.sh b/tests/df/df-symlink.sh index 6d96bd2a..b5930978 100755 --- a/tests/df/df-symlink.sh +++ b/tests/df/df-symlink.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df dereferences symlinks to disk nodes -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ compare exp out || fail=1 # Ensure we output the same values for device nodes and '.' # This was not the case in coreutil-8.22 on systems # where the device in the mount list was a symlink itself. -# I.E. '.' => /dev/mapper/fedora-home -> /dev/dm-2 +# I.e., '.' => /dev/mapper/fedora-home -> /dev/dm-2 df --out=source,target '.' > out || fail=1 compare exp out || fail=1 diff --git a/tests/df/header.sh b/tests/df/header.sh index 664ef800..d315a33f 100755 --- a/tests/df/header.sh +++ b/tests/df/header.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that "df ." outputs a header. -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh index 9ea2036d..c35da6b8 100755 --- a/tests/df/no-mtab-status.sh +++ b/tests/df/no-mtab-status.sh @@ -2,7 +2,7 @@ # Test df's behaviour when the mount list cannot be read. # This test is skipped on systems that lack LD_PRELOAD support; that's fine. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,8 @@ print_ver_ df require_gcc_shared_ -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ || skip_ "no mntent.h available to confirm the interface" @@ -30,10 +31,43 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \ || skip_ "getmntent is not used on this system" # Simulate "mtab" failure. -cat > k.c <<'EOF' || framework_failure_ +cat > k.c <<EOF || framework_failure_ +#define _GNU_SOURCE #include <stdio.h> #include <errno.h> #include <mntent.h> +#include <string.h> +#include <dlfcn.h> + +#define STREQ(a, b) (strcmp (a, b) == 0) + +FILE* fopen(const char *path, const char *mode) +{ + static FILE* (*fopen_func)(char const *, char const *); + + /* get reference to original (libc provided) fopen */ + if (!fopen_func) + { + fopen_func = (FILE*(*)(char const *, char const *)) + dlsym(RTLD_NEXT, "fopen"); + if (!fopen_func) + { + fprintf (stderr, "Failed to find fopen()\n"); + errno = ESRCH; + return NULL; + } + } + + /* Returning ENOENT here will get read_file_system_list() + to fall back to using getmntent() below. */ + if (STREQ (path, "/proc/self/mountinfo")) + { + errno = ENOENT; + return NULL; + } + else + return fopen_func(path, mode); +} struct mntent *getmntent (FILE *fp) { @@ -54,34 +88,38 @@ EOF gcc_shared_ k.c k.so \ || framework_failure_ 'failed to build shared library' +cleanup_() { unset LD_PRELOAD; } + +export LD_PRELOAD=$LD_PRELOAD:./k.so + # Test if LD_PRELOAD works: -LD_PRELOAD=./k.so df +df 2>/dev/null test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?" # These tests are supposed to succeed: -LD_PRELOAD=./k.so df '.' || fail=1 -LD_PRELOAD=./k.so df -i '.' || fail=1 -LD_PRELOAD=./k.so df -T '.' || fail=1 -LD_PRELOAD=./k.so df -Ti '.' || fail=1 -LD_PRELOAD=./k.so df --total '.' || fail=1 +df '.' || fail=1 +df -i '.' || fail=1 +df -T '.' || fail=1 +df -Ti '.' || fail=1 +df --total '.' || fail=1 # These tests are supposed to fail: -LD_PRELOAD=./k.so df && fail=1 -LD_PRELOAD=./k.so df -i && fail=1 -LD_PRELOAD=./k.so df -T && fail=1 -LD_PRELOAD=./k.so df -Ti && fail=1 -LD_PRELOAD=./k.so df --total && fail=1 +returns_ 1 df || fail=1 +returns_ 1 df -i || fail=1 +returns_ 1 df -T || fail=1 +returns_ 1 df -Ti || fail=1 +returns_ 1 df --total || fail=1 -LD_PRELOAD=./k.so df -a && fail=1 -LD_PRELOAD=./k.so df -a '.' && fail=1 +returns_ 1 df -a || fail=1 +returns_ 1 df -a '.' || fail=1 -LD_PRELOAD=./k.so df -l && fail=1 -LD_PRELOAD=./k.so df -l '.' && fail=1 +returns_ 1 df -l || fail=1 +returns_ 1 df -l '.' || fail=1 -LD_PRELOAD=./k.so df -t hello && fail=1 -LD_PRELOAD=./k.so df -t hello '.' && fail=1 +returns_ 1 df -t hello || fail=1 +returns_ 1 df -t hello '.' || fail=1 -LD_PRELOAD=./k.so df -x hello && fail=1 -LD_PRELOAD=./k.so df -x hello '.' && fail=1 +returns_ 1 df -x hello || fail=1 +returns_ 1 df -x hello '.' || fail=1 Exit $fail diff --git a/tests/df/over-mount-device.sh b/tests/df/over-mount-device.sh index a85ce8db..82eab4bd 100755 --- a/tests/df/over-mount-device.sh +++ b/tests/df/over-mount-device.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df /dev/loop0 errors out if overmounted by another device -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2014-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/problematic-chars.sh b/tests/df/problematic-chars.sh index bdabf0c0..eb938f6b 100755 --- a/tests/df/problematic-chars.sh +++ b/tests/df/problematic-chars.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that df outputs one line per entry -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh index 52b9014a..40696047 100755 --- a/tests/df/skip-duplicates.sh +++ b/tests/df/skip-duplicates.sh @@ -2,7 +2,7 @@ # Test df's behavior when the mount list contains duplicate entries. # This test is skipped on systems that lack LD_PRELOAD support; that's fine. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,10 +23,15 @@ require_gcc_shared_ # We use --local here so as to not activate # potentially very many remote mounts. -df --local || skip_ "df fails" +df --local || skip_ 'df fails' export CU_NONROOT_FS=$(df --local --output=target 2>&1 | grep /. | head -n1) -test -z "$CU_NONROOT_FS" && unique_entries=1 || unique_entries=2 +export CU_REMOTE_FS=$(df --local --output=target 2>&1 | grep /. | + tail -n+2 | head -n1) + +unique_entries=1 +test -z "$CU_NONROOT_FS" || unique_entries=$(expr $unique_entries + 1) +test -z "$CU_REMOTE_FS" || unique_entries=$(expr $unique_entries + 2) grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \ || skip_ "no mntent.h available to confirm the interface" @@ -35,17 +40,51 @@ grep '^#define HAVE_GETMNTENT 1' $CONFIG_HEADER > /dev/null \ || skip_ "getmntent is not used on this system" # Simulate an mtab file to test various cases. -cat > k.c <<'EOF' || framework_failure_ +cat > k.c <<EOF || framework_failure_ +#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> -#include <string.h> +#include <errno.h> #include <mntent.h> +#include <string.h> +#include <dlfcn.h> + +#define STREQ(a, b) (strcmp (a, b) == 0) + +FILE* fopen(const char *path, const char *mode) +{ + static FILE* (*fopen_func)(char const *, char const *); + + /* get reference to original (libc provided) fopen */ + if (!fopen_func) + { + fopen_func = (FILE*(*)(char const *, char const *)) + dlsym(RTLD_NEXT, "fopen"); + if (!fopen_func) + { + fprintf (stderr, "Failed to find fopen()\n"); + errno = ESRCH; + return NULL; + } + } + + /* Returning ENOENT here will get read_file_system_list() + to fall back to using getmntent() below. */ + if (STREQ (path, "/proc/self/mountinfo")) + { + errno = ENOENT; + return NULL; + } + else + return fopen_func(path, mode); +} #define STREQ(a, b) (strcmp (a, b) == 0) struct mntent *getmntent (FILE *fp) { static char *nonroot_fs; + static char *remote_fs; static int done; /* Prove that LD_PRELOAD works. */ @@ -56,13 +95,16 @@ struct mntent *getmntent (FILE *fp) } static struct mntent mntents[] = { - {.mnt_fsname="/short", .mnt_dir="/invalid/mount/dir"}, - {.mnt_fsname="fsname", .mnt_dir="/",}, - {.mnt_fsname="/fsname", .mnt_dir="/."}, - {.mnt_fsname="/fsname", .mnt_dir="/"}, - {.mnt_fsname="virtfs", .mnt_dir="/NONROOT", .mnt_type="fstype1"}, - {.mnt_fsname="virtfs2", .mnt_dir="/NONROOT", .mnt_type="fstype2"}, - {.mnt_fsname="netns", .mnt_dir="net:[1234567]"}, + {.mnt_fsname="/short", .mnt_dir="/invalid/mount/dir", .mnt_opts=""}, + {.mnt_fsname="fsname", .mnt_dir="/", .mnt_opts=""}, + {.mnt_fsname="/fsname", .mnt_dir="/.", .mnt_opts=""}, + {.mnt_fsname="/fsname", .mnt_dir="/", .mnt_opts=""}, + {.mnt_fsname="virtfs", .mnt_dir="/NONROOT", .mnt_type="t1", .mnt_opts=""}, + {.mnt_fsname="virtfs2", .mnt_dir="/NONROOT", .mnt_type="t2", .mnt_opts=""}, + {.mnt_fsname="netns", .mnt_dir="net:[1234567]", .mnt_opts=""}, + {.mnt_fsname="rem:ote1",.mnt_dir="/REMOTE", .mnt_opts=""}, + {.mnt_fsname="rem:ote1",.mnt_dir="/REMOTE", .mnt_opts=""}, + {.mnt_fsname="rem:ote2",.mnt_dir="/REMOTE", .mnt_opts=""}, }; if (done == 1) @@ -70,17 +112,28 @@ struct mntent *getmntent (FILE *fp) nonroot_fs = getenv ("CU_NONROOT_FS"); if (!nonroot_fs || !*nonroot_fs) nonroot_fs = "/"; /* merge into / entries. */ + + remote_fs = getenv ("CU_REMOTE_FS"); } if (done == 1 && !getenv ("CU_TEST_DUPE_INVALID")) done++; /* skip the first entry. */ - while (done++ <= 7) + while (done++ <= 10) { if (!mntents[done-2].mnt_type) mntents[done-2].mnt_type = "-"; + if (!mntents[done-2].mnt_opts) + mntents[done-2].mnt_opts = "-"; if (STREQ (mntents[done-2].mnt_dir, "/NONROOT")) mntents[done-2].mnt_dir = nonroot_fs; + if (STREQ (mntents[done-2].mnt_dir, "/REMOTE")) + { + if (!remote_fs || !*remote_fs) + continue; + else + mntents[done-2].mnt_dir = remote_fs; + } return &mntents[done-2]; } @@ -93,17 +146,23 @@ gcc_shared_ k.c k.so \ || framework_failure_ 'failed to build shared library' # Test if LD_PRELOAD works: -LD_PRELOAD=./k.so df +LD_PRELOAD=$LD_PRELOAD:./k.so df test -f x || skip_ "internal test failure: maybe LD_PRELOAD doesn't work?" # The fake mtab file should only contain entries # having the same device number; thus the output should # consist of a header and unique entries. -LD_PRELOAD=./k.so df -T >out || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so df -T >out || fail=1 test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; } +# With --total we should suppress the duplicate but separate remote file system +LD_PRELOAD=$LD_PRELOAD:./k.so df --total >out || fail=1 +test "$CU_REMOTE_FS" && elide_remote=1 || elide_remote=0 +test $(wc -l <out) -eq $(expr 2 + $unique_entries - $elide_remote) || + { fail=1; cat out; } + # Ensure we don't fail when unable to stat (currently) unavailable entries -LD_PRELOAD=./k.so CU_TEST_DUPE_INVALID=1 df -T >out || fail=1 +LD_PRELOAD=$LD_PRELOAD:./k.so CU_TEST_DUPE_INVALID=1 df -T >out || fail=1 test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; } # df should also prefer "/fsname" over "fsname" @@ -114,11 +173,12 @@ if test "$unique_entries" = 2; then fi # df should use the last seen devname (mnt_fsname) and devtype (mnt_type) -test $(grep -c 'virtfs2.*fstype2' <out) -eq 1 || { fail=1; cat out; } +test $(grep -c 'virtfs2.*t2' <out) -eq 1 || { fail=1; cat out; } # Ensure that filtering duplicates does not affect -a processing. -LD_PRELOAD=./k.so df -a >out || fail=1 -test $(wc -l <out) -eq 6 || { fail=1; cat out; } +LD_PRELOAD=$LD_PRELOAD:./k.so df -a >out || fail=1 +total_fs=6; test "$CU_REMOTE_FS" && total_fs=$(expr $total_fs + 3) +test $(wc -l <out) -eq $total_fs || { fail=1; cat out; } # Ensure placeholder "-" values used for the eclipsed "virtfs" test $(grep -c 'virtfs *-' <out) -eq 1 || { fail=1; cat out; } diff --git a/tests/df/skip-rootfs.sh b/tests/df/skip-rootfs.sh index 94f32c6b..43ba70b4 100755 --- a/tests/df/skip-rootfs.sh +++ b/tests/df/skip-rootfs.sh @@ -1,7 +1,7 @@ #!/bin/sh # Test df's behavior for skipping the pseudo "rootfs" file system. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,11 +19,14 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ df -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" # Verify that rootfs is in mtab (and shown when the -a option is specified). +# Note this is the case when /proc/self/mountinfo is parsed +# rather than /proc/mounts. I.e., when libmount is being used. df -a >out || fail=1 -grep '^rootfs' out || skip_ "no rootfs in mtab" +grep '^rootfs' out || skip_ 'no rootfs in mtab' # Ensure that rootfs is suppressed when no options is specified. df >out || fail=1 @@ -32,7 +35,7 @@ grep '^rootfs' out && { fail=1; cat out; } # Ensure that rootfs is yet skipped when explicitly specifying "-t rootfs". # As df emits "no file systems processed" in this case, it would be a failure # if df exited with status Zero. -df -t rootfs >out && fail=1 +returns_ 1 df -t rootfs >out || fail=1 grep '^rootfs' out && { fail=1; cat out; } # Ensure that the rootfs is shown when explicitly both specifying "-t rootfs" diff --git a/tests/df/total-unprocessed.sh b/tests/df/total-unprocessed.sh index 9b17c8aa..9779471d 100755 --- a/tests/df/total-unprocessed.sh +++ b/tests/df/total-unprocessed.sh @@ -2,7 +2,7 @@ # Ensure that df exits non-Zero and writes an error message when # --total is used but no file system has been processed. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/tests/df/total-verify.sh b/tests/df/total-verify.sh index 63cbe8f7..ba50b03c 100755 --- a/tests/df/total-verify.sh +++ b/tests/df/total-verify.sh @@ -1,7 +1,7 @@ #!/bin/sh # Ensure "df --total" computes accurate totals -# Copyright (C) 2008-2014 Free Software Foundation, Inc. +# Copyright (C) 2008-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,8 @@ print_ver_ df require_perl_ -df || skip_ "df fails" +# Protect against inaccessible remote mounts etc. +timeout 10 df || skip_ "df fails" cat <<\EOF > check-df || framework_failure_ my ($total, $used, $avail) = (0, 0, 0); diff --git a/tests/df/unreadable.sh b/tests/df/unreadable.sh index 4ad23373..9e3da0ed 100755 --- a/tests/df/unreadable.sh +++ b/tests/df/unreadable.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure that df can handle an unreadable argument -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2015 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by |