shred,sort: ensure faster unaligned access to rand module
[coreutils.git] / init.cfg
blobdb861944c6af45c18dc59294489f7512760bea2a
1 # This file is sourced by init.sh, *before* its initialization.
3 # Copyright (C) 2010-2016 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 # This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
19 # TESTS_ENVIRONMENT definition.
20 stderr_fileno_=9
22 # Having an unsearchable directory in PATH causes execve to fail with EACCES
23 # when applied to an unresolvable program name, contrary to the desired ENOENT.
24 # Avoid the problem by rewriting PATH to exclude unsearchable directories.
25 # Also, if PATH lacks /sbin and/or /usr/sbin, append it/them.
26 sanitize_path_()
28   # FIXME: remove double quotes around $IFS when all tests use init.sh.
29   # They constitute a work-around for a bug in FreeBSD 8.1's /bin/sh.
30   local saved_IFS="$IFS"
31     IFS=:
32     set -- $PATH
33   IFS=$saved_IFS
35   local d d1
36   local colon=
37   local new_path=
38   for d in "$@"; do
39     test -z "$d" && d1=. || d1=$d
40     if ls -d "$d1/." > /dev/null 2>&1; then
41       new_path="$new_path$colon$d"
42       colon=':'
43     fi
44   done
46   for d in /sbin /usr/sbin ; do
47     case ":$new_path:" in
48       *:$d:*) ;;
49       *) new_path="$new_path:$d" ;;
50     esac
51   done
53   PATH=$new_path
54   export PATH
57 getlimits_()
59   eval $(getlimits)
60   test "$INT_MAX" || fatal_ "running getlimits"
63 require_no_default_acl_()
65   if getfacl --version < /dev/null > /dev/null 2>&1; then
66     getfacl "$1" | grep '^default:' && skip_ 'Default ACL detected'
67   else
68     ls -ld "$1" | grep '.........+' && skip_ 'ACL detected'
69   fi
72 require_acl_()
74   getfacl --version < /dev/null > /dev/null 2>&1 \
75     && setfacl --version < /dev/null > /dev/null 2>&1 \
76       || skip_ "This test requires getfacl and setfacl."
78   id -u bin > /dev/null 2>&1 \
79     || skip_ "This test requires a local user named bin."
82 is_local_dir_()
84   test $# = 1 || framework_failure_
85   df --local "$1" >/dev/null 2>&1
88 require_mount_list_()
90   local mount_list_fail='cannot read table of mounted file systems'
91   df --local 2>&1 | grep -F "$mount_list_fail" >/dev/null &&
92     skip_ "$mount_list_fail"
95 dump_mount_list_()
97   cat /proc/self/mountinfo ||
98   cat /proc/self/mounts ||
99   cat /proc/mounts ||
100   cat /etc/mtab
103 require_local_dir_()
105   require_mount_list_
106   is_local_dir_ . ||
107     skip_ "This test must be run on a local file system."
110 require_selinux_()
112   # When in a chroot of an SELinux-enabled system, but with a mock-simulated
113   # SELinux-*disabled* system, recognize that SELinux is disabled system wide:
114   grep 'selinuxfs$' /proc/filesystems > /dev/null \
115     || skip_ "this system lacks SELinux support"
117   # Independent of whether SELinux is enabled system-wide,
118   # the current file system may lack SELinux support.
119   # Also the current build may have SELinux support disabled.
120   case $(ls -Zd .) in
121     '? .'|'unlabeled .')
122       test -z "$CONFIG_HEADER" \
123         && framework_failure_ 'CONFIG_HEADER not defined'
124       grep '^#define HAVE_SELINUX_SELINUX_H 1' "$CONFIG_HEADER" > /dev/null \
125         && selinux_missing_="(file) system" || selinux_missing_="build"
126       skip_ "this $selinux_missing_ lacks SELinux support"
127     ;;
128   esac
131 # Skip this test if we're not in SELinux "enforcing" mode.
132 require_selinux_enforcing_()
134   require_selinux_
135   test "$(getenforce)" = Enforcing \
136     || skip_ "This test is useful only with SELinux in Enforcing mode."
139 require_smack_()
141   grep 'smackfs$' /proc/filesystems > /dev/null \
142     || skip_ "this system lacks SMACK support"
144   test "$(ls -Zd .)" != '? .' \
145     || skip_ "this file system lacks SMACK support"
148 require_openat_support_()
150   # Skip this test if your system has neither the openat-style functions
151   # nor /proc/self/fd support with which to emulate them.
153   test -z "$CONFIG_HEADER" \
154     && framework_failure_ 'CONFIG_HEADER not defined'
156   _skip=yes
157   grep '^#define HAVE_OPENAT' "$CONFIG_HEADER" > /dev/null && _skip=no
158   test -d /proc/self/fd && _skip=no
159   if test $_skip = yes; then
160     skip_ 'this system lacks openat support'
161   fi
164 # Return true if command runs with the
165 # ulimit specified in the first argument
166 ulimit_supported_()
168   local v
169   v="$1"
170   shift
172   (
173     # Try to disable core dumps which may
174     # occur with memory constraints
175     trap '' SEGV; ulimit -c 0;
177     ulimit -v $v && "$@"
178   ) >/dev/null 2>&1
181 # Determine the minimum required VM limit to run the given command.
182 # Output that value to stdout ... to be used by the caller.
183 # Return 0 in case of success, and a non-Zero value otherwise.
184 get_min_ulimit_v_()
186   local v
187   local page_size
189   # Increase result by this amount to avoid alignment issues
190   page_size=$(getconf PAGESIZE || echo 4096)
191   page_size=$(($page_size / 1024))
193   for v in $( seq 5000 5000 50000 ); do
194     if ulimit_supported_ $v "$@"; then
195       local prev_v
196       prev_v=$v
197       for v in $( seq $(($prev_v-1000)) -1000 1000 ); do
198         ulimit_supported_ $v "$@" ||
199           {
200             ret_v=$((prev_v + $page_size))
201             echo $ret_v
202             return 0
203           }
204         prev_v=$v
205       done
206     fi
207   done
208   # The above did not find a working limit.  Echo a very small number - just
209   # in case the caller does not handle the non-Zero return value.
210   echo 1; return 1
213 require_readable_root_()
215   test -r / || skip_ "/ is not readable"
218 # Skip the current test if strace is not available or doesn't work
219 # with the named syscall.  Usage: require_strace_ unlink
220 require_strace_()
222   test $# = 1 || framework_failure_
224   strace -V < /dev/null > /dev/null 2>&1 ||
225     skip_ 'no strace program'
227   strace -qe "$1" echo > /dev/null 2>&1 ||
228     skip_ 'strace -qe "'"$1"'" does not work'
230   # On some linux/sparc64 systems, strace works fine on 32-bit executables,
231   # but prints only one line of output for every 64-bit executable.
232   strace -o log-help ls --help >/dev/null || framework_failure_
233   n_lines_help=$(wc -l < log-help)
234   rm -f log-help
235   if test $n_lines_help = 0 || test $n_lines_help = 1; then
236     skip_ 'strace produces no more than one line of output'
237   fi
240 # Skip the current test if valgrind doesn't work,
241 # which could happen if not installed,
242 # or hasn't support for the built architecture,
243 # or hasn't appropriate error suppressions installed etc.
244 require_valgrind_()
246   valgrind --error-exitcode=1 true 2>/dev/null ||
247     skip_ "requires a working valgrind"
250 # Skip the current test if setfacl doesn't work on the current file system,
251 # which could happen if not installed, or if ACLs are not supported by the
252 # kernel or the file system, or are turned off via mount options.
254 # Work around the following two issues:
256 # 1) setfacl maps ACLs into file permission bits if on "noacl" file systems.
258 # On file systems which do not support ACLs (e.g. ext4 mounted with -o noacl),
259 # setfacl operates on the regular file permission bits, and only fails if the
260 # given ACL spec does not fit into there.  Thus, to test if ACLs really work
261 # on the current file system, pass an ACL spec which can't be mapped that way.
262 # "Default" ACLs (-d) seem to fulfill this requirement.
264 # 2) setfacl only invokes the underlying system call if the ACL would change.
266 # If the given ACL spec would not change the ACLs on the file, then setfacl
267 # does not invoke the underlying system call - setxattr().  Therefore, to test
268 # if setting ACLs really works on the current file system, call setfacl twice
269 # with conflictive ACL specs.
270 require_setfacl_()
272   local d='acltestdir_'
273   mkdir $d || framework_failure_
274   local f=0
276   setfacl -d -m user::r-x $d \
277     && setfacl -d -m user::rwx $d \
278     || f=1
279   rm -rf $d || framework_failure_
280   test $f = 0 \
281     || skip_ "setfacl does not work on the current file system"
284 # Require a controlling input 'terminal'.
285 require_controlling_input_terminal_()
287   tty -s || have_input_tty=no
288   test -t 0 || have_input_tty=no
289   if test "$have_input_tty" = no; then
290     skip_ 'requires controlling input terminal
291 This test must have a controlling input "terminal", so it may not be
292 run via "batch", "at", or "ssh".  On some systems, it may not even be
293 run in the background.'
294   fi
297 require_built_()
299   skip_=no
300   for i in "$@"; do
301     case " $built_programs " in
302       *" $i "*) ;;
303       *) echo "$i: not built" 1>&2; skip_=yes ;;
304     esac
305   done
307   test $skip_ = yes && skip_ "required program(s) not built"
310 require_file_system_bytes_free_()
312   local req=$1
313   local expr=$(stat -f --printf "$req / %S <= %a" .)
314   $AWK "BEGIN{ exit !($expr) }" \
315     || skip_ "this test needs at least $req bytes of free space"
318 uid_is_privileged_()
320   # Make sure id -u succeeds.
321   my_uid=$(id -u) \
322     || { echo "$0: cannot run 'id -u'" 1>&2; return 1; }
324   # Make sure it gives valid output.
325   case $my_uid in
326     0) ;;
327     *[!0-9]*)
328       echo "$0: invalid output ('$my_uid') from 'id -u'" 1>&2
329       return 1 ;;
330     *) return 1 ;;
331   esac
334 get_process_status_()
336   sed -n '/^State:[      ]*\([[:alpha:]]\).*/s//\1/p' /proc/$1/status
339 # Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
340 # to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
341 # =,u=rw,g=rx,o=wx).  Ignore ACLs.
342 rwx_to_mode_()
344   case $# in
345     1) rwx=$1;;
346     *) echo "$0: wrong number of arguments" 1>&2
347       echo "Usage: $0 ls-style-mode-string" 1>&2
348       return;;
349   esac
351   case $rwx in
352     [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
353     [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-][+.]) ;;
354     *) echo "$0: invalid mode string: $rwx" 1>&2; return;;
355   esac
357   # Perform these conversions:
358   # S  s
359   # s  xs
360   # T  t
361   # t  xt
362   # The 'T' and 't' ones are only valid for 'other'.
363   s='s/S/@/;s/s/x@/;s/@/s/'
364   t='s/T/@/;s/t/x@/;s/@/t/'
366   u=$(echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s)
367   g=$(echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s)
368   o=$(echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t)
369   echo "=$u$g$o"
372 # Set the global variable stty_reversible_ to a space-separated list of the
373 # reversible settings from stty.c.  stty_reversible_ also starts and ends
374 # with a space.
375 stty_reversible_init_()
377   # Pad start with one space for the first option to match in query function.
378   stty_reversible_=' '$(perl -lne '/^ *{"(.*?)",.*\bREV\b/ and print $1' \
379     "$abs_top_srcdir"/src/stty.c | tr '\n' ' ')
380   # Ensure that there are at least 62, i.e., so we're alerted if
381   # reformatting the source empties the list.
382   test 62 -le $(echo "$stty_reversible_"|wc -w)  \
383     || framework_failure_ "too few reversible settings"
386 # Test whether $1 is one of stty's reversible options.
387 stty_reversible_query_()
389   case $stty_reversible_ in
390     '')
391       framework_failure_ "stty_reversible_init_() not called?";;
392     *" $1 "*)
393       return 0;;
394     *)
395       return 1;;
396   esac
399 skip_if_()
401   case $1 in
402     root) skip_ must be run as root ;;
403     non-root) skip_ must be run as non-root ;;
404     *) ;;  # FIXME?
405   esac
408 very_expensive_()
410   if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
411     skip_ 'very expensive: disabled by default
412 This test is very expensive, so it is disabled by default.
413 To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
414 environment variable set to yes.  E.g.,
416   env RUN_VERY_EXPENSIVE_TESTS=yes make check
418 or use the shortcut target of the toplevel Makefile,
420   make check-very-expensive
422   fi
425 expensive_()
427   if test "$RUN_EXPENSIVE_TESTS" != yes; then
428     skip_ 'expensive: disabled by default
429 This test is relatively expensive, so it is disabled by default.
430 To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
431 environment variable set to yes.  E.g.,
433   env RUN_EXPENSIVE_TESTS=yes make check
435 or use the shortcut target of the toplevel Makefile,
437   make check-expensive
439   fi
442 # Test whether we can run our just-built root owned rm,
443 # i.e., that $NON_ROOT_USERNAME has access to the build directory.
444 nonroot_has_perm_()
446   require_built_ chroot
448   local rm_version=$(
449     chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
450       rm --version |
451     sed -n '1s/.* //p'
452   )
453   case ":$rm_version:" in
454       :$PACKAGE_VERSION:) ;;
455       *) return 1;;
456   esac
459 require_root_()
461   uid_is_privileged_ || skip_ "must be run as root"
462   NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
463   NON_ROOT_GID=${NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)}
465   # When the current test invokes chroot, call nonroot_has_perm_
466   # to check for a common problem.
467   grep '^[ ]*chroot' "../$0" \
468     && { nonroot_has_perm_ \
469            || skip_ "user $NON_ROOT_USERNAME lacks execute permissions"; }
472 skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }
474 # Set 'groups' to a space-separated list of at least two groups
475 # of which the user is a member.
476 require_membership_in_two_groups_()
478   test $# = 0 || framework_failure_
480   groups=${COREUTILS_GROUPS-$( (id -G || /usr/xpg4/bin/id -G) 2>/dev/null)}
481   case "$groups" in
482     *' '*) ;;
483     *) skip_ 'requires membership in two groups
484 this test requires that you be a member of more than one group,
485 but running 'id -G'\'' either failed or found just one.  If you really
486 are a member of at least two groups, then rerun this test with
487 COREUTILS_GROUPS set in your environment to the space-separated list
488 of group names or numbers.  E.g.,
490   env COREUTILS_GROUPS='\''users cdrom'\'' make check
493      ;;
494   esac
497 # Is /proc/$PID/status supported?
498 require_proc_pid_status_()
500     sleep 2 &
501     local pid=$!
502     sleep .5
503     grep '^State:[       ]*[S]' /proc/$pid/status > /dev/null 2>&1 ||
504     skip_ "/proc/$pid/status: missing or 'different'"
505     kill $pid
508 # Does trap support signal names?
509 # Old versions of ash did not.
510 require_trap_signame_()
512     (trap '' CHLD) || skip_ 'requires trap with signal name support'
515 # Does kill support sending signal to whole group?
516 # dash 0.5.8 at least does not.
517 require_kill_group_()
519     kill -0 -- -1 || skip_ 'requires kill with group signalling support'
522 # Return nonzero if the specified path is on a file system for
523 # which FIEMAP support exists.  Note some file systems (like ext3 and btrfs)
524 # only support FIEMAP for files, not directories.
525 fiemap_capable_()
527   if ! python < /dev/null; then
528     warn_ 'fiemap_capable_: python missing: assuming not fiemap capable'
529     return 1
530   fi
531   python "$abs_srcdir"/tests/fiemap-capable "$@"
534 # Skip the current test if "." lacks d_type support.
535 require_dirent_d_type_()
537   python < /dev/null \
538     || skip_ python missing: assuming no d_type support
540   python "$abs_srcdir"/tests/d_type-check \
541     || skip_ requires d_type support
544 # Skip the current test if we lack Perl.
545 require_perl_()
547   : ${PERL=perl}
548   $PERL -e 'use warnings' > /dev/null 2>&1 \
549     || skip_ 'configure did not find a usable version of Perl'
552 # Does the current (working-dir) file system support sparse files?
553 require_sparse_support_()
555   test $# = 0 || framework_failure_
556   # Test whether we can create a sparse file.
557   # For example, on Darwin6.5 with a file system of type hfs, it's not possible.
558   # NTFS requires 128K before a hole appears in a sparse file.
559   t=sparse.$$
560   dd bs=1 seek=128K of=$t < /dev/null 2> /dev/null
561   set x $(du -sk $t)
562   kb_size=$2
563   rm -f $t
564   if test $kb_size -ge 128; then
565     skip_ 'this file system does not support sparse files'
566   fi
569 # Compile a shared lib using the GCC options for doing so.
570 # Pass input and output file as parameters respectively.
571 # Any other optional parmeters are passed to $CC.
572 gcc_shared_()
574   local in=$1
575   local out=$2
576   shift 2 || return 1
578   $CC -Wall -shared --std=gnu99 -fPIC -O2 $* "$in" -o "$out" -ldl
581 # There are a myriad of ways to build shared libs,
582 # so we only consider running tests requiring shared libs,
583 # on platforms that support building them as follows.
584 require_gcc_shared_()
586   gcc_shared_ '-' 'd.so' -xc < /dev/null 2>&1 \
587     || skip_ '$CC -shared ... failed to build a shared lib'
588   rm -f d.so
591 mkfifo_or_skip_()
593   test $# = 1 || framework_failure_
594   if ! mkfifo "$1"; then
595     # Make an exception of this case -- usually we interpret framework-creation
596     # failure as a test failure.  However, in this case, when running on a SunOS
597     # system using a disk NFS mounted from OpenBSD, the above fails like this:
598     # mkfifo: cannot make fifo 'fifo-10558': Not owner
599     skip_ 'unable to create a fifo'
600   fi
603 # Disable the current test if the working directory seems to have
604 # the setgid bit set.
605 skip_if_setgid_()
607   setgid_tmpdir=setgid-$$
608   (umask 77; mkdir $setgid_tmpdir)
609   perms=$(stat --printf %A $setgid_tmpdir)
610   rmdir $setgid_tmpdir
611   case $perms in
612     drwx------);;
613     drwxr-xr-x);;  # Windows98 + DJGPP 2.03
614     *) skip_ 'this directory has the setgid bit set';;
615   esac
618 # Skip if files are created with a different group to the current user
619 # This can happen due to a setgid dir, or by some other mechanism on OS X:
620 # http://unix.stackexchange.com/q/63865
621 # http://bugs.gnu.org/14024#41
622 skip_if_nondefault_group_()
624   touch grp.$$
625   gen_ug=$(stat -c '%u:%g' grp.$$)
626   rm grp.$$
627   test "$gen_ug" = "$(id -ru):$(id -rg)" ||
628     skip_ 'Files are created with a different gid'
631 skip_if_mcstransd_is_running_()
633   test $# = 0 || framework_failure_
635   # When mcstransd is running, you'll see only the 3-component
636   # version of file-system context strings.  Detect that,
637   # and if it's running, skip this test.
638   __ctx=$(stat --printf='%C\n' .) || framework_failure_
639   case $__ctx in
640     *:*:*:*) ;; # four components is ok
641     *) # anything else probably means mcstransd is running
642         skip_ "unexpected context '$__ctx'; turn off mcstransd" ;;
643   esac
646 # Skip the current test if umask doesn't work as usual.
647 # This test should be run in the temporary directory that ends
648 # up being removed via the trap commands.
649 working_umask_or_skip_()
651   umask 022
652   touch file1 file2
653   chmod 644 file2
654   perms=$(ls -l file1 file2 | sed 's/ .*//' | uniq)
655   rm -f file1 file2
657   case $perms in
658   *'
659   '*) skip_ 'your build directory has unusual umask semantics'
660   esac
663 # Retry a function requiring a sufficient delay to _pass_
664 # using a truncated exponential backoff method.
665 #     Example: retry_delay_ dd_reblock_1 .1 6
666 # This example will call the dd_reblock_1 function with
667 # an initial delay of .1 second and call it at most 6 times
668 # with a max delay of 3.2s (doubled each time), or a total of 6.3s
669 # Note ensure you do _not_ quote the parameter to GNU sleep in
670 # your function, as it may contain separate values that sleep
671 # needs to accumulate.
672 # Further function arguments will be forwarded to the test function.
673 retry_delay_()
675   local test_func=$1
676   local init_delay=$2
677   local max_n_tries=$3
678   shift 3 || return 1
680   local attempt=1
681   local num_sleeps=$attempt
682   local time_fail
683   while test $attempt -le $max_n_tries; do
684     local delay=$($AWK -v n=$num_sleeps -v s="$init_delay" \
685                   'BEGIN { print s * n }')
686     "$test_func" "$delay" "$@" && { time_fail=0; break; } || time_fail=1
687     attempt=$(expr $attempt + 1)
688     num_sleeps=$(expr $num_sleeps '*' 2)
689   done
690   test "$time_fail" = 0
693 # Call this with a list of programs under test immediately after
694 # sourcing init.sh.
695 print_ver_()
697   require_built_ "$@"
698   if test "$VERBOSE" = yes; then
699     local i
700     for i in $*; do
701       env $i --version
702     done
703   fi
706 # Are we running on GNU/Hurd?
707 require_gnu_()
709   test "$(uname)" = GNU \
710     || skip_ 'not running on GNU/Hurd'
713 sanitize_path_