]>
Commit | Line | Data |
---|---|---|
9894961b DB |
1 | #!/bin/bash |
2 | ||
3 | # | |
4 | # Copyright (C) 2010 Davidlohr Bueso <dave@gnu.org> | |
5 | # | |
a9485396 | 6 | # This file is part of util-linux. |
9894961b DB |
7 | # |
8 | # This file is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 2 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This file is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | ||
e130ce53 | 19 | TS_TOPDIR="${0%/*}/../.." |
9894961b | 20 | TS_DESC="partitions probing" |
3a8f26bd | 21 | PARTS=3 |
9894961b DB |
22 | |
23 | . $TS_TOPDIR/functions.sh | |
9894961b DB |
24 | ts_init "$*" |
25 | ||
2f791546 SK |
26 | ts_check_test_command "$TS_CMD_PARTX" |
27 | ts_check_test_command "$TS_CMD_ADDPART" | |
28 | ts_check_test_command "$TS_CMD_DELPART" | |
29 | ||
30 | ts_skip_nonroot | |
9894961b | 31 | |
3a951379 RM |
32 | shopt -s nullglob |
33 | ||
34 | function check_partition_count | |
35 | { | |
36 | # this function needs shopt -s nullglob | |
37 | local cnt_want=$1 | |
38 | local devname=$(basename $TS_DEVICE) | |
39 | local parts=(/sys/block/${devname}/${devname}*) | |
40 | local cnt_have=${#parts[@]} | |
41 | ||
42 | if [ $cnt_have -eq $cnt_want ]; then | |
43 | return 0 | |
44 | fi | |
45 | echo "error: expected $cnt_want partitions, have $cnt_have" >&2 | |
46 | echo "${parts[@]}" >&2 | |
47 | return 1 | |
48 | } | |
49 | ||
f45df374 RM |
50 | # set global variable TS_DEVICE |
51 | ts_scsi_debug_init dev_size_mb=50 | |
3a8f26bd OO |
52 | |
53 | ts_init_subtest "addpart" | |
3a951379 RM |
54 | { |
55 | $TS_CMD_ADDPART ${TS_DEVICE} 1 0 1 && | |
56 | echo OK || | |
57 | echo "Unable to add partition" | |
58 | check_partition_count 1 | |
cbf858aa | 59 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
60 | ts_finalize_subtest |
61 | ||
0adc576d | 62 | udevadm settle |
3a8f26bd OO |
63 | |
64 | ts_init_subtest "delpart" | |
3a951379 RM |
65 | { |
66 | $TS_CMD_DELPART ${TS_DEVICE} 1 && | |
67 | echo OK || | |
68 | echo "Unable to remove partition" | |
69 | check_partition_count 0 | |
cbf858aa | 70 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
71 | ts_finalize_subtest |
72 | ||
5c711ba9 | 73 | ts_scsi_debug_rmmod |
3a8f26bd | 74 | |
f45df374 RM |
75 | # set global variable TS_DEVICE |
76 | ts_scsi_debug_init dev_size_mb=50 num_parts=$PARTS | |
3a8f26bd OO |
77 | |
78 | ts_init_subtest "detect-parts" | |
3a951379 RM |
79 | { |
80 | $TS_CMD_PARTX --show $TS_DEVICE && | |
81 | echo OK || | |
82 | echo "Unable to list partitions" | |
83 | check_partition_count $PARTS | |
cbf858aa | 84 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
85 | ts_finalize_subtest |
86 | ||
0adc576d KZ |
87 | udevadm settle |
88 | ||
3a8f26bd OO |
89 | ts_init_subtest "delete-all" |
90 | #delete partinfo | |
3a951379 RM |
91 | { |
92 | $TS_CMD_PARTX --delete $TS_DEVICE && | |
93 | echo "partitions deleted" || | |
94 | echo "Unable to delete partitions on $TS_DEVICE" | |
95 | check_partition_count 0 | |
cbf858aa | 96 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
97 | ts_finalize_subtest |
98 | ||
0adc576d KZ |
99 | udevadm settle |
100 | ||
3a8f26bd | 101 | ts_init_subtest "add-all" |
f45df374 | 102 | #read TS_DEVICE and restore the partinfo |
3a951379 RM |
103 | { |
104 | $TS_CMD_PARTX --add $TS_DEVICE && | |
105 | echo "partitions added" || | |
106 | echo "Unable to add partitions for $TS_DEVICE" | |
107 | check_partition_count $PARTS | |
cbf858aa | 108 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
109 | ts_finalize_subtest |
110 | ||
0adc576d | 111 | udevadm settle |
3a8f26bd | 112 | |
3eb433df | 113 | ts_init_subtest "update-one" |
f45df374 | 114 | #read TS_DEVICE and update second partition |
3a951379 RM |
115 | { |
116 | $TS_CMD_PARTX --update ${TS_DEVICE}2 && | |
117 | echo "partitions updated" || | |
118 | echo "Unable to update 2nd partition for $TS_DEVICE" | |
119 | check_partition_count $PARTS | |
cbf858aa | 120 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3eb433df KZ |
121 | ts_finalize_subtest |
122 | ||
123 | udevadm settle | |
124 | ||
3a8f26bd OO |
125 | ts_init_subtest "delete-one" |
126 | #remove last partition only | |
3a951379 RM |
127 | { |
128 | $TS_CMD_PARTX -d --nr -1 $TS_DEVICE && | |
129 | echo "last partition removed" || | |
130 | echo "Unable to remove a partition on $TS_DEVICE" | |
131 | check_partition_count $((PARTS-1)) | |
cbf858aa | 132 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
133 | ts_finalize_subtest |
134 | ||
0adc576d KZ |
135 | udevadm settle |
136 | ||
3a8f26bd OO |
137 | ts_init_subtest "delete-non-existent" |
138 | #attempt to remove it again | |
3a951379 | 139 | { |
5200aa99 KZ |
140 | # remove non-existing partitions (ENXIO) is not error |
141 | # | |
142 | # see ab025087f91b66ee8e23a16bc49eb0d9bd421d65 and | |
143 | # 53ae7d60cfeacd4e87bfe6fcc015b58b78ef4555 | |
144 | # | |
3a951379 | 145 | $TS_CMD_PARTX -d --nr $PARTS $TS_DEVICE && |
5200aa99 KZ |
146 | echo "partx: OK" || |
147 | echo "partx failed: removed non-existing partition" | |
cbf858aa | 148 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
149 | ts_finalize_subtest |
150 | ||
0adc576d KZ |
151 | udevadm settle |
152 | ||
3a8f26bd OO |
153 | ts_init_subtest "add-existing" |
154 | #try adding an existing partition | |
3a951379 RM |
155 | { |
156 | $TS_CMD_PARTX -a --nr 1 $TS_DEVICE 2>/dev/null && | |
157 | echo "partx failed: re-added an existing partition" || | |
158 | echo "partx: OK" | |
cbf858aa | 159 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
160 | ts_finalize_subtest |
161 | ||
0adc576d KZ |
162 | udevadm settle |
163 | ||
3a8f26bd OO |
164 | ts_init_subtest "change-by-range" |
165 | # {-a|-d} --nr 0 should handle all partitions | |
3a951379 RM |
166 | { |
167 | $TS_CMD_PARTX -d --nr 0 $TS_DEVICE && | |
168 | echo "partitions deleted" || | |
169 | echo "Unable to delete partitions on $TS_DEVICE" | |
170 | check_partition_count 0 | |
171 | $TS_CMD_PARTX -a --nr 0 $TS_DEVICE && | |
172 | echo "partitions added" || | |
173 | echo "Failed to add $TS_DEVICE partitions" | |
174 | check_partition_count $PARTS | |
cbf858aa | 175 | } >> $TS_OUTPUT 2>> $TS_ERRLOG |
3a8f26bd OO |
176 | ts_finalize_subtest |
177 | ||
9894961b | 178 | ts_finalize |