~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to tests/init.cfg

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

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
# This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
 
4
# TESTS_ENVIRONMENT definition.
 
5
stderr_fileno_=9
 
6
 
 
7
# For repeatability, reset the environment to known value.
 
8
LANG=C
 
9
LC_ALL=C
 
10
TZ=UTC
 
11
export LANG LC_ALL TZ
 
12
export PARTED_SUPPRESS_FILE_SYSTEM_MANIPULATION_WARNING=1
 
13
 
 
14
# Protect ourselves from common misconfiguration to export
 
15
# CDPATH into the environment
 
16
unset CDPATH
 
17
 
 
18
# Suppress readline initialization garbage.
 
19
unset TERM
 
20
 
 
21
sector_size_=${PARTED_SECTOR_SIZE:-512}
 
22
 
 
23
require_512_byte_sector_size_()
 
24
{
 
25
  test $sector_size_ = 512 || skip_ 'FS test with sector size != 512'
 
26
}
 
27
 
 
28
# Having an unsearchable directory in PATH causes execve to fail with EACCES
 
29
# when applied to an unresolvable program name, contrary to the desired ENOENT.
 
30
# Avoid the problem by rewriting PATH to exclude unsearchable directories.
 
31
# Also, if PATH lacks /sbin and/or /usr/sbin, append it/them.
 
32
sanitize_path_()
 
33
{
 
34
  # FIXME: remove double quotes around $IFS when all tests use init.sh.
 
35
  # They constitute a work-around for a bug in FreeBSD 8.1's /bin/sh.
 
36
  local saved_IFS="$IFS"
 
37
    IFS=:
 
38
    set -- $PATH
 
39
  IFS=$saved_IFS
 
40
 
 
41
  local d d1
 
42
  local colon=
 
43
  local new_path=
 
44
  for d in "$@"; do
 
45
    test -z "$d" && d1=. || d1=$d
 
46
    if ls -d "$d1/." > /dev/null 2>&1; then
 
47
      new_path="$new_path$colon$d"
 
48
      colon=':'
 
49
    fi
 
50
  done
 
51
 
 
52
  for d in /sbin /usr/sbin ; do
 
53
    case ":$new_path:" in
 
54
      *:$d:*) ;;
 
55
      *) new_path="$new_path:$d" ;;
 
56
    esac
 
57
  done
 
58
 
 
59
  PATH=$new_path
 
60
  export PATH
 
61
}
 
62
 
 
63
require_udevadm_settle_()
 
64
{
 
65
  udevadm --help > /dev/null \
 
66
    || skip_ 'udevadm command is required for this test'
 
67
}
 
68
 
 
69
require_perl_digest_crc_()
 
70
{
 
71
  local ok=0
 
72
  local t
 
73
  t=$(perl -le 'use Digest::CRC qw(crc32); print crc32("123")') \
 
74
    && test $t = 2286445522 && ok=1
 
75
  test $ok = 1 \
 
76
    || skip_ "this test requires Perl's Digest::CRC module"
 
77
}
 
78
 
 
79
# We need two cleanup functions.  One, cleanup_final_, is sometimes
 
80
# used (transparently) via t-local.sh's modprobe/rmmod code.
 
81
# The other is used e.g., to unmount.
 
82
cleanup_final_() { :; }
 
83
cleanup_fn_() { :; }
 
84
cleanup_() { cleanup_fn_; cleanup_final_; }
 
85
 
 
86
# Use this for a test that requires an actual hardware device, e.g., a real
 
87
# disk, a USB key, or a CD-RW.  The envvars $DEVICE_TO_ERASE and
 
88
# $DEVICE_TO_ERASE_SIZE must be set properly.  Otherwise, skip the test.
 
89
require_erasable_()
 
90
{
 
91
  # Skip quietly if both envvars are not specified.
 
92
  test -n "$DEVICE_TO_ERASE" && test -n "$DEVICE_TO_ERASE_SIZE" \
 
93
    || skip_ 'This test requires an erasable device and you have not properly' \
 
94
        'set the $DEVICE_TO_ERASE and $DEVICE_TO_ERASE_SIZE envvars.'
 
95
 
 
96
  # Since testing a drive with parted destroys all data on that drive,
 
97
  # we have rather draconian safety requirements that should help avoid
 
98
  # accidents.  If $dev_ is the name of the device,
 
99
  # - running "parted -s $dev_ print" must succeed, and
 
100
  # - its output must include a line matching /^Disk $dev_: $DEV_SIZE$/
 
101
  # - Neither $dev_ nor any $dev_[0-9]* may be mounted.
 
102
  dev_=$DEVICE_TO_ERASE
 
103
  sz=$DEVICE_TO_ERASE_SIZE
 
104
  parted_output=$(parted -s $dev_ print) || fail_ "no such device: $dev_"
 
105
  parted -s $dev_ print|grep "^Disk $dev_: $sz$" \
 
106
    > /dev/null || fail_ "actual device size is not $sz"
 
107
  # Try to see if $dev_ or any of its partitions is mounted.
 
108
  # This is not reliable.  FIXME: find a better way.
 
109
  # Maybe expose parted's own test for whether a disk is in use.
 
110
  # The following assume that $dev_ is canonicalized, e.g., that $dev_
 
111
  # contains no "//" or "/./" components.
 
112
 
 
113
  # Prefer df --local, if it works, so we don't waste time
 
114
  # enumerating lots of automounted file systems.
 
115
  ( df --local / > /dev/null 2>&1 ) && df='df --local' || df=df
 
116
  $df | grep "^$dev_" && fail_ "$dev_ is already mounted"
 
117
  $df | grep "^$dev_[0-9]" && fail_ "a partition of $dev_ is already mounted"
 
118
}
 
119
 
 
120
# At least Fedora 16 (kernel 3.1.6-1.fc16.x86_64) fails this test.
 
121
require_partitionable_loop_device_()
 
122
{
 
123
  case $(cat /sys/devices/virtual/block/$(basename $1)/ext_range) in
 
124
    0|1) skip_ your system does not support loop partitioning;;
 
125
  esac
 
126
}
 
127
 
 
128
sanitize_path_
 
129
 
 
130
. "$abs_top_srcdir/tests/t-lib-helpers.sh"
 
131
. "$abs_top_srcdir/tests/t-local.sh"