summaryrefslogtreecommitdiff
path: root/tests/df/skip-duplicates.sh
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-09-30 18:22:48 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-09-30 18:22:48 +0400
commitc18578632fd3c9e513e613a86ba2b7c4ebee6c45 (patch)
tree377f4d4e3f0a6471a5012126078fcd97f4c67242 /tests/df/skip-duplicates.sh
parent974ab3dd887985e3aa347f3c6521f819296396a0 (diff)
downloadcoreutils-c18578632fd3c9e513e613a86ba2b7c4ebee6c45.tar.gz
Imported Upstream version 8.23upstream/8.23
Diffstat (limited to 'tests/df/skip-duplicates.sh')
-rwxr-xr-xtests/df/skip-duplicates.sh95
1 files changed, 69 insertions, 26 deletions
diff --git a/tests/df/skip-duplicates.sh b/tests/df/skip-duplicates.sh
index ad5249b5..52b9014a 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-2013 Free Software Foundation, Inc.
+# Copyright (C) 2012-2014 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,65 +19,108 @@
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ df
+require_gcc_shared_
-df || skip_ "df fails"
+# We use --local here so as to not activate
+# potentially very many remote mounts.
+df --local || skip_ "df fails"
-# Simulate an mtab file with two entries of the same device number.
+export CU_NONROOT_FS=$(df --local --output=target 2>&1 | grep /. | head -n1)
+test -z "$CU_NONROOT_FS" && unique_entries=1 || unique_entries=2
+
+grep '^#define HAVE_MNTENT_H 1' $CONFIG_HEADER > /dev/null \
+ || skip_ "no mntent.h available to confirm the interface"
+
+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_
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <mntent.h>
+#define STREQ(a, b) (strcmp (a, b) == 0)
+
struct mntent *getmntent (FILE *fp)
{
+ static char *nonroot_fs;
+ static int done;
+
/* Prove that LD_PRELOAD works. */
- static int done = 0;
if (!done)
{
fclose (fopen ("x", "w"));
++done;
}
- static struct mntent mntent;
+ 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]"},
+ };
+
+ if (done == 1)
+ {
+ nonroot_fs = getenv ("CU_NONROOT_FS");
+ if (!nonroot_fs || !*nonroot_fs)
+ nonroot_fs = "/"; /* merge into / entries. */
+ }
+
+ if (done == 1 && !getenv ("CU_TEST_DUPE_INVALID"))
+ done++; /* skip the first entry. */
- while (done++ < 4)
+ while (done++ <= 7)
{
- /* File system - Mounted on
- fsname /
- /fsname /root
- /fsname /
- */
- mntent.mnt_fsname = (done == 2) ? "fsname" : "/fsname";
- mntent.mnt_dir = (done == 3) ? "/root" : "/";
- mntent.mnt_type = "-";
-
- return &mntent;
+ if (!mntents[done-2].mnt_type)
+ mntents[done-2].mnt_type = "-";
+ if (STREQ (mntents[done-2].mnt_dir, "/NONROOT"))
+ mntents[done-2].mnt_dir = nonroot_fs;
+ return &mntents[done-2];
}
+
return NULL;
}
EOF
# Then compile/link it:
-gcc --std=gnu99 -shared -fPIC -ldl -O2 k.c -o k.so \
- || skip_ "getmntent hack does not work on this platform"
+gcc_shared_ k.c k.so \
+ || framework_failure_ 'failed to build shared library'
# Test if LD_PRELOAD works:
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 2 entries, both
+# The fake mtab file should only contain entries
# having the same device number; thus the output should
-# consist of a header and one entry.
-LD_PRELOAD=./k.so df >out || fail=1
-test $(wc -l <out) -eq 2 || { fail=1; cat out; }
+# consist of a header and unique entries.
+LD_PRELOAD=./k.so df -T >out || fail=1
+test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { 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
+test $(wc -l <out) -eq $(expr 1 + $unique_entries) || { fail=1; cat out; }
# df should also prefer "/fsname" over "fsname"
-test $(grep -c '/fsname' <out) -eq 1 || { fail=1; cat out; }
-# ... and "/fsname" with '/' as Mounted on over '/root'
-test $(grep -c '/root' <out) -eq 0 || { fail=1; cat out; }
+if test "$unique_entries" = 2; then
+ test $(grep -c '/fsname' <out) -eq 1 || { fail=1; cat out; }
+ # ... and "/fsname" with '/' as Mounted on over '/.'
+ test $(grep -cF '/.' <out) -eq 0 || { fail=1; cat out; }
+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; }
# Ensure that filtering duplicates does not affect -a processing.
LD_PRELOAD=./k.so df -a >out || fail=1
-test $(wc -l <out) -eq 4 || { fail=1; cat out; }
+test $(wc -l <out) -eq 6 || { fail=1; cat out; }
+# Ensure placeholder "-" values used for the eclipsed "virtfs"
+test $(grep -c 'virtfs *-' <out) -eq 1 || { fail=1; cat out; }
# Ensure that filtering duplicates does not affect
# argument processing (now without the fake getmntent()).