1 # source this file; set up for tests
3 # Copyright (C) 2009 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Skip this test if the shell lacks support for functions.
20 eval 'function_test() { return 11; }; function_test'
21 if test $?
!= 11; then
22 echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2
28 echo "$0: skipping test: $@" |
head -1 1>&9
29 echo "$0: skipping test: $@" 1>&2
37 error_
"Error running getlimits"
42 getfacl
--version < /dev
/null
> /dev
/null
2>&1 \
43 && setfacl
--version < /dev
/null
> /dev
/null
2>&1 \
44 || skip_test_
"This test requires getfacl and setfacl."
46 id
-u bin
> /dev
/null
2>&1 \
47 || skip_test_
"This test requires a local user named bin."
53 # Expect to be able to exec a program in 10MB of virtual memory,
54 # but not in 20KB. I chose "date". It must not be a shell built-in
55 # function, so you can't use echo, printf, true, etc.
56 # Of course, in coreutils, I could use $top_builddir/src/true,
57 # but this should be able to work for other projects, too.
58 ( ulimit -v 10000; date ) > /dev
/null
2>&1 || ulimit_works
=no
59 ( ulimit -v 20; date ) > /dev
/null
2>&1 && ulimit_works
=no
61 test $ulimit_works = no \
62 && skip_test_
"this shell lacks ulimit support"
65 require_readable_root_
()
67 test -r / || skip_test_
"/ is not readable"
70 # Skip the current test if strace is not available or doesn't work
71 # with the named syscall. Usage: require_strace_ unlink
74 test $# = 1 || framework_failure
76 strace
-V < /dev
/null
> /dev
/null
2>&1 ||
77 skip_test_
'no strace program'
79 strace
-qe "$1" echo > /dev
/null
2>&1 ||
80 skip_test_
'strace -qe "'"$1"'" does not work'
83 # Require a controlling input `terminal'.
84 require_controlling_input_terminal_
()
86 tty
-s || have_input_tty
=no
87 test -t 0 || have_input_tty
=no
88 if test "$have_input_tty" = no
; then
89 skip_test_
'requires controlling input terminal
90 This test must have a controlling input "terminal", so it may not be
91 run via "batch", "at", or "ssh". On some systems, it may not even be
92 run in the background.'
100 case " $built_programs " in
102 *) echo "$i: not built" 1>&2; skip_
=yes ;;
106 test $skip_ = yes && skip_test_
"required program(s) not built"
111 # Make sure id -u succeeds.
113 ||
{ echo "$0: cannot run \`id -u'" 1>&2; return 1; }
115 # Make sure it gives valid output.
119 echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
125 get_process_status_
()
127 sed -n '/^State:[ ]*\([[:alpha:]]\).*/s//\1/p' /proc
/$1/status
130 # Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
131 # to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
132 # =,u=rw,g=rx,o=wx). Ignore ACLs.
137 *) echo "$0: wrong number of arguments" 1>&2
138 echo "Usage: $0 ls-style-mode-string" 1>&2
143 [ld-
][rwx-
][rwx-
][rwxsS-
][rwx-
][rwx-
][rwxsS-
][rwx-
][rwx-
][rwxtT-
]) ;;
144 [ld-
][rwx-
][rwx-
][rwxsS-
][rwx-
][rwx-
][rwxsS-
][rwx-
][rwx-
][rwxtT-
][+.
]) ;;
145 *) echo "$0: invalid mode string: $rwx" 1>&2; return;;
148 # Perform these conversions:
153 # The `T' and `t' ones are only valid for `other'.
154 s
='s/S/@/;s/s/x@/;s/@/s/'
155 t
='s/T/@/;s/t/x@/;s/@/t/'
157 u
=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
158 g
=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
159 o
=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`
166 root
) skip_test_ must be run as root
;;
167 non-root
) skip_test_ must be run as non-root
;;
176 skip_test_
"this system (or maybe just" \
177 "the current file system) lacks SELinux support"
184 if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
185 skip_test_
'very expensive: disabled by default
186 This test is very expensive, so it is disabled by default.
187 To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
188 environment variable set to yes. E.g.,
190 env RUN_VERY_EXPENSIVE_TESTS=yes make check
197 if test "$RUN_EXPENSIVE_TESTS" != yes; then
198 skip_test_
'expensive: disabled by default
199 This test is relatively expensive, so it is disabled by default.
200 To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
201 environment variable set to yes. E.g.,
203 env RUN_EXPENSIVE_TESTS=yes make check
210 uid_is_privileged_ || skip_test_
"must be run as root"
211 NON_ROOT_USERNAME
=${NON_ROOT_USERNAME=nobody}
212 NON_ROOT_GROUP
=${NON_ROOT_GROUP=nobody}
215 skip_if_root_
() { uid_is_privileged_
&& skip_test_
"must be run as non-root"; }
216 error_
() { echo "$0: $@" 1>&2; Exit
1; }
217 framework_failure
() { error_
'failure in testing framework'; }
219 # Set `groups' to a space-separated list of at least two groups
220 # of which the user is a member.
221 require_membership_in_two_groups_
()
223 test $# = 0 || framework_failure
225 groups
=${COREUTILS_GROUPS-`(id -G || /usr/xpg4/bin/id -G) 2>/dev/null`}
228 *) skip_test_
'requires membership in two groups
229 this test requires that you be a member of more than one group,
230 but running `id -G'\'' either failed or found just one. If you really
231 are a member of at least two groups, then rerun this test with
232 COREUTILS_GROUPS set in your environment to the space-separated list
233 of group names or numbers. E.g.,
235 env COREUTILS_GROUPS='users cdrom
' make check
242 # Is /proc/$PID/status supported?
243 require_proc_pid_status_
()
248 grep '^State:[ ]*[S]' /proc
/$pid/status
> /dev
/null
2>&1 ||
249 skip_test_
"/proc/$pid/status: missing or 'different'"
253 # Does the current (working-dir) file system support sparse files?
254 require_sparse_support_
()
256 test $# = 0 || framework_failure
257 # Test whether we can create a sparse file.
258 # For example, on Darwin6.5 with a file system of type hfs, it's not possible.
259 # NTFS requires 128K before a hole appears in a sparse file.
261 dd bs
=1 seek
=128K of
=$t < /dev
/null
2> /dev
/null
265 if test $kb_size -ge 128; then
266 skip_test_
'this file system does not support sparse files'
272 test $# = 1 || framework_failure
273 if ! mkfifo "$1"; then
274 # Make an exception of this case -- usually we interpret framework-creation
275 # failure as a test failure. However, in this case, when running on a SunOS
276 # system using a disk NFS mounted from OpenBSD, the above fails like this:
277 # mkfifo: cannot make fifo `fifo-10558': Not owner
278 skip_test_
'NOTICE: unable to create test prerequisites'
282 # Disable the current test if the working directory seems to have
283 # the setgid bit set.
286 setgid_tmpdir
=setgid-$$
287 (umask 77; mkdir
$setgid_tmpdir)
288 perms
=$
(stat
--printf %A
$setgid_tmpdir)
292 drwxr-xr-x
);; # Windows98 + DJGPP 2.03
293 *) skip_test_
'this directory has the setgid bit set';;
297 skip_if_mcstransd_is_running_
()
299 test $# = 0 || framework_failure
301 # When mcstransd is running, you'll see only the 3-component
302 # version of file-system context strings. Detect that,
303 # and if it's running, skip this test.
304 __ctx
=$
(stat
--printf='%C\n' .
) || framework_failure
306 *:*:*:*) ;; # four components is ok
307 *) # anything else probably means mcstransd is running
308 skip_test_
"unexpected context '$__ctx'; turn off mcstransd" ;;
312 # Skip the current test if umask doesn't work as usual.
313 # This test should be run in the temporary directory that ends
314 # up being removed via the trap commands.
315 working_umask_or_skip_
()
320 perms
=`ls -l file1 file2 | sed 's/ .*//' | uniq`
325 '*) skip_test_
'your build directory has unusual umask semantics'
329 # We use a trap below for cleanup. This requires us to go through
330 # hoops to get the right exit status transported through the signal.
331 # So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
332 # Turn off errexit here so that we don't trip the bug with OSF1/Tru64
333 # sh inside this function.
343 this_test_
() { echo "./$0" |
sed 's,.*/,,'; }
344 this_test
=$
(this_test_
)
346 # This is a stub function that is run upon trap (upon regular exit and
347 # interrupt). Override it with a per-test function, e.g., to unmount
348 # a partition, or to undo any other global state changes.
351 t_
=$
("$abs_top_builddir/src/mktemp" -d --tmp="$test_dir_" cu-
$this_test.XXXXXXXXXX
)\
352 || error_
"failed to create temporary directory in $test_dir_"
358 cd "$test_dir_" && chmod -R u
+rwx
"$t_" && rm -rf "$t_" && exit $__st
361 # Run each test from within a temporary sub-directory named after the
362 # test itself, and arrange to remove it upon exception or normal exit.
364 trap 'Exit $?' 1 2 13 15
366 cd "$t_" || error_
"failed to cd to $t_"
368 if ( diff --version < /dev
/null
2>&1 |
grep GNU
) 2>&1 > /dev
/null
; then
369 compare
() { diff -u "$@"; }
370 elif ( cmp --version < /dev
/null
2>&1 |
grep GNU
) 2>&1 > /dev
/null
; then
371 compare
() { cmp -s "$@"; }
373 compare
() { cmp "$@"; }
377 # indent-tabs-mode: nil