]>
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 | |
b8669191 GKH |
19 | # |
20 | # Modified April 9, 2004 by Leann Ogasawara <ogasawara@osdl.org> | |
21 | # - expanded @tests array to add more symlinks and permissions tests | |
22 | # - some of the symlinks tests also test lack of node creation | |
23 | # - added symlink_test() function | |
24 | # - moved permissions and major_minor tests into their own functions | |
a367f04e GKH |
25 | |
26 | use warnings; | |
27 | use strict; | |
28 | ||
f8f00338 | 29 | my $PWD = $ENV{PWD}; |
a367f04e GKH |
30 | my $sysfs = "sys/"; |
31 | my $udev_bin = "../udev"; | |
32 | my $udev_root = "udev-root/"; # !!! directory will be removed !!! | |
36043f84 | 33 | my $udev_db = ".udev.tdb"; |
a367f04e | 34 | my $perm = "udev.permissions"; |
72ffa78d GKH |
35 | my $main_conf = "udev-test.conf"; |
36 | my $conf_tmp = "udev-test.rules"; | |
a367f04e GKH |
37 | |
38 | ||
39 | my @tests = ( | |
40 | { | |
fa19f181 KS |
41 | desc => "label test of scsi disc", |
42 | subsys => "block", | |
f61d732a | 43 | devpath => "/block/sda", |
c013b034 | 44 | exp_name => "boot_disk" , |
fa19f181 | 45 | conf => <<EOF |
16378373 | 46 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n" |
ac28b86d | 47 | KERNEL="ttyUSB0", NAME="visor" |
a367f04e GKH |
48 | EOF |
49 | }, | |
50 | { | |
fa19f181 KS |
51 | desc => "label test of scsi partition", |
52 | subsys => "block", | |
f61d732a | 53 | devpath => "/block/sda/sda1", |
c013b034 | 54 | exp_name => "boot_disk1" , |
fa19f181 | 55 | conf => <<EOF |
16378373 | 56 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n" |
83be97ba KS |
57 | EOF |
58 | }, | |
59 | { | |
fa19f181 KS |
60 | desc => "label test of pattern match", |
61 | subsys => "block", | |
f61d732a | 62 | devpath => "/block/sda/sda1", |
c013b034 | 63 | exp_name => "boot_disk1" , |
fa19f181 | 64 | conf => <<EOF |
16378373 KS |
65 | BUS="scsi", SYSFS{vendor}="?IBM-ESXS", NAME="boot_disk%n-1" |
66 | BUS="scsi", SYSFS{vendor}="IBM-ESXS?", NAME="boot_disk%n-2" | |
67 | BUS="scsi", SYSFS{vendor}="IBM-ES??", NAME="boot_disk%n" | |
68 | BUS="scsi", SYSFS{vendor}="IBM-ESXSS", NAME="boot_disk%n-3" | |
358c8c20 GKH |
69 | EOF |
70 | }, | |
71 | { | |
fa19f181 KS |
72 | desc => "label test of multiple sysfs files", |
73 | subsys => "block", | |
f61d732a | 74 | devpath => "/block/sda/sda1", |
fa19f181 KS |
75 | exp_name => "boot_disk1" , |
76 | conf => <<EOF | |
16378373 KS |
77 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_diskX%n" |
78 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_disk%n" | |
358c8c20 GKH |
79 | EOF |
80 | }, | |
81 | { | |
fa19f181 KS |
82 | desc => "label test of max sysfs files", |
83 | subsys => "block", | |
f61d732a | 84 | devpath => "/block/sda/sda1", |
fa19f181 KS |
85 | exp_name => "boot_disk1" , |
86 | conf => <<EOF | |
16378373 KS |
87 | 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" |
88 | 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 |
89 | EOF |
90 | }, | |
91 | { | |
fa19f181 KS |
92 | desc => "catch device by *", |
93 | subsys => "tty", | |
f61d732a | 94 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
95 | exp_name => "visor/0" , |
96 | conf => <<EOF | |
ac28b86d | 97 | KERNEL="ttyUSB*", NAME="visor/%n" |
2e317184 GKH |
98 | EOF |
99 | }, | |
100 | { | |
fa19f181 KS |
101 | desc => "catch device by * - take 2", |
102 | subsys => "tty", | |
f61d732a | 103 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
104 | exp_name => "visor/0" , |
105 | conf => <<EOF | |
2e317184 GKH |
106 | KERNEL="*USB1", NAME="bad" |
107 | KERNEL="*USB0", NAME="visor/%n" | |
9f1da361 KS |
108 | EOF |
109 | }, | |
110 | { | |
fa19f181 KS |
111 | desc => "catch device by ?", |
112 | subsys => "tty", | |
f61d732a | 113 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
114 | exp_name => "visor/0" , |
115 | conf => <<EOF | |
ac28b86d KS |
116 | KERNEL="ttyUSB??*", NAME="visor/%n-1" |
117 | KERNEL="ttyUSB??", NAME="visor/%n-2" | |
118 | KERNEL="ttyUSB?", NAME="visor/%n" | |
9f1da361 KS |
119 | EOF |
120 | }, | |
121 | { | |
fa19f181 KS |
122 | desc => "catch device by character class", |
123 | subsys => "tty", | |
f61d732a | 124 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
125 | exp_name => "visor/0" , |
126 | conf => <<EOF | |
ac28b86d KS |
127 | KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1" |
128 | KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2" | |
129 | KERNEL="ttyUSB[0-9]*", NAME="visor/%n" | |
a367f04e GKH |
130 | EOF |
131 | }, | |
132 | { | |
fa19f181 KS |
133 | desc => "replace kernel name", |
134 | subsys => "tty", | |
f61d732a | 135 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
136 | exp_name => "visor" , |
137 | conf => <<EOF | |
ac28b86d | 138 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
139 | EOF |
140 | }, | |
141 | { | |
fa19f181 KS |
142 | desc => "Handle comment lines in config file (and replace kernel name)", |
143 | subsys => "tty", | |
f61d732a | 144 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
145 | exp_name => "visor" , |
146 | conf => <<EOF | |
281ff00a | 147 | # this is a comment |
ac28b86d | 148 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
149 | |
150 | EOF | |
151 | }, | |
152 | { | |
fa19f181 KS |
153 | desc => "Handle comment lines in config file with whitespace (and replace kernel name)", |
154 | subsys => "tty", | |
f61d732a | 155 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
156 | exp_name => "visor" , |
157 | conf => <<EOF | |
281ff00a | 158 | # this is a comment with whitespace before the comment |
ac28b86d | 159 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a | 160 | |
3db7fa27 KS |
161 | EOF |
162 | }, | |
163 | { | |
164 | desc => "Handle whitespace only lines (and replace kernel name)", | |
165 | subsys => "tty", | |
166 | devpath => "/class/tty/ttyUSB0", | |
167 | exp_name => "whitespace" , | |
168 | conf => <<EOF | |
169 | ||
170 | ||
171 | ||
172 | # this is a comment with whitespace before the comment | |
173 | KERNEL="ttyUSB0", NAME="whitespace" | |
174 | ||
175 | ||
176 | ||
281ff00a GKH |
177 | EOF |
178 | }, | |
179 | { | |
fa19f181 KS |
180 | desc => "Handle empty lines in config file (and replace kernel name)", |
181 | subsys => "tty", | |
f61d732a | 182 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
183 | exp_name => "visor" , |
184 | conf => <<EOF | |
281ff00a | 185 | |
ac28b86d | 186 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a | 187 | |
5499d319 KS |
188 | EOF |
189 | }, | |
190 | { | |
fa19f181 KS |
191 | desc => "subdirectory handling", |
192 | subsys => "tty", | |
f61d732a | 193 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
194 | exp_name => "sub/direct/ory/visor" , |
195 | conf => <<EOF | |
ac28b86d | 196 | KERNEL="ttyUSB0", NAME="sub/direct/ory/visor" |
a367f04e GKH |
197 | EOF |
198 | }, | |
199 | { | |
fa19f181 KS |
200 | desc => "place on bus of scsi partition", |
201 | subsys => "block", | |
f61d732a | 202 | devpath => "/block/sda/sda3", |
fa19f181 KS |
203 | exp_name => "first_disk3" , |
204 | conf => <<EOF | |
ac28b86d | 205 | BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n" |
a367f04e GKH |
206 | EOF |
207 | }, | |
208 | { | |
fa19f181 KS |
209 | desc => "test NAME substitution chars", |
210 | subsys => "block", | |
f61d732a | 211 | devpath => "/block/sda/sda3", |
fa19f181 KS |
212 | exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , |
213 | conf => <<EOF | |
ac28b86d | 214 | BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b" |
63ead27c KS |
215 | EOF |
216 | }, | |
217 | { | |
fa19f181 KS |
218 | desc => "test NAME substitution chars (with length limit)", |
219 | subsys => "block", | |
f61d732a | 220 | devpath => "/block/sda/sda3", |
fa19f181 KS |
221 | exp_name => "M8-m3-n3-b0:0-sIBM" , |
222 | conf => <<EOF | |
63ead27c | 223 | BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}" |
59525115 GKH |
224 | EOF |
225 | }, | |
226 | { | |
fa19f181 KS |
227 | desc => "old style SYSFS_ attribute", |
228 | subsys => "block", | |
f61d732a | 229 | devpath => "/block/sda", |
fa19f181 KS |
230 | exp_name => "good" , |
231 | conf => <<EOF | |
59525115 | 232 | BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="good" |
a27cd06c KS |
233 | EOF |
234 | }, | |
235 | { | |
fa19f181 KS |
236 | desc => "sustitution of sysfs value (%s{file})", |
237 | subsys => "block", | |
f61d732a | 238 | devpath => "/block/sda", |
fa19f181 KS |
239 | exp_name => "disk-IBM-ESXS-sda" , |
240 | conf => <<EOF | |
16378373 | 241 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k" |
a27cd06c | 242 | KERNEL="ttyUSB0", NAME="visor" |
a367f04e GKH |
243 | EOF |
244 | }, | |
245 | { | |
fa19f181 KS |
246 | desc => "program result substitution", |
247 | subsys => "block", | |
f61d732a | 248 | devpath => "/block/sda/sda3", |
fa19f181 KS |
249 | exp_name => "special-device-3" , |
250 | conf => <<EOF | |
ac28b86d KS |
251 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="-special-*", NAME="%c-1-%n" |
252 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c-2-%n" | |
253 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n" | |
254 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n" | |
255 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n" | |
f608f8ac KS |
256 | EOF |
257 | }, | |
258 | { | |
259 | desc => "program result substitution (no argument should be subsystem)", | |
260 | subsys => "block", | |
261 | devpath => "/block/sda/sda3", | |
262 | exp_name => "subsys_block" , | |
263 | conf => <<EOF | |
264 | BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block" | |
bbbe503e KS |
265 | EOF |
266 | }, | |
267 | { | |
268 | desc => "program result substitution (newline removal)", | |
269 | subsys => "block", | |
270 | devpath => "/block/sda/sda3", | |
271 | exp_name => "newline_removed" , | |
272 | conf => <<EOF | |
273 | BUS="scsi", PROGRAM="/bin/echo test", RESULT="test", NAME="newline_removed" | |
f3b04a2e GKH |
274 | EOF |
275 | }, | |
276 | { | |
fa19f181 KS |
277 | desc => "program result substitution", |
278 | subsys => "block", | |
f61d732a | 279 | devpath => "/block/sda/sda3", |
fa19f181 KS |
280 | exp_name => "test-0:0:0:0" , |
281 | conf => <<EOF | |
ac28b86d | 282 | BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c" |
8ffb636f KS |
283 | EOF |
284 | }, | |
285 | { | |
fa19f181 KS |
286 | desc => "program with escaped format char (tricky: callout returns format char!)", |
287 | subsys => "block", | |
f61d732a | 288 | devpath => "/block/sda/sda3", |
fa19f181 KS |
289 | exp_name => "escape-3" , |
290 | conf => <<EOF | |
8ffb636f | 291 | BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c" |
dde05ccb GKH |
292 | EOF |
293 | }, | |
294 | { | |
fa19f181 KS |
295 | desc => "program with lots of arguments", |
296 | subsys => "block", | |
f61d732a | 297 | devpath => "/block/sda/sda3", |
fa19f181 KS |
298 | exp_name => "foo9" , |
299 | conf => <<EOF | |
dde05ccb | 300 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}" |
35b38379 KS |
301 | EOF |
302 | }, | |
303 | { | |
fa19f181 KS |
304 | desc => "program with subshell", |
305 | subsys => "block", | |
f61d732a | 306 | devpath => "/block/sda/sda3", |
fa19f181 KS |
307 | exp_name => "bar9" , |
308 | conf => <<EOF | |
35b38379 KS |
309 | BUS="scsi", PROGRAM="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL="sda3", NAME="%c{7}" |
310 | EOF | |
311 | }, | |
312 | { | |
fa19f181 KS |
313 | desc => "program arguments combined with apostrophes", |
314 | subsys => "block", | |
f61d732a | 315 | devpath => "/block/sda/sda3", |
fa19f181 KS |
316 | exp_name => "foo7" , |
317 | conf => <<EOF | |
35b38379 | 318 | BUS="scsi", PROGRAM="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL="sda3", NAME="%c{5}" |
56c963dc PM |
319 | EOF |
320 | }, | |
321 | { | |
fa19f181 KS |
322 | desc => "characters before the %c{N} substitution", |
323 | subsys => "block", | |
f61d732a | 324 | devpath => "/block/sda/sda3", |
fa19f181 KS |
325 | exp_name => "my-foo9" , |
326 | conf => <<EOF | |
56c963dc PM |
327 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}" |
328 | EOF | |
329 | }, | |
330 | { | |
fa19f181 KS |
331 | desc => "substitute the second to last argument", |
332 | subsys => "block", | |
f61d732a | 333 | devpath => "/block/sda/sda3", |
fa19f181 KS |
334 | exp_name => "my-foo8" , |
335 | conf => <<EOF | |
56c963dc | 336 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}" |
8ff8bbba GKH |
337 | EOF |
338 | }, | |
339 | { | |
fa19f181 KS |
340 | desc => "invalid program for device with no bus", |
341 | subsys => "tty", | |
f61d732a | 342 | devpath => "/class/tty/console", |
fa19f181 KS |
343 | exp_name => "TTY" , |
344 | conf => <<EOF | |
ac28b86d KS |
345 | BUS="scsi", PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo" |
346 | KERNEL="console", NAME="TTY" | |
1d936fbc GKH |
347 | EOF |
348 | }, | |
349 | { | |
fa19f181 KS |
350 | desc => "valid program for device with no bus", |
351 | subsys => "tty", | |
f61d732a | 352 | devpath => "/class/tty/console", |
fa19f181 KS |
353 | exp_name => "foo" , |
354 | conf => <<EOF | |
ac28b86d KS |
355 | PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo" |
356 | KERNEL="console", NAME="TTY" | |
64682333 GKH |
357 | EOF |
358 | }, | |
359 | { | |
fa19f181 KS |
360 | desc => "invalid label for device with no bus", |
361 | subsys => "tty", | |
f61d732a | 362 | devpath => "/class/tty/console", |
fa19f181 KS |
363 | exp_name => "TTY" , |
364 | conf => <<EOF | |
16378373 | 365 | BUS="foo", SYSFS{dev}="5:1", NAME="foo" |
ac28b86d | 366 | KERNEL="console", NAME="TTY" |
64682333 GKH |
367 | EOF |
368 | }, | |
369 | { | |
fa19f181 KS |
370 | desc => "valid label for device with no bus", |
371 | subsys => "tty", | |
f61d732a | 372 | devpath => "/class/tty/console", |
fa19f181 KS |
373 | exp_name => "foo" , |
374 | conf => <<EOF | |
16378373 | 375 | SYSFS{dev}="5:1", NAME="foo" |
ac28b86d | 376 | KERNEL="console", NAME="TTY" |
772558f4 GKH |
377 | EOF |
378 | }, | |
379 | { | |
fa19f181 KS |
380 | desc => "program and bus type match", |
381 | subsys => "block", | |
f61d732a | 382 | devpath => "/block/sda", |
fa19f181 KS |
383 | exp_name => "scsi-0:0:0:0" , |
384 | conf => <<EOF | |
ac28b86d KS |
385 | BUS="usb", PROGRAM="/bin/echo -n usb-%b", NAME="%c" |
386 | BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", NAME="%c" | |
387 | BUS="foo", PROGRAM="/bin/echo -n foo-%b", NAME="%c" | |
724257d9 GKH |
388 | EOF |
389 | }, | |
390 | { | |
fa19f181 KS |
391 | desc => "create all possible partitions", |
392 | subsys => "block", | |
f61d732a | 393 | devpath => "/block/sda", |
fa19f181 KS |
394 | exp_name => "boot_disk15" , |
395 | conf => <<EOF | |
16378373 | 396 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME{all_partitions}="boot_disk" |
50e5de03 KS |
397 | EOF |
398 | }, | |
399 | { | |
fa19f181 KS |
400 | desc => "sysfs parent hierarchy", |
401 | subsys => "tty", | |
f61d732a | 402 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
403 | exp_name => "visor" , |
404 | conf => <<EOF | |
16378373 | 405 | SYSFS{idProduct}="2008", NAME="visor" |
f0142622 GKH |
406 | EOF |
407 | }, | |
408 | { | |
fa19f181 KS |
409 | desc => "name test with ! in the name", |
410 | subsys => "block", | |
f61d732a | 411 | devpath => "/block/rd!c0d0", |
fa19f181 KS |
412 | exp_name => "rd/c0d0" , |
413 | conf => <<EOF | |
f0142622 GKH |
414 | BUS="scsi", NAME="%k" |
415 | KERNEL="ttyUSB0", NAME="visor" | |
b9fc973b GKH |
416 | EOF |
417 | }, | |
418 | { | |
fa19f181 KS |
419 | desc => "name test with ! in the name, but no matching rule", |
420 | subsys => "block", | |
f61d732a | 421 | devpath => "/block/rd!c0d0", |
fa19f181 KS |
422 | exp_name => "rd/c0d0" , |
423 | conf => <<EOF | |
b9fc973b | 424 | KERNEL="ttyUSB0", NAME="visor" |
0f36e68e GKH |
425 | EOF |
426 | }, | |
427 | { | |
428 | desc => "name test with ! in the name for a partition", | |
429 | subsys => "block", | |
430 | devpath => "/block/cciss!c0d0/cciss!c0d0p1", | |
431 | exp_name => "cciss/c0d0p1" , | |
432 | conf => <<EOF | |
433 | BUS="scsi", NAME="%k" | |
434 | KERNEL="ttyUSB0", NAME="visor" | |
93656247 PM |
435 | EOF |
436 | }, | |
437 | { | |
fa19f181 KS |
438 | desc => "ID rule", |
439 | subsys => "block", | |
f61d732a | 440 | devpath => "/block/sda", |
fa19f181 KS |
441 | exp_name => "scsi-0:0:0:0", |
442 | conf => <<EOF | |
93656247 PM |
443 | BUS="usb", ID="0:0:0:0", NAME="not-scsi" |
444 | BUS="scsi", ID="0:0:0:1", NAME="no-match" | |
445 | BUS="scsi", ID=":0", NAME="short-id" | |
446 | BUS="scsi", ID="/0:0:0:0", NAME="no-match" | |
447 | BUS="scsi", ID="0:0:0:0", NAME="scsi-0:0:0:0" | |
448 | EOF | |
449 | }, | |
450 | { | |
fa19f181 KS |
451 | desc => "ID wildcard all", |
452 | subsys => "block", | |
f61d732a | 453 | devpath => "/block/sda", |
fa19f181 KS |
454 | exp_name => "scsi-0:0:0:0", |
455 | conf => <<EOF | |
93656247 PM |
456 | BUS="scsi", ID="*:1", NAME="no-match" |
457 | BUS="scsi", ID="*:0:1", NAME="no-match" | |
458 | BUS="scsi", ID="*:0:0:1", NAME="no-match" | |
459 | BUS="scsi", ID="*", NAME="scsi-0:0:0:0" | |
460 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
461 | EOF | |
462 | }, | |
463 | { | |
fa19f181 KS |
464 | desc => "ID wildcard partial", |
465 | subsys => "block", | |
f61d732a | 466 | devpath => "/block/sda", |
fa19f181 KS |
467 | exp_name => "scsi-0:0:0:0", |
468 | conf => <<EOF | |
93656247 PM |
469 | BUS="scsi", ID="*:0", NAME="scsi-0:0:0:0" |
470 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
471 | EOF | |
472 | }, | |
473 | { | |
fa19f181 KS |
474 | desc => "ID wildcard partial 2", |
475 | subsys => "block", | |
f61d732a | 476 | devpath => "/block/sda", |
fa19f181 KS |
477 | exp_name => "scsi-0:0:0:0", |
478 | conf => <<EOF | |
93656247 PM |
479 | BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0" |
480 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
d5f91372 KS |
481 | EOF |
482 | }, | |
483 | { | |
fa19f181 KS |
484 | desc => "ignore SYSFS attribute whitespace", |
485 | subsys => "block", | |
f61d732a | 486 | devpath => "/block/sda", |
fa19f181 KS |
487 | exp_name => "ignored", |
488 | conf => <<EOF | |
d5f91372 KS |
489 | BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE", NAME="ignored" |
490 | EOF | |
491 | }, | |
492 | { | |
fa19f181 KS |
493 | desc => "do not ignore SYSFS attribute whitespace", |
494 | subsys => "block", | |
f61d732a | 495 | devpath => "/block/sda", |
fa19f181 KS |
496 | exp_name => "matched-with-space", |
497 | conf => <<EOF | |
d5f91372 KS |
498 | BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="wrong-to-ignore" |
499 | BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="matched-with-space" | |
0a5417a0 KS |
500 | EOF |
501 | }, | |
502 | { | |
b8669191 | 503 | desc => "permissions test", |
fa19f181 | 504 | subsys => "block", |
f61d732a | 505 | devpath => "/block/sda", |
b8669191 GKH |
506 | exp_name => "node", |
507 | exp_perms => "5000::0444", | |
fa19f181 | 508 | conf => <<EOF |
b8669191 | 509 | BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", MODE="0444" |
c612a0ac KS |
510 | EOF |
511 | }, | |
512 | { | |
b8669191 GKH |
513 | desc => "permissions ttyUSB0:root:uucp:0660", |
514 | subsys => "tty", | |
515 | devpath => "/class/tty/ttyUSB0", | |
516 | exp_name => "ttyUSB0", | |
517 | exp_perms => "0:14:0660", | |
518 | conf => <<EOF | |
519 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
520 | EOF | |
521 | }, | |
522 | { | |
523 | desc => "permissions tty0::root:0444", | |
524 | subsys => "tty", | |
525 | devpath => "/class/tty/tty0", | |
526 | exp_name => "tty0", | |
527 | exp_perms => "0:0:0444", | |
528 | conf => <<EOF | |
529 | KERNEL="tty0", NAME="tty0" | |
530 | EOF | |
531 | }, | |
532 | { | |
533 | desc => "permissions tty1:root::0555", | |
534 | subsys => "tty", | |
535 | devpath => "/class/tty/tty1", | |
536 | exp_name => "tty1", | |
537 | exp_perms => "0:0:0555", | |
538 | conf => <<EOF | |
539 | KERNEL="tty1", NAME="tty1" | |
540 | EOF | |
541 | }, | |
542 | { | |
543 | desc => "permissions tty2:::0777", | |
544 | subsys => "tty", | |
545 | devpath => "/class/tty/tty2", | |
546 | exp_name => "tty2", | |
547 | exp_perms => "0:0:0777", | |
548 | conf => <<EOF | |
549 | KERNEL="tty2", NAME="tty2" | |
550 | EOF | |
551 | }, | |
552 | { | |
553 | desc => "permissions tty3:::", | |
554 | subsys => "tty", | |
555 | devpath => "/class/tty/tty3", | |
556 | exp_name => "tty3", | |
557 | exp_perms => "0:0:0", | |
558 | conf => <<EOF | |
559 | KERNEL="tty3", NAME="tty3" | |
560 | EOF | |
561 | }, | |
562 | { | |
563 | desc => "permissions i2c-300:root:sys:0744", | |
564 | subsys => "i2c-dev", | |
565 | devpath => "/class/i2c-dev/i2c-300", | |
566 | exp_name => "i2c-300", | |
567 | exp_perms => "0:3:0744", | |
568 | conf => <<EOF | |
569 | KERNEL="i2c-300", NAME="i2c-300" | |
570 | EOF | |
571 | }, | |
572 | { | |
573 | desc => "permissions i2c-fake1:root:7:0007", | |
574 | subsys => "i2c-dev", | |
575 | devpath => "/class/i2c-dev/i2c-fake1", | |
576 | exp_name => "i2c-fake1", | |
577 | exp_perms => "0:7:0007", | |
578 | conf => <<EOF | |
579 | KERNEL="i2c-fake1", NAME="i2c-fake1" | |
580 | EOF | |
581 | }, | |
582 | { | |
583 | desc => "permissions ttyS[01]:0:5:0700", | |
584 | subsys => "tty", | |
585 | devpath => "/class/tty/ttyS1", | |
586 | exp_name => "ttyS1", | |
587 | exp_perms => "0:5:0700", | |
588 | conf => <<EOF | |
589 | KERNEL="ttyS1", NAME="ttyS1" | |
590 | EOF | |
591 | }, | |
592 | { | |
593 | desc => "permissions ttyS[4-9]:tty:5:0060", | |
594 | subsys => "tty", | |
595 | devpath => "/class/tty/ttyS7", | |
596 | exp_name => "ttyS7", | |
597 | exp_perms => "0:5:0060", | |
598 | conf => <<EOF | |
599 | KERNEL="ttyS7", NAME="ttyS7" | |
600 | EOF | |
601 | }, | |
602 | { | |
603 | desc => "permissions tty4:0:5:0707", | |
604 | subsys => "ttyS4", | |
605 | devpath => "/class/tty/tty4", | |
606 | exp_name => "tty4", | |
607 | exp_perms => "0:5:0707", | |
608 | conf => <<EOF | |
609 | KERNEL="tty4", NAME="tty4" | |
610 | EOF | |
611 | }, | |
612 | { | |
613 | desc => "permissions tty4?:0:5:0007", | |
614 | subsys => "tty", | |
615 | devpath => "/class/tty/tty44", | |
616 | exp_name => "tty44", | |
617 | exp_perms => "0:5:0007", | |
618 | conf => <<EOF | |
619 | KERNEL="tty44", NAME="tty44" | |
620 | EOF | |
621 | }, | |
622 | { | |
623 | desc => "permissions tty3[!3]:::0467", | |
624 | subsys => "tty", | |
625 | devpath => "/class/tty/tty35", | |
626 | exp_name => "tty35", | |
627 | exp_perms => "0:0:0467", | |
628 | conf => <<EOF | |
629 | KERNEL="tty35", NAME="tty35" | |
630 | EOF | |
631 | }, | |
632 | { | |
633 | desc => "permissions tty33:bad:name:0500", | |
634 | subsys => "tty", | |
635 | devpath => "/class/tty/tty33", | |
636 | exp_name => "tty33", | |
637 | exp_perms => "0:0:0500", | |
638 | conf => <<EOF | |
639 | KERNEL="tty33", NAME="tty33" | |
640 | EOF | |
641 | }, | |
642 | { | |
643 | desc => "permissions rtc:0:users:0600", | |
644 | subsys => "misc", | |
645 | devpath => "/class/misc/rtc", | |
646 | exp_name => "misc/rtc", | |
647 | exp_perms => "0:100:0600", | |
648 | conf => <<EOF | |
649 | KERNEL="rtc", NAME="misc/rtc" | |
650 | EOF | |
651 | }, | |
652 | { | |
653 | desc => "permissions misc:0:users:0600", | |
654 | subsys => "misc", | |
655 | devpath => "/class/misc/psaux", | |
656 | exp_name => "misc/psaux", | |
657 | exp_perms => "0:100:0600", | |
658 | conf => <<EOF | |
659 | KERNEL="psaux", NAME="misc/psaux" | |
660 | EOF | |
661 | }, | |
662 | { | |
663 | desc => "permissions set OWNER=5000", | |
fa19f181 | 664 | subsys => "block", |
f61d732a | 665 | devpath => "/block/sda", |
fa19f181 | 666 | exp_name => "node", |
b8669191 | 667 | exp_perms => "5000::0600", |
fa19f181 | 668 | conf => <<EOF |
b8669191 GKH |
669 | BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000" |
670 | EOF | |
671 | }, | |
672 | { | |
673 | desc => "permissions set GROUP=100", | |
674 | subsys => "block", | |
675 | devpath => "/block/sda", | |
676 | exp_name => "node", | |
677 | exp_perms => ":100:0600", | |
678 | conf => <<EOF | |
679 | BUS="scsi", KERNEL="sda", NAME="node", GROUP="100" | |
680 | EOF | |
681 | }, | |
682 | { | |
683 | desc => "permissions set mode=0777", | |
684 | subsys => "block", | |
685 | devpath => "/block/sda", | |
686 | exp_name => "node", | |
687 | exp_perms => "::0777", | |
688 | conf => <<EOF | |
689 | BUS="scsi", KERNEL="sda", NAME="node", MODE="0777" | |
690 | EOF | |
691 | }, | |
692 | { | |
693 | desc => "permissions set OWNER=5000 GROUP=100 MODE=0777", | |
694 | subsys => "block", | |
695 | devpath => "/block/sda", | |
696 | exp_name => "node", | |
697 | exp_perms => "5000:100:0777", | |
698 | conf => <<EOF | |
699 | BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777" | |
700 | EOF | |
701 | }, | |
702 | { | |
703 | desc => "permissions override OWNER to 5000", | |
704 | subsys => "tty", | |
705 | devpath => "/class/tty/ttyUSB0", | |
706 | exp_name => "ttyUSB0", | |
707 | exp_perms => "5000:14:0660", | |
708 | conf => <<EOF | |
709 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000" | |
710 | EOF | |
711 | }, | |
712 | { | |
713 | desc => "permissions override GROUP to 100", | |
714 | subsys => "tty", | |
715 | devpath => "/class/tty/ttyUSB0", | |
716 | exp_name => "ttyUSB0", | |
717 | exp_perms => ":100:0660", | |
718 | conf => <<EOF | |
719 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100" | |
720 | EOF | |
721 | }, | |
722 | { | |
723 | desc => "permissions override MODE to 0060", | |
724 | subsys => "tty", | |
725 | devpath => "/class/tty/ttyUSB0", | |
726 | exp_name => "ttyUSB0", | |
727 | exp_perms => ":14:0060", | |
728 | conf => <<EOF | |
729 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060" | |
730 | EOF | |
731 | }, | |
732 | { | |
733 | desc => "permissions override OWNER, GROUP, MODE", | |
734 | subsys => "tty", | |
735 | devpath => "/class/tty/ttyUSB0", | |
736 | exp_name => "ttyUSB0", | |
737 | exp_perms => "5000:100:0777", | |
738 | conf => <<EOF | |
739 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777" | |
fa19f181 KS |
740 | EOF |
741 | }, | |
742 | { | |
743 | desc => "major/minor number test", | |
744 | subsys => "block", | |
f61d732a | 745 | devpath => "/block/sda", |
fa19f181 | 746 | exp_name => "node", |
fa19f181 KS |
747 | exp_majorminor => "8:0", |
748 | conf => <<EOF | |
7ddb6f47 | 749 | BUS="scsi", KERNEL="sda", NAME="node" |
a5e8d2b4 GKH |
750 | EOF |
751 | }, | |
752 | { | |
753 | desc => "big minor number test", | |
754 | subsys => "i2c-dev", | |
f61d732a | 755 | devpath => "/class/i2c-dev/i2c-300", |
a5e8d2b4 GKH |
756 | exp_name => "node", |
757 | exp_majorminor => "89:300", | |
758 | conf => <<EOF | |
759 | KERNEL="i2c-300", NAME="node" | |
7d12d4e1 GKH |
760 | EOF |
761 | }, | |
762 | { | |
763 | desc => "big major number test", | |
764 | subsys => "i2c-dev", | |
f61d732a | 765 | devpath => "/class/i2c-dev/i2c-fake1", |
7d12d4e1 GKH |
766 | exp_name => "node", |
767 | exp_majorminor => "4095:1", | |
768 | conf => <<EOF | |
769 | KERNEL="i2c-fake1", NAME="node" | |
770 | EOF | |
771 | }, | |
772 | { | |
773 | desc => "big major and big minor number test", | |
774 | subsys => "i2c-dev", | |
f61d732a | 775 | devpath => "/class/i2c-dev/i2c-fake2", |
7d12d4e1 GKH |
776 | exp_name => "node", |
777 | exp_majorminor => "4094:89999", | |
778 | conf => <<EOF | |
779 | KERNEL="i2c-fake2", NAME="node" | |
2b0f835c KS |
780 | EOF |
781 | }, | |
782 | { | |
783 | desc => "multiple symlinks with format char", | |
784 | subsys => "tty", | |
785 | devpath => "/class/tty/ttyUSB0", | |
786 | exp_name => "symlink2-ttyUSB0", | |
787 | exp_target => "ttyUSB0", | |
788 | conf => <<EOF | |
789 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b" | |
b8669191 GKH |
790 | EOF |
791 | }, | |
792 | { | |
793 | desc => "symlink creation (same directory)", | |
794 | subsys => "tty", | |
795 | devpath => "/class/tty/ttyUSB0", | |
796 | exp_name => "visor0", | |
797 | exp_target => "ttyUSB0", | |
798 | conf => <<EOF | |
799 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n" | |
800 | EOF | |
801 | }, | |
802 | { | |
803 | desc => "symlink creation (relative link forward)", | |
804 | subsys => "block", | |
805 | devpath => "/block/sda/sda2", | |
806 | exp_name => "1/2/symlink" , | |
807 | exp_target => "a/b/node", | |
808 | conf => <<EOF | |
809 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink" | |
810 | EOF | |
811 | }, | |
812 | { | |
813 | desc => "symlink creation (relative link back and forward)", | |
814 | subsys => "block", | |
815 | devpath => "/block/sda/sda2", | |
816 | exp_name => "1/2/c/d/symlink" , | |
817 | exp_target => "../../a/b/node", | |
818 | conf => <<EOF | |
819 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink" | |
820 | EOF | |
821 | }, | |
822 | { | |
823 | desc => "multiple symlinks", | |
824 | subsys => "tty", | |
825 | devpath => "/class/tty/ttyUSB0", | |
826 | exp_name => "second-0" , | |
827 | exp_target => "visor" , | |
828 | conf => <<EOF | |
829 | KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n" | |
830 | EOF | |
831 | }, | |
832 | { | |
833 | desc => "symlink only rule", | |
834 | subsys => "block", | |
835 | devpath => "/block/sda", | |
836 | exp_name => "symlink-only2", | |
837 | exp_target => "link", | |
838 | conf => <<EOF | |
839 | BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1" | |
840 | BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2" | |
841 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0" | |
842 | EOF | |
843 | }, | |
844 | { | |
845 | desc => "symlink name empty", | |
846 | subsys => "block", | |
847 | devpath => "/block/sda", | |
848 | exp_name => "", | |
849 | exp_target => "link", | |
850 | exp_error => "yes", | |
851 | conf => <<EOF | |
852 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="" | |
853 | EOF | |
854 | }, | |
855 | { | |
856 | desc => "symlink name '.'", | |
857 | subsys => "block", | |
858 | devpath => "/block/sda", | |
859 | exp_name => ".", | |
860 | exp_target => "link", | |
861 | exp_error => "yes", | |
862 | conf => <<EOF | |
863 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="." | |
864 | EOF | |
865 | }, | |
866 | { | |
867 | desc => "symlink to empty name", | |
868 | subsys => "block", | |
869 | devpath => "/block/sda", | |
870 | exp_name => "symlink", | |
871 | exp_target => "", | |
872 | exp_error => "yes", | |
873 | conf => <<EOF | |
874 | BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink" | |
875 | EOF | |
876 | }, | |
877 | { | |
878 | desc => "symlink and name empty", | |
879 | subsys => "block", | |
880 | devpath => "/block/sda", | |
881 | exp_name => "", | |
882 | exp_target => "", | |
883 | exp_error => "yes", | |
884 | conf => <<EOF | |
885 | BUS="scsi", KERNEL="sda", NAME="", SYMLINK="" | |
886 | EOF | |
887 | }, | |
888 | { | |
889 | desc => "symlink node to itself", | |
890 | subsys => "tty", | |
891 | devpath => "/class/tty/tty0", | |
892 | exp_name => "link", | |
893 | exp_target => "link", | |
894 | conf => <<EOF | |
895 | KERNEL="tty0", NAME="link", SYMLINK="link" | |
896 | EOF | |
897 | }, | |
898 | { | |
899 | desc => "symlink %n substitution", | |
900 | subsys => "tty", | |
901 | devpath => "/class/tty/ttyUSB0", | |
902 | exp_name => "symlink0", | |
903 | exp_target => "ttyUSB0", | |
904 | conf => <<EOF | |
905 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink%n" | |
906 | EOF | |
907 | }, | |
908 | { | |
909 | desc => "symlink %k substitution", | |
910 | subsys => "tty", | |
911 | devpath => "/class/tty/ttyUSB0", | |
912 | exp_name => "symlink-ttyUSB0", | |
913 | exp_target => "ttyUSB0", | |
914 | conf => <<EOF | |
915 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink-%k" | |
916 | EOF | |
917 | }, | |
918 | { | |
919 | desc => "symlink %M:%m substitution", | |
920 | subsys => "tty", | |
921 | devpath => "/class/tty/ttyUSB0", | |
922 | exp_name => "major-188:0", | |
923 | exp_target => "ttyUSB0", | |
924 | conf => <<EOF | |
925 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="major-%M:%m" | |
926 | EOF | |
927 | }, | |
928 | { | |
929 | desc => "symlink %b substitution", | |
930 | subsys => "block", | |
931 | devpath => "/block/sda", | |
932 | exp_name => "symlink-0:0:0:0", | |
933 | exp_target => "node", | |
934 | conf => <<EOF | |
935 | BUS="scsi", KERNEL="sda", NAME="node", SYMLINK="symlink-%b" | |
936 | EOF | |
937 | }, | |
938 | { | |
939 | desc => "symlink %c substitution", | |
940 | subsys => "tty", | |
941 | devpath => "/class/tty/ttyUSB0", | |
942 | exp_name => "test", | |
943 | exp_target => "ttyUSB0", | |
944 | conf => <<EOF | |
945 | KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo test" NAME="ttyUSB%n", SYMLINK="%c" | |
946 | EOF | |
947 | }, | |
948 | { | |
949 | desc => "symlink %c{N} substitution", | |
950 | subsys => "tty", | |
951 | devpath => "/class/tty/ttyUSB0", | |
952 | exp_name => "test", | |
953 | exp_target => "ttyUSB0", | |
954 | conf => <<EOF | |
955 | KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2}" | |
956 | EOF | |
957 | }, | |
958 | { | |
959 | desc => "symlink %c{N+} substitution", | |
960 | subsys => "tty", | |
961 | devpath => "/class/tty/ttyUSB0", | |
962 | exp_name => "this", | |
963 | exp_target => "ttyUSB0", | |
964 | conf => <<EOF | |
965 | KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2+}" | |
966 | EOF | |
967 | }, | |
968 | { | |
969 | desc => "symlink only rule with %c{N+}", | |
970 | subsys => "block", | |
971 | devpath => "/block/sda", | |
972 | exp_name => "test", | |
973 | exp_target => "link", | |
974 | conf => <<EOF | |
975 | BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo link test this" SYMLINK="%c{2+}" | |
976 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0" | |
977 | EOF | |
978 | }, | |
979 | { | |
980 | desc => "symlink %s{filename} substitution", | |
981 | subsys => "tty", | |
982 | devpath => "/class/tty/ttyUSB0", | |
983 | exp_name => "188:0", | |
984 | exp_target => "ttyUSB0", | |
985 | conf => <<EOF | |
986 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%s{dev}" | |
987 | EOF | |
988 | }, | |
989 | { | |
990 | desc => "symlink %Ns{filename} substitution", | |
991 | subsys => "tty", | |
992 | devpath => "/class/tty/ttyUSB0", | |
993 | exp_name => "188", | |
994 | exp_target => "ttyUSB0", | |
995 | conf => <<EOF | |
996 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%3s{dev}" | |
997 | EOF | |
998 | }, | |
999 | { | |
1000 | desc => "symlink with '%' in name", | |
1001 | subsys => "tty", | |
1002 | devpath => "/class/tty/ttyUSB0", | |
1003 | exp_name => "percent%sign", | |
1004 | exp_target => "ttyUSB0", | |
1005 | conf => <<EOF | |
1006 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="percent%%sign" | |
1007 | EOF | |
1008 | }, | |
1009 | { | |
1010 | desc => "symlink with '%' in name", | |
1011 | subsys => "tty", | |
1012 | devpath => "/class/tty/ttyUSB0", | |
1013 | exp_name => "%ttyUSB0_name", | |
1014 | exp_target => "ttyUSB0", | |
1015 | conf => <<EOF | |
1016 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%%%k_name" | |
1017 | EOF | |
1018 | }, | |
1019 | { | |
1020 | desc => "program result substitution (numbered part of)", | |
1021 | subsys => "block", | |
1022 | devpath => "/block/sda/sda3", | |
1023 | exp_name => "link1", | |
1024 | exp_target => "node", | |
1025 | conf => <<EOF | |
1026 | BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}" | |
1027 | EOF | |
1028 | }, | |
1029 | { | |
1030 | desc => "program result substitution (numbered part of+)", | |
1031 | subsys => "block", | |
1032 | devpath => "/block/sda/sda3", | |
1033 | exp_name => "link4", | |
1034 | exp_target => "node", | |
1035 | conf => <<EOF | |
1036 | BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}" | |
0345b862 KS |
1037 | EOF |
1038 | }, | |
1039 | { | |
1040 | desc => "enumeration char test (single test)", | |
1041 | subsys => "block", | |
1042 | devpath => "/block/sda", | |
1043 | exp_name => "cdrom", | |
1044 | conf => <<EOF | |
1045 | KERNEL="sda", NAME="cdrom%e" | |
1046 | EOF | |
1047 | }, | |
1048 | { | |
1049 | desc => "enumeration char test sequence (1/5 keep)", | |
1050 | subsys => "block", | |
1051 | devpath => "/block/sda", | |
1052 | exp_name => "cdrom", | |
1053 | option => "keep", | |
1054 | conf => <<EOF | |
1055 | KERNEL="sda", NAME="cdrom%e" | |
1056 | EOF | |
1057 | }, | |
1058 | { | |
1059 | desc => "enumeration char test sequence 2/5 (keep)", | |
1060 | subsys => "block", | |
1061 | devpath => "/block/sda/sda1", | |
1062 | exp_name => "enum", | |
1063 | option => "keep", | |
1064 | conf => <<EOF | |
1065 | KERNEL="sda1", NAME="enum%e" | |
1066 | EOF | |
1067 | }, | |
1068 | { | |
1069 | desc => "enumeration char test sequence 3/5 (keep)", | |
1070 | subsys => "block", | |
1071 | devpath => "/block/sda/sda2", | |
1072 | exp_name => "cdrom1", | |
1073 | option => "keep", | |
1074 | conf => <<EOF | |
1075 | KERNEL="sda2", NAME="cdrom%e" | |
1076 | EOF | |
1077 | }, | |
1078 | { | |
1079 | desc => "enumeration char test sequence 4/5 (keep)", | |
1080 | subsys => "block", | |
1081 | devpath => "/block/sda/sda3", | |
1082 | exp_name => "enum1", | |
1083 | option => "keep", | |
1084 | conf => <<EOF | |
1085 | KERNEL="sda3", NAME="enum%e" | |
1086 | EOF | |
1087 | }, | |
1088 | { | |
1089 | desc => "enumeration char test sequence 5/5 (clean)", | |
1090 | subsys => "block", | |
1091 | devpath => "/block/sda/sda4", | |
1092 | exp_name => "cdrom2", | |
1093 | option => "clear", | |
1094 | conf => <<EOF | |
1095 | KERNEL="sda4", NAME="cdrom%e" | |
1096 | EOF | |
1097 | }, | |
1098 | { | |
1099 | desc => "enumeration char test after cleanup (single test)", | |
1100 | subsys => "block", | |
1101 | devpath => "/block/sda", | |
1102 | exp_name => "cdrom", | |
1103 | conf => <<EOF | |
1104 | KERNEL="sda", NAME="cdrom%e" | |
a367f04e GKH |
1105 | EOF |
1106 | }, | |
1107 | ); | |
1108 | ||
1109 | # set env | |
1110 | $ENV{UDEV_TEST} = "yes"; | |
1111 | $ENV{SYSFS_PATH} = $sysfs; | |
72ffa78d | 1112 | $ENV{UDEV_CONFIG_FILE} = $main_conf; |
bbbe503e | 1113 | $ENV{UDEV_NO_DEVD} = "yes"; |
a367f04e GKH |
1114 | |
1115 | ||
1116 | sub udev { | |
1117 | my ($action, $subsys, $devpath, $config) = @_; | |
1118 | ||
1119 | $ENV{DEVPATH} = $devpath; | |
a367f04e GKH |
1120 | |
1121 | # create temporary config | |
1122 | open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp"; | |
1123 | print CONF $$config; | |
1124 | close CONF; | |
1125 | ||
1126 | $ENV{ACTION} = $action; | |
1127 | system("$udev_bin $subsys"); | |
1128 | } | |
1129 | ||
e5fbfe0a | 1130 | my $error = 0; |
72ffa78d | 1131 | |
b8669191 GKH |
1132 | sub permissions_test { |
1133 | my($config, $uid, $gid, $mode) = @_; | |
1134 | ||
1135 | my $wrong = 0; | |
1136 | $config->{exp_perms} =~ m/^(.*):(.*):(.*)$/; | |
1137 | if ($1 ne "") { | |
1138 | if ($uid != $1) { $wrong = 1; }; | |
1139 | } | |
1140 | if ($2 ne "") { | |
1141 | if ($gid != $2) { $wrong = 1; }; | |
1142 | } | |
1143 | if ($3 ne "") { | |
1144 | if (($mode & 07777) != oct($3)) { $wrong = 1; }; | |
1145 | } | |
1146 | if ($wrong == 0) { | |
1147 | print "permissions: ok "; | |
1148 | } else { | |
1149 | printf "expected permissions are: %i:%i:%#o\n", $1, $2, oct($3); | |
1150 | printf "created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; | |
1151 | $error++; | |
1152 | } | |
1153 | } | |
1154 | ||
1155 | sub major_minor_test { | |
1156 | my($config, $rdev) = @_; | |
1157 | ||
1158 | my $major = ($rdev >> 8) & 0xfff; | |
1159 | my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); | |
1160 | my $wrong = 0; | |
1161 | ||
1162 | $config->{exp_majorminor} =~ m/^(.*):(.*)$/; | |
1163 | if ($1 ne "") { | |
1164 | if ($major != $1) { $wrong = 1; }; | |
1165 | } | |
1166 | if ($2 ne "") { | |
1167 | if ($minor != $2) { $wrong = 1; }; | |
1168 | } | |
1169 | if ($wrong == 0) { | |
1170 | print "major:minor: ok "; | |
1171 | } else { | |
1172 | printf "expected major:minor is: %i:%i\n", $1, $2; | |
1173 | printf "created major:minor is : %i:%i\n", $major, $minor; | |
1174 | print "major:minor: error "; | |
1175 | $error++; | |
1176 | } | |
1177 | } | |
1178 | ||
1179 | sub symlink_test { | |
1180 | my ($config) = @_; | |
1181 | ||
1182 | my $output = `ls -l $PWD/$udev_root$config->{exp_name}`; | |
1183 | ||
1184 | if ($output =~ m/(.*)-> (.*)/) { | |
1185 | if ($2 eq $config->{exp_target}) { | |
1186 | print "symlink: ok "; | |
1187 | } else { | |
1188 | print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; | |
1189 | print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n"; | |
1190 | if ($config->{exp_error}) { | |
1191 | print "as expected "; | |
1192 | } else { | |
1193 | $error++; | |
1194 | } | |
1195 | } | |
1196 | } else { | |
1197 | print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; | |
1198 | print "symlink: not created "; | |
1199 | if ($config->{exp_error}) { | |
1200 | print "as expected "; | |
1201 | } else { | |
1202 | $error++; | |
1203 | } | |
1204 | } | |
1205 | } | |
1206 | ||
2e317184 GKH |
1207 | sub run_test { |
1208 | my ($config, $number) = @_; | |
fa19f181 | 1209 | |
2e317184 | 1210 | print "TEST $number: $config->{desc}\n"; |
b8669191 GKH |
1211 | |
1212 | if ($config->{exp_target}) { | |
1213 | print "device \'$config->{devpath}\' expecting symlink '$config->{exp_name}' to node \'$config->{exp_target}\'\n"; | |
1214 | } else { | |
1215 | print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n"; | |
1216 | } | |
1217 | ||
a367f04e GKH |
1218 | |
1219 | udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf}); | |
b8669191 GKH |
1220 | |
1221 | if ((-e "$PWD/$udev_root$config->{exp_name}") || | |
1222 | (-l "$PWD/$udev_root$config->{exp_name}")) { | |
fa19f181 KS |
1223 | |
1224 | my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, | |
1225 | $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$config->{exp_name}"); | |
1226 | ||
c013b034 | 1227 | if (defined($config->{exp_perms})) { |
b8669191 | 1228 | permissions_test($config, $uid, $gid, $mode); |
c612a0ac | 1229 | } |
fa19f181 | 1230 | if (defined($config->{exp_majorminor})) { |
b8669191 GKH |
1231 | major_minor_test($config, $rdev); |
1232 | } | |
1233 | if (defined($config->{exp_target})) { | |
1234 | symlink_test($config); | |
fa19f181 | 1235 | } |
a367f04e GKH |
1236 | print "add: ok "; |
1237 | } else { | |
b8669191 GKH |
1238 | print "add: error "; |
1239 | if ($config->{exp_error}) { | |
1240 | print "as expected "; | |
1241 | } else { | |
1242 | print "\n\n"; | |
1243 | system("tree $udev_root"); | |
1244 | print "\n"; | |
1245 | $error++; | |
1246 | } | |
a367f04e GKH |
1247 | } |
1248 | ||
0345b862 KS |
1249 | if (defined($config->{option}) && $config->{option} eq "keep") { |
1250 | print "\n\n"; | |
1251 | return; | |
1252 | } | |
1253 | ||
a367f04e | 1254 | udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf}); |
fa19f181 KS |
1255 | if ((-e "$PWD/$udev_root$config->{exp_name}") || |
1256 | (-l "$PWD/$udev_root$config->{exp_name}")) { | |
b8669191 GKH |
1257 | print "remove: error "; |
1258 | if ($config->{exp_error}) { | |
1259 | print "as expected\n\n"; | |
1260 | } else { | |
1261 | print "\n\n"; | |
1262 | system("tree $udev_root"); | |
1263 | print "\n"; | |
1264 | $error++; | |
1265 | } | |
a367f04e GKH |
1266 | } else { |
1267 | print "remove: ok\n\n"; | |
1268 | } | |
0345b862 KS |
1269 | |
1270 | if (defined($config->{option}) && $config->{option} eq "clear") { | |
1271 | unlink($udev_db); | |
1272 | system("rm -rf $udev_root"); | |
1273 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1274 | } | |
1275 | ||
a367f04e GKH |
1276 | } |
1277 | ||
2e317184 GKH |
1278 | # prepare |
1279 | system("rm -rf $udev_root"); | |
1280 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1281 | ||
1282 | # create initial config file | |
1283 | open CONF, ">$main_conf" || die "unable to create config file: $main_conf"; | |
1284 | print CONF "udev_root=\"$udev_root\"\n"; | |
1285 | print CONF "udev_db=\"$udev_db\"\n"; | |
1286 | print CONF "udev_rules=\"$conf_tmp\"\n"; | |
1287 | print CONF "udev_permissions=\"$perm\"\n"; | |
1288 | close CONF; | |
1289 | ||
1290 | my $test_num = 1; | |
1291 | ||
1292 | if ($ARGV[0]) { | |
1293 | # only run one test | |
1294 | $test_num = $ARGV[0]; | |
2e317184 | 1295 | |
0345b862 KS |
1296 | if (defined($tests[$test_num-1]->{desc})) { |
1297 | print "udev-test will run test number $test_num only:\n\n"; | |
1298 | run_test($tests[$test_num-1], $test_num); | |
1299 | } else { | |
1300 | print "test does not exist.\n"; | |
1301 | } | |
2e317184 GKH |
1302 | } else { |
1303 | # test all | |
1304 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; | |
1305 | ||
1306 | foreach my $config (@tests) { | |
1307 | run_test($config, $test_num); | |
1308 | $test_num++; | |
2e317184 GKH |
1309 | } |
1310 | } | |
1311 | ||
a367f04e GKH |
1312 | print "$error errors occured\n\n"; |
1313 | ||
1314 | # cleanup | |
36043f84 | 1315 | unlink($udev_db); |
a367f04e GKH |
1316 | system("rm -rf $udev_root"); |
1317 | unlink($conf_tmp); | |
72ffa78d | 1318 | unlink($main_conf); |
a367f04e | 1319 |