]>
Commit | Line | Data |
---|---|---|
a367f04e GKH |
1 | #!/usr/bin/perl |
2 | ||
3 | # udev-test | |
4 | # | |
5 | # Provides automated testing of the udev binary. | |
6 | # The whole test is self contained in this file, except the matching sysfs tree. | |
7 | # Simply extend the @tests array, to add a new test variant. | |
8 | # | |
9 | # Every test is driven by its own temporary config file. | |
10 | # This program prepares the environment, creates the config and calls udev. | |
11 | # | |
12 | # udev reads the config, looks at the provided sysfs and | |
13 | # first creates and then removes the device node. | |
14 | # After creation and removal the result is checked against the | |
15 | # expected value and the result is printed. | |
16 | # | |
17 | # happy testing, | |
18 | # Kay Sievers <kay.sievers@vrfy.org>, 2003 | |
19 | ||
20 | ||
21 | use warnings; | |
22 | use strict; | |
23 | ||
f8f00338 | 24 | my $PWD = $ENV{PWD}; |
a367f04e GKH |
25 | my $sysfs = "sys/"; |
26 | my $udev_bin = "../udev"; | |
27 | my $udev_root = "udev-root/"; # !!! directory will be removed !!! | |
36043f84 | 28 | my $udev_db = ".udev.tdb"; |
a367f04e | 29 | my $perm = "udev.permissions"; |
72ffa78d GKH |
30 | my $main_conf = "udev-test.conf"; |
31 | my $conf_tmp = "udev-test.rules"; | |
a367f04e GKH |
32 | |
33 | ||
34 | my @tests = ( | |
35 | { | |
36 | desc => "label test of scsi disc", | |
37 | subsys => "block", | |
38 | devpath => "block/sda", | |
39 | expected => "boot_disk" , | |
40 | conf => <<EOF | |
16378373 | 41 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n" |
ac28b86d | 42 | KERNEL="ttyUSB0", NAME="visor" |
a367f04e GKH |
43 | EOF |
44 | }, | |
45 | { | |
46 | desc => "label test of scsi partition", | |
47 | subsys => "block", | |
48 | devpath => "block/sda/sda1", | |
49 | expected => "boot_disk1" , | |
50 | conf => <<EOF | |
16378373 | 51 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n" |
83be97ba KS |
52 | EOF |
53 | }, | |
54 | { | |
55 | desc => "label test of pattern match", | |
56 | subsys => "block", | |
57 | devpath => "block/sda/sda1", | |
58 | expected => "boot_disk1" , | |
59 | conf => <<EOF | |
16378373 KS |
60 | BUS="scsi", SYSFS{vendor}="?IBM-ESXS", NAME="boot_disk%n-1" |
61 | BUS="scsi", SYSFS{vendor}="IBM-ESXS?", NAME="boot_disk%n-2" | |
62 | BUS="scsi", SYSFS{vendor}="IBM-ES??", NAME="boot_disk%n" | |
63 | BUS="scsi", SYSFS{vendor}="IBM-ESXSS", NAME="boot_disk%n-3" | |
358c8c20 GKH |
64 | EOF |
65 | }, | |
66 | { | |
67 | desc => "label test of multiple sysfs files", | |
68 | subsys => "block", | |
69 | devpath => "block/sda/sda1", | |
70 | expected => "boot_disk1" , | |
71 | conf => <<EOF | |
16378373 KS |
72 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_diskX%n" |
73 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_disk%n" | |
358c8c20 GKH |
74 | EOF |
75 | }, | |
76 | { | |
77 | desc => "label test of max sysfs files", | |
78 | subsys => "block", | |
79 | devpath => "block/sda/sda1", | |
80 | expected => "boot_disk1" , | |
81 | conf => <<EOF | |
16378373 KS |
82 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="2", SYSFS{queue_depth}="32", NAME="boot_diskXX%n" |
83 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="0", NAME="boot_disk%n" | |
0db6d4cc KS |
84 | EOF |
85 | }, | |
86 | { | |
9f1da361 | 87 | desc => "catch device by *", |
0db6d4cc KS |
88 | subsys => "tty", |
89 | devpath => "class/tty/ttyUSB0", | |
90 | expected => "visor/0" , | |
91 | conf => <<EOF | |
ac28b86d | 92 | KERNEL="ttyUSB*", NAME="visor/%n" |
2e317184 GKH |
93 | EOF |
94 | }, | |
95 | { | |
96 | desc => "catch device by * - take 2", | |
97 | subsys => "tty", | |
98 | devpath => "class/tty/ttyUSB0", | |
99 | expected => "visor/0" , | |
100 | conf => <<EOF | |
101 | KERNEL="*USB1", NAME="bad" | |
102 | KERNEL="*USB0", NAME="visor/%n" | |
9f1da361 KS |
103 | EOF |
104 | }, | |
105 | { | |
106 | desc => "catch device by ?", | |
107 | subsys => "tty", | |
108 | devpath => "class/tty/ttyUSB0", | |
109 | expected => "visor/0" , | |
110 | conf => <<EOF | |
ac28b86d KS |
111 | KERNEL="ttyUSB??*", NAME="visor/%n-1" |
112 | KERNEL="ttyUSB??", NAME="visor/%n-2" | |
113 | KERNEL="ttyUSB?", NAME="visor/%n" | |
9f1da361 KS |
114 | EOF |
115 | }, | |
116 | { | |
117 | desc => "catch device by character class", | |
118 | subsys => "tty", | |
119 | devpath => "class/tty/ttyUSB0", | |
120 | expected => "visor/0" , | |
121 | conf => <<EOF | |
ac28b86d KS |
122 | KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1" |
123 | KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2" | |
124 | KERNEL="ttyUSB[0-9]*", NAME="visor/%n" | |
a367f04e GKH |
125 | EOF |
126 | }, | |
127 | { | |
128 | desc => "replace kernel name", | |
129 | subsys => "tty", | |
130 | devpath => "class/tty/ttyUSB0", | |
131 | expected => "visor" , | |
132 | conf => <<EOF | |
ac28b86d | 133 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
134 | EOF |
135 | }, | |
136 | { | |
137 | desc => "Handle comment lines in config file (and replace kernel name)", | |
138 | subsys => "tty", | |
139 | devpath => "class/tty/ttyUSB0", | |
140 | expected => "visor" , | |
141 | conf => <<EOF | |
142 | # this is a comment | |
ac28b86d | 143 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
144 | |
145 | EOF | |
146 | }, | |
147 | { | |
148 | desc => "Handle comment lines in config file with whitespace (and replace kernel name)", | |
149 | subsys => "tty", | |
150 | devpath => "class/tty/ttyUSB0", | |
151 | expected => "visor" , | |
152 | conf => <<EOF | |
153 | # this is a comment with whitespace before the comment | |
ac28b86d | 154 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
155 | |
156 | EOF | |
157 | }, | |
158 | { | |
159 | desc => "Handle empty lines in config file (and replace kernel name)", | |
160 | subsys => "tty", | |
161 | devpath => "class/tty/ttyUSB0", | |
162 | expected => "visor" , | |
163 | conf => <<EOF | |
164 | ||
ac28b86d | 165 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a | 166 | |
5499d319 KS |
167 | EOF |
168 | }, | |
169 | { | |
170 | desc => "subdirectory handling", | |
171 | subsys => "tty", | |
172 | devpath => "class/tty/ttyUSB0", | |
173 | expected => "sub/direct/ory/visor" , | |
174 | conf => <<EOF | |
ac28b86d | 175 | KERNEL="ttyUSB0", NAME="sub/direct/ory/visor" |
a367f04e GKH |
176 | EOF |
177 | }, | |
178 | { | |
179 | desc => "place on bus of scsi partition", | |
180 | subsys => "block", | |
181 | devpath => "block/sda/sda3", | |
182 | expected => "first_disk3" , | |
183 | conf => <<EOF | |
ac28b86d | 184 | BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n" |
a367f04e GKH |
185 | EOF |
186 | }, | |
187 | { | |
188 | desc => "test NAME substitution chars", | |
189 | subsys => "block", | |
190 | devpath => "block/sda/sda3", | |
191 | expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , | |
192 | conf => <<EOF | |
ac28b86d | 193 | BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b" |
63ead27c KS |
194 | EOF |
195 | }, | |
196 | { | |
197 | desc => "test NAME substitution chars (with length limit)", | |
198 | subsys => "block", | |
199 | devpath => "block/sda/sda3", | |
200 | expected => "M8-m3-n3-b0:0-sIBM" , | |
201 | conf => <<EOF | |
202 | BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}" | |
59525115 GKH |
203 | EOF |
204 | }, | |
205 | { | |
206 | desc => "old style SYSFS_ attribute", | |
207 | subsys => "block", | |
208 | devpath => "block/sda", | |
209 | expected => "good" , | |
210 | conf => <<EOF | |
211 | BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="good" | |
a27cd06c KS |
212 | EOF |
213 | }, | |
214 | { | |
215 | desc => "sustitution of sysfs value (%s{file})", | |
216 | subsys => "block", | |
217 | devpath => "block/sda", | |
218 | expected => "disk-IBM-ESXS-sda" , | |
219 | conf => <<EOF | |
16378373 | 220 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k" |
a27cd06c | 221 | KERNEL="ttyUSB0", NAME="visor" |
a367f04e GKH |
222 | EOF |
223 | }, | |
224 | { | |
ac28b86d | 225 | desc => "program result substitution", |
a367f04e GKH |
226 | subsys => "block", |
227 | devpath => "block/sda/sda3", | |
228 | expected => "special-device-3" , | |
229 | conf => <<EOF | |
ac28b86d KS |
230 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="-special-*", NAME="%c-1-%n" |
231 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c-2-%n" | |
232 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n" | |
233 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n" | |
234 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n" | |
f3b04a2e GKH |
235 | EOF |
236 | }, | |
237 | { | |
ac28b86d | 238 | desc => "program result substitution", |
f3b04a2e GKH |
239 | subsys => "block", |
240 | devpath => "block/sda/sda3", | |
241 | expected => "test-0:0:0:0" , | |
242 | conf => <<EOF | |
ac28b86d | 243 | BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c" |
8ffb636f KS |
244 | EOF |
245 | }, | |
246 | { | |
247 | desc => "program with escaped format char (tricky: callout returns format char!)", | |
248 | subsys => "block", | |
249 | devpath => "block/sda/sda3", | |
250 | expected => "escape-3" , | |
251 | conf => <<EOF | |
252 | BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c" | |
dde05ccb GKH |
253 | EOF |
254 | }, | |
255 | { | |
256 | desc => "program with lots of arguments", | |
257 | subsys => "block", | |
258 | devpath => "block/sda/sda3", | |
259 | expected => "foo9" , | |
260 | conf => <<EOF | |
261 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}" | |
56c963dc PM |
262 | EOF |
263 | }, | |
264 | { | |
265 | desc => "characters before the %c{N} substitution", | |
266 | subsys => "block", | |
267 | devpath => "block/sda/sda3", | |
268 | expected => "my-foo9" , | |
269 | conf => <<EOF | |
270 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}" | |
271 | EOF | |
272 | }, | |
273 | { | |
274 | desc => "substitute the second to last argument", | |
275 | subsys => "block", | |
276 | devpath => "block/sda/sda3", | |
277 | expected => "my-foo8" , | |
278 | conf => <<EOF | |
279 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}" | |
b1c5e333 KS |
280 | EOF |
281 | }, | |
282 | { | |
ac28b86d | 283 | desc => "program result substitution (numbered part of)", |
b1c5e333 KS |
284 | subsys => "block", |
285 | devpath => "block/sda/sda3", | |
286 | expected => "link1" , | |
287 | conf => <<EOF | |
88f09368 | 288 | BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}" |
8ff8bbba GKH |
289 | EOF |
290 | }, | |
291 | { | |
ac28b86d | 292 | desc => "invalid program for device with no bus", |
8ff8bbba GKH |
293 | subsys => "tty", |
294 | devpath => "class/tty/console", | |
295 | expected => "TTY" , | |
296 | conf => <<EOF | |
ac28b86d KS |
297 | BUS="scsi", PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo" |
298 | KERNEL="console", NAME="TTY" | |
1d936fbc GKH |
299 | EOF |
300 | }, | |
301 | { | |
ac28b86d | 302 | desc => "valid program for device with no bus", |
1d936fbc GKH |
303 | subsys => "tty", |
304 | devpath => "class/tty/console", | |
305 | expected => "foo" , | |
306 | conf => <<EOF | |
ac28b86d KS |
307 | PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo" |
308 | KERNEL="console", NAME="TTY" | |
64682333 GKH |
309 | EOF |
310 | }, | |
311 | { | |
312 | desc => "invalid label for device with no bus", | |
313 | subsys => "tty", | |
314 | devpath => "class/tty/console", | |
315 | expected => "TTY" , | |
316 | conf => <<EOF | |
16378373 | 317 | BUS="foo", SYSFS{dev}="5:1", NAME="foo" |
ac28b86d | 318 | KERNEL="console", NAME="TTY" |
64682333 GKH |
319 | EOF |
320 | }, | |
321 | { | |
322 | desc => "valid label for device with no bus", | |
323 | subsys => "tty", | |
324 | devpath => "class/tty/console", | |
325 | expected => "foo" , | |
326 | conf => <<EOF | |
16378373 | 327 | SYSFS{dev}="5:1", NAME="foo" |
ac28b86d | 328 | KERNEL="console", NAME="TTY" |
772558f4 GKH |
329 | EOF |
330 | }, | |
331 | { | |
ac28b86d | 332 | desc => "program and bus type match", |
772558f4 GKH |
333 | subsys => "block", |
334 | devpath => "block/sda", | |
335 | expected => "scsi-0:0:0:0" , | |
336 | conf => <<EOF | |
ac28b86d KS |
337 | BUS="usb", PROGRAM="/bin/echo -n usb-%b", NAME="%c" |
338 | BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", NAME="%c" | |
339 | BUS="foo", PROGRAM="/bin/echo -n foo-%b", NAME="%c" | |
3d150dfb KS |
340 | EOF |
341 | }, | |
342 | { | |
343 | desc => "symlink creation (same directory)", | |
344 | subsys => "tty", | |
345 | devpath => "class/tty/ttyUSB0", | |
346 | expected => "visor0" , | |
347 | conf => <<EOF | |
ac28b86d | 348 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n" |
3d150dfb KS |
349 | EOF |
350 | }, | |
351 | { | |
352 | desc => "symlink creation (relative link back)", | |
353 | subsys => "block", | |
354 | devpath => "block/sda/sda2", | |
355 | expected => "1/2/a/b/symlink" , | |
356 | conf => <<EOF | |
16378373 | 357 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/node", SYMLINK="1/2/a/b/symlink" |
3d150dfb KS |
358 | EOF |
359 | }, | |
360 | { | |
361 | desc => "symlink creation (relative link forward)", | |
362 | subsys => "block", | |
363 | devpath => "block/sda/sda2", | |
364 | expected => "1/2/symlink" , | |
365 | conf => <<EOF | |
16378373 | 366 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink" |
3d150dfb KS |
367 | EOF |
368 | }, | |
369 | { | |
370 | desc => "symlink creation (relative link back and forward)", | |
371 | subsys => "block", | |
372 | devpath => "block/sda/sda2", | |
373 | expected => "1/2/c/d/symlink" , | |
374 | conf => <<EOF | |
16378373 | 375 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink" |
4763256c KS |
376 | EOF |
377 | }, | |
378 | { | |
379 | desc => "multiple symlinks", | |
380 | subsys => "tty", | |
381 | devpath => "class/tty/ttyUSB0", | |
382 | expected => "second-0" , | |
383 | conf => <<EOF | |
ac28b86d | 384 | KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n" |
724257d9 GKH |
385 | EOF |
386 | }, | |
387 | { | |
50e5de03 KS |
388 | desc => "create all possible partitions", |
389 | subsys => "block", | |
390 | devpath => "block/sda", | |
391 | expected => "boot_disk15" , | |
392 | conf => <<EOF | |
16378373 | 393 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME{all_partitions}="boot_disk" |
50e5de03 KS |
394 | EOF |
395 | }, | |
396 | { | |
397 | desc => "sysfs parent hierarchy", | |
724257d9 GKH |
398 | subsys => "tty", |
399 | devpath => "class/tty/ttyUSB0", | |
400 | expected => "visor" , | |
401 | conf => <<EOF | |
16378373 | 402 | SYSFS{idProduct}="2008", NAME="visor" |
f0142622 GKH |
403 | EOF |
404 | }, | |
405 | { | |
406 | desc => "name test with ! in the name", | |
407 | subsys => "block", | |
408 | devpath => "block/rd!c0d0", | |
409 | expected => "rd/c0d0" , | |
410 | conf => <<EOF | |
411 | BUS="scsi", NAME="%k" | |
412 | KERNEL="ttyUSB0", NAME="visor" | |
b9fc973b GKH |
413 | EOF |
414 | }, | |
415 | { | |
416 | desc => "name test with ! in the name, but no matching rule", | |
417 | subsys => "block", | |
418 | devpath => "block/rd!c0d0", | |
419 | expected => "rd/c0d0" , | |
420 | conf => <<EOF | |
421 | KERNEL="ttyUSB0", NAME="visor" | |
93656247 PM |
422 | EOF |
423 | }, | |
424 | { | |
425 | desc => "ID rule", | |
426 | subsys => "block", | |
427 | devpath => "block/sda", | |
428 | expected => "scsi-0:0:0:0", | |
429 | conf => <<EOF | |
430 | BUS="usb", ID="0:0:0:0", NAME="not-scsi" | |
431 | BUS="scsi", ID="0:0:0:1", NAME="no-match" | |
432 | BUS="scsi", ID=":0", NAME="short-id" | |
433 | BUS="scsi", ID="/0:0:0:0", NAME="no-match" | |
434 | BUS="scsi", ID="0:0:0:0", NAME="scsi-0:0:0:0" | |
435 | EOF | |
436 | }, | |
437 | { | |
438 | desc => "ID wildcard all", | |
439 | subsys => "block", | |
440 | devpath => "block/sda", | |
441 | expected => "scsi-0:0:0:0", | |
442 | conf => <<EOF | |
443 | BUS="scsi", ID="*:1", NAME="no-match" | |
444 | BUS="scsi", ID="*:0:1", NAME="no-match" | |
445 | BUS="scsi", ID="*:0:0:1", NAME="no-match" | |
446 | BUS="scsi", ID="*", NAME="scsi-0:0:0:0" | |
447 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
448 | EOF | |
449 | }, | |
450 | { | |
451 | desc => "ID wildcard partial", | |
452 | subsys => "block", | |
453 | devpath => "block/sda", | |
454 | expected => "scsi-0:0:0:0", | |
455 | conf => <<EOF | |
456 | BUS="scsi", ID="*:0", NAME="scsi-0:0:0:0" | |
457 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
458 | EOF | |
459 | }, | |
460 | { | |
461 | desc => "ID wildcard partial 2", | |
462 | subsys => "block", | |
463 | devpath => "block/sda", | |
464 | expected => "scsi-0:0:0:0", | |
465 | conf => <<EOF | |
466 | BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0" | |
467 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
a367f04e GKH |
468 | EOF |
469 | }, | |
470 | ); | |
471 | ||
472 | # set env | |
473 | $ENV{UDEV_TEST} = "yes"; | |
474 | $ENV{SYSFS_PATH} = $sysfs; | |
72ffa78d | 475 | $ENV{UDEV_CONFIG_FILE} = $main_conf; |
a367f04e GKH |
476 | |
477 | ||
478 | sub udev { | |
479 | my ($action, $subsys, $devpath, $config) = @_; | |
480 | ||
481 | $ENV{DEVPATH} = $devpath; | |
a367f04e GKH |
482 | |
483 | # create temporary config | |
484 | open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp"; | |
485 | print CONF $$config; | |
486 | close CONF; | |
487 | ||
488 | $ENV{ACTION} = $action; | |
489 | system("$udev_bin $subsys"); | |
490 | } | |
491 | ||
e5fbfe0a | 492 | my $error = 0; |
72ffa78d | 493 | |
2e317184 GKH |
494 | sub run_test { |
495 | my ($config, $number) = @_; | |
496 | ||
497 | print "TEST $number: $config->{desc}\n"; | |
ac28b86d | 498 | print "device \'$config->{devpath}\' expecting node \'$config->{expected}\'\n"; |
a367f04e GKH |
499 | |
500 | udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf}); | |
501 | if (-e "$PWD/$udev_root$config->{expected}") { | |
502 | print "add: ok "; | |
503 | } else { | |
504 | print "add: error\n"; | |
505 | system("tree $udev_root"); | |
506 | print "\n"; | |
507 | $error++; | |
a367f04e GKH |
508 | } |
509 | ||
510 | udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf}); | |
3d150dfb KS |
511 | if ((-e "$PWD/$udev_root$config->{expected}") || |
512 | (-l "$PWD/$udev_root$config->{expected}")) { | |
a367f04e GKH |
513 | print "remove: error\n\n"; |
514 | system("tree $udev_root"); | |
515 | $error++; | |
516 | } else { | |
517 | print "remove: ok\n\n"; | |
518 | } | |
519 | } | |
520 | ||
2e317184 GKH |
521 | # prepare |
522 | system("rm -rf $udev_root"); | |
523 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
524 | ||
525 | # create initial config file | |
526 | open CONF, ">$main_conf" || die "unable to create config file: $main_conf"; | |
527 | print CONF "udev_root=\"$udev_root\"\n"; | |
528 | print CONF "udev_db=\"$udev_db\"\n"; | |
529 | print CONF "udev_rules=\"$conf_tmp\"\n"; | |
530 | print CONF "udev_permissions=\"$perm\"\n"; | |
531 | close CONF; | |
532 | ||
533 | my $test_num = 1; | |
534 | ||
535 | if ($ARGV[0]) { | |
536 | # only run one test | |
537 | $test_num = $ARGV[0]; | |
538 | print "udev-test will run test number $test_num only\n"; | |
539 | ||
b9fc973b | 540 | run_test($tests[$test_num-1], $test_num); |
2e317184 GKH |
541 | } else { |
542 | # test all | |
543 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; | |
544 | ||
545 | foreach my $config (@tests) { | |
546 | run_test($config, $test_num); | |
547 | $test_num++; | |
548 | ||
549 | } | |
550 | } | |
551 | ||
a367f04e GKH |
552 | print "$error errors occured\n\n"; |
553 | ||
554 | # cleanup | |
36043f84 | 555 | unlink($udev_db); |
a367f04e GKH |
556 | system("rm -rf $udev_root"); |
557 | unlink($conf_tmp); | |
72ffa78d | 558 | unlink($main_conf); |
a367f04e | 559 |