~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/init.cfg

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This file is sourced by init.sh, *before* its initialization.
2
 
 
3
 
# Copyright (C) 2010-2011 Free Software Foundation, Inc.
4
 
 
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.
9
 
 
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.
14
 
 
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/>.
17
 
 
18
 
 
19
 
# This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
20
 
# TESTS_ENVIRONMENT definition.
21
 
stderr_fileno_=9
22
 
 
23
 
# Having an unsearchable directory in PATH causes execve to fail with EACCES
24
 
# when applied to an unresolvable program name, contrary to the desired ENOENT.
25
 
# Avoid the problem by rewriting PATH to exclude unsearchable directories.
26
 
sanitize_path_()
27
 
{
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
34
 
 
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
45
 
 
46
 
  PATH=$new_path
47
 
  export PATH
48
 
}
49
 
 
50
 
getlimits_()
51
 
{
52
 
  eval $(getlimits)
53
 
  test "$INT_MAX" || fatal_ "running getlimits"
54
 
}
55
 
 
56
 
require_acl_()
57
 
{
58
 
  getfacl --version < /dev/null > /dev/null 2>&1 \
59
 
    && setfacl --version < /dev/null > /dev/null 2>&1 \
60
 
      || skip_ "This test requires getfacl and setfacl."
61
 
 
62
 
  id -u bin > /dev/null 2>&1 \
63
 
    || skip_ "This test requires a local user named bin."
64
 
}
65
 
 
66
 
is_local_dir_()
67
 
{
68
 
  test $# = 1 || framework_failure_
69
 
  df --local "$1" >/dev/null 2>&1
70
 
}
71
 
 
72
 
require_local_dir_()
73
 
{
74
 
  is_local_dir_ . ||
75
 
    skip_ "This test must be run on a local file system."
76
 
}
77
 
 
78
 
# Skip this test if we're not in SELinux "enforcing" mode.
79
 
require_selinux_enforcing_()
80
 
{
81
 
  test "$(getenforce)" = Enforcing \
82
 
    || skip_ "This test is useful only with SELinux in Enforcing mode."
83
 
}
84
 
 
85
 
require_openat_support_()
86
 
{
87
 
  # Skip this test if your system has neither the openat-style functions
88
 
  # nor /proc/self/fd support with which to emulate them.
89
 
  test -z "$CONFIG_HEADER" \
90
 
    && skip_ 'internal error: CONFIG_HEADER not defined'
91
 
 
92
 
  _skip=yes
93
 
  grep '^#define HAVE_OPENAT' "$CONFIG_HEADER" > /dev/null && _skip=no
94
 
  test -d /proc/self/fd && _skip=no
95
 
  if test $_skip = yes; then
96
 
    skip_ 'this system lacks openat support'
97
 
  fi
98
 
}
99
 
 
100
 
require_ulimit_()
101
 
{
102
 
  ulimit_works=yes
103
 
  # Expect to be able to exec a program in 10MB of virtual memory,
104
 
  # but not in 20KB.  I chose "date".  It must not be a shell built-in
105
 
  # function, so you can't use echo, printf, true, etc.
106
 
  # Of course, in coreutils, I could use $top_builddir/src/true,
107
 
  # but this should be able to work for other projects, too.
108
 
  ( ulimit -v 10000; date ) > /dev/null 2>&1 || ulimit_works=no
109
 
  ( ulimit -v 20;    date ) > /dev/null 2>&1 && ulimit_works=no
110
 
 
111
 
  test $ulimit_works = no \
112
 
    && skip_ "this shell lacks ulimit support"
113
 
}
114
 
 
115
 
require_readable_root_()
116
 
{
117
 
  test -r / || skip_ "/ is not readable"
118
 
}
119
 
 
120
 
# Skip the current test if strace is not available or doesn't work
121
 
# with the named syscall.  Usage: require_strace_ unlink
122
 
require_strace_()
123
 
{
124
 
  test $# = 1 || framework_failure_
125
 
 
126
 
  strace -V < /dev/null > /dev/null 2>&1 ||
127
 
    skip_ 'no strace program'
128
 
 
129
 
  strace -qe "$1" echo > /dev/null 2>&1 ||
130
 
    skip_ 'strace -qe "'"$1"'" does not work'
131
 
}
132
 
 
133
 
# Require a controlling input `terminal'.
134
 
require_controlling_input_terminal_()
135
 
