2010-06-30 23:06:53 +08:00
|
|
|
# This file is sourced by init.sh, *before* its initialization.
|
|
|
|
|
2023-01-01 22:50:15 +08:00
|
|
|
# Copyright (C) 2010-2023 Free Software Foundation, Inc.
|
2011-08-08 15:26:18 +08:00
|
|
|
|
|
|
|
# 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
|
2017-09-19 16:13:23 +08:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2011-08-08 15:26:18 +08:00
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
# This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
|
|
|
|
# TESTS_ENVIRONMENT definition.
|
|
|
|
stderr_fileno_=9
|
|
|
|
|
|
|
|
# Having an unsearchable directory in PATH causes execve to fail with EACCES
|
|
|
|
# when applied to an unresolvable program name, contrary to the desired ENOENT.
|
|
|
|
# Avoid the problem by rewriting PATH to exclude unsearchable directories.
|
2011-12-01 08:04:34 +08:00
|
|
|
# Also, if PATH lacks /sbin and/or /usr/sbin, append it/them.
|
2010-06-30 23:06:53 +08:00
|
|
|
sanitize_path_()
|
|
|
|
{
|
2010-11-06 22:20:06 +08:00
|
|
|
# FIXME: remove double quotes around $IFS when all tests use init.sh.
|
|
|
|
# They constitute a work-around for a bug in FreeBSD 8.1's /bin/sh.
|
|
|
|
local saved_IFS="$IFS"
|
2010-06-30 23:06:53 +08:00
|
|
|
IFS=:
|
|
|
|
set -- $PATH
|
|
|
|
IFS=$saved_IFS
|
|
|
|
|
|
|
|
local d d1
|
|
|
|
local colon=
|
|
|
|
local new_path=
|
|
|
|
for d in "$@"; do
|
|
|
|
test -z "$d" && d1=. || d1=$d
|
|
|
|
if ls -d "$d1/." > /dev/null 2>&1; then
|
|
|
|
new_path="$new_path$colon$d"
|
|
|
|
colon=':'
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-12-01 08:04:34 +08:00
|
|
|
for d in /sbin /usr/sbin ; do
|
|
|
|
case ":$new_path:" in
|
|
|
|
*:$d:*) ;;
|
|
|
|
*) new_path="$new_path:$d" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
PATH=$new_path
|
|
|
|
export PATH
|
|
|
|
}
|
|
|
|
|
|
|
|
getlimits_()
|
|
|
|
{
|
|
|
|
eval $(getlimits)
|
2011-08-04 16:48:38 +08:00
|
|
|
test "$INT_MAX" || fatal_ "running getlimits"
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2015-10-14 22:18:34 +08:00
|
|
|
require_no_default_acl_()
|
|
|
|
{
|
|
|
|
if getfacl --version < /dev/null > /dev/null 2>&1; then
|
|
|
|
getfacl "$1" | grep '^default:' && skip_ 'Default ACL detected'
|
|
|
|
else
|
|
|
|
ls -ld "$1" | grep '.........+' && skip_ 'ACL detected'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
require_acl_()
|
|
|
|
{
|
|
|
|
getfacl --version < /dev/null > /dev/null 2>&1 \
|
|
|
|
&& setfacl --version < /dev/null > /dev/null 2>&1 \
|
2011-06-14 22:22:41 +08:00
|
|
|
|| skip_ "This test requires getfacl and setfacl."
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
id -u bin > /dev/null 2>&1 \
|
2011-06-14 22:22:41 +08:00
|
|
|
|| skip_ "This test requires a local user named bin."
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2010-09-02 20:22:41 +08:00
|
|
|
is_local_dir_()
|
|
|
|
{
|
2011-08-05 02:52:31 +08:00
|
|
|
test $# = 1 || framework_failure_
|
2010-09-02 20:22:41 +08:00
|
|
|
df --local "$1" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2012-08-08 23:38:38 +08:00
|
|
|
require_mount_list_()
|
|
|
|
{
|
|
|
|
local mount_list_fail='cannot read table of mounted file systems'
|
2015-04-06 01:21:38 +08:00
|
|
|
df --local 2>&1 | grep -F "$mount_list_fail" >/dev/null &&
|
2012-08-08 23:38:38 +08:00
|
|
|
skip_ "$mount_list_fail"
|
|
|
|
}
|
|
|
|
|
2016-01-16 21:53:48 +08:00
|
|
|
dump_mount_list_()
|
|
|
|
{
|
|
|
|
cat /proc/self/mountinfo ||
|
|
|
|
cat /proc/self/mounts ||
|
|
|
|
cat /proc/mounts ||
|
|
|
|
cat /etc/mtab
|
|
|
|
}
|
|
|
|
|
2010-09-02 20:22:41 +08:00
|
|
|
require_local_dir_()
|
|
|
|
{
|
2012-08-08 23:38:38 +08:00
|
|
|
require_mount_list_
|
2010-09-02 20:22:41 +08:00
|
|
|
is_local_dir_ . ||
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ "This test must be run on a local file system."
|
2010-09-02 20:22:41 +08:00
|
|
|
}
|
|
|
|
|
2013-12-05 08:02:41 +08:00
|
|
|
require_selinux_()
|
|
|
|
{
|
|
|
|
# When in a chroot of an SELinux-enabled system, but with a mock-simulated
|
|
|
|
# SELinux-*disabled* system, recognize that SELinux is disabled system wide:
|
|
|
|
grep 'selinuxfs$' /proc/filesystems > /dev/null \
|
|
|
|
|| skip_ "this system lacks SELinux support"
|
|
|
|
|
|
|
|
# Independent of whether SELinux is enabled system-wide,
|
|
|
|
# the current file system may lack SELinux support.
|
|
|
|
# Also the current build may have SELinux support disabled.
|
|
|
|
case $(ls -Zd .) in
|
|
|
|
'? .'|'unlabeled .')
|
|
|
|
test -z "$CONFIG_HEADER" \
|
|
|
|
&& framework_failure_ 'CONFIG_HEADER not defined'
|
|
|
|
grep '^#define HAVE_SELINUX_SELINUX_H 1' "$CONFIG_HEADER" > /dev/null \
|
|
|
|
&& selinux_missing_="(file) system" || selinux_missing_="build"
|
|
|
|
skip_ "this $selinux_missing_ lacks SELinux support"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-02-11 22:07:52 +08:00
|
|
|
# Return the SELinux type component if available
|
|
|
|
get_selinux_type() { ls -Zd "$1" | sed -n 's/.*:\(.*_t\)[: ].*/\1/p'; }
|
|
|
|
|
|
|
|
# Whether SELinux Multi Level Security is enabled
|
|
|
|
mls_enabled_() {
|
|
|
|
sestatus 2>&1 |
|
|
|
|
grep 'Policy MLS status:.*enabled' > /dev/null
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
# Skip this test if we're not in SELinux "enforcing" mode.
|
|
|
|
require_selinux_enforcing_()
|
|
|
|
{
|
2013-12-05 08:02:41 +08:00
|
|
|
require_selinux_
|
2010-06-30 23:06:53 +08:00
|
|
|
test "$(getenforce)" = Enforcing \
|
2011-06-14 22:22:41 +08:00
|
|
|
|| skip_ "This test is useful only with SELinux in Enforcing mode."
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2014-01-01 00:09:14 +08:00
|
|
|
require_smack_()
|
|
|
|
{
|
|
|
|
grep 'smackfs$' /proc/filesystems > /dev/null \
|
|
|
|
|| skip_ "this system lacks SMACK support"
|
|
|
|
|
|
|
|
test "$(ls -Zd .)" != '? .' \
|
|
|
|
|| skip_ "this file system lacks SMACK support"
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
require_openat_support_()
|
|
|
|
{
|
|
|
|
# Skip this test if your system has neither the openat-style functions
|
|
|
|
# nor /proc/self/fd support with which to emulate them.
|
2013-12-05 08:02:41 +08:00
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
test -z "$CONFIG_HEADER" \
|
2013-12-05 08:02:41 +08:00
|
|
|
&& framework_failure_ 'CONFIG_HEADER not defined'
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
_skip=yes
|
|
|
|
grep '^#define HAVE_OPENAT' "$CONFIG_HEADER" > /dev/null && _skip=no
|
|
|
|
test -d /proc/self/fd && _skip=no
|
|
|
|
if test $_skip = yes; then
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'this system lacks openat support'
|
2010-06-30 23:06:53 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-01-14 09:52:34 +08:00
|
|
|
# Return true if command runs with the
|
|
|
|
# ulimit specified in the first argument
|
|
|
|
ulimit_supported_()
|
|
|
|
{
|
|
|
|
local v
|
|
|
|
v="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
(
|
|
|
|
# Try to disable core dumps which may
|
|
|
|
# occur with memory constraints
|
|
|
|
trap '' SEGV; ulimit -c 0;
|
|
|
|
|
|
|
|
ulimit -v $v && "$@"
|
|
|
|
) >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
maint: use adaptive approach for `ulimit -v` based tests
When configured with either 'symlinks' or 'shebangs' as value for
the --enable-single-binary option, tests based on `ulimit -v` are
skipped. The reason is that the multicall 'coreutils' binary requires
much more memory due to shared libraries being loaded, and the size of
the 'date' binary (~290KiB) compared to the multicall binary (~5MiB),
of course. Finally, in the case of 'shebangs', the starting shell
requires more memory, too
Instead of using hard-coded values for the memory limit, use an
adaptive approach: first determine the amount of memory for a similar,
yet more trivial invocation of the command, and then do the real test
run using that limit (plus some buffer in some cases).
* init.cfg (require_ulimit_v_): Remove function.
(get_min_ulimit_v_): Add function to determine the minimum memory limit
required for a given command in an adaptive way.
* cfg.mk (sc_prohibit_test_ulimit_without_require_): Change the name
of the above function in the syntax-check rule.
* tests/cp/link-heap.sh: Use the above function to determine the
minimum memory required to run a command simpler than in the real test
run. Use that limit plus a buffer there. While at it, change to list
of commands in the subshell to fail also if the beginning `ulimit -v`
fails.
* tests/dd/no-allocate.sh: Likewise.
* tests/misc/csplit-heap.sh: Likewise.
* tests/misc/cut-huge-range.sh: Likewise.
* tests/misc/head-c.sh: Likewise.
* tests/misc/printf-surprise.sh: Likewise.
* tests/split/line-bytes.sh: Likewise.
* tests/rm/many-dir-entries-vs-OOM.sh: Likewise - doing it separately
for each program under test.
2015-09-23 05:23:26 +08:00
|
|
|
# Determine the minimum required VM limit to run the given command.
|
|
|
|
# Output that value to stdout ... to be used by the caller.
|
|
|
|
# Return 0 in case of success, and a non-Zero value otherwise.
|
|
|
|
get_min_ulimit_v_()
|
2010-06-30 23:06:53 +08:00
|
|
|
{
|
2015-12-16 10:07:56 +08:00
|
|
|
local v
|
|
|
|
local page_size
|
|
|
|
|
|
|
|
# Increase result by this amount to avoid alignment issues
|
|
|
|
page_size=$(getconf PAGESIZE || echo 4096)
|
|
|
|
page_size=$(($page_size / 1024))
|
|
|
|
|
maint: use adaptive approach for `ulimit -v` based tests
When configured with either 'symlinks' or 'shebangs' as value for
the --enable-single-binary option, tests based on `ulimit -v` are
skipped. The reason is that the multicall 'coreutils' binary requires
much more memory due to shared libraries being loaded, and the size of
the 'date' binary (~290KiB) compared to the multicall binary (~5MiB),
of course. Finally, in the case of 'shebangs', the starting shell
requires more memory, too
Instead of using hard-coded values for the memory limit, use an
adaptive approach: first determine the amount of memory for a similar,
yet more trivial invocation of the command, and then do the real test
run using that limit (plus some buffer in some cases).
* init.cfg (require_ulimit_v_): Remove function.
(get_min_ulimit_v_): Add function to determine the minimum memory limit
required for a given command in an adaptive way.
* cfg.mk (sc_prohibit_test_ulimit_without_require_): Change the name
of the above function in the syntax-check rule.
* tests/cp/link-heap.sh: Use the above function to determine the
minimum memory required to run a command simpler than in the real test
run. Use that limit plus a buffer there. While at it, change to list
of commands in the subshell to fail also if the beginning `ulimit -v`
fails.
* tests/dd/no-allocate.sh: Likewise.
* tests/misc/csplit-heap.sh: Likewise.
* tests/misc/cut-huge-range.sh: Likewise.
* tests/misc/head-c.sh: Likewise.
* tests/misc/printf-surprise.sh: Likewise.
* tests/split/line-bytes.sh: Likewise.
* tests/rm/many-dir-entries-vs-OOM.sh: Likewise - doing it separately
for each program under test.
2015-09-23 05:23:26 +08:00
|
|
|
for v in $( seq 5000 5000 50000 ); do
|
2016-01-14 09:52:34 +08:00
|
|
|
if ulimit_supported_ $v "$@"; then
|
2015-12-16 10:07:56 +08:00
|
|
|
local prev_v
|
maint: use adaptive approach for `ulimit -v` based tests
When configured with either 'symlinks' or 'shebangs' as value for
the --enable-single-binary option, tests based on `ulimit -v` are
skipped. The reason is that the multicall 'coreutils' binary requires
much more memory due to shared libraries being loaded, and the size of
the 'date' binary (~290KiB) compared to the multicall binary (~5MiB),
of course. Finally, in the case of 'shebangs', the starting shell
requires more memory, too
Instead of using hard-coded values for the memory limit, use an
adaptive approach: first determine the amount of memory for a similar,
yet more trivial invocation of the command, and then do the real test
run using that limit (plus some buffer in some cases).
* init.cfg (require_ulimit_v_): Remove function.
(get_min_ulimit_v_): Add function to determine the minimum memory limit
required for a given command in an adaptive way.
* cfg.mk (sc_prohibit_test_ulimit_without_require_): Change the name
of the above function in the syntax-check rule.
* tests/cp/link-heap.sh: Use the above function to determine the
minimum memory required to run a command simpler than in the real test
run. Use that limit plus a buffer there. While at it, change to list
of commands in the subshell to fail also if the beginning `ulimit -v`
fails.
* tests/dd/no-allocate.sh: Likewise.
* tests/misc/csplit-heap.sh: Likewise.
* tests/misc/cut-huge-range.sh: Likewise.
* tests/misc/head-c.sh: Likewise.
* tests/misc/printf-surprise.sh: Likewise.
* tests/split/line-bytes.sh: Likewise.
* tests/rm/many-dir-entries-vs-OOM.sh: Likewise - doing it separately
for each program under test.
2015-09-23 05:23:26 +08:00
|
|
|
prev_v=$v
|
|
|
|
for v in $( seq $(($prev_v-1000)) -1000 1000 ); do
|
2016-01-14 09:52:34 +08:00
|
|
|
ulimit_supported_ $v "$@" ||
|
2015-12-16 10:07:56 +08:00
|
|
|
{
|
|
|
|
ret_v=$((prev_v + $page_size))
|
|
|
|
echo $ret_v
|
|
|
|
return 0
|
|
|
|
}
|
maint: use adaptive approach for `ulimit -v` based tests
When configured with either 'symlinks' or 'shebangs' as value for
the --enable-single-binary option, tests based on `ulimit -v` are
skipped. The reason is that the multicall 'coreutils' binary requires
much more memory due to shared libraries being loaded, and the size of
the 'date' binary (~290KiB) compared to the multicall binary (~5MiB),
of course. Finally, in the case of 'shebangs', the starting shell
requires more memory, too
Instead of using hard-coded values for the memory limit, use an
adaptive approach: first determine the amount of memory for a similar,
yet more trivial invocation of the command, and then do the real test
run using that limit (plus some buffer in some cases).
* init.cfg (require_ulimit_v_): Remove function.
(get_min_ulimit_v_): Add function to determine the minimum memory limit
required for a given command in an adaptive way.
* cfg.mk (sc_prohibit_test_ulimit_without_require_): Change the name
of the above function in the syntax-check rule.
* tests/cp/link-heap.sh: Use the above function to determine the
minimum memory required to run a command simpler than in the real test
run. Use that limit plus a buffer there. While at it, change to list
of commands in the subshell to fail also if the beginning `ulimit -v`
fails.
* tests/dd/no-allocate.sh: Likewise.
* tests/misc/csplit-heap.sh: Likewise.
* tests/misc/cut-huge-range.sh: Likewise.
* tests/misc/head-c.sh: Likewise.
* tests/misc/printf-surprise.sh: Likewise.
* tests/split/line-bytes.sh: Likewise.
* tests/rm/many-dir-entries-vs-OOM.sh: Likewise - doing it separately
for each program under test.
2015-09-23 05:23:26 +08:00
|
|
|
prev_v=$v
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# The above did not find a working limit. Echo a very small number - just
|
|
|
|
# in case the caller does not handle the non-Zero return value.
|
|
|
|
echo 1; return 1
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
require_readable_root_()
|
|
|
|
{
|
2011-06-14 22:22:41 +08:00
|
|
|
test -r / || skip_ "/ is not readable"
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Skip the current test if strace is not available or doesn't work
|
|
|
|
# with the named syscall. Usage: require_strace_ unlink
|
|
|
|
require_strace_()
|
|
|
|
{
|
2011-08-05 02:52:31 +08:00
|
|
|
test $# = 1 || framework_failure_
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
strace -V < /dev/null > /dev/null 2>&1 ||
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'no strace program'
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
strace -qe "$1" echo > /dev/null 2>&1 ||
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'strace -qe "'"$1"'" does not work'
|
2011-10-08 23:11:10 +08:00
|
|
|
|
|
|
|
# On some linux/sparc64 systems, strace works fine on 32-bit executables,
|
|
|
|
# but prints only one line of output for every 64-bit executable.
|
|
|
|
strace -o log-help ls --help >/dev/null || framework_failure_
|
|
|
|
n_lines_help=$(wc -l < log-help)
|
|
|
|
rm -f log-help
|
|
|
|
if test $n_lines_help = 0 || test $n_lines_help = 1; then
|
|
|
|
skip_ 'strace produces no more than one line of output'
|
|
|
|
fi
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2012-12-20 08:09:15 +08:00
|
|
|
# Skip the current test if valgrind doesn't work,
|
|
|
|
# which could happen if not installed,
|
|
|
|
# or hasn't support for the built architecture,
|
|
|
|
# or hasn't appropriate error suppressions installed etc.
|
2012-08-18 13:25:28 +08:00
|
|
|
require_valgrind_()
|
|
|
|
{
|
2012-12-20 08:09:15 +08:00
|
|
|
valgrind --error-exitcode=1 true 2>/dev/null ||
|
|
|
|
skip_ "requires a working valgrind"
|
2012-08-18 13:25:28 +08:00
|
|
|
}
|
|
|
|
|
2014-01-10 23:48:25 +08:00
|
|
|
# Skip the current test if setfacl doesn't work on the current file system,
|
|
|
|
# which could happen if not installed, or if ACLs are not supported by the
|
|
|
|
# kernel or the file system, or are turned off via mount options.
|
|
|
|
#
|
|
|
|
# Work around the following two issues:
|
|
|
|
#
|
|
|
|
# 1) setfacl maps ACLs into file permission bits if on "noacl" file systems.
|
|
|
|
#
|
|
|
|
# On file systems which do not support ACLs (e.g. ext4 mounted with -o noacl),
|
|
|
|
# setfacl operates on the regular file permission bits, and only fails if the
|
|
|
|
# given ACL spec does not fit into there. Thus, to test if ACLs really work
|
|
|
|
# on the current file system, pass an ACL spec which can't be mapped that way.
|
|
|
|
# "Default" ACLs (-d) seem to fulfill this requirement.
|
|
|
|
#
|
|
|
|
# 2) setfacl only invokes the underlying system call if the ACL would change.
|
|
|
|
#
|
|
|
|
# If the given ACL spec would not change the ACLs on the file, then setfacl
|
|
|
|
# does not invoke the underlying system call - setxattr(). Therefore, to test
|
|
|
|
# if setting ACLs really works on the current file system, call setfacl twice
|
|
|
|
# with conflictive ACL specs.
|
2011-10-03 19:49:47 +08:00
|
|
|
require_setfacl_()
|
|
|
|
{
|
2014-01-10 23:48:25 +08:00
|
|
|
local d='acltestdir_'
|
|
|
|
mkdir $d || framework_failure_
|
|
|
|
local f=0
|
|
|
|
|
|
|
|
setfacl -d -m user::r-x $d \
|
|
|
|
&& setfacl -d -m user::rwx $d \
|
|
|
|
|| f=1
|
|
|
|
rm -rf $d || framework_failure_
|
|
|
|
test $f = 0 \
|
2011-10-03 19:49:47 +08:00
|
|
|
|| skip_ "setfacl does not work on the current file system"
|
|
|
|
}
|
|
|
|
|
2012-01-08 00:47:58 +08:00
|
|
|
# Require a controlling input 'terminal'.
|
2010-06-30 23:06:53 +08:00
|
|
|
require_controlling_input_terminal_()
|
|
|
|
{
|
2017-04-06 02:34:42 +08:00
|
|
|
have_input_tty=yes
|
2010-06-30 23:06:53 +08:00
|
|
|
tty -s || have_input_tty=no
|
|
|
|
test -t 0 || have_input_tty=no
|
|
|
|
if test "$have_input_tty" = no; then
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'requires controlling input terminal
|
2010-06-30 23:06:53 +08:00
|
|
|
This test must have a controlling input "terminal", so it may not be
|
|
|
|
run via "batch", "at", or "ssh". On some systems, it may not even be
|
|
|
|
run in the background.'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
require_built_()
|
|
|
|
{
|
|
|
|
skip_=no
|
|
|
|
for i in "$@"; do
|
|
|
|
case " $built_programs " in
|
|
|
|
*" $i "*) ;;
|
|
|
|
*) echo "$i: not built" 1>&2; skip_=yes ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2011-06-14 22:22:41 +08:00
|
|
|
test $skip_ = yes && skip_ "required program(s) not built"
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2011-04-04 03:54:10 +08:00
|
|
|
require_file_system_bytes_free_()
|
|
|
|
{
|
|
|
|
local req=$1
|
|
|
|
local expr=$(stat -f --printf "$req / %S <= %a" .)
|
2012-05-16 13:46:51 +08:00
|
|
|
$AWK "BEGIN{ exit !($expr) }" \
|
2011-06-14 22:22:41 +08:00
|
|
|
|| skip_ "this test needs at least $req bytes of free space"
|
2011-04-04 03:54:10 +08:00
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
uid_is_privileged_()
|
|
|
|
{
|
|
|
|
# Make sure id -u succeeds.
|
|
|
|
my_uid=$(id -u) \
|
2012-01-08 00:43:50 +08:00
|
|
|
|| { echo "$0: cannot run 'id -u'" 1>&2; return 1; }
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
# Make sure it gives valid output.
|
|
|
|
case $my_uid in
|
|
|
|
0) ;;
|
|
|
|
*[!0-9]*)
|
2012-01-08 00:43:50 +08:00
|
|
|
echo "$0: invalid output ('$my_uid') from 'id -u'" 1>&2
|
2010-06-30 23:06:53 +08:00
|
|
|
return 1 ;;
|
|
|
|
*) return 1 ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
get_process_status_()
|
|
|
|
{
|
|
|
|
sed -n '/^State:[ ]*\([[:alpha:]]\).*/s//\1/p' /proc/$1/status
|
|
|
|
}
|
|
|
|
|
|
|
|
# Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
|
|
|
|
# to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
|
|
|
|
# =,u=rw,g=rx,o=wx). Ignore ACLs.
|
|
|
|
rwx_to_mode_()
|
|
|
|
{
|
|
|
|
case $# in
|
|
|
|
1) rwx=$1;;
|
|
|
|
*) echo "$0: wrong number of arguments" 1>&2
|
|
|
|
echo "Usage: $0 ls-style-mode-string" 1>&2
|
|
|
|
return;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $rwx in
|
|
|
|
[ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
|
|
|
|
[ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-][+.]) ;;
|
|
|
|
*) echo "$0: invalid mode string: $rwx" 1>&2; return;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Perform these conversions:
|
|
|
|
# S s
|
|
|
|
# s xs
|
|
|
|
# T t
|
|
|
|
# t xt
|
2012-01-08 00:47:58 +08:00
|
|
|
# The 'T' and 't' ones are only valid for 'other'.
|
2010-06-30 23:06:53 +08:00
|
|
|
s='s/S/@/;s/s/x@/;s/@/s/'
|
|
|
|
t='s/T/@/;s/t/x@/;s/@/t/'
|
|
|
|
|
2012-04-04 02:32:44 +08:00
|
|
|
u=$(echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s)
|
|
|
|
g=$(echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s)
|
|
|
|
o=$(echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t)
|
2010-06-30 23:06:53 +08:00
|
|
|
echo "=$u$g$o"
|
|
|
|
}
|
|
|
|
|
2012-04-10 16:10:50 +08:00
|
|
|
# Set the global variable stty_reversible_ to a space-separated list of the
|
|
|
|
# reversible settings from stty.c. stty_reversible_ also starts and ends
|
|
|
|
# with a space.
|
|
|
|
stty_reversible_init_()
|
|
|
|
{
|
2022-04-10 22:47:52 +08:00
|
|
|
require_perl_
|
2012-04-10 16:10:50 +08:00
|
|
|
# Pad start with one space for the first option to match in query function.
|
|
|
|
stty_reversible_=' '$(perl -lne '/^ *{"(.*?)",.*\bREV\b/ and print $1' \
|
2012-09-03 03:55:18 +08:00
|
|
|
"$abs_top_srcdir"/src/stty.c | tr '\n' ' ')
|
2012-04-10 16:10:50 +08:00
|
|
|
# Ensure that there are at least 62, i.e., so we're alerted if
|
|
|
|
# reformatting the source empties the list.
|
|
|
|
test 62 -le $(echo "$stty_reversible_"|wc -w) \
|
|
|
|
|| framework_failure_ "too few reversible settings"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test whether $1 is one of stty's reversible options.
|
|
|
|
stty_reversible_query_()
|
|
|
|
{
|
|
|
|
case $stty_reversible_ in
|
|
|
|
'')
|
|
|
|
framework_failure_ "stty_reversible_init_() not called?";;
|
|
|
|
*" $1 "*)
|
|
|
|
return 0;;
|
|
|
|
*)
|
|
|
|
return 1;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
skip_if_()
|
|
|
|
{
|
|
|
|
case $1 in
|
2011-06-14 22:22:41 +08:00
|
|
|
root) skip_ must be run as root ;;
|
|
|
|
non-root) skip_ must be run as non-root ;;
|
2010-06-30 23:06:53 +08:00
|
|
|
*) ;; # FIXME?
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
very_expensive_()
|
|
|
|
{
|
|
|
|
if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'very expensive: disabled by default
|
2010-06-30 23:06:53 +08:00
|
|
|
This test is very expensive, so it is disabled by default.
|
|
|
|
To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
|
|
|
|
environment variable set to yes. E.g.,
|
|
|
|
|
|
|
|
env RUN_VERY_EXPENSIVE_TESTS=yes make check
|
2011-09-20 02:02:22 +08:00
|
|
|
|
|
|
|
or use the shortcut target of the toplevel Makefile,
|
|
|
|
|
|
|
|
make check-very-expensive
|
2010-06-30 23:06:53 +08:00
|
|
|
'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
expensive_()
|
|
|
|
{
|
|
|
|
if test "$RUN_EXPENSIVE_TESTS" != yes; then
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'expensive: disabled by default
|
2010-06-30 23:06:53 +08:00
|
|
|
This test is relatively expensive, so it is disabled by default.
|
|
|
|
To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
|
|
|
|
environment variable set to yes. E.g.,
|
|
|
|
|
|
|
|
env RUN_EXPENSIVE_TESTS=yes make check
|
2011-09-20 02:02:22 +08:00
|
|
|
|
|
|
|
or use the shortcut target of the toplevel Makefile,
|
|
|
|
|
|
|
|
make check-expensive
|
2010-06-30 23:06:53 +08:00
|
|
|
'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-05-20 01:21:57 +08:00
|
|
|
# Test whether we can run our just-built root owned rm,
|
2012-09-06 18:00:16 +08:00
|
|
|
# i.e., that $NON_ROOT_USERNAME has access to the build directory.
|
2014-05-20 01:21:57 +08:00
|
|
|
nonroot_has_perm_()
|
2012-09-06 18:00:16 +08:00
|
|
|
{
|
2014-05-20 01:21:57 +08:00
|
|
|
require_built_ chroot
|
|
|
|
|
2012-09-06 18:00:16 +08:00
|
|
|
local rm_version=$(
|
chroot: perform chdir("/") again unless new --skip-chdir is specified
Since commit v8.22-94-g99960ee, chroot(1) skips the chroot(2) syscall
for "/" arguments (and synonyms). The problem is that it also skips
the following chdir("/") call in that case. The latter breaks existing
scripts which expect "/" to be the working directory inside the chroot.
While the first part of the change - i.e., skipping chroot("/") - is
okay for consistency with systems where it might succeed for a non-root
user, the second part might be malicious, e.g.
cd /home/user && chroot '/' bin/foo
In the "best" case, chroot(1) could not execute 'bin/foo' with ENOENT,
but in the worst case, chroot(1) would execute '/home/user/bin/foo' in
the case that exists - instead of '/bin/foo'.
Revert that second part of the patch, i.e., perform the chdir("/)
in the common case again - unless the new --skip-chdir option is
specified. Restrict this new option to the case of "/" arguments.
* src/chroot.c (SKIP_CHDIR): Add enum.
(long_opts): Add entry for the new --skip-chdir option.
(usage): Add --skip-chdir option, and while at it, move the other
to options into alphabetical order.
(main): Accept the above new option, allowing it only in the case
when NEWROOT is the old "/".
Move down the chdir() call after the if-clause to ensure it is
run in any case - unless --skip-chdir is specified.
Add a 'newroot' variable for the new root directory as it is used
in a couple of places now.
* tests/misc/chroot-fail.sh: Invert the last tests which check the
working directory of the execvp()ed program when a "/"-like
argument was passed: now expect it to be "/" - unless --skip-chdir
is given.
* doc/coreutils.texi (chroot invocation): Document the new option.
Document that chroot(1) usually calls chdir("/") unless the new
--skip-chdir option is specified. Sort options.
* NEWS (Changes in behavior): Mention the fix.
(New features): Mention the new option.
* init.cfg (nonroot_has_perm_): Add chroot's new --skip-chdir option.
* tests/cp/preserve-gid.sh (t1): Likewise.
* tests/cp/special-bits.sh: Likewise.
* tests/id/setgid.sh: Likewise.
* tests/misc/truncate-owned-by-other.sh: Likewise.
* tests/mv/sticky-to-xpart.sh: Likewise.
* tests/rm/fail-2eperm.sh: Likewise.
* tests/rm/no-give-up.sh: Likewise.
* tests/touch/now-owned-by-other.sh: Likewise.
Reported by Andreas Schwab in http://bugs.gnu.org/18062
2014-08-01 08:07:33 +08:00
|
|
|
chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
|
|
|
|
rm --version |
|
2012-11-01 23:50:51 +08:00
|
|
|
sed -n '1s/.* //p'
|
2012-09-06 18:00:16 +08:00
|
|
|
)
|
|
|
|
case ":$rm_version:" in
|
|
|
|
:$PACKAGE_VERSION:) ;;
|
|
|
|
*) return 1;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
require_root_()
|
|
|
|
{
|
2011-06-14 22:22:41 +08:00
|
|
|
uid_is_privileged_ || skip_ "must be run as root"
|
2010-06-30 23:06:53 +08:00
|
|
|
NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
|
2014-06-26 19:41:01 +08:00
|
|
|
NON_ROOT_GID=${NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)}
|
2012-09-06 18:00:16 +08:00
|
|
|
|
2014-05-20 01:21:57 +08:00
|
|
|
# When the current test invokes chroot, call nonroot_has_perm_
|
2012-09-06 18:00:16 +08:00
|
|
|
# to check for a common problem.
|
2014-05-20 01:21:57 +08:00
|
|
|
grep '^[ ]*chroot' "../$0" \
|
|
|
|
&& { nonroot_has_perm_ \
|
2012-09-06 18:00:16 +08:00
|
|
|
|| skip_ "user $NON_ROOT_USERNAME lacks execute permissions"; }
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }
|
2010-06-30 23:06:53 +08:00
|
|
|
|
2012-01-08 00:47:58 +08:00
|
|
|
# Set 'groups' to a space-separated list of at least two groups
|
2010-06-30 23:06:53 +08:00
|
|
|
# of which the user is a member.
|
|
|
|
require_membership_in_two_groups_()
|
|
|
|
{
|
2011-08-05 02:52:31 +08:00
|
|
|
test $# = 0 || framework_failure_
|
2010-06-30 23:06:53 +08:00
|
|
|
|
2023-02-19 05:27:45 +08:00
|
|
|
groups=
|
|
|
|
for group_ in 1 \
|
|
|
|
${COREUTILS_GROUPS-$( (id -G || /usr/xpg4/bin/id -G) 2>/dev/null)}
|
|
|
|
do
|
|
|
|
# Skip group numbers equal to 2**N - 1 for common N,
|
|
|
|
# as they are possibly reserved groups like 'nogroup'.
|
|
|
|
case $group_ in
|
|
|
|
1 | 32767 | 65535 | 2147483647 | 4294967295) ;;
|
|
|
|
9223372036854775807 | 18446744073709551615) ;;
|
|
|
|
*) test -z "$groups" || groups="$groups "
|
|
|
|
groups="$groups$group_";;
|
|
|
|
esac
|
|
|
|
done
|
2010-06-30 23:06:53 +08:00
|
|
|
case "$groups" in
|
|
|
|
*' '*) ;;
|
2011-06-14 22:22:41 +08:00
|
|
|
*) skip_ 'requires membership in two groups
|
2010-06-30 23:06:53 +08:00
|
|
|
this test requires that you be a member of more than one group,
|
2018-07-02 00:05:53 +08:00
|
|
|
but running '\''id -G'\'' either failed or found just one. If you really
|
2010-06-30 23:06:53 +08:00
|
|
|
are a member of at least two groups, then rerun this test with
|
|
|
|
COREUTILS_GROUPS set in your environment to the space-separated list
|
|
|
|
of group names or numbers. E.g.,
|
|
|
|
|
2011-09-01 17:11:06 +08:00
|
|
|
env COREUTILS_GROUPS='\''users cdrom'\'' make check
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Is /proc/$PID/status supported?
|
|
|
|
require_proc_pid_status_()
|
|
|
|
{
|
|
|
|
sleep 2 &
|
|
|
|
local pid=$!
|
|
|
|
sleep .5
|
|
|
|
grep '^State:[ ]*[S]' /proc/$pid/status > /dev/null 2>&1 ||
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ "/proc/$pid/status: missing or 'different'"
|
2010-06-30 23:06:53 +08:00
|
|
|
kill $pid
|
|
|
|
}
|
|
|
|
|
2015-11-10 02:50:21 +08:00
|
|
|
# Does trap support signal names?
|
|
|
|
# Old versions of ash did not.
|
|
|
|
require_trap_signame_()
|
|
|
|
{
|
|
|
|
(trap '' CHLD) || skip_ 'requires trap with signal name support'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Does kill support sending signal to whole group?
|
|
|
|
# dash 0.5.8 at least does not.
|
|
|
|
require_kill_group_()
|
|
|
|
{
|
|
|
|
kill -0 -- -1 || skip_ 'requires kill with group signalling support'
|
|
|
|
}
|
|
|
|
|
2011-02-05 06:05:20 +08:00
|
|
|
# Return nonzero if the specified path is on a file system for
|
2021-05-09 21:29:01 +08:00
|
|
|
# which SEEK_DATA support exists.
|
|
|
|
seek_data_capable_()
|
2011-01-31 21:44:15 +08:00
|
|
|
{
|
2023-02-24 04:28:51 +08:00
|
|
|
# Check that SEEK_HOLE support is enabled
|
|
|
|
# Note APFS was seen to not create sparse files < 16MiB
|
|
|
|
if ! truncate -s16M file.sparse_; then
|
|
|
|
warn_ "can't create a sparse file: assuming not SEEK_DATA capable"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! cp --debug --reflink=never file.sparse_ file.sparse_.cp \
|
|
|
|
| grep SEEK_HOLE; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that SEEK_HOLE is supported on the passed file
|
2021-05-09 21:29:01 +08:00
|
|
|
{ python3 < /dev/null && PYTHON_=python3; } ||
|
|
|
|
{ python < /dev/null && PYTHON_=python; }
|
|
|
|
|
|
|
|
if test x"$PYTHON_" = x; then
|
|
|
|
warn_ 'seek_data_capable_: python missing: assuming not SEEK_DATA capable'
|
|
|
|
return 1
|
2011-02-05 06:05:20 +08:00
|
|
|
fi
|
2021-09-25 21:23:37 +08:00
|
|
|
|
|
|
|
# Use timeout if available to skip cases where SEEK_DATA takes a long time.
|
|
|
|
# We saw FreeBSD 9.1 take 35s to return from SEEK_DATA for a 1TiB empty file.
|
|
|
|
# Note lseek() is uninterruptible on FreeBSD 9.1, but it does eventually
|
|
|
|
# return, and the timeout will ensure a failure return from the process.
|
|
|
|
timeout --version >/dev/null && TIMEOUT_='timeout 10'
|
|
|
|
|
|
|
|
$TIMEOUT_ $PYTHON_ "$abs_srcdir"/tests/seek-data-capable "$@"
|
2011-01-31 21:44:15 +08:00
|
|
|
}
|
|
|
|
|
ls: allow stat-free use of --color
Even on a system with d_type support, the default use of --color
makes ls stat every file in order to be able to honor settings like
EXEC, STICKY, ORPHAN, SETUID, etc., because those settings require
information that is not provided by dirent.d_type. However, if
for a potentially large performance gain, you are willing to disable
those settings, you can now make ls --color give type-related coloring
and perform no stat calls at all (other than the unavoidable call-per-
command-line argument). Before this change, even with all of those
attributes disabled, ls --color would still stat every directory.
Now, we're down to the minimum of one stat call per command-line arg.
* src/ls.c (gobble_file): With --color, don't stat a
non-command-line-specified directory when no directory-coloring
attribute is enabled.
* tests/init.cfg (require_dirent_d_type_): New function.
* tests/d_type-check: New script, mostly from Pádraig Brady.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/ls/stat-free-color: New test.
* tests/Makefile.am (TESTS): Add it.
* doc/coreutils.texi (General output formatting): Describe how
to use dircolors to make ls --color refrain from calling stat
on a d_type-enabled file system.
Prompted by a query from Josef Bacik.
2011-05-11 23:13:53 +08:00
|
|
|
# Skip the current test if "." lacks d_type support.
|
|
|
|
require_dirent_d_type_()
|
|
|
|
{
|
|
|
|
python < /dev/null \
|
2011-06-14 22:22:41 +08:00
|
|
|
|| skip_ python missing: assuming no d_type support
|
ls: allow stat-free use of --color
Even on a system with d_type support, the default use of --color
makes ls stat every file in order to be able to honor settings like
EXEC, STICKY, ORPHAN, SETUID, etc., because those settings require
information that is not provided by dirent.d_type. However, if
for a potentially large performance gain, you are willing to disable
those settings, you can now make ls --color give type-related coloring
and perform no stat calls at all (other than the unavoidable call-per-
command-line argument). Before this change, even with all of those
attributes disabled, ls --color would still stat every directory.
Now, we're down to the minimum of one stat call per command-line arg.
* src/ls.c (gobble_file): With --color, don't stat a
non-command-line-specified directory when no directory-coloring
attribute is enabled.
* tests/init.cfg (require_dirent_d_type_): New function.
* tests/d_type-check: New script, mostly from Pádraig Brady.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/ls/stat-free-color: New test.
* tests/Makefile.am (TESTS): Add it.
* doc/coreutils.texi (General output formatting): Describe how
to use dircolors to make ls --color refrain from calling stat
on a d_type-enabled file system.
Prompted by a query from Josef Bacik.
2011-05-11 23:13:53 +08:00
|
|
|
|
2012-09-03 03:55:18 +08:00
|
|
|
python "$abs_srcdir"/tests/d_type-check \
|
2011-06-14 22:22:41 +08:00
|
|
|
|| skip_ requires d_type support
|
ls: allow stat-free use of --color
Even on a system with d_type support, the default use of --color
makes ls stat every file in order to be able to honor settings like
EXEC, STICKY, ORPHAN, SETUID, etc., because those settings require
information that is not provided by dirent.d_type. However, if
for a potentially large performance gain, you are willing to disable
those settings, you can now make ls --color give type-related coloring
and perform no stat calls at all (other than the unavoidable call-per-
command-line argument). Before this change, even with all of those
attributes disabled, ls --color would still stat every directory.
Now, we're down to the minimum of one stat call per command-line arg.
* src/ls.c (gobble_file): With --color, don't stat a
non-command-line-specified directory when no directory-coloring
attribute is enabled.
* tests/init.cfg (require_dirent_d_type_): New function.
* tests/d_type-check: New script, mostly from Pádraig Brady.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/ls/stat-free-color: New test.
* tests/Makefile.am (TESTS): Add it.
* doc/coreutils.texi (General output formatting): Describe how
to use dircolors to make ls --color refrain from calling stat
on a d_type-enabled file system.
Prompted by a query from Josef Bacik.
2011-05-11 23:13:53 +08:00
|
|
|
}
|
|
|
|
|
2011-09-02 05:59:02 +08:00
|
|
|
# Skip the current test if we lack Perl.
|
|
|
|
require_perl_()
|
|
|
|
{
|
|
|
|
: ${PERL=perl}
|
|
|
|
$PERL -e 'use warnings' > /dev/null 2>&1 \
|
|
|
|
|| skip_ 'configure did not find a usable version of Perl'
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
# Does the current (working-dir) file system support sparse files?
|
|
|
|
require_sparse_support_()
|
|
|
|
{
|
2011-08-05 02:52:31 +08:00
|
|
|
test $# = 0 || framework_failure_
|
2010-06-30 23:06:53 +08:00
|
|
|
# Test whether we can create a sparse file.
|
|
|
|
# For example, on Darwin6.5 with a file system of type hfs, it's not possible.
|
|
|
|
# NTFS requires 128K before a hole appears in a sparse file.
|
|
|
|
t=sparse.$$
|
|
|
|
dd bs=1 seek=128K of=$t < /dev/null 2> /dev/null
|
2012-04-04 02:32:44 +08:00
|
|
|
set x $(du -sk $t)
|
2010-06-30 23:06:53 +08:00
|
|
|
kb_size=$2
|
|
|
|
rm -f $t
|
|
|
|
if test $kb_size -ge 128; then
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'this file system does not support sparse files'
|
2010-06-30 23:06:53 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-03-01 10:03:59 +08:00
|
|
|
# Libraries needed when we compile a shared library.
|
|
|
|
gcc_shared_libs_=
|
|
|
|
|
2014-01-14 03:39:52 +08:00
|
|
|
# Compile a shared lib using the GCC options for doing so.
|
|
|
|
# Pass input and output file as parameters respectively.
|
2023-02-21 22:18:52 +08:00
|
|
|
# Any other optional parameters are passed to $CC.
|
2014-01-14 03:39:52 +08:00
|
|
|
gcc_shared_()
|
|
|
|
{
|
|
|
|
local in=$1
|
|
|
|
local out=$2
|
|
|
|
shift 2 || return 1
|
|
|
|
|
2020-03-01 10:03:59 +08:00
|
|
|
$CC -Wall -shared --std=gnu99 -fPIC -O2 $* "$in" -o "$out" $gcc_shared_libs_
|
2014-01-14 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-27 20:51:43 +08:00
|
|
|
# There are a myriad of ways to build shared libs,
|
|
|
|
# so we only consider running tests requiring shared libs,
|
|
|
|
# on platforms that support building them as follows.
|
|
|
|
require_gcc_shared_()
|
|
|
|
{
|
2020-03-01 10:03:59 +08:00
|
|
|
# Try two different values for gcc_shared_libs_.
|
|
|
|
gcc_shared_libs_='-ldl'
|
|
|
|
if gcc_shared_ '-' 'd.so' -xc < /dev/null 2>&1; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
gcc_shared_libs_=
|
|
|
|
if gcc_shared_ '-' 'd.so' -xc < /dev/null 2>&1; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
skip_ '$CC -shared ... failed to build a shared lib'
|
|
|
|
fi
|
|
|
|
fi
|
2014-01-14 03:39:52 +08:00
|
|
|
rm -f d.so
|
2013-03-27 20:51:43 +08:00
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
mkfifo_or_skip_()
|
|
|
|
{
|
2011-08-05 02:52:31 +08:00
|
|
|
test $# = 1 || framework_failure_
|
2010-06-30 23:06:53 +08:00
|
|
|
if ! mkfifo "$1"; then
|
|
|
|
# Make an exception of this case -- usually we interpret framework-creation
|
|
|
|
# failure as a test failure. However, in this case, when running on a SunOS
|
2021-07-29 03:22:11 +08:00
|
|
|
# system using a file system NFS mounted from OpenBSD, the above fails like
|
|
|
|
# this:
|
2012-01-08 00:47:58 +08:00
|
|
|
# mkfifo: cannot make fifo 'fifo-10558': Not owner
|
2011-06-14 22:22:41 +08:00
|
|
|
skip_ 'unable to create a fifo'
|
2010-06-30 23:06:53 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-20 16:13:15 +08:00
|
|
|
trap_sigpipe_or_skip_()
|
|
|
|
{
|
2022-11-15 21:57:47 +08:00
|
|
|
timeout --version >/dev/null ||
|
|
|
|
skip_ 'trapping SIGPIPE cannot be safely checked'
|
|
|
|
|
|
|
|
(trap '' PIPE && timeout 10 yes |:) 2>&1 | grep 'Broken pipe' >/dev/null ||
|
2019-01-20 16:13:15 +08:00
|
|
|
skip_ 'trapping SIGPIPE is not supported'
|
|
|
|
}
|
|
|
|
|
2020-03-02 05:49:16 +08:00
|
|
|
require_bash_as_SHELL_()
|
|
|
|
{
|
|
|
|
if bash --version >/dev/null 2>&1; then
|
|
|
|
SHELL='bash'
|
|
|
|
else
|
|
|
|
skip_ 'bash is required'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
# Disable the current test if the working directory seems to have
|
|
|
|
# the setgid bit set.
|
|
|
|
skip_if_setgid_()
|
|
|
|
{
|
|
|
|
setgid_tmpdir=setgid-$$
|
|
|
|
(umask 77; mkdir $setgid_tmpdir)
|
|
|
|
perms=$(stat --printf %A $setgid_tmpdir)
|
|
|
|
rmdir $setgid_tmpdir
|
|
|
|
case $perms in
|
|
|
|
drwx------);;
|
|
|
|
drwxr-xr-x);; # Windows98 + DJGPP 2.03
|
2011-06-14 22:22:41 +08:00
|
|
|
*) skip_ 'this directory has the setgid bit set';;
|
2010-06-30 23:06:53 +08:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2013-04-13 05:57:45 +08:00
|
|
|
# Skip if files are created with a different group to the current user
|
|
|
|
# This can happen due to a setgid dir, or by some other mechanism on OS X:
|
2017-09-19 16:13:23 +08:00
|
|
|
# https://unix.stackexchange.com/q/63865
|
2017-01-15 14:57:51 +08:00
|
|
|
# https://bugs.gnu.org/14024#41
|
2013-04-13 05:57:45 +08:00
|
|
|
skip_if_nondefault_group_()
|
|
|
|
{
|
|
|
|
touch grp.$$
|
|
|
|
gen_ug=$(stat -c '%u:%g' grp.$$)
|
|
|
|
rm grp.$$
|
|
|
|
test "$gen_ug" = "$(id -ru):$(id -rg)" ||
|
|
|
|
skip_ 'Files are created with a different gid'
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
skip_if_mcstransd_is_running_()
|
|
|
|
{
|
2011-08-05 02:52:31 +08:00
|
|
|
test $# = 0 || framework_failure_
|
2010-06-30 23:06:53 +08:00
|
|
|
|
|
|
|
# When mcstransd is running, you'll see only the 3-component
|
|
|
|
# version of file-system context strings. Detect that,
|
|
|
|
# and if it's running, skip this test.
|
2011-08-05 02:52:31 +08:00
|
|
|
__ctx=$(stat --printf='%C\n' .) || framework_failure_
|
2010-06-30 23:06:53 +08:00
|
|
|
case $__ctx in
|
2016-02-11 22:07:52 +08:00
|
|
|
*:*:*:*) __ctx_ok=1 ;; # four components is ok
|
|
|
|
*:*:*) # three components is ok too if there is no MLS
|
2016-12-19 04:37:21 +08:00
|
|
|
mls_enabled_ || __ctx_ok=1 ;;
|
2010-06-30 23:06:53 +08:00
|
|
|
esac
|
2016-02-11 22:07:52 +08:00
|
|
|
|
|
|
|
test "$__ctx_ok" ||
|
|
|
|
skip_ "unexpected context '$__ctx'; turn off mcstransd"
|
2010-06-30 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Skip the current test if umask doesn't work as usual.
|
|
|
|
# This test should be run in the temporary directory that ends
|
|
|
|
# up being removed via the trap commands.
|
|
|
|
working_umask_or_skip_()
|
|
|
|
{
|
|
|
|
umask 022
|
|
|
|
touch file1 file2
|
|
|
|
chmod 644 file2
|
2012-04-04 02:32:44 +08:00
|
|
|
perms=$(ls -l file1 file2 | sed 's/ .*//' | uniq)
|
2010-06-30 23:06:53 +08:00
|
|
|
rm -f file1 file2
|
|
|
|
|
|
|
|
case $perms in
|
|
|
|
*'
|
2011-06-14 22:22:41 +08:00
|
|
|
'*) skip_ 'your build directory has unusual umask semantics'
|
2010-06-30 23:06:53 +08:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:02:56 +08:00
|
|
|
# Retry a function requiring a sufficient delay to _pass_
|
|
|
|
# using a truncated exponential backoff method.
|
2010-12-22 18:49:25 +08:00
|
|
|
# Example: retry_delay_ dd_reblock_1 .1 6
|
2010-07-05 15:53:10 +08:00
|
|
|
# This example will call the dd_reblock_1 function with
|
|
|
|
# an initial delay of .1 second and call it at most 6 times
|
|
|
|
# with a max delay of 3.2s (doubled each time), or a total of 6.3s
|
|
|
|
# Note ensure you do _not_ quote the parameter to GNU sleep in
|
2012-04-04 02:32:44 +08:00
|
|
|
# your function, as it may contain separate values that sleep
|
2010-07-05 15:53:10 +08:00
|
|
|
# needs to accumulate.
|
2013-04-20 22:33:06 +08:00
|
|
|
# Further function arguments will be forwarded to the test function.
|
2010-07-05 15:53:10 +08:00
|
|
|
retry_delay_()
|
|
|
|
{
|
|
|
|
local test_func=$1
|
|
|
|
local init_delay=$2
|
|
|
|
local max_n_tries=$3
|
2013-04-20 22:33:06 +08:00
|
|
|
shift 3 || return 1
|
2010-07-05 15:53:10 +08:00
|
|
|
|
|
|
|
local attempt=1
|
|
|
|
local num_sleeps=$attempt
|
|
|
|
local time_fail
|
|
|
|
while test $attempt -le $max_n_tries; do
|
|
|
|
local delay=$($AWK -v n=$num_sleeps -v s="$init_delay" \
|
2010-11-08 18:26:08 +08:00
|
|
|
'BEGIN { print s * n }')
|
2013-04-20 22:33:06 +08:00
|
|
|
"$test_func" "$delay" "$@" && { time_fail=0; break; } || time_fail=1
|
2010-07-05 15:53:10 +08:00
|
|
|
attempt=$(expr $attempt + 1)
|
|
|
|
num_sleeps=$(expr $num_sleeps '*' 2)
|
|
|
|
done
|
|
|
|
test "$time_fail" = 0
|
|
|
|
}
|
|
|
|
|
2010-11-16 15:05:11 +08:00
|
|
|
# Call this with a list of programs under test immediately after
|
|
|
|
# sourcing init.sh.
|
|
|
|
print_ver_()
|
|
|
|
{
|
2015-11-10 22:05:50 +08:00
|
|
|
require_built_ "$@"
|
2010-11-16 15:05:11 +08:00
|
|
|
if test "$VERBOSE" = yes; then
|
|
|
|
local i
|
|
|
|
for i in $*; do
|
|
|
|
env $i --version
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-11-12 08:25:45 +08:00
|
|
|
# Are we running on GNU/Hurd?
|
|
|
|
require_gnu_()
|
|
|
|
{
|
|
|
|
test "$(uname)" = GNU \
|
|
|
|
|| skip_ 'not running on GNU/Hurd'
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:06:53 +08:00
|
|
|
sanitize_path_
|