1 # source this file; set up for tests
3 # Skip this test if the shell lacks support for functions.
5 eval 'function_test() { return 11; }; function_test'
7 echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2
13 echo "$0: skipping test: $@" 1>&2
19 getfacl --version < /dev/null > /dev/null 2>&1 \
20 && setfacl --version < /dev/null > /dev/null 2>&1 \
21 || skip_test_ "This test requires getfacl and setfacl."
23 id -u bin > /dev/null 2>&1 \
24 || skip_test_ "This test requires a local user named bin."
30 # Expect to be able to exec a program in 10MB of virtual memory,
31 # but not in 20KB. I chose "date". It must not be a shell built-in
32 # function, so you can't use echo, printf, true, etc.
33 # Of course, in coreutils, I could use $top_builddir/src/true,
34 # but this should be able to work for other projects, too.
35 ( ulimit -v 10000; date ) > /dev/null 2>&1 || ulimit_works=no
36 ( ulimit -v 20; date ) > /dev/null 2>&1 && ulimit_works=no
38 test $ulimit_works = no \
39 && skip_test_ "this shell lacks ulimit support"
42 require_readable_root_()
44 test -r / || skip_test_ "/ is not readable"
47 # Skip the current test if strace is not available or doesn't work
48 # with the named syscall. Usage: require_strace_ unlink
51 test $# = 1 || framework_failure
53 strace -V < /dev/null > /dev/null 2>&1 ||
54 skip_test_ 'no strace program'
56 strace -qe "$1" echo > /dev/null 2>&1 ||
57 skip_test_ 'strace -qe "'"$1"'" does not work'
60 # Require a controlling input `terminal'.
61 require_controlling_input_terminal_()
63 tty -s || have_input_tty=no
64 test -t 1 || have_input_tty=no
65 if test "$have_input_tty" = no; then
66 echo "$0: This test must have a controlling input \`terminal'," 1>&2
67 echo " so it may not be run via \`batch', \`at', or \`rsh'." 1>&2
68 echo " On some systems, it may not even be run in the background." 1>&2
77 case " $built_programs " in
79 *) echo "$i: not built" 1>&2; skip_=yes ;;
83 test $skip_ = yes && skip_test_ "required program(s) not built"
88 # Make sure id -u succeeds.
90 || { echo "$0: cannot run \`id -u'" 1>&2; return 1; }
92 # Make sure it gives valid output.
96 echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
102 # Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
103 # to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
104 # =,u=rw,g=rx,o=wx). Ignore ACLs.
109 *) echo "$0: wrong number of arguments" 1>&2
110 echo "Usage: $0 ls-style-mode-string" 1>&2
115 [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
116 [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]+) ;;
117 *) echo "$0: invalid mode string: $rwx" 1>&2; return;;
120 # Perform these conversions:
125 # The `T' and `t' ones are only valid for `other'.
126 s='s/S/@/;s/s/x@/;s/@/s/'
127 t='s/T/@/;s/t/x@/;s/@/t/'
129 u=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
130 g=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
131 o=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`
138 root) skip_test_ must be run as root ;;
139 non-root) skip_test_ must be run as non-root ;;
148 skip_test_ "this system (or maybe just" \
149 "the current file system) lacks SELinux support"
156 if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
158 This test is very expensive, so it is disabled by default.
159 To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
160 environment variable set to yes. E.g.,
162 env RUN_VERY_EXPENSIVE_TESTS=yes make check
169 if test "$RUN_EXPENSIVE_TESTS" != yes; then
171 This test is relatively expensive, so it is disabled by default.
172 To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
173 environment variable set to yes. E.g.,
175 env RUN_EXPENSIVE_TESTS=yes make check
182 uid_is_privileged_ || skip_test_ "must be run as root"
183 NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
186 skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; }
187 error_() { echo "$0: $@" 1>&2; Exit 1; }
188 framework_failure() { error_ 'failure in testing framework'; }
190 # Set `groups' to a space-separated list of at least two groups
191 # of which the user is a member.
192 require_membership_in_two_groups_()
194 test $# = 0 || framework_failure
196 groups=${COREUTILS_GROUPS-`(id -G || /usr/xpg4/bin/id -G) 2>/dev/null`}
200 $0: this test requires that you be a member of more than one group,
201 but running `id -G'\'' either failed or found just one. If you really
202 are a member of at least two groups, then rerun this test with
203 COREUTILS_GROUPS set in your environment to the space-separated list
204 of group names or numbers. E.g.,
206 env COREUTILS_GROUPS='users cdrom' make check
213 # Does the current (working-dir) file system support sparse files?
214 require_sparse_support_()
216 test $# = 0 || framework_failure
217 # Test whether we can create a sparse file.
218 # For example, on Darwin6.5 with a file system of type hfs, it's not possible.
219 # NTFS requires 128K before a hole appears in a sparse file.
221 dd bs=1 seek=128K of=$t < /dev/null 2> /dev/null
225 if test $kb_size -ge 128; then
226 skip_test_ 'this file system does not support sparse files'
232 test $# = 1 || framework_failure
233 if ! mkfifo "$1"; then
234 # Make an exception of this case -- usually we interpret framework-creation
235 # failure as a test failure. However, in this case, when running on a SunOS
236 # system using a disk NFS mounted from OpenBSD, the above fails like this:
237 # mkfifo: cannot make fifo `fifo-10558': Not owner
238 skip_test_ 'NOTICE: unable to create test prerequisites'
242 skip_if_mcstransd_is_running_()
244 test $# = 0 || framework_failure
246 # When mcstransd is running, you'll see only the 3-component
247 # version of file-system context strings. Detect that,
248 # and if it's running, skip this test.
249 __ctx=$(stat --printf='%C\n' .) || framework_failure
251 *:*:*:*) ;; # four components is ok
252 *) # anything else probably means mcstransd is running
253 skip_test_ "unexpected context '$__ctx'; turn off mcstransd" ;;
257 # Skip the current test if umask doesn't work as usual.
258 # This test should be run in the temporary directory that ends
259 # up being removed via the trap commands.
260 working_umask_or_skip_()
265 perms=`ls -l file1 file2 | sed 's/ .*//' | uniq`
270 '*) skip_test_ 'your build directory has unusual umask semantics'
274 # We use a trap below for cleanup. This requires us to go through
275 # hoops to get the right exit status transported through the signal.
276 # So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
277 # Turn off errexit here so that we don't trip the bug with OSF1/Tru64
278 # sh inside this function.
288 this_test_() { echo "./$0" | sed 's,.*/,,'; }
289 this_test=$(this_test_)
291 # This is a stub function that is run upon trap (upon regular exit and
292 # interrupt). Override it with a per-test function, e.g., to unmount
293 # a partition, or to undo any other global state changes.
296 t_=$("$abs_top_builddir/src/mktemp" -d --tmp="$test_dir_" cu-$this_test.XXXXXXXXXX)\
297 || error_ "failed to create temporary directory in $test_dir_"
303 cd "$test_dir_" && chmod -R u+rwx "$t_" && rm -rf "$t_" && exit $__st
306 # Run each test from within a temporary sub-directory named after the
307 # test itself, and arrange to remove it upon exception or normal exit.
309 trap 'Exit $?' 1 2 13 15
311 cd "$t_" || error_ "failed to cd to $t_"
313 if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
314 compare() { diff -u "$@"; }
315 elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
316 compare() { cmp -s "$@"; }
318 compare() { cmp "$@"; }
322 # indent-tabs-mode: nil