{
136
 
  tty -s || have_input_tty=no
137
 
  test -t 0 || have_input_tty=no
138
 
  if test "$have_input_tty" = no; then
139
 
    skip_ 'requires controlling input terminal
140
 
This test must have a controlling input "terminal", so it may not be
141
 
run via "batch", "at", or "ssh".  On some systems, it may not even be
142
 
run in the background.'
143
 
  fi
144
 
}
145
 
 
146
 
require_built_()
147
 
{
148
 
  skip_=no
149
 
  for i in "$@"; do
150
 
    case " $built_programs " in
151
 
      *" $i "*) ;;
152
 
      *) echo "$i: not built" 1>&2; skip_=yes ;;
153
 
    esac
154
 
  done
155
 
 
156
 
  test $skip_ = yes && skip_ "required program(s) not built"
157
 
}
158
 
 
159
 
require_file_system_bytes_free_()
160
 
{
161
 
  local req=$1
162
 
  local expr=$(stat -f --printf "$req / %S <= %a" .)
163
 
  awk "BEGIN{ exit !($expr) }" \
164
 
    || skip_ "this test needs at least $req bytes of free space"
165
 
}
166
 
 
167
 
uid_is_privileged_()
168
 
{
169
 
  # Make sure id -u succeeds.
170
 
  my_uid=$(id -u) \
171
 
    || { echo "$0: cannot run \`id -u'" 1>&2; return 1; }
172
 
 
173
 
  # Make sure it gives valid output.
174
 
  case $my_uid in
175
 
    0) ;;
176
 
    *[!0-9]*)
177
 
      echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
178
 
      return 1 ;;
179
 
    *) return 1 ;;
180
 
  esac
181
 
}
182
 
 
183
 
# Some versions of sudo do not include /sbin in PATH.
184
 
# Test if mkfs is in PATH, otherwise try to adapt PATH.
185
 
require_mkfs_PATH_()
186
 
{
187
 
  type mkfs && return
188
 
 
189
 
  case ":$PATH:" in
190
 
    *:/sbin:*) skip_ "no usable mkfs found" ;;
191
 
  esac
192
 
 
193
 
  test -x /sbin/mkfs \
194
 
    || skip_ "no usable mkfs found"
195
 
 
196
 
  PATH="$PATH:/sbin"
197
 
  export PATH
198
 
}
199
 
 
200
 
get_process_status_()
201
 
{
202
 
  sed -n '/^State:[      ]*\([[:alpha:]]\).*/s//\1/p' /proc/$1/status
203
 
}
204
 
 
205
 
# Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
206
 
# to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
207
 
# =,u=rw,g=rx,o=wx).  Ignore ACLs.
208
 
rwx_to_mode_()
209
 
{
210
 
  case $# in
211
 
    1) rwx=$1;;
212
 
    *) echo "$0: wrong number of arguments" 1>&2
213
 
      echo "Usage: $0 ls-style-mode-string" 1>&2
214
 
      return;;
215
 
  esac
216
 
 
217
 
  case $rwx in
218
 
    [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
219
 
    [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-][+.]) ;;
220
 
    *) echo "$0: invalid mode string: $rwx" 1>&2; return;;
221
 
  esac
222
 
 
223
 
  # Perform these conversions:
224
 
  # S  s
225
 
  # s  xs
226
 
  # T  t
227
 
  # t  xt
228
 
  # The `T' and `t' ones are only valid for `other'.
229
 
  s='s/S/@/;s/s/x@/;s/@/s/'
230
 
  t='s/T/@/;s/t/x@/;s/@/t/'
231
 
 
232
 
  u=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
233
 
  g=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
