OSDN Git Service

maint: update all FSF copyright year lists to include 2010
[android-x86/external-parted.git] / tests / t5000-tags.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="test bios_grub flag in gpt labels"
19
20 : ${srcdir=.}
21 . $srcdir/test-lib.sh
22 ss=$sector_size_
23
24 dev=loop-file
25 N=300 # number of sectors
26
27 part_sectors=128
28 start_sector=60
29 end_sector=$(expr $start_sector + $part_sectors - 1)
30
31 test_expect_success \
32     "setup: reasonable params" \
33     'test $end_sector -lt $N'
34
35 test_expect_success \
36     "setup: create zeroed device" \
37     'dd if=/dev/zero of=$dev bs=${ss}c count=$N 2> /dev/null'
38
39 test_expect_success \
40     'create gpt label' \
41     'parted -s $dev mklabel gpt > empty 2>&1'
42
43 test_expect_success 'ensure there was no output' \
44     'compare /dev/null empty'
45
46 test_expect_success \
47     'print the table (before adding a partition)' \
48     'parted -m -s $dev unit s print > t 2>&1 &&
49      sed 's,.*/$dev:,$dev:,' t > out'
50
51 test_expect_success \
52     'check for expected output' \
53     'printf "BYT;\n$dev:${N}s:file:$ss:$ss:gpt:;\n" > exp &&
54      compare exp out'
55
56 test_expect_success \
57     'add a partition' \
58     'parted -s $dev u s mkpart name1 ${start_sector} ${end_sector} >out 2>&1'
59
60 test_expect_success \
61     'print the table before modification' \
62     '
63      parted -m -s $dev unit s print > t 2>&1 &&
64      sed 's,.*/$dev:,$dev:,' t >> out
65     '
66
67 test_expect_success \
68     'set the new bios_grub attribute' \
69     'parted -m -s $dev set 1 bios_grub on'
70
71 test_expect_success \
72     'print the table after modification' \
73     '
74      parted -m -s $dev unit s print > t 2>&1
75      sed 's,.*/$dev:,$dev:,' t >> out
76     '
77
78 gen_exp()
79 {
80   cat <<EOF
81 BYT;
82 $dev:${N}s:file:$ss:$ss:gpt:;
83 1:${start_sector}s:${end_sector}s:${part_sectors}s::name1:;
84 BYT;
85 $dev:${N}s:file:$ss:$ss:gpt:;
86 1:${start_sector}s:${end_sector}s:${part_sectors}s::name1:bios_grub;
87 EOF
88 }
89
90 test_expect_success 'check for expected output' \
91     '
92      gen_exp > exp &&
93      compare exp out
94     '
95
96 test_done