init.cfg 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. # This file is sourced by init.sh, *before* its initialization.
  2. # Copyright (C) 2010-2021 Free Software Foundation, Inc.
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. # This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
  14. # TESTS_ENVIRONMENT definition.
  15. stderr_fileno_=9
  16. # Having an unsearchable directory in PATH causes execve to fail with EACCES
  17. # when applied to an unresolvable program name, contrary to the desired ENOENT.
  18. # Avoid the problem by rewriting PATH to exclude unsearchable directories.
  19. # Also, if PATH lacks /sbin and/or /usr/sbin, append it/them.
  20. sanitize_path_()
  21. {
  22. # FIXME: remove double quotes around $IFS when all tests use init.sh.
  23. # They constitute a work-around for a bug in FreeBSD 8.1's /bin/sh.
  24. local saved_IFS="$IFS"
  25. IFS=:
  26. set -- $PATH
  27. IFS=$saved_IFS
  28. local d d1
  29. local colon=
  30. local new_path=
  31. for d in "$@"; do
  32. test -z "$d" && d1=. || d1=$d
  33. if ls -d "$d1/." > /dev/null 2>&1; then
  34. new_path="$new_path$colon$d"
  35. colon=':'
  36. fi
  37. done
  38. for d in /sbin /usr/sbin ; do
  39. case ":$new_path:" in
  40. *:$d:*) ;;
  41. *) new_path="$new_path:$d" ;;
  42. esac
  43. done
  44. PATH=$new_path
  45. export PATH
  46. }
  47. getlimits_()
  48. {
  49. eval $(getlimits)
  50. test "$INT_MAX" || fatal_ "running getlimits"
  51. }
  52. require_no_default_acl_()
  53. {
  54. if getfacl --version < /dev/null > /dev/null 2>&1; then
  55. getfacl "$1" | grep '^default:' && skip_ 'Default ACL detected'
  56. else
  57. ls -ld "$1" | grep '.........+' && skip_ 'ACL detected'
  58. fi
  59. }
  60. require_acl_()
  61. {
  62. getfacl --version < /dev/null > /dev/null 2>&1 \
  63. && setfacl --version < /dev/null > /dev/null 2>&1 \
  64. || skip_ "This test requires getfacl and setfacl."
  65. id -u bin > /dev/null 2>&1 \
  66. || skip_ "This test requires a local user named bin."
  67. }
  68. is_local_dir_()
  69. {
  70. test $# = 1 || framework_failure_
  71. df --local "$1" >/dev/null 2>&1
  72. }
  73. require_mount_list_()
  74. {
  75. local mount_list_fail='cannot read table of mounted file systems'
  76. df --local 2>&1 | grep -F "$mount_list_fail" >/dev/null &&
  77. skip_ "$mount_list_fail"
  78. }
  79. dump_mount_list_()
  80. {
  81. cat /proc/self/mountinfo ||
  82. cat /proc/self/mounts ||
  83. cat /proc/mounts ||
  84. cat /etc/mtab
  85. }
  86. require_local_dir_()
  87. {
  88. require_mount_list_
  89. is_local_dir_ . ||
  90. skip_ "This test must be run on a local file system."
  91. }
  92. require_selinux_()
  93. {
  94. # When in a chroot of an SELinux-enabled system, but with a mock-simulated
  95. # SELinux-*disabled* system, recognize that SELinux is disabled system wide:
  96. grep 'selinuxfs$' /proc/filesystems > /dev/null \
  97. || skip_ "this system lacks SELinux support"
  98. # Independent of whether SELinux is enabled system-wide,
  99. # the current file system may lack SELinux support.
  100. # Also the current build may have SELinux support disabled.
  101. case $(ls -Zd .) in
  102. '? .'|'unlabeled .')
  103. test -z "$CONFIG_HEADER" \
  104. && framework_failure_ 'CONFIG_HEADER not defined'
  105. grep '^#define HAVE_SELINUX_SELINUX_H 1' "$CONFIG_HEADER" > /dev/null \
  106. && selinux_missing_="(file) system" || selinux_missing_="build"
  107. skip_ "this $selinux_missing_ lacks SELinux support"
  108. ;;
  109. esac
  110. }
  111. # Return the SELinux type component if available
  112. get_selinux_type() { ls -Zd "$1" | sed -n 's/.*:\(.*_t\)[: ].*/\1/p'; }
  113. # Whether SELinux Multi Level Security is enabled
  114. mls_enabled_() {
  115. sestatus 2>&1 |
  116. grep 'Policy MLS status:.*enabled' > /dev/null
  117. }
  118. # Skip this test if we're not in SELinux "enforcing" mode.
  119. require_selinux_enforcing_()
  120. {
  121. require_selinux_
  122. test "$(getenforce)" = Enforcing \
  123. || skip_ "This test is useful only with SELinux in Enforcing mode."
  124. }
  125. require_smack_()
  126. {
  127. grep 'smackfs$' /proc/filesystems > /dev/null \
  128. || skip_ "this system lacks SMACK support"
  129. test "$(ls -Zd .)" != '? .' \
  130. || skip_ "this file system lacks SMACK support"
  131. }
  132. require_openat_support_()
  133. {
  134. # Skip this test if your system has neither the openat-style functions
  135. # nor /proc/self/fd support with which to emulate them.
  136. test -z "$CONFIG_HEADER" \
  137. && framework_failure_ 'CONFIG_HEADER not defined'
  138. _skip=yes
  139. grep '^#define HAVE_OPENAT' "$CONFIG_HEADER" > /dev/null && _skip=no
  140. test -d /proc/self/fd && _skip=no
  141. if test $_skip = yes; then
  142. skip_ 'this system lacks openat support'
  143. fi
  144. }
  145. # Return true if command runs with the
  146. # ulimit specified in the first argument
  147. ulimit_supported_()
  148. {
  149. local v
  150. v="$1"
  151. shift
  152. (
  153. # Try to disable core dumps which may
  154. # occur with memory constraints
  155. trap '' SEGV; ulimit -c 0;
  156. ulimit -v $v && "$@"
  157. ) >/dev/null 2>&1
  158. }
  159. # Determine the minimum required VM limit to run the given command.
  160. # Output that value to stdout ... to be used by the caller.
  161. # Return 0 in case of success, and a non-Zero value otherwise.
  162. get_min_ulimit_v_()
  163. {
  164. local v
  165. local page_size
  166. # Increase result by this amount to avoid alignment issues
  167. page_size=$(getconf PAGESIZE || echo 4096)
  168. page_size=$(($page_size / 1024))
  169. for v in $( seq 5000 5000 50000 ); do
  170. if ulimit_supported_ $v "$@"; then
  171. local prev_v
  172. prev_v=$v
  173. for v in $( seq $(($prev_v-1000)) -1000 1000 ); do
  174. ulimit_supported_ $v "$@" ||
  175. {
  176. ret_v=$((prev_v + $page_size))
  177. echo $ret_v
  178. return 0
  179. }
  180. prev_v=$v
  181. done
  182. fi
  183. done
  184. # The above did not find a working limit. Echo a very small number - just
  185. # in case the caller does not handle the non-Zero return value.
  186. echo 1; return 1
  187. }
  188. require_readable_root_()
  189. {
  190. test -r / || skip_ "/ is not readable"
  191. }
  192. # Skip the current test if strace is not available or doesn't work
  193. # with the named syscall. Usage: require_strace_ unlink
  194. require_strace_()
  195. {
  196. test $# = 1 || framework_failure_
  197. strace -V < /dev/null > /dev/null 2>&1 ||
  198. skip_ 'no strace program'
  199. strace -qe "$1" echo > /dev/null 2>&1 ||
  200. skip_ 'strace -qe "'"$1"'" does not work'
  201. # On some linux/sparc64 systems, strace works fine on 32-bit executables,
  202. # but prints only one line of output for every 64-bit executable.
  203. strace -o log-help ls --help >/dev/null || framework_failure_
  204. n_lines_help=$(wc -l < log-help)
  205. rm -f log-help
  206. if test $n_lines_help = 0 || test $n_lines_help = 1; then
  207. skip_ 'strace produces no more than one line of output'
  208. fi
  209. }
  210. # Skip the current test if valgrind doesn't work,
  211. # which could happen if not installed,
  212. # or hasn't support for the built architecture,
  213. # or hasn't appropriate error suppressions installed etc.
  214. require_valgrind_()
  215. {
  216. valgrind --error-exitcode=1 true 2>/dev/null ||
  217. skip_ "requires a working valgrind"
  218. }
  219. # Skip the current test if setfacl doesn't work on the current file system,
  220. # which could happen if not installed, or if ACLs are not supported by the
  221. # kernel or the file system, or are turned off via mount options.
  222. #
  223. # Work around the following two issues:
  224. #
  225. # 1) setfacl maps ACLs into file permission bits if on "noacl" file systems.
  226. #
  227. # On file systems which do not support ACLs (e.g. ext4 mounted with -o noacl),
  228. # setfacl operates on the regular file permission bits, and only fails if the
  229. # given ACL spec does not fit into there. Thus, to test if ACLs really work
  230. # on the current file system, pass an ACL spec which can't be mapped that way.
  231. # "Default" ACLs (-d) seem to fulfill this requirement.
  232. #
  233. # 2) setfacl only invokes the underlying system call if the ACL would change.
  234. #
  235. # If the given ACL spec would not change the ACLs on the file, then setfacl
  236. # does not invoke the underlying system call - setxattr(). Therefore, to test
  237. # if setting ACLs really works on the current file system, call setfacl twice
  238. # with conflictive ACL specs.
  239. require_setfacl_()
  240. {
  241. local d='acltestdir_'
  242. mkdir $d || framework_failure_
  243. local f=0
  244. setfacl -d -m user::r-x $d \
  245. && setfacl -d -m user::rwx $d \
  246. || f=1
  247. rm -rf $d || framework_failure_
  248. test $f = 0 \
  249. || skip_ "setfacl does not work on the current file system"
  250. }
  251. # Require a controlling input 'terminal'.
  252. require_controlling_input_terminal_()
  253. {
  254. have_input_tty=yes
  255. tty -s || have_input_tty=no
  256. test -t 0 || have_input_tty=no
  257. if test "$have_input_tty" = no; then
  258. skip_ 'requires controlling input terminal
  259. This test must have a controlling input "terminal", so it may not be
  260. run via "batch", "at", or "ssh". On some systems, it may not even be
  261. run in the background.'
  262. fi
  263. }
  264. require_built_()
  265. {
  266. skip_=no
  267. for i in "$@"; do
  268. case " $built_programs " in
  269. *" $i "*) ;;
  270. *) echo "$i: not built" 1>&2; skip_=yes ;;
  271. esac
  272. done
  273. test $skip_ = yes && skip_ "required program(s) not built"
  274. }
  275. require_file_system_bytes_free_()
  276. {
  277. local req=$1
  278. local expr=$(stat -f --printf "$req / %S <= %a" .)
  279. $AWK "BEGIN{ exit !($expr) }" \
  280. || skip_ "this test needs at least $req bytes of free space"
  281. }
  282. uid_is_privileged_()
  283. {
  284. # Make sure id -u succeeds.
  285. my_uid=$(id -u) \
  286. || { echo "$0: cannot run 'id -u'" 1>&2; return 1; }
  287. # Make sure it gives valid output.
  288. case $my_uid in
  289. 0) ;;
  290. *[!0-9]*)
  291. echo "$0: invalid output ('$my_uid') from 'id -u'" 1>&2
  292. return 1 ;;
  293. *) return 1 ;;
  294. esac
  295. }
  296. get_process_status_()
  297. {
  298. sed -n '/^State:[ ]*\([[:alpha:]]\).*/s//\1/p' /proc/$1/status
  299. }
  300. # Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
  301. # to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
  302. # =,u=rw,g=rx,o=wx). Ignore ACLs.
  303. rwx_to_mode_()
  304. {
  305. case $# in
  306. 1) rwx=$1;;
  307. *) echo "$0: wrong number of arguments" 1>&2
  308. echo "Usage: $0 ls-style-mode-string" 1>&2
  309. return;;
  310. esac
  311. case $rwx in
  312. [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
  313. [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-][+.]) ;;
  314. *) echo "$0: invalid mode string: $rwx" 1>&2; return;;
  315. esac
  316. # Perform these conversions:
  317. # S s
  318. # s xs
  319. # T t
  320. # t xt
  321. # The 'T' and 't' ones are only valid for 'other'.
  322. s='s/S/@/;s/s/x@/;s/@/s/'
  323. t='s/T/@/;s/t/x@/;s/@/t/'
  324. u=$(echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s)
  325. g=$(echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s)
  326. o=$(echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t)
  327. echo "=$u$g$o"
  328. }
  329. skip_if_()
  330. {
  331. case $1 in
  332. root) skip_ must be run as root ;;
  333. non-root) skip_ must be run as non-root ;;
  334. *) ;; # FIXME?
  335. esac
  336. }
  337. very_expensive_()
  338. {
  339. if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
  340. skip_ 'very expensive: disabled by default
  341. This test is very expensive, so it is disabled by default.
  342. To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
  343. environment variable set to yes. E.g.,
  344. env RUN_VERY_EXPENSIVE_TESTS=yes make check
  345. or use the shortcut target of the toplevel Makefile,
  346. make check-very-expensive
  347. '
  348. fi
  349. }
  350. expensive_()
  351. {
  352. if test "$RUN_EXPENSIVE_TESTS" != yes; then
  353. skip_ 'expensive: disabled by default
  354. This test is relatively expensive, so it is disabled by default.
  355. To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
  356. environment variable set to yes. E.g.,
  357. env RUN_EXPENSIVE_TESTS=yes make check
  358. or use the shortcut target of the toplevel Makefile,
  359. make check-expensive
  360. '
  361. fi
  362. }
  363. # Test whether we can run our just-built root owned find,
  364. # i.e., that $NON_ROOT_USERNAME has access to the build directory.
  365. nonroot_has_perm_()
  366. {
  367. require_built_ chroot
  368. local find_version=$(
  369. chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
  370. find --version |
  371. sed -n '1s/.* //p'
  372. )
  373. case ":$find_version:" in
  374. :$PACKAGE_VERSION:) ;;
  375. *) return 1;;
  376. esac
  377. }
  378. require_root_()
  379. {
  380. uid_is_privileged_ || skip_ "must be run as root"
  381. NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
  382. NON_ROOT_GID=${NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)}
  383. # When the current test invokes chroot, call nonroot_has_perm_
  384. # to check for a common problem.
  385. grep '^[ ]*chroot' "../$0" \
  386. && { nonroot_has_perm_ \
  387. || skip_ "user $NON_ROOT_USERNAME lacks execute permissions"; }
  388. }
  389. skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }
  390. # Set 'groups' to a space-separated list of at least two groups
  391. # of which the user is a member.
  392. require_membership_in_two_groups_()
  393. {
  394. test $# = 0 || framework_failure_
  395. groups=${FINDUTILS_GROUPS-$( (id -G || /usr/xpg4/bin/id -G) 2>/dev/null)}
  396. case "$groups" in
  397. *' '*) ;;
  398. *) skip_ 'requires membership in two groups
  399. this test requires that you be a member of more than one group,
  400. but running '\''id -G'\'' either failed or found just one. If you really
  401. are a member of at least two groups, then rerun this test with
  402. FINDUTILS_GROUPS set in your environment to the space-separated list
  403. of group names or numbers. E.g.,
  404. env FINDUTILS_GROUPS='\''users cdrom'\'' make check
  405. '
  406. ;;
  407. esac
  408. }
  409. # Is /proc/$PID/status supported?
  410. require_proc_pid_status_()
  411. {
  412. sleep 2 &
  413. local pid=$!
  414. sleep .5
  415. grep '^State:[ ]*[S]' /proc/$pid/status > /dev/null 2>&1 ||
  416. skip_ "/proc/$pid/status: missing or 'different'"
  417. kill $pid
  418. }
  419. # Does trap support signal names?
  420. # Old versions of ash did not.
  421. require_trap_signame_()
  422. {
  423. (trap '' CHLD) || skip_ 'requires trap with signal name support'
  424. }
  425. # Does kill support sending signal to whole group?
  426. # dash 0.5.8 at least does not.
  427. require_kill_group_()
  428. {
  429. kill -0 -- -1 || skip_ 'requires kill with group signalling support'
  430. }
  431. # Return nonzero if the specified path is on a file system for
  432. # which FIEMAP support exists. Note some file systems (like ext3 and btrfs)
  433. # only support FIEMAP for files, not directories.
  434. fiemap_capable_()
  435. {
  436. if ! python < /dev/null; then
  437. warn_ 'fiemap_capable_: python missing: assuming not fiemap capable'
  438. return 1
  439. fi
  440. python "$abs_srcdir"/tests/fiemap-capable "$@"
  441. }
  442. # Skip the current test if "." lacks d_type support.
  443. require_dirent_d_type_()
  444. {
  445. python < /dev/null \
  446. || skip_ python missing: assuming no d_type support
  447. python "$abs_srcdir"/tests/d_type-check \
  448. || skip_ requires d_type support
  449. }
  450. # Skip the current test if we lack Perl.
  451. require_perl_()
  452. {
  453. : ${PERL=perl}
  454. $PERL -e 'use warnings' > /dev/null 2>&1 \
  455. || skip_ 'configure did not find a usable version of Perl'
  456. }
  457. # Does the current (working-dir) file system support sparse files?
  458. require_sparse_support_()
  459. {
  460. test $# = 0 || framework_failure_
  461. # Test whether we can create a sparse file.
  462. # For example, on Darwin6.5 with a file system of type hfs, it's not possible.
  463. # NTFS requires 128K before a hole appears in a sparse file.
  464. t=sparse.$$
  465. dd bs=1 seek=128K of=$t < /dev/null 2> /dev/null
  466. set x $(du -sk $t)
  467. kb_size=$2
  468. rm -f $t
  469. if test $kb_size -ge 128; then
  470. skip_ 'this file system does not support sparse files'
  471. fi
  472. }
  473. # Compile a shared lib using the GCC options for doing so.
  474. # Pass input and output file as parameters respectively.
  475. # Any other optional parmeters are passed to $CC.
  476. gcc_shared_()
  477. {
  478. local in=$1
  479. local out=$2
  480. shift 2 || return 1
  481. $CC -Wall -shared --std=gnu99 -fPIC -O2 $* "$in" -o "$out" -ldl
  482. }
  483. # There are a myriad of ways to build shared libs,
  484. # so we only consider running tests requiring shared libs,
  485. # on platforms that support building them as follows.
  486. require_gcc_shared_()
  487. {
  488. gcc_shared_ '-' 'd.so' -xc < /dev/null 2>&1 \
  489. || skip_ '$CC -shared ... failed to build a shared lib'
  490. rm -f d.so
  491. }
  492. mkfifo_or_skip_()
  493. {
  494. test $# = 1 || framework_failure_
  495. if ! mkfifo "$1"; then
  496. # Make an exception of this case -- usually we interpret framework-creation
  497. # failure as a test failure. However, in this case, when running on a SunOS
  498. # system using a disk NFS mounted from OpenBSD, the above fails like this:
  499. # mkfifo: cannot make fifo 'fifo-10558': Not owner
  500. skip_ 'unable to create a fifo'
  501. fi
  502. }
  503. # Disable the current test if the working directory seems to have
  504. # the setgid bit set.
  505. skip_if_setgid_()
  506. {
  507. setgid_tmpdir=setgid-$$
  508. (umask 77; mkdir $setgid_tmpdir)
  509. perms=$(stat --printf %A $setgid_tmpdir)
  510. rmdir $setgid_tmpdir
  511. case $perms in
  512. drwx------);;
  513. drwxr-xr-x);; # Windows98 + DJGPP 2.03
  514. *) skip_ 'this directory has the setgid bit set';;
  515. esac
  516. }
  517. # Skip if files are created with a different group to the current user
  518. # This can happen due to a setgid dir, or by some other mechanism on OS X:
  519. # https://unix.stackexchange.com/q/63865
  520. # https://bugs.gnu.org/14024#41
  521. skip_if_nondefault_group_()
  522. {
  523. touch grp.$$
  524. gen_ug=$(stat -c '%u:%g' grp.$$)
  525. rm grp.$$
  526. test "$gen_ug" = "$(id -ru):$(id -rg)" ||
  527. skip_ 'Files are created with a different gid'
  528. }
  529. skip_if_mcstransd_is_running_()
  530. {
  531. test $# = 0 || framework_failure_
  532. # When mcstransd is running, you'll see only the 3-component
  533. # version of file-system context strings. Detect that,
  534. # and if it's running, skip this test.
  535. __ctx=$(stat --printf='%C\n' .) || framework_failure_
  536. case $__ctx in
  537. *:*:*:*) __ctx_ok=1 ;; # four components is ok
  538. *:*:*) # three components is ok too if there is no MLS
  539. mls_enabled_ || __ctx_ok=1 ;;
  540. esac
  541. test "$__ctx_ok" ||
  542. skip_ "unexpected context '$__ctx'; turn off mcstransd"
  543. }
  544. # Skip the current test if umask doesn't work as usual.
  545. # This test should be run in the temporary directory that ends
  546. # up being removed via the trap commands.
  547. working_umask_or_skip_()
  548. {
  549. umask 022
  550. touch file1 file2
  551. chmod 644 file2
  552. perms=$(ls -l file1 file2 | sed 's/ .*//' | uniq)
  553. rm -f file1 file2
  554. case $perms in
  555. *'
  556. '*) skip_ 'your build directory has unusual umask semantics'
  557. esac
  558. }
  559. # Retry a function requiring a sufficient delay to _pass_
  560. # using a truncated exponential backoff method.
  561. # Example: retry_delay_ dd_reblock_1 .1 6
  562. # This example will call the dd_reblock_1 function with
  563. # an initial delay of .1 second and call it at most 6 times
  564. # with a max delay of 3.2s (doubled each time), or a total of 6.3s
  565. # Note ensure you do _not_ quote the parameter to GNU sleep in
  566. # your function, as it may contain separate values that sleep
  567. # needs to accumulate.
  568. # Further function arguments will be forwarded to the test function.
  569. retry_delay_()
  570. {
  571. local test_func=$1
  572. local init_delay=$2
  573. local max_n_tries=$3
  574. shift 3 || return 1
  575. local attempt=1
  576. local num_sleeps=$attempt
  577. local time_fail
  578. while test $attempt -le $max_n_tries; do
  579. local delay=$($AWK -v n=$num_sleeps -v s="$init_delay" \
  580. 'BEGIN { print s * n }')
  581. "$test_func" "$delay" "$@" && { time_fail=0; break; } || time_fail=1
  582. attempt=$(expr $attempt + 1)
  583. num_sleeps=$(expr $num_sleeps '*' 2)
  584. done
  585. test "$time_fail" = 0
  586. }
  587. # Call this with a list of programs under test immediately after
  588. # sourcing init.sh.
  589. print_ver_()
  590. {
  591. require_built_ "$@"
  592. if test "$VERBOSE" = yes; then
  593. local i
  594. for i in $*; do
  595. env $i --version
  596. done
  597. fi
  598. }
  599. # Are we running on GNU/Hurd?
  600. require_gnu_()
  601. {
  602. test "$(uname)" = GNU \
  603. || skip_ 'not running on GNU/Hurd'
  604. }
  605. # Prepend all our source directories to PATH.
  606. fu_path_prepend_()
  607. {
  608. path_prepend_ "${srcdir=.}/find" "${srcdir=.}/locate" "${srcdir=.}/xargs"
  609. }
  610. sanitize_path_