OSDN Git Service

tests: libparted/tests: use init.sh, not test-lib.sh
[android-x86/external-parted.git] / libparted / tests / t2100-zerolen.sh
1 #!/bin/sh
2 # run the zerolen unit tests in a directory supporting O_DIRECT
3
4 # Copyright (C) 2007-2010 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 . "${abs_top_srcdir=../..}/tests/init.sh"; path_prepend_ .
20 . $abs_top_srcdir/tests/t-lib-helpers.sh
21 # Need root privileges to create a device-mapper device.
22 require_root_
23 device_mapper_required_
24
25 init_root_dir_
26
27 # This test only makes sense on Linux.
28 test "$(uname -s)" = Linux \
29   || skip_ "not on Linux"
30
31 test "x$DYNAMIC_LOADING" = xyes \
32   || skip_ "no dynamic loading support"
33
34 test "x$ENABLE_DEVICE_MAPPER" = xyes \
35   || skip_ "no device-mapper support"
36
37 # Device map name - should be random to not conflict with existing ones on
38 # the system
39 linear_=plinear-$$
40
41 cleanup_()
42 {
43   # 'dmsetup remove' may fail because udev is still processing the device.
44   # Try it repeatedly for 2s.
45   i=0
46   incr=1
47   while :; do
48     dmsetup remove $linear_ > /dev/null 2>&1 && break
49     sleep .1 2>/dev/null || { sleep 1; incr=10; }
50     i=$(expr $i + $incr); test $i = 20 && break
51   done
52   if test $i = 20; then
53     dmsetup remove $linear_
54   fi
55
56   test -n "$d1" && losetup -d "$d1"
57   rm -f "$f1"
58 }
59
60 f1=$(pwd)/1
61 d1=$(loop_setup_ "$f1") \
62   || skip_ "is this partition mounted with 'nodev'?"
63
64 echo "0 1024 linear $d1 0" | dmsetup create "$linear_" \
65   || skip_ "unable to create dm device"
66
67 wait_for_dev_to_appear_ "/dev/mapper/$linear_" \
68   || skip_ "dm device did not appear"
69
70 zerolen /dev/mapper/$linear_ || fail=1
71
72 Exit $fail