Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: rootdev_test.sh

Issue 3141038: rootdev: fix -d, add -c and -r. ifdefs for so use (Closed) Base URL: http://src.chromium.org/git/rootdev.git
Patch Set: integrated feedback; added functional tests Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « rootdev.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/sh
2 # Copyright (C) 2010 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 #
6 # Simple functional test harness for rootdev
7 # TODO(wad) rootdev should be rewritten in C++ and gmocked.
8
9 set -u
10
11 warn () {
12 echo "WARN: $@" 1>&2
13 }
14
15 error () {
16 echo "ERROR: $@" 1>&2
17 exit 1
18 }
19
20 PASS_COUNT=0
21 pass () {
22 echo "PASS:$1" 1>&2
23 PASS_COUNT=$((PASS_COUNT + 1))
24 return 0
25 }
26
27 FAIL_COUNT=0
28 fail () {
29 echo "FAIL:$1" 1>&2
30 FAIL_COUNT=$((FAIL_COUNT + 1))
31 return 0
32 }
33
34 WORKDIR=
35 cleanup () {
36 if [ -n "$WORKDIR" ]; then
37 rm -rf "$WORKDIR"
38 fi
39 trap - EXIT
40 }
41
42 setup () {
43 WORKDIR=$(mktemp -d rootdev_test.XXXXXXX)
44 if [ ! -d "$WORKDIR" ]; then
45 error "Failed to create temporary work dir"
46 fi
47 trap cleanup EXIT
48 }
49
50 run_test () {
51 setup
52 echo "RUN:$1" 1>&2
53 eval $1
54 ret=$?
55 cleanup
56 if [ $ret -eq 0 ]; then
57 pass $1
58 else
59 fail $1
60 fi
61 }
62
63 expect () {
64 cond="$1"
65 eval test $1
66 if [ $? -ne 0 ]; then
67 warn "expect: $1"
68 return 1
69 fi
70 return 0
71 }
72
73 if [ ! -e ./rootdev ]; then
74 error "rootdev must be in the cwd"
75 fi
76
77 if [ "$USER" != "root" ]; then
78 error "Must be run as root to use mknod ($USER)"
79 fi
80
81 t00_bad_sys_dir () {
82 out=$(./rootdev --block $WORKDIR 2>/dev/null)
83 expect "$? -ne 0" || return 1
84 expect "-z '$out'" || return 1
85 }
86 run_test t00_bad_sys_dir
87
88 h00_setup_sda_tree() {
89 local block=$1
90 local dev=$2
91 mkdir -p $block
92 mkdir -p $dev
93 mkdir -p $block/sda/sda1
94 mkdir -p $block/sda/sda2
95 echo "10:0" > $block/sda/dev
96 echo "10:1" > $block/sda/sda1/dev
97 echo "10:2" > $block/sda/sda2/dev
98 mknod $dev/sda1 b 10 1
99 mknod $dev/sda2 b 10 2
100 mknod $dev/sda b 10 0
101 }
102
103 t01_sys_dev_match () {
104 local block=$WORKDIR/sys/block
105 local dev=$WORKDIR/dev
106 h00_setup_sda_tree $block $dev
107
108 out=$(./rootdev --dev $dev --block $block --major 10 --minor 1 2>/dev/null)
109 expect "$? -eq 0" || return 1
110 expect "'$dev/sda1' = '$out'" || return 1
111 }
112 run_test t01_sys_dev_match
113
114 t02_sys_dev_match_block () {
115 local block=$WORKDIR/sys/block
116 local dev=$WORKDIR/dev
117 h00_setup_sda_tree $block $dev
118
119 out=$(./rootdev --dev $dev --block $block --major 10 --minor 0 2>/dev/null)
120 expect "$? -eq 0" || return 1
121 expect "'$dev/sda' = '$out'" || return 1
122 }
123 run_test t02_sys_dev_match_block
124
125 t03_sys_dev_match_block_no_dev () {
126 local block=$WORKDIR/sys/block
127 local dev=$WORKDIR/dev
128 h00_setup_sda_tree $block $dev
129 rm $dev/sda
130
131 out=$(./rootdev --dev $dev --block $block --major 10 --minor 0 2>/dev/null)
132 expect "$? -eq 1" || return 1
133 expect "'$dev/sda' = '$out'" || return 1
134 }
135 run_test t03_sys_dev_match_block_no_dev
136
137 t04_sys_dev_match_block_no_dev_ignore () {
138 local block=$WORKDIR/sys/block
139 local dev=$WORKDIR/dev
140 h00_setup_sda_tree $block $dev
141 rm $dev/sda
142
143 out=$(./rootdev -i --dev $dev --block $block --major 10 --minor 0 2>/dev/null)
144 expect "$? -eq 0" || return 1
145 expect "'$dev/sda' = '$out'" || return 1
146 }
147 run_test t04_sys_dev_match_block_no_dev_ignore
148
149
150 h01_setup_dm_tree() {
151 local block=$1
152 local dev=$2
153 mkdir -p $block
154 mkdir -p $dev
155 mkdir -p $block/dm-0
156 mkdir -p $block/dm-0/slaves/sda1
157 echo "254:0" > $block/dm-0/dev
158 echo "10:1" > $block/dm-0/slaves/sda1/dev
159 mknod $dev/dm-0 b 254 0
160 }
161
162 t05_match_dm () {
163 local block=$WORKDIR/sys/block
164 local dev=$WORKDIR/dev
165 h00_setup_sda_tree $block $dev
166 h01_setup_dm_tree $block $dev
167
168 out=$(./rootdev --dev $dev --block $block --major 254 --minor 0 \
169 2>/dev/null)
170 expect "$? -eq 0" || return 1
171 expect "'$dev/dm-0' = '$out'" || return 1
172 }
173 run_test t05_match_dm
174
175 t06_match_dm_slave () {
176 local block=$WORKDIR/sys/block
177 local dev=$WORKDIR/dev
178 h00_setup_sda_tree $block $dev
179 h01_setup_dm_tree $block $dev
180
181 out=$(./rootdev -s --dev $dev --block $block --major 254 --minor 0 \
182 2>/dev/null)
183 expect "$? -eq 0" || return 1
184 expect "'$dev/sda1' = '$out'" || return 1
185 }
186 run_test t06_match_dm_slave
187
188 t07_safe_fail_on_no_slave () {
189 local block=$WORKDIR/sys/block
190 local dev=$WORKDIR/dev
191 h00_setup_sda_tree $block $dev
192 h01_setup_dm_tree $block $dev
193
194 out=$(./rootdev -s --dev $dev --block $block --major 10 --minor 1 \
195 2>/dev/null)
196 expect "$? -eq 0" || return 1
197 expect "'$dev/sda1' = '$out'" || return 1
198 }
199 run_test t07_safe_fail_on_no_slave
200
201 t08_safe_fail_on_no_slave_dev () {
202 local block=$WORKDIR/sys/block
203 local dev=$WORKDIR/dev
204 h00_setup_sda_tree $block $dev
205 h01_setup_dm_tree $block $dev
206 # If the matching dev node is missing, an error code will be returned
207 # but the path will still represent the slave.
208 rm $dev/sda1
209
210 out=$(./rootdev -s --dev $dev --block $block --major 254 --minor 0 \
211 2>/dev/null)
212 expect "$? -eq 1" || return 1
213 expect "'$dev/sda1' = '$out'" || return 1
214 }
215 run_test t08_safe_fail_on_no_slave_dev
216
217 t09_safe_fail_on_no_slave_dev_ignore () {
218 local block=$WORKDIR/sys/block
219 local dev=$WORKDIR/dev
220 h00_setup_sda_tree $block $dev
221 h01_setup_dm_tree $block $dev
222 # If the matching dev node is missing, an error code will be returned
223 # but the path will still represent the slave.
224 rm $dev/sda1
225
226 out=$(./rootdev -i -s --dev $dev --block $block --major 254 --minor 0 \
227 2>/dev/null)
228 expect "$? -eq 0" || return 1
229 expect "'$dev/sda1' = '$out'" || return 1
230 }
231 run_test t09_safe_fail_on_no_slave_dev_ignore
232
233 h02_setup_mmc_tree() {
234 local block=$1
235 local dev=$2
236 mkdir -p $block
237 mkdir -p $dev
238 mkdir -p $block/mmcblk0/mmcblk0p1
239 mkdir -p $block/mmcblk0/mmcblk0p2
240 echo "11:0" > $block/mmcblk0/dev
241 echo "11:1" > $block/mmcblk0/mmcblk0p1/dev
242 echo "11:2" > $block/mmcblk0/mmcblk0p2/dev
243 mknod $dev/mmcblk0 b 11 0
244 mknod $dev/mmcblk0p1 b 11 1
245 mknod $dev/mmcblk0p2 b 11 2
246 }
247
248 t10_mmcdev () {
249 local block=$WORKDIR/sys/block
250 local dev=$WORKDIR/dev
251 h02_setup_mmc_tree $block $dev
252 out=$(./rootdev --dev $dev --block $block --major 11 --minor 2 \
253 2>/dev/null)
254 expect "$? -eq 0" || return 1
255 expect "'$dev/mmcblk0p2' = '$out'" || return 1
256 }
257 run_test t10_mmcdev
258
259 t11_mmcdev_strip () {
260 local block=$WORKDIR/sys/block
261 local dev=$WORKDIR/dev
262 h02_setup_mmc_tree $block $dev
263 out=$(./rootdev -d --dev $dev --block $block --major 11 --minor 2 \
264 2>/dev/null)
265 expect "$? -eq 0" || return 1
266 expect "'$dev/mmcblk0' = '$out'" || return 1
267 }
268 run_test t11_mmcdev_strip
269
270 t12_sda_strip () {
271 local block=$WORKDIR/sys/block
272 local dev=$WORKDIR/dev
273 h00_setup_sda_tree $block $dev
274 out=$(./rootdev -d --dev $dev --block $block --major 10 --minor 2 \
275 2>/dev/null)
276 expect "$? -eq 0" || return 1
277 expect "'$dev/sda' = '$out'" || return 1
278 }
279 run_test t12_sda_strip
280
281 # TODO(wad) add node creation tests
282
283 TEST_COUNT=$((PASS_COUNT + FAIL_COUNT))
284
285 echo "----"
286 echo "Test passed: $PASS_COUNT / $TEST_COUNT"
287 echo "Test failed: $FAIL_COUNT / $TEST_COUNT"
288
289 if [ $FAIL_COUNT -ne 0 ]; then
290 exit 1
291 fi
OLDNEW
« no previous file with comments | « rootdev.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698