init.cfg 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. # This file is sourced by init.sh, *before* its initialization.
  2. # Copyright (C) 2010-2018 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. # Set the global variable stty_reversible_ to a space-separated list of the
  330. # reversible settings from stty.c. stty_reversible_ also starts and ends
  331. # with a space.
  332. stty_reversible_init_()
  333. {
  334. # Pad start with one space for the first option to match in query function.
  335. stty_reversible_=' '$(perl -lne '/^ *{"(.*?)",.*\bREV\b/ and print $1' \
  336. "$abs_top_srcdir"/src/stty.c | tr '\n' ' ')
  337. # Ensure that there are at least 62, i.e., so we're alerted if
  338. # reformatting the source empties the list.
  339. test 62 -le $(echo "$stty_reversible_"|wc -w) \
  340. || framework_failure_ "too few reversible settings"
  341. }
  342. # Test whether $1 is one of stty's reversible options.
  343. stty_reversible_query_()
  344. {
  345. case $stty_reversible_ in
  346. '')
  347. framework_failure_ "stty_reversible_init_() not called?";;
  348. *" $1 "*)
  349. return 0;;
  350. *)
  351. return 1;;
  352. esac
  353. }
  354. skip_if_()
  355. {
  356. case $1 in
  357. root) skip_ must be run as root ;;
  358. non-root) skip_ must be run as non-root ;;
  359. *) ;; # FIXME?
  360. esac
  361. }
  362. very_expensive_()
  363. {
  364. if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
  365. skip_ 'very expensive: disabled by default
  366. This test is very expensive, so it is disabled by default.
  367. To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
  368. environment variable set to yes. E.g.,
  369. env RUN_VERY_EXPENSIVE_TESTS=yes make check
  370. or use the shortcut target of the toplevel Makefile,
  371. make check-very-expensive
  372. '
  373. fi
  374. }
  375. expensive_()
  376. {
  377. if test "$RUN_EXPENSIVE_TESTS" != yes; then
  378. skip_ 'expensive: disabled by default
  379. This test is relatively expensive, so it is disabled by default.
  380. To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
  381. environment variable set to yes. E.g.,
  382. env RUN_EXPENSIVE_TESTS=yes make check
  383. or use the shortcut target of the toplevel Makefile,
  384. make check-expensive
  385. '
  386. fi
  387. }
  388. # Test whether we can run our just-built root owned rm,
  389. # i.e., that $NON_ROOT_USERNAME has access to the build directory.
  390. nonroot_has_perm_()
  391. {
  392. require_built_ chroot
  393. local rm_version=$(
  394. chroot --skip-chdir --user=$NON_ROOT_USERNAME / env PATH="$PATH" \
  395. rm --version |
  396. sed -n '1s/.* //p'
  397. )
  398. case ":$rm_version:" in
  399. :$PACKAGE_VERSION:) ;;
  400. *) return 1;;
  401. esac
  402. }
  403. require_root_()
  404. {
  405. uid_is_privileged_ || skip_ "must be run as root"
  406. NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
  407. NON_ROOT_GID=${NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)}
  408. # When the current test invokes chroot, call nonroot_has_perm_
  409. # to check for a common problem.
  410. grep '^[ ]*chroot' "../$0" \
  411. && { nonroot_has_perm_ \
  412. || skip_ "user $NON_ROOT_USERNAME lacks execute permissions"; }
  413. }
  414. skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }
  415. # Set 'groups' to a space-separated list of at least two groups
  416. # of which the user is a member.
  417. require_membership_in_two_groups_()
  418. {
  419. test $# = 0 || framework_failure_
  420. groups=${COREUTILS_GROUPS-$( (id -G || /usr/xpg4/bin/id -G) 2>/dev/null)}
  421. case "$groups" in
  422. *' '*) ;;
  423. *) skip_ 'requires membership in two groups
  424. this test requires that you be a member of more than one group,
  425. but running '\''id -G'\'' either failed or found just one. If you really
  426. are a member of at least two groups, then rerun this test with
  427. COREUTILS_GROUPS set in your environment to the space-separated list
  428. of group names or numbers. E.g.,
  429. env COREUTILS_GROUPS='\''users cdrom'\'' make check
  430. '
  431. ;;
  432. esac
  433. }
  434. # Is /proc/$PID/status supported?
  435. require_proc_pid_status_()
  436. {
  437. sleep 2 &
  438. local pid=$!
  439. sleep .5
  440. grep '^State:[ ]*[S]' /proc/$pid/status > /dev/null 2>&1 ||
  441. skip_ "/proc/$pid/status: missing or 'different'"
  442. kill $pid
  443. }
  444. # Does trap support signal names?
  445. # Old versions of ash did not.
  446. require_trap_signame_()
  447. {
  448. (trap '' CHLD) || skip_ 'requires trap with signal name support'
  449. }
  450. # Does kill support sending signal to whole group?
  451. # dash 0.5.8 at least does not.
  452. require_kill_group_()
  453. {
  454. kill -0 -- -1 || skip_ 'requires kill with group signalling support'
  455. }
  456. # Return nonzero if the specified path is on a file system for
  457. # which FIEMAP support exists. Note some file systems (like ext3 and btrfs)
  458. # only support FIEMAP for files, not directories.
  459. fiemap_capable_()
  460. {
  461. if ! python < /dev/null; then
  462. warn_ 'fiemap_capable_: python missing: assuming not fiemap capable'
  463. return 1
  464. fi
  465. python "$abs_srcdir"/tests/fiemap-capable "$@"
  466. }
  467. # Skip the current test if "." lacks d_type support.
  468. require_dirent_d_type_()
  469. {
  470. python < /dev/null \
  471. || skip_ python missing: assuming no d_type support
  472. python "$abs_srcdir"/tests/d_type-check \
  473. || skip_ requires d_type support
  474. }
  475. # Skip the current test if we lack Perl.
  476. require_perl_()
  477. {
  478. : ${PERL=perl}
  479. $PERL -e 'use warnings' > /dev/null 2>&1 \
  480. || skip_ 'configure did not find a usable version of Perl'
  481. }
  482. # Does the current (working-dir) file system support sparse files?
  483. require_sparse_support_()
  484. {
  485. test $# = 0 || framework_failure_
  486. # Test whether we can create a sparse file.
  487. # For example, on Darwin6.5 with a file system of type hfs, it's not possible.
  488. # NTFS requires 128K before a hole appears in a sparse file.
  489. t=sparse.$$
  490. dd bs=1 seek=128K of=$t < /dev/null 2> /dev/null
  491. set x $(du -sk $t)
  492. kb_size=$2
  493. rm -f $t
  494. if test $kb_size -ge 128; then
  495. skip_ 'this file system does not support sparse files'
  496. fi
  497. }
  498. # Compile a shared lib using the GCC options for doing so.
  499. # Pass input and output file as parameters respectively.
  500. # Any other optional parmeters are passed to $CC.
  501. gcc_shared_()
  502. {
  503. local in=$1
  504. local out=$2
  505. shift 2 || return 1
  506. $CC -Wall -shared --std=gnu99 -fPIC -O2 $* "$in" -o "$out" -ldl
  507. }
  508. # There are a myriad of ways to build shared libs,
  509. # so we only consider running tests requiring shared libs,
  510. # on platforms that support building them as follows.
  511. require_gcc_shared_()
  512. {
  513. gcc_shared_ '-' 'd.so' -xc < /dev/null 2>&1 \
  514. || skip_ '$CC -shared ... failed to build a shared lib'
  515. rm -f d.so
  516. }
  517. mkfifo_or_skip_()
  518. {
  519. test $# = 1 || framework_failure_
  520. if ! mkfifo "$1"; then
  521. # Make an exception of this case -- usually we interpret framework-creation
  522. # failure as a test failure. However, in this case, when running on a SunOS
  523. # system using a disk NFS mounted from OpenBSD, the above fails like this:
  524. # mkfifo: cannot make fifo 'fifo-10558': Not owner
  525. skip_ 'unable to create a fifo'
  526. fi
  527. }
  528. # Disable the current test if the working directory seems to have
  529. # the setgid bit set.
  530. skip_if_setgid_()
  531. {
  532. setgid_tmpdir=setgid-$$
  533. (umask 77; mkdir $setgid_tmpdir)
  534. perms=$(stat --printf %A $setgid_tmpdir)
  535. rmdir $setgid_tmpdir
  536. case $perms in
  537. drwx------);;
  538. drwxr-xr-x);; # Windows98 + DJGPP 2.03
  539. *) skip_ 'this directory has the setgid bit set';;
  540. esac
  541. }
  542. # Skip if files are created with a different group to the current user
  543. # This can happen due to a setgid dir, or by some other mechanism on OS X:
  544. # https://unix.stackexchange.com/q/63865
  545. # https://bugs.gnu.org/14024#41
  546. skip_if_nondefault_group_()
  547. {
  548. touch grp.$$
  549. gen_ug=$(stat -c '%u:%g' grp.$$)
  550. rm grp.$$
  551. test "$gen_ug" = "$(id -ru):$(id -rg)" ||
  552. skip_ 'Files are created with a different gid'
  553. }
  554. skip_if_mcstransd_is_running_()
  555. {
  556. test $# = 0 || framework_failure_
  557. # When mcstransd is running, you'll see only the 3-component
  558. # version of file-system context strings. Detect that,
  559. # and if it's running, skip this test.
  560. __ctx=$(stat --printf='%C\n' .) || framework_failure_
  561. case $__ctx in
  562. *:*:*:*) __ctx_ok=1 ;; # four components is ok
  563. *:*:*) # three components is ok too if there is no MLS
  564. mls_enabled_ || __ctx_ok=1 ;;
  565. esac
  566. test "$__ctx_ok" ||
  567. skip_ "unexpected context '$__ctx'; turn off mcstransd"
  568. }
  569. # Skip the current test if umask doesn't work as usual.
  570. # This test should be run in the temporary directory that ends
  571. # up being removed via the trap commands.
  572. working_umask_or_skip_()
  573. {
  574. umask 022
  575. touch file1 file2
  576. chmod 644 file2
  577. perms=$(ls -l file1 file2 | sed 's/ .*//' | uniq)
  578. rm -f file1 file2
  579. case $perms in
  580. *'
  581. '*) skip_ 'your build directory has unusual umask semantics'
  582. esac
  583. }
  584. # Retry a function requiring a sufficient delay to _pass_
  585. # using a truncated exponential backoff method.
  586. # Example: retry_delay_ dd_reblock_1 .1 6
  587. # This example will call the dd_reblock_1 function with
  588. # an initial delay of .1 second and call it at most 6 times
  589. # with a max delay of 3.2s (doubled each time), or a total of 6.3s
  590. # Note ensure you do _not_ quote the parameter to GNU sleep in
  591. # your function, as it may contain separate values that sleep
  592. # needs to accumulate.
  593. # Further function arguments will be forwarded to the test function.
  594. retry_delay_()
  595. {
  596. local test_func=$1
  597. local init_delay=$2
  598. local max_n_tries=$3
  599. shift 3 || return 1
  600. local attempt=1
  601. local num_sleeps=$attempt
  602. local time_fail
  603. while test $attempt -le $max_n_tries; do
  604. local delay=$($AWK -v n=$num_sleeps -v s="$init_delay" \
  605. 'BEGIN { print s * n }')
  606. "$test_func" "$delay" "$@" && { time_fail=0; break; } || time_fail=1
  607. attempt=$(expr $attempt + 1)
  608. num_sleeps=$(expr $num_sleeps '*' 2)
  609. done
  610. test "$time_fail" = 0
  611. }
  612. # Call this with a list of programs under test immediately after
  613. # sourcing init.sh.
  614. print_ver_()
  615. {
  616. require_built_ "$@"
  617. if test "$VERBOSE" = yes; then
  618. local i
  619. for i in $*; do
  620. env $i --version
  621. done
  622. fi
  623. }
  624. # Are we running on GNU/Hurd?
  625. require_gnu_()
  626. {
  627. test "$(uname)" = GNU \
  628. || skip_ 'not running on GNU/Hurd'
  629. }
  630. sanitize_path_