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
20 # Expect to be able to exec a program in 10MB of virtual memory,
21 # but not in 20KB. I chose "date". It must not be a shell built-in
22 # function, so you can't use echo, printf, true, etc.
23 # Of course, in coreutils, I could use $top_builddir/src/true,
24 # but this should be able to work for other projects, too.
25 ( ulimit -v 10000; date ) > /dev
/null
2>&1 || ulimit_works
=no
26 ( ulimit -v 20; date ) > /dev
/null
2>&1 && ulimit_works
=no
28 test $ulimit_works = no \
29 && skip_test_
"this shell lacks ulimit support"
34 # Make sure id -u succeeds.
36 ||
{ echo "$0: cannot run \`id -u'" 1>&2; return 1; }
38 # Make sure it gives valid output.
42 echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
51 root
) skip_test_ must be run as root
;;
52 non-root
) skip_test_ must be run as non-root
;;
61 skip_test_
"this system (or maybe just" \
62 "the current file system) lacks SELinux support"
67 skip_if_root_
() { uid_is_privileged_
&& skip_test_
"must be run as non-root"; }
68 error_
() { echo "$0: $@" 1>&2; (exit 1); exit 1; }
69 framework_failure
() { error_
'failure in testing framework'; }
73 this_test_
() { echo "./$0" |
sed 's,.*/,,'; }
74 this_test
=$
(this_test_
)
76 .
$srcdir/..
/envvar-check
78 # This is a stub function that is run upon trap (upon regular exit and
79 # interrupt). Override it with a per-test function, e.g., to unmount
80 # a partition, or to undo any other global state changes.
83 t_
=$
($abs_top_builddir/src
/mktemp
-d --tmp="$test_dir_" cu-
$this_test.XXXXXXXXXX
)\
84 || error_
"failed to create temporary directory in $test_dir_"
86 # Run each test from within a temporary sub-directory named after the
87 # test itself, and arrange to remove it upon exception or normal exit.
88 trap 'st=$?; cleanup_; d='"$t_"';
89 cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0
90 trap '(exit $?); exit $?' 1 2 13 15
92 cd $t_ || error_
"failed to cd to $t_"
94 if ( diff --version < /dev
/null
2>&1 |
grep GNU
) 2>&1 > /dev
/null
; then
95 compare
() { diff -u "$@"; }
96 elif ( cmp --version < /dev
/null
2>&1 |
grep GNU
) 2>&1 > /dev
/null
; then
97 compare
() { cmp -s "$@"; }
99 compare
() { cmp "$@"; }
103 # indent-tabs-mode: nil