234
 
  o=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`
235
 
  echo "=$u$g$o"
236
 
}
237
 
 
238
 
skip_if_()
239
 
{
240
 
  case $1 in
241
 
    root) skip_ must be run as root ;;
242
 
    non-root) skip_ must be run as non-root ;;
243
 
    *) ;;  # FIXME?
244
 
  esac
245
 
}
246
 
 
247
 
require_selinux_()
248
 
{
249
 
  # When in a chroot of an SELinux-enabled system, but with a mock-simulated
250
 
  # SELinux-*disabled* system, recognize that SELinux is disabled system wide:
251
 
  grep 'selinuxfs$' /proc/filesystems > /dev/null \
252
 
    || skip_ "this system lacks SELinux support"
253
 
 
254
 
  # Independent of whether SELinux is enabled system-wide,
255
 
  # the current file system may lack SELinux support.
256
 
  case `ls -Zd .` in
257
 
    '? .'|'unlabeled .')
258
 
      skip_ "this system (or maybe just" \
259
 
        "the current file system) lacks SELinux support"
260
 
    ;;
261
 
  esac
262
 
}
263
 
 
264
 
very_expensive_()
265
 
{
266
 
  if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
267
 
    skip_ 'very expensive: disabled by default
268
 
This test is very expensive, so it is disabled by default.
269
 
To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
270
 
environment variable set to yes.  E.g.,
271
 
 
272
 
  env RUN_VERY_EXPENSIVE_TESTS=yes make check
273
 
'
274
 
  fi
275
 
}
276
 
 
277
 
expensive_()
278
 
{
279
 
  if test "$RUN_EXPENSIVE_TESTS" != yes; then
280
 
    skip_ 'expensive: disabled by default
281
 
This test is relatively expensive, so it is disabled by default.
282
 
To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
283
 
environment variable set to yes.  E.g.,
284
 
 
285
 
  env RUN_EXPENSIVE_TESTS=yes make check
286
 
'
287
 
  fi
288
 
}
289
 
 
290
 
require_root_()
291
 
{
292
 
  uid_is_privileged_ || skip_ "must be run as root"
293
 
  NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
294
 
  NON_ROOT_GROUP=${NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)}
295
 
}
296
 
 
297
 
skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }
298
 
 
299
 
# Set `groups' to a space-separated list of at least two groups
300
 
# of which the user is a member.
301
 
require_membership_in_two_groups_()
302
 
{
303
 
  test $# = 0 || framework_failure_
304
 
 
305
 
  groups=${COREUTILS_GROUPS-`(id -G || /usr/xpg4/bin/id -G) 2>/dev/null`}
306
 
  case "$groups" in
307
 
    *' '*) ;;
308
 
    *) skip_ 'requires membership in two groups
309
 
this test requires that you be a member of more than one group,
310
 
but running `id -G'\'' either failed or found just one.  If you really
311
 
are a member of at least two groups, then rerun this test with
312
 
COREUTILS_GROUPS set in your environment to the space-separated list
313
 
of group names or numbers.  E.g.,
314
 
 
315
 
  env COREUTILS_GROUPS='\''users cdrom'\'' make check
316
 
 
317
 
'
318
 
     ;;
319
 
  esac
320
 
}
321
 
 
322
 
# Is /proc/$PID/status supported?
323
 
require_proc_pid_status_()
324
 
{
325
 
    sleep 2 &
326
 
    local pid=$!
327
 
    sleep .5
328
 
    grep '^State:[       ]*[S]' /proc/$pid/status > /dev/null 2>&1 ||
329
 
    skip_ "/proc/$pid/status: missing or 'different'"
330
 
    kill $pid
331
 
}
332
 
 
333
 
# Return nonzero if the specified path is on a file system for
334
 
# which FIEMAP support exists.  Note some file systems (like ext3 and btrfs)
335
 
# only support FIEMAP for files, not directories.
336
 
fiemap_capable_()
337
 
{
338
 
  if ! python < /dev/null; then
339
 
    warn_ 'fiemap_capable_: python missing: assuming not fiemap capable'
340
 
    return 1
341
 
  fi
342
 
  python $abs_srcdir/fiemap-capable "$@"
343
 
}
344
 
 
345
 
# Skip the current test if "." lacks d_type support.
346
 
require_dirent_d_type_()
347
 
{
348
 
  python < /dev/null \
349
 
    || skip_ python missing: assuming no d_type support
350
 
 
351
 
  python $abs_srcdir/d_type-check \
352
 
    || skip_ requires d_type support
353
 
}
354
 
 
355
 
# Skip the current test if we lack Perl.
356
 
require_perl_()
357
 
{
358
 
  : ${PERL=perl}
359
 
  $PERL -e 'use warnings' > /dev/null 2>&1 \
360
 
    || skip_ 'configure did not find a usable version of Perl'
361
 
}
362
 
 
363
 
# Does the current (working-dir) file system support sparse files?
364
 
require_sparse_support_()
365
 
{
366
 
  test $# = 0 || framework_failure_
367
 
  # Test whether we can create a sparse file.
368
 
  # For example, on Darwin6.5 with a file system of type hfs, it's not possible.
369
 
  # NTFS requires 128K before a hole appears in a sparse file.
370
 
  t=sparse.$$
371
 
  dd bs=1 seek=128K of=$t < /dev/null 2> /dev/null
372
 
  set x `du -sk $t`
373
 
  kb_size=$2
374
 
  rm -f $t
375
 
  if test $kb_size -ge 128; then
376
 
    skip_ 'this file system does not support sparse files'
377
 
  fi
378
 
}
379
 
 
380
 
mkfifo_or_skip_()
381
 
{
382
 
  test $# = 1 || framework_failure_
383
 
  if ! mkfifo "$1"; then
384
 
    # Make an exception of this case -- usually we interpret framework-creation
385
 
    # failure as a test failure.  However, in this case, when running on a SunOS
386
 
    # system using a disk NFS mounted from OpenBSD, the above fails like this:
387
 
    # mkfifo: cannot make fifo `fifo-10558': Not owner
