]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: df: hide /proc without using LD_PRELOAD
authoroech3 <79379754+oech3@users.noreply.github.com>
Tue, 30 Dec 2025 12:03:11 +0000 (21:03 +0900)
committerPádraig Brady <P@draigBrady.com>
Thu, 1 Jan 2026 13:18:51 +0000 (13:18 +0000)
* tests/df/no-mtab-status-masked-proc.sh: A new test similar
to no-mtab-status.sh but should work with static builds.
* tests/local.mk: Reference the new test.
https://github.com/coreutils/coreutils/pull/156

tests/df/no-mtab-status-masked-proc.sh [new file with mode: 0755]
tests/local.mk

diff --git a/tests/df/no-mtab-status-masked-proc.sh b/tests/df/no-mtab-status-masked-proc.sh
new file mode 100755 (executable)
index 0000000..52c2951
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Test df's behavior when /proc cannot be read.
+# This is an alternative for no-mtab-status.sh for static binaries.
+# This test is skipped if User namespace sandbox is unavailable.
+
+# Copyright (C) 2025 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ df
+skip_if_root_
+
+# Protect against inaccessible remote mounts etc.
+timeout 10 df || skip_ "df fails"
+
+unshare -rm true || skip_ 'User namespace sandbox is disabled'
+
+# mask /proc
+df() {
+  unshare -rm bash -c \
+    "mount -t tmpfs tmpfs /proc && command df \"\$@\"" -- "$@";
+}
+
+df /proc || fail=1
+returns_ 1 df /proc/self || framework_failure_
+
+# Keep the following in sync with no-mtab-status.sh
+
+# These tests are supposed to succeed:
+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:
+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
+
+returns_ 1 df -a || fail=1
+returns_ 1 df -a '.' || fail=1
+
+returns_ 1 df -l || fail=1
+returns_ 1 df -l '.' || fail=1
+
+returns_ 1 df -t hello || fail=1
+returns_ 1 df -t hello '.' || fail=1
+
+returns_ 1 df -x hello || fail=1
+returns_ 1 df -x hello '.' || fail=1
+
+Exit $fail
index 33527d37954a9871360a18cce83a01072b30ca18..fb85bf384ffec8d2717d4e89740eacbb80139d80 100644 (file)
@@ -581,6 +581,7 @@ all_tests =                                 \
   tests/df/unreadable.sh                       \
   tests/df/total-unprocessed.sh                        \
   tests/df/no-mtab-status.sh                   \
+  tests/df/no-mtab-status-masked-proc.sh                       \
   tests/df/skip-duplicates.sh                  \
   tests/df/skip-rootfs.sh                      \
   tests/dd/ascii.sh                            \