OSDN Git Service

libparted: ignore zero-length devices
[android-x86/external-parted.git] / libparted / tests / t2100-zerolen.sh
1 #!/bin/sh
2
3 # Copyright (C) 2007-2010 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 test_description='run the zerolen unit tests in a directory supporting O_DIRECT'
19
20 # Need root privileges to create a device-mapper device.
21 privileges_required_=1
22 device_mapper_required_=1
23
24 : ${top_srcdir=../..}
25 . "$top_srcdir/tests/test-lib.sh"
26
27 init_root_dir_
28
29 # This test only makes sense on Linux.
30 test "$(uname -s)" = Linux \
31   || skip_test_ "not on Linux"
32
33 test "x$DYNAMIC_LOADING" = xyes \
34   || skip_test_ "no dynamic loading support"
35
36 test "x$ENABLE_DEVICE_MAPPER" = xyes \
37   || skip_test_ "no device-mapper support"
38
39 # Device map name - should be random to not conflict with existing ones on
40 # the system
41 linear_=plinear-$$
42
43 cleanup_()
44 {
45   # 'dmsetup remove' may fail because udev is still processing the device.
46   # Try it repeatedly for 2s.
47   i=0
48   incr=1
49   while :; do
50     dmsetup remove $linear_ > /dev/null 2>&1 && break
51     sleep .1 2>/dev/null || { sleep 1; incr=10; }
52     i=$(expr $i + $incr); test $i = 20 && break
53   done
54   if test $i = 20; then
55     dmsetup remove $linear_
56   fi
57
58   test -n "$d1" && losetup -d "$d1"
59   rm -f "$f1"
60 }
61
62 f1=$(pwd)/1
63 d1=$(loop_setup_ "$f1") \
64   || skip_test_ "is this partition mounted with 'nodev'?"
65
66 echo "0 1024 linear $d1 0" | dmsetup create "$linear_" \
67   || skip_test_ "unable to create dm device"
68
69 wait_for_dev_to_appear_ "/dev/mapper/$linear_" \
70   || skip_test_ "dm device did not appear"
71
72 test_expect_success \
73     'run the actual tests' "zerolen /dev/mapper/$linear_"
74
75 test_done