OSDN Git Service

c5fbb5e8f5a56ca71963aaa5b49fd4112299912e
[android-x86/external-parted.git] / tests / init.cfg
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 require_udevadm_settle_()
29 {
30   udevadm --help > /dev/null \
31     || skip_ 'udevadm command is required for this test'
32 }
33
34 # We need two cleanup functions.  One, cleanup_final_, is sometimes
35 # used (transparently) via t-local.sh's modprobe/rmmod code.
36 # The other is used e.g., to unmount.
37 cleanup_final_() { :; }
38 cleanup_fn_() { :; }
39 cleanup_() { cleanup_fn_; cleanup_final_; }
40
41 # Use this for a test that requires an actual hardware device, e.g., a real
42 # disk, a USB key, or a CD-RW.  The envvars $DEVICE_TO_ERASE and
43 # $DEVICE_TO_ERASE_SIZE must be set properly.  Otherwise, skip the test.
44 require_erasable_()
45 {
46   # Skip quietly if both envvars are not specified.
47   test -n "$DEVICE_TO_ERASE" && test -n "$DEVICE_TO_ERASE_SIZE" \
48     || skip_ 'This test requires an erasable device and you have not properly' \
49         'set the $DEVICE_TO_ERASE and $DEVICE_TO_ERASE_SIZE envvars.'
50
51   # Since testing a drive with parted destroys all data on that drive,
52   # we have rather draconian safety requirements that should help avoid
53   # accidents.  If $dev_ is the name of the device,
54   # - running "parted -s $dev_ print" must succeed, and
55   # - its output must include a line matching /^Disk $dev_: $DEV_SIZE$/
56   # - Neither $dev_ nor any $dev_[0-9]* may be mounted.
57   dev_=$DEVICE_TO_ERASE
58   sz=$DEVICE_TO_ERASE_SIZE
59   parted_output=$(parted -s $dev_ print) || fail_ "no such device: $dev_"
60   parted -s $dev_ print|grep "^Disk $dev_: $sz$" \
61     > /dev/null || fail_ "actual device size is not $sz"
62   # Try to see if $dev_ or any of its partitions is mounted.
63   # This is not reliable.  FIXME: find a better way.
64   # Maybe expose parted's own test for whether a disk is in use.
65   # The following assume that $dev_ is canonicalized, e.g., that $dev_
66   # contains no "//" or "/./" components.
67
68   # Prefer df --local, if it works, so we don't waste time
69   # enumerating lots of automounted file systems.
70   ( df --local / > /dev/null 2>&1 ) && df='df --local' || df=df
71   $df | grep "^$dev_" && fail_ "$dev_ is already mounted"
72   $df | grep "^$dev_[0-9]" && fail_ "a partition of $dev_ is already mounted"
73 }
74
75 . "$abs_top_srcdir/tests/t-lib-helpers.sh"
76 . "$abs_top_srcdir/tests/t-local.sh"