388
 
    skip_ 'unable to create a fifo'
389
 
  fi
390
 
}
391
 
 
392
 
# Disable the current test if the working directory seems to have
393
 
# the setgid bit set.
394
 
skip_if_setgid_()
395
 
{
396
 
  setgid_tmpdir=setgid-$$
397
 
  (umask 77; mkdir $setgid_tmpdir)
398
 
  perms=$(stat --printf %A $setgid_tmpdir)
399
 
  rmdir $setgid_tmpdir
400
 
  case $perms in
401
 
    drwx------);;
402
 
    drwxr-xr-x);;  # Windows98 + DJGPP 2.03
403
 
    *) skip_ 'this directory has the setgid bit set';;
404
 
  esac
405
 
}
406
 
 
407
 
skip_if_mcstransd_is_running_()
408
 
{
409
 
  test $# = 0 || framework_failure_
410
 
 
411
 
  # When mcstransd is running, you'll see only the 3-component
412
 
  # version of file-system context strings.  Detect that,
413
 
  # and if it's running, skip this test.
414
 
  __ctx=$(stat --printf='%C\n' .) || framework_failure_
415
 
  case $__ctx in
416
 
    *:*:*:*) ;; # four components is ok
417
 
    *) # anything else probably means mcstransd is running
418
 
        skip_ "unexpected context '$__ctx'; turn off mcstransd" ;;
419
 
  esac
420
 
}
421
 
 
422
 
# Skip the current test if umask doesn't work as usual.
423
 
# This test should be run in the temporary directory that ends
424
 
# up being removed via the trap commands.
425
 
working_umask_or_skip_()
426
 
{
427
 
  umask 022
428
 
  touch file1 file2
429
 
  chmod 644 file2
430
 
  perms=`ls -l file1 file2 | sed 's/ .*//' | uniq`
431
 
  rm -f file1 file2
432
 
 
433
 
  case $perms in
434
 
  *'
435
 
  '*) skip_ 'your build directory has unusual umask semantics'
436
 
  esac
437
 
}
438
 
 
439
 
# Retry a function requiring a sufficient delay to _pass_
440
 
# using a truncated exponential backoff method.
441
 
#     Example: retry_delay_ dd_reblock_1 .1 6
442
 
# This example will call the dd_reblock_1 function with
443
 
# an initial delay of .1 second and call it at most 6 times
444
 
# with a max delay of 3.2s (doubled each time), or a total of 6.3s
445
 
# Note ensure you do _not_ quote the parameter to GNU sleep in
446
 
# your function, as it may contain separate values that `sleep`
447
 
# needs to accumulate.
448
 
retry_delay_()
449
 
{
450
 
  local test_func=$1
451
 
  local init_delay=$2
452
 
  local max_n_tries=$3
453
 
 
454
 
  local attempt=1
455
 
  local num_sleeps=$attempt
456
 
  local time_fail
457
 
  while test $attempt -le $max_n_tries; do
458
 
    local delay=$($AWK -v n=$num_sleeps -v s="$init_delay" \
459
 
                  'BEGIN { print s * n }')
460
 
    "$test_func" "$delay" && { time_fail=0; break; } || time_fail=1
461
 
    attempt=$(expr $attempt + 1)
462
 
    num_sleeps=$(expr $num_sleeps '*' 2)
463
 
  done
464
 
  test "$time_fail" = 0
465
 
}
466
 
 
467
 
# Call this with a list of programs under test immediately after
468
 
# sourcing init.sh.
469
 
print_ver_()
470
 
{
471
 
  if test "$VERBOSE" = yes; then
472
 
    local i
473
 
    for i in $*; do
474
 
      env $i --version
475
 
    done
476
 
  fi
477
 
}
478
 
 
479
 
sanitize_path_