]>
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 | # | |
65005a7f | 12 | # udev parses the rules, looks at the provided sysfs and |
a367f04e GKH |
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 | # | |
a367f04e | 17 | # Kay Sievers <kay.sievers@vrfy.org>, 2003 |
f22e9686 | 18 | # Leann Ogasawara <ogasawara@osdl.org>, 2004 |
a367f04e GKH |
19 | |
20 | use warnings; | |
21 | use strict; | |
22 | ||
65005a7f KS |
23 | my $PWD = $ENV{PWD}; |
24 | my $sysfs = "sys/"; | |
25 | my $udev_bin = "../udev"; | |
26 | my $udev_root = "udev-root/"; # !!! directory will be removed !!! | |
27 | my $udev_db = ".udevdb"; | |
28 | my $udev_conf = "udev-test.conf"; | |
29 | my $udev_rules = "udev-test.rules"; | |
a367f04e | 30 | |
18ebc430 GKH |
31 | # uncomment following line to run udev with valgrind. |
32 | # Should make this a runtime option to the script someday... | |
33 | #my $udev_bin = "valgrind --tool=memcheck --leak-check=yes ../udev"; | |
a367f04e GKH |
34 | |
35 | my @tests = ( | |
36 | { | |
fa19f181 KS |
37 | desc => "label test of scsi disc", |
38 | subsys => "block", | |
f61d732a | 39 | devpath => "/block/sda", |
c013b034 | 40 | exp_name => "boot_disk" , |
65005a7f | 41 | rules => <<EOF |
28ce66de KS |
42 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n" |
43 | KERNEL=="ttyUSB0", NAME="visor" | |
a367f04e GKH |
44 | EOF |
45 | }, | |
46 | { | |
fa19f181 KS |
47 | desc => "label test of scsi partition", |
48 | subsys => "block", | |
f61d732a | 49 | devpath => "/block/sda/sda1", |
c013b034 | 50 | exp_name => "boot_disk1" , |
65005a7f | 51 | rules => <<EOF |
28ce66de | 52 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n" |
83be97ba KS |
53 | EOF |
54 | }, | |
55 | { | |
fa19f181 KS |
56 | desc => "label test of pattern match", |
57 | subsys => "block", | |
f61d732a | 58 | devpath => "/block/sda/sda1", |
c013b034 | 59 | exp_name => "boot_disk1" , |
65005a7f | 60 | rules => <<EOF |
28ce66de KS |
61 | BUS=="scsi", SYSFS{vendor}=="?IBM-ESXS", NAME="boot_disk%n-1" |
62 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS?", NAME="boot_disk%n-2" | |
63 | BUS=="scsi", SYSFS{vendor}=="IBM-ES??", NAME="boot_disk%n" | |
64 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXSS", NAME="boot_disk%n-3" | |
358c8c20 GKH |
65 | EOF |
66 | }, | |
67 | { | |
fa19f181 KS |
68 | desc => "label test of multiple sysfs files", |
69 | subsys => "block", | |
f61d732a | 70 | devpath => "/block/sda/sda1", |
fa19f181 | 71 | exp_name => "boot_disk1" , |
65005a7f | 72 | rules => <<EOF |
28ce66de KS |
73 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", NAME="boot_diskX%n" |
74 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", NAME="boot_disk%n" | |
358c8c20 GKH |
75 | EOF |
76 | }, | |
77 | { | |
fa19f181 KS |
78 | desc => "label test of max sysfs files", |
79 | subsys => "block", | |
f61d732a | 80 | devpath => "/block/sda/sda1", |
fa19f181 | 81 | exp_name => "boot_disk1" , |
65005a7f | 82 | rules => <<EOF |
28ce66de KS |
83 | 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" |
84 | 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 |
85 | EOF |
86 | }, | |
87 | { | |
fa19f181 KS |
88 | desc => "catch device by *", |
89 | subsys => "tty", | |
f61d732a | 90 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 91 | exp_name => "visor/0" , |
65005a7f | 92 | rules => <<EOF |
28ce66de | 93 | KERNEL=="ttyUSB*", NAME="visor/%n" |
2e317184 GKH |
94 | EOF |
95 | }, | |
96 | { | |
fa19f181 KS |
97 | desc => "catch device by * - take 2", |
98 | subsys => "tty", | |
f61d732a | 99 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 100 | exp_name => "visor/0" , |
65005a7f | 101 | rules => <<EOF |
28ce66de KS |
102 | KERNEL=="*USB1", NAME="bad" |
103 | KERNEL=="*USB0", NAME="visor/%n" | |
9f1da361 KS |
104 | EOF |
105 | }, | |
106 | { | |
fa19f181 KS |
107 | desc => "catch device by ?", |
108 | subsys => "tty", | |
f61d732a | 109 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 110 | exp_name => "visor/0" , |
65005a7f | 111 | rules => <<EOF |
28ce66de KS |
112 | KERNEL=="ttyUSB??*", NAME="visor/%n-1" |
113 | KERNEL=="ttyUSB??", NAME="visor/%n-2" | |
114 | KERNEL=="ttyUSB?", NAME="visor/%n" | |
9f1da361 KS |
115 | EOF |
116 | }, | |
117 | { | |
fa19f181 KS |
118 | desc => "catch device by character class", |
119 | subsys => "tty", | |
f61d732a | 120 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 121 | exp_name => "visor/0" , |
65005a7f | 122 | rules => <<EOF |
28ce66de KS |
123 | KERNEL=="ttyUSB[A-Z]*", NAME="visor/%n-1" |
124 | KERNEL=="ttyUSB?[0-9]", NAME="visor/%n-2" | |
125 | KERNEL=="ttyUSB[0-9]*", NAME="visor/%n" | |
a367f04e GKH |
126 | EOF |
127 | }, | |
128 | { | |
fa19f181 KS |
129 | desc => "replace kernel name", |
130 | subsys => "tty", | |
f61d732a | 131 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 132 | exp_name => "visor" , |
65005a7f | 133 | rules => <<EOF |
28ce66de | 134 | KERNEL=="ttyUSB0", NAME="visor" |
281ff00a GKH |
135 | EOF |
136 | }, | |
137 | { | |
fa19f181 KS |
138 | desc => "Handle comment lines in config file (and replace kernel name)", |
139 | subsys => "tty", | |
f61d732a | 140 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 141 | exp_name => "visor" , |
65005a7f | 142 | rules => <<EOF |
281ff00a | 143 | # this is a comment |
28ce66de | 144 | KERNEL=="ttyUSB0", NAME="visor" |
281ff00a GKH |
145 | |
146 | EOF | |
147 | }, | |
148 | { | |
fa19f181 KS |
149 | desc => "Handle comment lines in config file with whitespace (and replace kernel name)", |
150 | subsys => "tty", | |
f61d732a | 151 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 152 | exp_name => "visor" , |
65005a7f | 153 | rules => <<EOF |
281ff00a | 154 | # this is a comment with whitespace before the comment |
28ce66de | 155 | KERNEL=="ttyUSB0", NAME="visor" |
281ff00a | 156 | |
3db7fa27 KS |
157 | EOF |
158 | }, | |
159 | { | |
160 | desc => "Handle whitespace only lines (and replace kernel name)", | |
161 | subsys => "tty", | |
162 | devpath => "/class/tty/ttyUSB0", | |
163 | exp_name => "whitespace" , | |
65005a7f | 164 | rules => <<EOF |
3db7fa27 KS |
165 | |
166 | ||
167 | ||
168 | # this is a comment with whitespace before the comment | |
28ce66de | 169 | KERNEL=="ttyUSB0", NAME="whitespace" |
3db7fa27 KS |
170 | |
171 | ||
172 | ||
281ff00a GKH |
173 | EOF |
174 | }, | |
175 | { | |
fa19f181 KS |
176 | desc => "Handle empty lines in config file (and replace kernel name)", |
177 | subsys => "tty", | |
f61d732a | 178 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 179 | exp_name => "visor" , |
65005a7f | 180 | rules => <<EOF |
281ff00a | 181 | |
28ce66de | 182 | KERNEL=="ttyUSB0", NAME="visor" |
281ff00a | 183 | |
9f8dfa19 KS |
184 | EOF |
185 | }, | |
186 | { | |
187 | desc => "Handle backslashed multi lines in config file (and replace kernel name)", | |
188 | subsys => "tty", | |
189 | devpath => "/class/tty/ttyUSB0", | |
190 | exp_name => "visor" , | |
65005a7f | 191 | rules => <<EOF |
28ce66de | 192 | KERNEL=="ttyUSB0", \\ |
9f8dfa19 KS |
193 | NAME="visor" |
194 | ||
77313cd0 KS |
195 | EOF |
196 | }, | |
197 | { | |
198 | desc => "preserve backslashes, if they are not for a newline", | |
199 | subsys => "tty", | |
200 | devpath => "/class/tty/ttyUSB0", | |
201 | exp_name => "aaa", | |
65005a7f | 202 | rules => <<EOF |
28ce66de | 203 | KERNEL=="ttyUSB0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", NAME="aaa" |
9f8dfa19 KS |
204 | EOF |
205 | }, | |
206 | { | |
207 | desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)", | |
208 | subsys => "tty", | |
209 | devpath => "/class/tty/ttyUSB0", | |
210 | exp_name => "visor" , | |
65005a7f | 211 | rules => <<EOF |
9f8dfa19 KS |
212 | |
213 | # | |
214 | \\ | |
215 | ||
216 | \\\\ | |
217 | ||
218 | #\\ | |
219 | ||
28ce66de | 220 | KERNEL=="ttyUSB0", \\ |
87da5b2c | 221 | NAME="visor" |
9f8dfa19 | 222 | |
5499d319 KS |
223 | EOF |
224 | }, | |
225 | { | |
fa19f181 KS |
226 | desc => "subdirectory handling", |
227 | subsys => "tty", | |
f61d732a | 228 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 229 | exp_name => "sub/direct/ory/visor" , |
65005a7f | 230 | rules => <<EOF |
28ce66de | 231 | KERNEL=="ttyUSB0", NAME="sub/direct/ory/visor" |
a367f04e GKH |
232 | EOF |
233 | }, | |
234 | { | |
fa19f181 KS |
235 | desc => "place on bus of scsi partition", |
236 | subsys => "block", | |
f61d732a | 237 | devpath => "/block/sda/sda3", |
fa19f181 | 238 | exp_name => "first_disk3" , |
65005a7f | 239 | rules => <<EOF |
28ce66de | 240 | BUS=="scsi", ID=="0:0:0:0", NAME="first_disk%n" |
a367f04e GKH |
241 | EOF |
242 | }, | |
243 | { | |
bf5d2964 | 244 | desc => "test substitution chars", |
fa19f181 | 245 | subsys => "block", |
f61d732a | 246 | devpath => "/block/sda/sda3", |
fa19f181 | 247 | exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , |
65005a7f | 248 | rules => <<EOF |
28ce66de | 249 | BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b" |
63ead27c KS |
250 | EOF |
251 | }, | |
252 | { | |
bf5d2964 | 253 | desc => "test substitution chars (with length limit)", |
fa19f181 | 254 | subsys => "block", |
f61d732a | 255 | devpath => "/block/sda/sda3", |
fa19f181 | 256 | exp_name => "M8-m3-n3-b0:0-sIBM" , |
65005a7f | 257 | rules => <<EOF |
28ce66de | 258 | BUS=="scsi", ID=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}" |
bd0ed2ff KS |
259 | EOF |
260 | }, | |
261 | { | |
319c6700 | 262 | desc => "import of shell-value file", |
bd0ed2ff KS |
263 | subsys => "block", |
264 | devpath => "/block/sda", | |
265 | exp_name => "subdir/sys/node" , | |
266 | rules => <<EOF | |
be0856c8 | 267 | BUS=="scsi", IMPORT{file}="test.all", NAME="subdir%E{SYSFSDIR}/node" |
bd0ed2ff | 268 | KERNEL=="ttyUSB0", NAME="visor" |
319c6700 KS |
269 | EOF |
270 | }, | |
271 | { | |
272 | desc => "import of shell-value returned from program", | |
273 | subsys => "block", | |
274 | devpath => "/block/sda", | |
275 | exp_name => "node12345678", | |
276 | rules => <<EOF | |
be0856c8 | 277 | BUS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678 \\n TEST_key2=98765 \'", NAME="node\$env{TEST_KEY}" |
319c6700 | 278 | KERNEL=="ttyUSB0", NAME="visor" |
a27cd06c KS |
279 | EOF |
280 | }, | |
281 | { | |
fa19f181 KS |
282 | desc => "sustitution of sysfs value (%s{file})", |
283 | subsys => "block", | |
f61d732a | 284 | devpath => "/block/sda", |
fa19f181 | 285 | exp_name => "disk-IBM-ESXS-sda" , |
65005a7f | 286 | rules => <<EOF |
28ce66de KS |
287 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="disk-%s{vendor}-%k" |
288 | KERNEL=="ttyUSB0", NAME="visor" | |
a367f04e GKH |
289 | EOF |
290 | }, | |
291 | { | |
fa19f181 KS |
292 | desc => "program result substitution", |
293 | subsys => "block", | |
f61d732a | 294 | devpath => "/block/sda/sda3", |
fa19f181 | 295 | exp_name => "special-device-3" , |
65005a7f | 296 | rules => <<EOF |
28ce66de KS |
297 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", NAME="%c-1-%n" |
298 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special--*", NAME="%c-2-%n" | |
299 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-device-", NAME="%c-3-%n" | |
300 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-devic", NAME="%c-4-%n" | |
301 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", NAME="%c-%n" | |
f608f8ac KS |
302 | EOF |
303 | }, | |
304 | { | |
305 | desc => "program result substitution (no argument should be subsystem)", | |
306 | subsys => "block", | |
307 | devpath => "/block/sda/sda3", | |
308 | exp_name => "subsys_block" , | |
65005a7f | 309 | rules => <<EOF |
28ce66de | 310 | BUS=="scsi", PROGRAM=="/bin/echo", RESULT=="block", NAME="subsys_block" |
bbbe503e KS |
311 | EOF |
312 | }, | |
313 | { | |
314 | desc => "program result substitution (newline removal)", | |
315 | subsys => "block", | |
316 | devpath => "/block/sda/sda3", | |
317 | exp_name => "newline_removed" , | |
65005a7f | 318 | rules => <<EOF |
28ce66de | 319 | BUS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", NAME="newline_removed" |
f3b04a2e GKH |
320 | EOF |
321 | }, | |
322 | { | |
fa19f181 KS |
323 | desc => "program result substitution", |
324 | subsys => "block", | |
f61d732a | 325 | devpath => "/block/sda/sda3", |
fa19f181 | 326 | exp_name => "test-0:0:0:0" , |
65005a7f | 327 | rules => <<EOF |
28ce66de | 328 | BUS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", NAME="%c" |
8ffb636f KS |
329 | EOF |
330 | }, | |
331 | { | |
fa19f181 KS |
332 | desc => "program with escaped format char (tricky: callout returns format char!)", |
333 | subsys => "block", | |
f61d732a | 334 | devpath => "/block/sda/sda3", |
fa19f181 | 335 | exp_name => "escape-3" , |
65005a7f | 336 | rules => <<EOF |
28ce66de | 337 | BUS=="scsi", PROGRAM=="/bin/echo -n escape-%%n", KERNEL=="sda3", NAME="%c" |
dde05ccb GKH |
338 | EOF |
339 | }, | |
340 | { | |
fa19f181 KS |
341 | desc => "program with lots of arguments", |
342 | subsys => "block", | |
f61d732a | 343 | devpath => "/block/sda/sda3", |
fa19f181 | 344 | exp_name => "foo9" , |
65005a7f | 345 | rules => <<EOF |
28ce66de | 346 | BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="%c{7}" |
35b38379 KS |
347 | EOF |
348 | }, | |
349 | { | |
fa19f181 KS |
350 | desc => "program with subshell", |
351 | subsys => "block", | |
f61d732a | 352 | devpath => "/block/sda/sda3", |
fa19f181 | 353 | exp_name => "bar9" , |
65005a7f | 354 | rules => <<EOF |
28ce66de | 355 | BUS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda3", NAME="%c{7}" |
35b38379 KS |
356 | EOF |
357 | }, | |
358 | { | |
fa19f181 KS |
359 | desc => "program arguments combined with apostrophes", |
360 | subsys => "block", | |
f61d732a | 361 | devpath => "/block/sda/sda3", |
fa19f181 | 362 | exp_name => "foo7" , |
65005a7f | 363 | rules => <<EOF |
28ce66de | 364 | BUS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda3", NAME="%c{5}" |
56c963dc PM |
365 | EOF |
366 | }, | |
367 | { | |
fa19f181 KS |
368 | desc => "characters before the %c{N} substitution", |
369 | subsys => "block", | |
f61d732a | 370 | devpath => "/block/sda/sda3", |
fa19f181 | 371 | exp_name => "my-foo9" , |
65005a7f | 372 | rules => <<EOF |
28ce66de | 373 | BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{7}" |
56c963dc PM |
374 | EOF |
375 | }, | |
376 | { | |
fa19f181 KS |
377 | desc => "substitute the second to last argument", |
378 | subsys => "block", | |
f61d732a | 379 | devpath => "/block/sda/sda3", |
fa19f181 | 380 | exp_name => "my-foo8" , |
65005a7f | 381 | rules => <<EOF |
28ce66de | 382 | BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{6}" |
bf5d2964 KS |
383 | EOF |
384 | }, | |
385 | { | |
386 | desc => "test substitution by variable name", | |
387 | subsys => "block", | |
388 | devpath => "/block/sda/sda3", | |
389 | exp_name => "Major:8-minor:3-kernelnumber:3-bus:0:0:0:0" , | |
390 | rules => <<EOF | |
391 | BUS=="scsi", ID=="0:0:0:0", NAME="Major:\$major-minor:\$minor-kernelnumber:\$number-bus:\$id" | |
392 | EOF | |
393 | }, | |
394 | { | |
395 | desc => "test substitution by variable name 2", | |
396 | subsys => "block", | |
397 | devpath => "/block/sda/sda3", | |
398 | exp_name => "Major:8-minor:3-kernelnumber:3-bus:0:0:0:0" , | |
399 | rules => <<EOF | |
400 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="Major:\$major-minor:%m-kernelnumber:\$number-bus:%b" | |
401 | EOF | |
402 | }, | |
403 | { | |
404 | desc => "test substitution by variable name 3", | |
405 | subsys => "block", | |
406 | devpath => "/block/sda/sda3", | |
407 | exp_name => "830:0:0:03" , | |
408 | rules => <<EOF | |
409 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="%M%m%b%n" | |
410 | EOF | |
411 | }, | |
412 | { | |
413 | desc => "test substitution by variable name 4", | |
414 | subsys => "block", | |
415 | devpath => "/block/sda/sda3", | |
416 | exp_name => "833" , | |
417 | rules => <<EOF | |
418 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="\$major\$minor\$number" | |
419 | EOF | |
420 | }, | |
421 | { | |
422 | desc => "test substitution by variable name 5", | |
423 | subsys => "block", | |
424 | devpath => "/block/sda/sda3", | |
425 | exp_name => "8330:0:0:0" , | |
426 | rules => <<EOF | |
427 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="\$major%m%n\$id" | |
8ff8bbba GKH |
428 | EOF |
429 | }, | |
430 | { | |
fa19f181 KS |
431 | desc => "invalid program for device with no bus", |
432 | subsys => "tty", | |
f61d732a | 433 | devpath => "/class/tty/console", |
fa19f181 | 434 | exp_name => "TTY" , |
65005a7f | 435 | rules => <<EOF |
28ce66de KS |
436 | BUS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo" |
437 | KERNEL=="console", NAME="TTY" | |
1d936fbc GKH |
438 | EOF |
439 | }, | |
440 | { | |
fa19f181 KS |
441 | desc => "valid program for device with no bus", |
442 | subsys => "tty", | |
f61d732a | 443 | devpath => "/class/tty/console", |
fa19f181 | 444 | exp_name => "foo" , |
65005a7f | 445 | rules => <<EOF |
28ce66de KS |
446 | PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo" |
447 | KERNEL=="console", NAME="TTY" | |
64682333 GKH |
448 | EOF |
449 | }, | |
450 | { | |
fa19f181 KS |
451 | desc => "invalid label for device with no bus", |
452 | subsys => "tty", | |
f61d732a | 453 | devpath => "/class/tty/console", |
fa19f181 | 454 | exp_name => "TTY" , |
65005a7f | 455 | rules => <<EOF |
28ce66de KS |
456 | BUS=="foo", SYSFS{dev}=="5:1", NAME="foo" |
457 | KERNEL=="console", NAME="TTY" | |
64682333 GKH |
458 | EOF |
459 | }, | |
460 | { | |
fa19f181 KS |
461 | desc => "valid label for device with no bus", |
462 | subsys => "tty", | |
f61d732a | 463 | devpath => "/class/tty/console", |
fa19f181 | 464 | exp_name => "foo" , |
65005a7f | 465 | rules => <<EOF |
28ce66de KS |
466 | SYSFS{dev}=="5:1", NAME="foo" |
467 | KERNEL=="console", NAME="TTY" | |
772558f4 GKH |
468 | EOF |
469 | }, | |
470 | { | |
fa19f181 KS |
471 | desc => "program and bus type match", |
472 | subsys => "block", | |
f61d732a | 473 | devpath => "/block/sda", |
fa19f181 | 474 | exp_name => "scsi-0:0:0:0" , |
65005a7f | 475 | rules => <<EOF |
28ce66de KS |
476 | BUS=="usb", PROGRAM=="/bin/echo -n usb-%b", NAME="%c" |
477 | BUS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", NAME="%c" | |
478 | BUS=="foo", PROGRAM=="/bin/echo -n foo-%b", NAME="%c" | |
724257d9 GKH |
479 | EOF |
480 | }, | |
481 | { | |
fa19f181 KS |
482 | desc => "create all possible partitions", |
483 | subsys => "block", | |
f61d732a | 484 | devpath => "/block/sda", |
fa19f181 | 485 | exp_name => "boot_disk15" , |
15139b8a | 486 | exp_majorminor => "8:15", |
65005a7f | 487 | rules => <<EOF |
28ce66de | 488 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME{all_partitions}="boot_disk" |
50e5de03 KS |
489 | EOF |
490 | }, | |
491 | { | |
fa19f181 KS |
492 | desc => "sysfs parent hierarchy", |
493 | subsys => "tty", | |
f61d732a | 494 | devpath => "/class/tty/ttyUSB0", |
fa19f181 | 495 | exp_name => "visor" , |
65005a7f | 496 | rules => <<EOF |
28ce66de | 497 | SYSFS{idProduct}=="2008", NAME="visor" |
f0142622 GKH |
498 | EOF |
499 | }, | |
500 | { | |
fa19f181 KS |
501 | desc => "name test with ! in the name", |
502 | subsys => "block", | |
f61d732a | 503 | devpath => "/block/rd!c0d0", |
fa19f181 | 504 | exp_name => "rd/c0d0" , |
65005a7f | 505 | rules => <<EOF |
28ce66de KS |
506 | BUS=="scsi", NAME="%k" |
507 | KERNEL=="ttyUSB0", NAME="visor" | |
b9fc973b GKH |
508 | EOF |
509 | }, | |
510 | { | |
fa19f181 KS |
511 | desc => "name test with ! in the name, but no matching rule", |
512 | subsys => "block", | |
f61d732a | 513 | devpath => "/block/rd!c0d0", |
fa19f181 | 514 | exp_name => "rd/c0d0" , |
65005a7f | 515 | rules => <<EOF |
28ce66de | 516 | KERNEL=="ttyUSB0", NAME="visor" |
0f36e68e GKH |
517 | EOF |
518 | }, | |
519 | { | |
520 | desc => "name test with ! in the name for a partition", | |
521 | subsys => "block", | |
522 | devpath => "/block/cciss!c0d0/cciss!c0d0p1", | |
523 | exp_name => "cciss/c0d0p1" , | |
65005a7f | 524 | rules => <<EOF |
28ce66de KS |
525 | BUS=="scsi", NAME="%k" |
526 | KERNEL=="ttyUSB0", NAME="visor" | |
93656247 PM |
527 | EOF |
528 | }, | |
529 | { | |
fa19f181 KS |
530 | desc => "ID rule", |
531 | subsys => "block", | |
f61d732a | 532 | devpath => "/block/sda", |
fa19f181 | 533 | exp_name => "scsi-0:0:0:0", |
65005a7f | 534 | rules => <<EOF |
28ce66de KS |
535 | BUS=="usb", ID=="0:0:0:0", NAME="not-scsi" |
536 | BUS=="scsi", ID=="0:0:0:1", NAME="no-match" | |
537 | BUS=="scsi", ID==":0", NAME="short-id" | |
538 | BUS=="scsi", ID=="/0:0:0:0", NAME="no-match" | |
539 | BUS=="scsi", ID=="0:0:0:0", NAME="scsi-0:0:0:0" | |
93656247 PM |
540 | EOF |
541 | }, | |
542 | { | |
fa19f181 KS |
543 | desc => "ID wildcard all", |
544 | subsys => "block", | |
f61d732a | 545 | devpath => "/block/sda", |
fa19f181 | 546 | exp_name => "scsi-0:0:0:0", |
65005a7f | 547 | rules => <<EOF |
28ce66de KS |
548 | BUS=="scsi", ID=="*:1", NAME="no-match" |
549 | BUS=="scsi", ID=="*:0:1", NAME="no-match" | |
550 | BUS=="scsi", ID=="*:0:0:1", NAME="no-match" | |
551 | BUS=="scsi", ID=="*", NAME="scsi-0:0:0:0" | |
552 | BUS=="scsi", ID=="0:0:0:0", NAME="bad" | |
93656247 PM |
553 | EOF |
554 | }, | |
555 | { | |
fa19f181 KS |
556 | desc => "ID wildcard partial", |
557 | subsys => "block", | |
f61d732a | 558 | devpath => "/block/sda", |
fa19f181 | 559 | exp_name => "scsi-0:0:0:0", |
65005a7f | 560 | rules => <<EOF |
28ce66de KS |
561 | BUS=="scsi", ID=="*:0", NAME="scsi-0:0:0:0" |
562 | BUS=="scsi", ID=="0:0:0:0", NAME="bad" | |
93656247 PM |
563 | EOF |
564 | }, | |
565 | { | |
fa19f181 KS |
566 | desc => "ID wildcard partial 2", |
567 | subsys => "block", | |
f61d732a | 568 | devpath => "/block/sda", |
fa19f181 | 569 | exp_name => "scsi-0:0:0:0", |
65005a7f | 570 | rules => <<EOF |
28ce66de KS |
571 | BUS=="scsi", ID=="*:0:0:0", NAME="scsi-0:0:0:0" |
572 | BUS=="scsi", ID=="0:0:0:0", NAME="bad" | |
d5f91372 KS |
573 | EOF |
574 | }, | |
575 | { | |
fa19f181 KS |
576 | desc => "ignore SYSFS attribute whitespace", |
577 | subsys => "block", | |
f61d732a | 578 | devpath => "/block/sda", |
fa19f181 | 579 | exp_name => "ignored", |
65005a7f | 580 | rules => <<EOF |
28ce66de | 581 | BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE", NAME="ignored" |
d5f91372 KS |
582 | EOF |
583 | }, | |
584 | { | |
fa19f181 KS |
585 | desc => "do not ignore SYSFS attribute whitespace", |
586 | subsys => "block", | |
f61d732a | 587 | devpath => "/block/sda", |
fa19f181 | 588 | exp_name => "matched-with-space", |
65005a7f | 589 | rules => <<EOF |
28ce66de KS |
590 | BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE ", NAME="wrong-to-ignore" |
591 | BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE ", NAME="matched-with-space" | |
0a5417a0 KS |
592 | EOF |
593 | }, | |
594 | { | |
8b36cc0f | 595 | desc => "permissions USER=bad GROUP=name", |
b8669191 GKH |
596 | subsys => "tty", |
597 | devpath => "/class/tty/tty33", | |
598 | exp_name => "tty33", | |
4ae6d03f | 599 | exp_perms => "0:0:0660", |
65005a7f | 600 | rules => <<EOF |
28ce66de | 601 | KERNEL=="tty33", NAME="tty33", OWNER="bad", GROUP="name" |
b8669191 GKH |
602 | EOF |
603 | }, | |
604 | { | |
8b36cc0f | 605 | desc => "permissions OWNER=5000", |
fa19f181 | 606 | subsys => "block", |
f61d732a | 607 | devpath => "/block/sda", |
fa19f181 | 608 | exp_name => "node", |
4ae6d03f | 609 | exp_perms => "5000::0660", |
65005a7f | 610 | rules => <<EOF |
28ce66de | 611 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="5000" |
b8669191 GKH |
612 | EOF |
613 | }, | |
614 | { | |
8b36cc0f | 615 | desc => "permissions GROUP=100", |
b8669191 GKH |
616 | subsys => "block", |
617 | devpath => "/block/sda", | |
618 | exp_name => "node", | |
4ae6d03f | 619 | exp_perms => ":100:0660", |
65005a7f | 620 | rules => <<EOF |
28ce66de | 621 | BUS=="scsi", KERNEL=="sda", NAME="node", GROUP="100" |
9b434de1 KS |
622 | EOF |
623 | }, | |
624 | { | |
625 | desc => "textual user id", | |
626 | subsys => "block", | |
627 | devpath => "/block/sda", | |
628 | exp_name => "node", | |
0bb43877 | 629 | exp_perms => "nobody::0660", |
65005a7f | 630 | rules => <<EOF |
0bb43877 | 631 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="nobody" |
9b434de1 KS |
632 | EOF |
633 | }, | |
634 | { | |
635 | desc => "textual group id", | |
636 | subsys => "block", | |
637 | devpath => "/block/sda", | |
638 | exp_name => "node", | |
639 | exp_perms => ":daemon:0660", | |
65005a7f | 640 | rules => <<EOF |
9b434de1 | 641 | BUS=="scsi", KERNEL=="sda", NAME="node", GROUP="daemon" |
c8278763 KS |
642 | EOF |
643 | }, | |
644 | { | |
645 | desc => "textual user/group id", | |
646 | subsys => "block", | |
647 | devpath => "/block/sda", | |
648 | exp_name => "node", | |
0bb43877 | 649 | exp_perms => "root:mail:0660", |
65005a7f | 650 | rules => <<EOF |
0bb43877 | 651 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="root", GROUP="mail" |
b8669191 GKH |
652 | EOF |
653 | }, | |
654 | { | |
8b36cc0f | 655 | desc => "permissions MODE=0777", |
b8669191 GKH |
656 | subsys => "block", |
657 | devpath => "/block/sda", | |
658 | exp_name => "node", | |
659 | exp_perms => "::0777", | |
65005a7f | 660 | rules => <<EOF |
28ce66de | 661 | BUS=="scsi", KERNEL=="sda", NAME="node", MODE="0777" |
b8669191 GKH |
662 | EOF |
663 | }, | |
664 | { | |
8b36cc0f | 665 | desc => "permissions OWNER=5000 GROUP=100 MODE=0777", |
b8669191 GKH |
666 | subsys => "block", |
667 | devpath => "/block/sda", | |
668 | exp_name => "node", | |
669 | exp_perms => "5000:100:0777", | |
65005a7f | 670 | rules => <<EOF |
28ce66de | 671 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777" |
b8669191 GKH |
672 | EOF |
673 | }, | |
674 | { | |
8b36cc0f | 675 | desc => "permissions OWNER to 5000", |
b8669191 GKH |
676 | subsys => "tty", |
677 | devpath => "/class/tty/ttyUSB0", | |
678 | exp_name => "ttyUSB0", | |
8b36cc0f | 679 | exp_perms => "5000::", |
65005a7f | 680 | rules => <<EOF |
28ce66de | 681 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000" |
b8669191 GKH |
682 | EOF |
683 | }, | |
684 | { | |
8b36cc0f | 685 | desc => "permissions GROUP to 100", |
b8669191 GKH |
686 | subsys => "tty", |
687 | devpath => "/class/tty/ttyUSB0", | |
688 | exp_name => "ttyUSB0", | |
4ae6d03f | 689 | exp_perms => ":100:0660", |
65005a7f | 690 | rules => <<EOF |
28ce66de | 691 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100" |
b8669191 GKH |
692 | EOF |
693 | }, | |
694 | { | |
8b36cc0f | 695 | desc => "permissions MODE to 0060", |
b8669191 GKH |
696 | subsys => "tty", |
697 | devpath => "/class/tty/ttyUSB0", | |
698 | exp_name => "ttyUSB0", | |
8b36cc0f | 699 | exp_perms => "::0060", |
65005a7f | 700 | rules => <<EOF |
28ce66de | 701 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060" |
b8669191 GKH |
702 | EOF |
703 | }, | |
704 | { | |
8b36cc0f | 705 | desc => "permissions OWNER, GROUP, MODE", |
b8669191 GKH |
706 | subsys => "tty", |
707 | devpath => "/class/tty/ttyUSB0", | |
708 | exp_name => "ttyUSB0", | |
709 | exp_perms => "5000:100:0777", | |
65005a7f | 710 | rules => <<EOF |
28ce66de | 711 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777" |
e9390146 KS |
712 | EOF |
713 | }, | |
714 | { | |
715 | desc => "permissions only rule", | |
716 | subsys => "tty", | |
717 | devpath => "/class/tty/ttyUSB0", | |
718 | exp_name => "ttyUSB0", | |
719 | exp_perms => "5000:100:0777", | |
65005a7f | 720 | rules => <<EOF |
28ce66de KS |
721 | KERNEL=="ttyUSB[0-9]*", OWNER="5000", GROUP="100", MODE="0777" |
722 | KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
723 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
eb870090 KS |
724 | EOF |
725 | }, | |
726 | { | |
727 | desc => "multiple permissions only rule", | |
728 | subsys => "tty", | |
729 | devpath => "/class/tty/ttyUSB0", | |
730 | exp_name => "ttyUSB0", | |
731 | exp_perms => "3000:4000:0777", | |
65005a7f | 732 | rules => <<EOF |
28ce66de KS |
733 | SUBSYSTEM=="tty", OWNER="3000" |
734 | SUBSYSTEM=="tty", GROUP="4000" | |
735 | SUBSYSTEM=="tty", MODE="0777" | |
736 | KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
737 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
eb870090 KS |
738 | EOF |
739 | }, | |
740 | { | |
741 | desc => "permissions only rule with override at NAME rule", | |
742 | subsys => "tty", | |
743 | devpath => "/class/tty/ttyUSB0", | |
744 | exp_name => "ttyUSB0", | |
745 | exp_perms => "3000:8000:0777", | |
65005a7f | 746 | rules => <<EOF |
28ce66de KS |
747 | SUBSYSTEM=="tty", OWNER="3000" |
748 | SUBSYSTEM=="tty", GROUP="4000" | |
749 | SUBSYSTEM=="tty", MODE="0777" | |
750 | KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
751 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="8000" | |
fa19f181 KS |
752 | EOF |
753 | }, | |
754 | { | |
755 | desc => "major/minor number test", | |
756 | subsys => "block", | |
f61d732a | 757 | devpath => "/block/sda", |
fa19f181 | 758 | exp_name => "node", |
fa19f181 | 759 | exp_majorminor => "8:0", |
65005a7f | 760 | rules => <<EOF |
28ce66de | 761 | BUS=="scsi", KERNEL=="sda", NAME="node" |
a5e8d2b4 GKH |
762 | EOF |
763 | }, | |
764 | { | |
765 | desc => "big minor number test", | |
766 | subsys => "i2c-dev", | |
f61d732a | 767 | devpath => "/class/i2c-dev/i2c-300", |
a5e8d2b4 GKH |
768 | exp_name => "node", |
769 | exp_majorminor => "89:300", | |
65005a7f | 770 | rules => <<EOF |
28ce66de | 771 | KERNEL=="i2c-300", NAME="node" |
7d12d4e1 GKH |
772 | EOF |
773 | }, | |
774 | { | |
775 | desc => "big major number test", | |
776 | subsys => "i2c-dev", | |
f61d732a | 777 | devpath => "/class/i2c-dev/i2c-fake1", |
7d12d4e1 GKH |
778 | exp_name => "node", |
779 | exp_majorminor => "4095:1", | |
65005a7f | 780 | rules => <<EOF |
28ce66de | 781 | KERNEL=="i2c-fake1", NAME="node" |
7d12d4e1 GKH |
782 | EOF |
783 | }, | |
784 | { | |
785 | desc => "big major and big minor number test", | |
786 | subsys => "i2c-dev", | |
f61d732a | 787 | devpath => "/class/i2c-dev/i2c-fake2", |
7d12d4e1 GKH |
788 | exp_name => "node", |
789 | exp_majorminor => "4094:89999", | |
65005a7f | 790 | rules => <<EOF |
28ce66de | 791 | KERNEL=="i2c-fake2", NAME="node" |
2b0f835c KS |
792 | EOF |
793 | }, | |
794 | { | |
795 | desc => "multiple symlinks with format char", | |
796 | subsys => "tty", | |
797 | devpath => "/class/tty/ttyUSB0", | |
798 | exp_name => "symlink2-ttyUSB0", | |
799 | exp_target => "ttyUSB0", | |
65005a7f | 800 | rules => <<EOF |
28ce66de | 801 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b" |
7b2bdb4b KS |
802 | EOF |
803 | }, | |
804 | { | |
805 | desc => "multiple symlinks with a lot of s p a c e s", | |
806 | subsys => "tty", | |
807 | devpath => "/class/tty/ttyUSB0", | |
808 | exp_name => "one", | |
809 | not_exp_name => " ", | |
810 | exp_target => "ttyUSB0", | |
811 | rules => <<EOF | |
812 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK=" one two " | |
b8669191 GKH |
813 | EOF |
814 | }, | |
815 | { | |
816 | desc => "symlink creation (same directory)", | |
817 | subsys => "tty", | |
818 | devpath => "/class/tty/ttyUSB0", | |
819 | exp_name => "visor0", | |
820 | exp_target => "ttyUSB0", | |
65005a7f | 821 | rules => <<EOF |
28ce66de | 822 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n" |
b8669191 GKH |
823 | EOF |
824 | }, | |
825 | { | |
826 | desc => "symlink creation (relative link forward)", | |
827 | subsys => "block", | |
828 | devpath => "/block/sda/sda2", | |
829 | exp_name => "1/2/symlink" , | |
830 | exp_target => "a/b/node", | |
65005a7f | 831 | rules => <<EOF |
28ce66de | 832 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink" |
b8669191 GKH |
833 | EOF |
834 | }, | |
835 | { | |
836 | desc => "symlink creation (relative link back and forward)", | |
837 | subsys => "block", | |
838 | devpath => "/block/sda/sda2", | |
839 | exp_name => "1/2/c/d/symlink" , | |
840 | exp_target => "../../a/b/node", | |
65005a7f | 841 | rules => <<EOF |
28ce66de | 842 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink" |
b8669191 GKH |
843 | EOF |
844 | }, | |
845 | { | |
846 | desc => "multiple symlinks", | |
847 | subsys => "tty", | |
848 | devpath => "/class/tty/ttyUSB0", | |
849 | exp_name => "second-0" , | |
850 | exp_target => "visor" , | |
65005a7f | 851 | rules => <<EOF |
28ce66de | 852 | KERNEL=="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n" |
b8669191 GKH |
853 | EOF |
854 | }, | |
855 | { | |
856 | desc => "symlink only rule", | |
857 | subsys => "block", | |
858 | devpath => "/block/sda", | |
859 | exp_name => "symlink-only2", | |
860 | exp_target => "link", | |
65005a7f | 861 | rules => <<EOF |
995aec87 KS |
862 | BUS=="scsi", KERNEL=="sda", SYMLINK+="symlink-only1" |
863 | BUS=="scsi", KERNEL=="sda", SYMLINK+="symlink-only2" | |
864 | BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="symlink0" | |
b8669191 GKH |
865 | EOF |
866 | }, | |
867 | { | |
868 | desc => "symlink name '.'", | |
869 | subsys => "block", | |
870 | devpath => "/block/sda", | |
871 | exp_name => ".", | |
872 | exp_target => "link", | |
1cec1c24 KS |
873 | exp_add_error => "yes", |
874 | exp_rem_error => "yes", | |
65005a7f | 875 | rules => <<EOF |
995aec87 | 876 | BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="." |
b8669191 GKH |
877 | EOF |
878 | }, | |
879 | { | |
880 | desc => "symlink node to itself", | |
881 | subsys => "tty", | |
882 | devpath => "/class/tty/tty0", | |
883 | exp_name => "link", | |
884 | exp_target => "link", | |
1cec1c24 | 885 | exp_rem_error => "yes", |
db949b02 | 886 | option => "clean", |
65005a7f | 887 | rules => <<EOF |
995aec87 | 888 | KERNEL=="tty0", NAME="link", SYMLINK+="link" |
b8669191 GKH |
889 | EOF |
890 | }, | |
891 | { | |
892 | desc => "symlink %n substitution", | |
893 | subsys => "tty", | |
894 | devpath => "/class/tty/ttyUSB0", | |
895 | exp_name => "symlink0", | |
896 | exp_target => "ttyUSB0", | |
65005a7f | 897 | rules => <<EOF |
995aec87 | 898 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="symlink%n" |
b8669191 GKH |
899 | EOF |
900 | }, | |
901 | { | |
902 | desc => "symlink %k substitution", | |
903 | subsys => "tty", | |
904 | devpath => "/class/tty/ttyUSB0", | |
905 | exp_name => "symlink-ttyUSB0", | |
906 | exp_target => "ttyUSB0", | |
65005a7f | 907 | rules => <<EOF |
995aec87 | 908 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="symlink-%k" |
b8669191 GKH |
909 | EOF |
910 | }, | |
911 | { | |
912 | desc => "symlink %M:%m substitution", | |
913 | subsys => "tty", | |
914 | devpath => "/class/tty/ttyUSB0", | |
915 | exp_name => "major-188:0", | |
916 | exp_target => "ttyUSB0", | |
65005a7f | 917 | rules => <<EOF |
995aec87 | 918 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="major-%M:%m" |
b8669191 GKH |
919 | EOF |
920 | }, | |
921 | { | |
922 | desc => "symlink %b substitution", | |
923 | subsys => "block", | |
924 | devpath => "/block/sda", | |
925 | exp_name => "symlink-0:0:0:0", | |
926 | exp_target => "node", | |
65005a7f | 927 | rules => <<EOF |
995aec87 | 928 | BUS=="scsi", KERNEL=="sda", NAME="node", SYMLINK+="symlink-%b" |
b8669191 GKH |
929 | EOF |
930 | }, | |
931 | { | |
932 | desc => "symlink %c substitution", | |
933 | subsys => "tty", | |
934 | devpath => "/class/tty/ttyUSB0", | |
935 | exp_name => "test", | |
936 | exp_target => "ttyUSB0", | |
65005a7f | 937 | rules => <<EOF |
995aec87 | 938 | KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo test" NAME="ttyUSB%n", SYMLINK+="%c" |
b8669191 GKH |
939 | EOF |
940 | }, | |
941 | { | |
942 | desc => "symlink %c{N} substitution", | |
943 | subsys => "tty", | |
944 | devpath => "/class/tty/ttyUSB0", | |
945 | exp_name => "test", | |
946 | exp_target => "ttyUSB0", | |
65005a7f | 947 | rules => <<EOF |
995aec87 | 948 | KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK+="%c{2}" |
b8669191 GKH |
949 | EOF |
950 | }, | |
951 | { | |
952 | desc => "symlink %c{N+} substitution", | |
953 | subsys => "tty", | |
954 | devpath => "/class/tty/ttyUSB0", | |
955 | exp_name => "this", | |
956 | exp_target => "ttyUSB0", | |
65005a7f | 957 | rules => <<EOF |
995aec87 | 958 | KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK+="%c{2+}" |
b8669191 GKH |
959 | EOF |
960 | }, | |
961 | { | |
962 | desc => "symlink only rule with %c{N+}", | |
963 | subsys => "block", | |
964 | devpath => "/block/sda", | |
965 | exp_name => "test", | |
966 | exp_target => "link", | |
65005a7f | 967 | rules => <<EOF |
995aec87 KS |
968 | BUS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}" |
969 | BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="symlink0" | |
b8669191 GKH |
970 | EOF |
971 | }, | |
972 | { | |
973 | desc => "symlink %s{filename} substitution", | |
974 | subsys => "tty", | |
975 | devpath => "/class/tty/ttyUSB0", | |
976 | exp_name => "188:0", | |
977 | exp_target => "ttyUSB0", | |
65005a7f | 978 | rules => <<EOF |
995aec87 | 979 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%s{dev}" |
b8669191 GKH |
980 | EOF |
981 | }, | |
982 | { | |
983 | desc => "symlink %Ns{filename} substitution", | |
984 | subsys => "tty", | |
985 | devpath => "/class/tty/ttyUSB0", | |
986 | exp_name => "188", | |
987 | exp_target => "ttyUSB0", | |
65005a7f | 988 | rules => <<EOF |
995aec87 | 989 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%3s{dev}" |
b8669191 GKH |
990 | EOF |
991 | }, | |
992 | { | |
993 | desc => "symlink with '%' in name", | |
994 | subsys => "tty", | |
995 | devpath => "/class/tty/ttyUSB0", | |
996 | exp_name => "percent%sign", | |
997 | exp_target => "ttyUSB0", | |
65005a7f | 998 | rules => <<EOF |
995aec87 | 999 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="percent%%sign" |
b8669191 GKH |
1000 | EOF |
1001 | }, | |
1002 | { | |
1003 | desc => "symlink with '%' in name", | |
1004 | subsys => "tty", | |
1005 | devpath => "/class/tty/ttyUSB0", | |
1006 | exp_name => "%ttyUSB0_name", | |
1007 | exp_target => "ttyUSB0", | |
65005a7f | 1008 | rules => <<EOF |
995aec87 | 1009 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%%%k_name" |
b8669191 GKH |
1010 | EOF |
1011 | }, | |
1012 | { | |
1013 | desc => "program result substitution (numbered part of)", | |
1014 | subsys => "block", | |
1015 | devpath => "/block/sda/sda3", | |
1016 | exp_name => "link1", | |
1017 | exp_target => "node", | |
65005a7f | 1018 | rules => <<EOF |
995aec87 | 1019 | BUS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2} %c{3}" |
b8669191 GKH |
1020 | EOF |
1021 | }, | |
1022 | { | |
1023 | desc => "program result substitution (numbered part of+)", | |
1024 | subsys => "block", | |
1025 | devpath => "/block/sda/sda3", | |
1026 | exp_name => "link4", | |
1027 | exp_target => "node", | |
65005a7f | 1028 | rules => <<EOF |
995aec87 | 1029 | BUS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}" |
0345b862 KS |
1030 | EOF |
1031 | }, | |
1032 | { | |
1033 | desc => "enumeration char test (single test)", | |
1034 | subsys => "block", | |
1035 | devpath => "/block/sda", | |
1036 | exp_name => "cdrom", | |
65005a7f | 1037 | rules => <<EOF |
28ce66de | 1038 | KERNEL=="sda", NAME="cdrom%e" |
0345b862 KS |
1039 | EOF |
1040 | }, | |
1041 | { | |
69aa6dfb | 1042 | desc => "enumeration char test sequence 1/5 (keep)", |
0345b862 KS |
1043 | subsys => "block", |
1044 | devpath => "/block/sda", | |
1045 | exp_name => "cdrom", | |
1046 | option => "keep", | |
65005a7f | 1047 | rules => <<EOF |
28ce66de | 1048 | KERNEL=="sda", NAME="cdrom%e" |
0345b862 KS |
1049 | EOF |
1050 | }, | |
1051 | { | |
1052 | desc => "enumeration char test sequence 2/5 (keep)", | |
1053 | subsys => "block", | |
1054 | devpath => "/block/sda/sda1", | |
1055 | exp_name => "enum", | |
1056 | option => "keep", | |
65005a7f | 1057 | rules => <<EOF |
28ce66de | 1058 | KERNEL=="sda1", NAME="enum%e" |
0345b862 KS |
1059 | EOF |
1060 | }, | |
1061 | { | |
1062 | desc => "enumeration char test sequence 3/5 (keep)", | |
1063 | subsys => "block", | |
1064 | devpath => "/block/sda/sda2", | |
1065 | exp_name => "cdrom1", | |
1066 | option => "keep", | |
65005a7f | 1067 | rules => <<EOF |
28ce66de | 1068 | KERNEL=="sda2", NAME="cdrom%e" |
0345b862 KS |
1069 | EOF |
1070 | }, | |
1071 | { | |
1072 | desc => "enumeration char test sequence 4/5 (keep)", | |
1073 | subsys => "block", | |
1074 | devpath => "/block/sda/sda3", | |
1075 | exp_name => "enum1", | |
1076 | option => "keep", | |
65005a7f | 1077 | rules => <<EOF |
28ce66de | 1078 | KERNEL=="sda3", NAME="enum%e" |
0345b862 KS |
1079 | EOF |
1080 | }, | |
1081 | { | |
1082 | desc => "enumeration char test sequence 5/5 (clean)", | |
1083 | subsys => "block", | |
1084 | devpath => "/block/sda/sda4", | |
1085 | exp_name => "cdrom2", | |
db949b02 | 1086 | option => "clean", |
65005a7f | 1087 | rules => <<EOF |
28ce66de | 1088 | KERNEL=="sda4", NAME="cdrom%e" |
0345b862 KS |
1089 | EOF |
1090 | }, | |
1091 | { | |
1092 | desc => "enumeration char test after cleanup (single test)", | |
1093 | subsys => "block", | |
1094 | devpath => "/block/sda", | |
1095 | exp_name => "cdrom", | |
65005a7f | 1096 | rules => <<EOF |
28ce66de | 1097 | KERNEL=="sda", NAME="cdrom%e" |
fd9efc00 KS |
1098 | EOF |
1099 | }, | |
1100 | { | |
1101 | desc => "ignore rule test", | |
1102 | subsys => "block", | |
1103 | devpath => "/block/sda", | |
a72e3f66 KS |
1104 | exp_name => "nothing", |
1105 | not_exp_name => "node", | |
1cec1c24 | 1106 | exp_add_error => "yes", |
65005a7f | 1107 | rules => <<EOF |
28ce66de | 1108 | BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore" |
fd9efc00 KS |
1109 | EOF |
1110 | }, | |
1111 | { | |
1112 | desc => "all_partitions, option-only rule", | |
1113 | subsys => "block", | |
1114 | devpath => "/block/sda", | |
1115 | exp_name => "node6", | |
65005a7f | 1116 | rules => <<EOF |
28ce66de KS |
1117 | SUBSYSTEM=="block", OPTIONS="all_partitions" |
1118 | BUS=="scsi", KERNEL=="sda", NAME="node" | |
fd9efc00 KS |
1119 | EOF |
1120 | }, | |
1121 | { | |
1122 | desc => "all_partitions, option-only rule (fail on partition)", | |
1123 | subsys => "block", | |
1124 | devpath => "/block/sda/sda1", | |
1125 | exp_name => "node6", | |
1cec1c24 | 1126 | exp_add_error => "yes", |
65005a7f | 1127 | rules => <<EOF |
28ce66de KS |
1128 | SUBSYSTEM=="block", OPTIONS="all_partitions" |
1129 | BUS=="scsi", KERNEL=="sda", NAME="node" | |
6818c51d KS |
1130 | EOF |
1131 | }, | |
1132 | { | |
7efa217d KS |
1133 | desc => "ignore remove event test", |
1134 | subsys => "block", | |
1135 | devpath => "/block/sda", | |
1136 | exp_name => "node", | |
1cec1c24 | 1137 | exp_rem_error => "yes", |
65005a7f | 1138 | rules => <<EOF |
28ce66de | 1139 | BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_remove" |
7efa217d KS |
1140 | EOF |
1141 | }, | |
1142 | { | |
1143 | desc => "ignore remove event test (with all partitions)", | |
1144 | subsys => "block", | |
1145 | devpath => "/block/sda", | |
1146 | exp_name => "node14", | |
1cec1c24 | 1147 | exp_rem_error => "yes", |
db949b02 | 1148 | option => "clean", |
65005a7f | 1149 | rules => <<EOF |
28ce66de | 1150 | BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_remove, all_partitions" |
7efa217d KS |
1151 | EOF |
1152 | }, | |
1153 | { | |
1154 | desc => "SUBSYSTEM match test", | |
6818c51d KS |
1155 | subsys => "block", |
1156 | devpath => "/block/sda", | |
1157 | exp_name => "node", | |
65005a7f | 1158 | rules => <<EOF |
28ce66de KS |
1159 | BUS=="scsi", KERNEL=="sda", NAME="should_not_match", SUBSYSTEM=="vc" |
1160 | BUS=="scsi", KERNEL=="sda", NAME="node", SUBSYSTEM=="block" | |
1161 | BUS=="scsi", KERNEL=="sda", NAME="should_not_match2", SUBSYSTEM=="vc" | |
2092fbcd KS |
1162 | EOF |
1163 | }, | |
1164 | { | |
7efa217d | 1165 | desc => "DRIVER match test", |
2092fbcd KS |
1166 | subsys => "block", |
1167 | devpath => "/block/sda", | |
1168 | exp_name => "node", | |
65005a7f | 1169 | rules => <<EOF |
28ce66de KS |
1170 | BUS=="scsi", KERNEL=="sda", NAME="should_not_match", DRIVER=="sd-wrong" |
1171 | BUS=="scsi", KERNEL=="sda", NAME="node", DRIVER=="sd" | |
c1ab0461 KS |
1172 | EOF |
1173 | }, | |
1174 | { | |
1175 | desc => "temporary node creation test", | |
1176 | subsys => "block", | |
1177 | devpath => "/block/sda", | |
fd42f6a1 | 1178 | exp_name => "node", |
65005a7f | 1179 | rules => <<EOF |
28ce66de | 1180 | BUS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" NAME="node" |
c1ab0461 KS |
1181 | EOF |
1182 | }, | |
1183 | { | |
1184 | desc => "devpath substitution test", | |
1185 | subsys => "block", | |
1186 | devpath => "/block/sda", | |
1187 | exp_name => "sda", | |
65005a7f | 1188 | rules => <<EOF |
28ce66de | 1189 | BUS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo %p", RESULT=="/block/sda" NAME="%k" |
69aa6dfb KS |
1190 | EOF |
1191 | }, | |
1192 | { | |
1193 | desc => "parent node name substitution test sequence 1/2 (keep)", | |
1194 | subsys => "block", | |
1195 | devpath => "/block/sda", | |
1196 | exp_name => "main_device", | |
1197 | option => "keep", | |
65005a7f | 1198 | rules => <<EOF |
28ce66de | 1199 | BUS=="scsi", KERNEL=="sda", NAME="main_device" |
69aa6dfb KS |
1200 | EOF |
1201 | }, | |
1202 | { | |
1203 | desc => "parent node name substitution test sequence 2/2 (clean)", | |
1204 | subsys => "block", | |
1205 | devpath => "/block/sda/sda1", | |
1206 | exp_name => "main_device-part-1", | |
1207 | option => "clean", | |
65005a7f | 1208 | rules => <<EOF |
28ce66de | 1209 | BUS=="scsi", KERNEL=="sda1", NAME="%P-part-1" |
69aa6dfb KS |
1210 | EOF |
1211 | }, | |
1212 | { | |
1213 | desc => "udev_root substitution", | |
1214 | subsys => "block", | |
1215 | devpath => "/block/sda/sda1", | |
1216 | exp_name => "start-udev-root-end", | |
65005a7f | 1217 | rules => <<EOF |
28ce66de | 1218 | BUS=="scsi", KERNEL=="sda1", NAME="start-%r-end" |
3b6ed8bb KS |
1219 | EOF |
1220 | }, | |
1221 | { | |
1222 | desc => "last_rule option", | |
1223 | subsys => "block", | |
1224 | devpath => "/block/sda/sda1", | |
1225 | exp_name => "last", | |
65005a7f | 1226 | rules => <<EOF |
995aec87 | 1227 | BUS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule" |
28ce66de KS |
1228 | BUS=="scsi", KERNEL=="sda1", NAME="very-last" |
1229 | EOF | |
1230 | }, | |
1231 | { | |
1232 | desc => "negation KERNEL!=", | |
1233 | subsys => "block", | |
1234 | devpath => "/block/sda/sda1", | |
1235 | exp_name => "match", | |
65005a7f | 1236 | rules => <<EOF |
28ce66de KS |
1237 | BUS=="scsi", KERNEL!="sda1", NAME="matches-but-is-negated" |
1238 | BUS=="scsi", KERNEL!="xsda1", NAME="match" | |
1239 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
1240 | EOF | |
1241 | }, | |
1242 | { | |
1243 | desc => "negation SUBSYSTEM!=", | |
1244 | subsys => "block", | |
1245 | devpath => "/block/sda/sda1", | |
1246 | exp_name => "not-anything", | |
65005a7f | 1247 | rules => <<EOF |
28ce66de KS |
1248 | BUS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", NAME="matches-but-is-negated" |
1249 | BUS=="scsi", SUBSYSTEM!="anything", NAME="not-anything" | |
1250 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
1251 | EOF | |
1252 | }, | |
1253 | { | |
1254 | desc => "negation PROGRAM!= exit code", | |
1255 | subsys => "block", | |
1256 | devpath => "/block/sda/sda1", | |
1257 | exp_name => "nonzero-program", | |
65005a7f | 1258 | rules => <<EOF |
28ce66de KS |
1259 | KERNEL=="sda1", PROGRAM!="/bin/false", NAME="nonzero-program" |
1260 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
38285d23 KS |
1261 | EOF |
1262 | }, | |
1263 | { | |
1264 | desc => "test for whitespace between the operator", | |
1265 | subsys => "block", | |
1266 | devpath => "/block/sda/sda1", | |
1267 | exp_name => "true", | |
65005a7f | 1268 | rules => <<EOF |
38285d23 KS |
1269 | KERNEL == "sda1" , NAME = "true" |
1270 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
3e5958de KS |
1271 | EOF |
1272 | }, | |
1273 | { | |
1274 | desc => "ENV{} test", | |
1275 | subsys => "block", | |
1276 | devpath => "/block/sda/sda1", | |
1277 | exp_name => "true", | |
65005a7f KS |
1278 | rules => <<EOF |
1279 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong" | |
1280 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", NAME="true" | |
1281 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad" | |
3e5958de KS |
1282 | EOF |
1283 | }, | |
1284 | { | |
1285 | desc => "ENV{} test", | |
1286 | subsys => "block", | |
1287 | devpath => "/block/sda/sda1", | |
1288 | exp_name => "true", | |
65005a7f KS |
1289 | rules => <<EOF |
1290 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong" | |
1291 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sdax1", NAME="no" | |
1292 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sda1", NAME="true" | |
1293 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad" | |
5618b561 KS |
1294 | EOF |
1295 | }, | |
1296 | { | |
1297 | desc => "ENV{} test (assign)", | |
1298 | subsys => "block", | |
1299 | devpath => "/block/sda/sda1", | |
1300 | exp_name => "true", | |
1301 | rules => <<EOF | |
1302 | BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true" | |
1303 | BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", NAME="no" | |
1304 | BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", NAME="true" | |
1305 | BUS=="scsi", KERNEL=="sda1", NAME="bad" | |
1306 | EOF | |
1307 | }, | |
1308 | { | |
1309 | desc => "ENV{} test (assign2)", | |
1310 | subsys => "block", | |
1311 | devpath => "/block/sda/sda1", | |
1312 | exp_name => "part", | |
1313 | rules => <<EOF | |
1314 | SUBSYSTEM=="block", KERNEL="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false" | |
1315 | SUBSYSTEM=="block", KERNEL="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true" | |
1316 | ENV{MAINDEVICE}=="true", NAME="disk" | |
1317 | ENV{PARTITION}=="true", NAME="part" | |
1318 | NAME="bad" | |
18614ab2 KS |
1319 | EOF |
1320 | }, | |
1321 | { | |
1322 | desc => "untrusted string sanitize", | |
1323 | subsys => "block", | |
1324 | devpath => "/block/sda/sda1", | |
1325 | exp_name => "sane", | |
1326 | rules => <<EOF | |
1327 | BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT="name_ _/sbin/badprogram_", NAME="sane" | |
98bbc835 KS |
1328 | EOF |
1329 | }, | |
1330 | { | |
1331 | desc => "read sysfs value from device down in the chain", | |
1332 | subsys => "block", | |
1333 | devpath => "/class/tty/ttyUSB0", | |
1334 | exp_name => "serial-0000:00:09.0", | |
1335 | rules => <<EOF | |
1336 | KERNEL=="ttyUSB*", NAME="serial-%s{serial}" | |
db949b02 KS |
1337 | EOF |
1338 | }, | |
1339 | { | |
1340 | desc => "match against empty key string", | |
1341 | subsys => "block", | |
1342 | devpath => "/block/sda", | |
1343 | exp_name => "ok", | |
1344 | rules => <<EOF | |
1345 | KERNEL=="sda", SYSFS{nothing}!="", NAME="not-1-ok" | |
1346 | KERNEL=="sda", SYSFS{nothing}=="", NAME="not-2-ok" | |
1347 | KERNEL=="sda", SYSFS{vendor}!="", NAME="ok" | |
1348 | KERNEL=="sda", SYSFS{vendor}=="", NAME="not-3-ok" | |
821d0ec8 KS |
1349 | EOF |
1350 | }, | |
1351 | { | |
1352 | desc => "check ACTION value", | |
1353 | subsys => "block", | |
1354 | devpath => "/block/sda", | |
1355 | exp_name => "ok", | |
1356 | rules => <<EOF | |
1357 | ACTION=="unknown", KERNEL=="sda", NAME="unknown-not-ok" | |
1358 | ACTION=="add", KERNEL=="sda", NAME="ok" | |
1359 | EOF | |
1360 | }, | |
1361 | { | |
1362 | desc => "apply NAME only once", | |
1363 | subsys => "block", | |
1364 | devpath => "/block/sda", | |
1365 | exp_name => "link", | |
1366 | exp_target => "ok", | |
1367 | rules => <<EOF | |
1368 | KERNEL=="sda", NAME="ok" | |
1369 | KERNEL=="sda", NAME="not-ok" | |
1370 | KERNEL=="sda", SYMLINK+="link" | |
1371 | EOF | |
1372 | }, | |
1373 | { | |
1374 | desc => "test RUN key", | |
1375 | subsys => "block", | |
1376 | devpath => "/block/sda", | |
1377 | exp_name => "testsymlink", | |
1378 | exp_target => "ok", | |
1379 | exp_rem_error => "yes", | |
1380 | option => "clean", | |
1381 | rules => <<EOF | |
1382 | KERNEL=="sda", NAME="ok", RUN+="/bin/ln -s ok %r/testsymlink" | |
1383 | KERNEL=="sda", NAME="not-ok" | |
f040a4a2 KS |
1384 | EOF |
1385 | }, | |
1386 | { | |
1387 | desc => "test RUN key and DEVNAME", | |
1388 | subsys => "block", | |
1389 | devpath => "/block/sda", | |
1390 | exp_name => "testsymlink", | |
1391 | exp_target => "ok", | |
1392 | exp_rem_error => "yes", | |
1393 | option => "clean", | |
1394 | rules => <<EOF | |
bf5d2964 | 1395 | KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$\$DEVNAME` %r/testsymlink'" |
f040a4a2 | 1396 | KERNEL=="sda", NAME="not-ok" |
821d0ec8 KS |
1397 | EOF |
1398 | }, | |
1399 | { | |
1400 | desc => "test RUN key remove", | |
1401 | subsys => "block", | |
1402 | devpath => "/block/sda", | |
1403 | exp_name => "testsymlink2", | |
1404 | exp_target => "ok2", | |
1405 | rules => <<EOF | |
1406 | KERNEL=="sda", NAME="ok2", RUN+="/bin/ln -s ok2 %r/testsymlink2" | |
1407 | KERNEL=="sda", ACTION=="remove", RUN+="/bin/rm -f %r/testsymlink2" | |
1408 | KERNEL=="sda", NAME="not-ok2" | |
c974742b KS |
1409 | EOF |
1410 | }, | |
1411 | { | |
1412 | desc => "final assignment", | |
1413 | subsys => "block", | |
1414 | devpath => "/block/sda", | |
1415 | exp_name => "ok", | |
1416 | exp_perms => "root:nobody:0640", | |
1417 | rules => <<EOF | |
1418 | KERNEL=="sda", GROUP:="nobody" | |
1419 | KERNEL=="sda", GROUP="not-ok", MODE="0640", NAME="ok" | |
1420 | EOF | |
1421 | }, | |
1422 | { | |
1423 | desc => "final assignment", | |
1424 | subsys => "block", | |
1425 | devpath => "/block/sda", | |
1426 | exp_name => "ok", | |
1427 | exp_perms => "root:nobody:0640", | |
1428 | rules => <<EOF | |
1429 | KERNEL=="sda", GROUP:="nobody" | |
1430 | SUBSYSTEM=="block", MODE:="640" | |
1431 | KERNEL=="sda", GROUP="not-ok", MODE="0666", NAME="ok" | |
bd0ed2ff KS |
1432 | EOF |
1433 | }, | |
1434 | { | |
1435 | desc => "env substitution", | |
1436 | subsys => "block", | |
1437 | devpath => "/block/sda", | |
1438 | exp_name => "node-add-me", | |
1439 | rules => <<EOF | |
1440 | KERNEL=="sda", MODE="0666", NAME="node-\$env{ACTION}-me" | |
995aec87 KS |
1441 | EOF |
1442 | }, | |
1443 | { | |
1444 | desc => "reset list to current value", | |
1445 | subsys => "tty", | |
1446 | devpath => "/class/tty/ttyUSB0", | |
1447 | exp_name => "three", | |
1448 | not_exp_name => "two", | |
1449 | exp_target => "node", | |
1450 | rules => <<EOF | |
1451 | KERNEL=="ttyUSB[0-9]*", SYMLINK+="one" | |
1452 | KERNEL=="ttyUSB[0-9]*", SYMLINK+="two" | |
1453 | KERNEL=="ttyUSB[0-9]*", SYMLINK="three" | |
1454 | KERNEL=="ttyUSB[0-9]*", NAME="node" | |
a72e3f66 KS |
1455 | EOF |
1456 | }, | |
1457 | { | |
1458 | desc => "test empty NAME", | |
1459 | subsys => "tty", | |
1460 | devpath => "/class/tty/ttyUSB0", | |
1461 | exp_name => "node", | |
1462 | not_exp_name => "wrong", | |
1463 | exp_add_error => "yes", | |
1464 | rules => <<EOF | |
1465 | KERNEL=="ttyUSB[0-9]*", NAME="" | |
1466 | KERNEL=="ttyUSB[0-9]*", NAME="wrong" | |
1467 | EOF | |
1468 | }, | |
1469 | { | |
1470 | desc => "test empty NAME 2", | |
1471 | subsys => "tty", | |
1472 | devpath => "/class/tty/ttyUSB0", | |
1473 | exp_name => "right", | |
1474 | rules => <<EOF | |
1475 | KERNEL=="ttyUSB[0-9]*", NAME="right" | |
1476 | KERNEL=="ttyUSB[0-9]*", NAME="" | |
1477 | KERNEL=="ttyUSB[0-9]*", NAME="wrong" | |
0cd4ac47 KS |
1478 | EOF |
1479 | }, | |
1480 | { | |
1481 | desc => "test multi matches", | |
1482 | subsys => "tty", | |
1483 | devpath => "/class/tty/ttyUSB0", | |
1484 | exp_name => "right", | |
1485 | rules => <<EOF | |
1486 | KERNEL=="ttyUSB*|nothing", NAME="right" | |
1487 | KERNEL=="ttyUSB*", NAME="wrong" | |
1488 | EOF | |
1489 | }, | |
1490 | { | |
1491 | desc => "test multi matches 2", | |
1492 | subsys => "tty", | |
1493 | devpath => "/class/tty/ttyUSB0", | |
1494 | exp_name => "right", | |
1495 | rules => <<EOF | |
1496 | KERNEL=="dontknow*|*nothing", NAME="nomatch" | |
1497 | KERNEL=="dontknow*|ttyUSB*|nothing*", NAME="right" | |
1498 | KERNEL=="ttyUSB*", NAME="wrong" | |
0bfb84e1 KS |
1499 | EOF |
1500 | }, | |
1501 | { | |
1502 | desc => "IMPORT parent test sequence 1/2 (keep)", | |
1503 | subsys => "block", | |
1504 | devpath => "/block/sda", | |
1505 | exp_name => "parent", | |
1506 | option => "keep", | |
1507 | rules => <<EOF | |
1508 | KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'" | |
1509 | KERNEL=="sda", NAME="parent" | |
1510 | EOF | |
1511 | }, | |
1512 | { | |
1513 | desc => "IMPORT parent test sequence 2/2 (keep)", | |
1514 | subsys => "block", | |
1515 | devpath => "/block/sda/sda1", | |
1516 | exp_name => "parentenv-parent_right", | |
1517 | option => "clean", | |
1518 | rules => <<EOF | |
1519 | KERNEL=="sda1", IMPORT{parent}="PARENT*", NAME="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}" | |
594dd610 KS |
1520 | EOF |
1521 | }, | |
1522 | { | |
1523 | desc => "GOTO test", | |
1524 | subsys => "block", | |
1525 | devpath => "/block/sda/sda1", | |
1526 | exp_name => "right", | |
1527 | rules => <<EOF | |
1528 | KERNEL=="sda1", GOTO="TEST" | |
1529 | KERNEL=="sda1", NAME="wrong" | |
1530 | KERNEL=="sda1", NAME="", LABEL="NO" | |
1531 | KERNEL=="sda1", NAME="right", LABEL="TEST" | |
1532 | KERNEL=="sda1", NAME="wrong2" | |
a367f04e GKH |
1533 | EOF |
1534 | }, | |
1535 | ); | |
1536 | ||
1537 | # set env | |
65005a7f | 1538 | $ENV{ENV_KEY_TEST} = "test"; |
a367f04e | 1539 | $ENV{SYSFS_PATH} = $sysfs; |
65005a7f | 1540 | $ENV{UDEV_CONFIG_FILE} = $udev_conf; |
bbbe503e | 1541 | $ENV{UDEV_NO_DEVD} = "yes"; |
16ac31aa | 1542 | $ENV{UDEV_NO_HOTPLUGD} = "yes"; |
a367f04e GKH |
1543 | |
1544 | ||
1545 | sub udev { | |
65005a7f | 1546 | my ($action, $subsys, $devpath, $rules) = @_; |
a367f04e GKH |
1547 | |
1548 | $ENV{DEVPATH} = $devpath; | |
a367f04e | 1549 | |
65005a7f KS |
1550 | # create temporary rules |
1551 | open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules"; | |
1552 | print CONF $$rules; | |
a367f04e GKH |
1553 | close CONF; |
1554 | ||
1555 | $ENV{ACTION} = $action; | |
1556 | system("$udev_bin $subsys"); | |
1557 | } | |
1558 | ||
e5fbfe0a | 1559 | my $error = 0; |
72ffa78d | 1560 | |
b8669191 | 1561 | sub permissions_test { |
65005a7f | 1562 | my($rules, $uid, $gid, $mode) = @_; |
b8669191 GKH |
1563 | |
1564 | my $wrong = 0; | |
9b434de1 KS |
1565 | my $userid; |
1566 | my $groupid; | |
1567 | ||
65005a7f | 1568 | $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/; |
b8669191 | 1569 | if ($1 ne "") { |
9b434de1 KS |
1570 | if (defined(getpwnam($1))) { |
1571 | $userid = int(getpwnam($1)); | |
1572 | } else { | |
1573 | $userid = $1; | |
1574 | } | |
1575 | if ($uid != $userid) { $wrong = 1; } | |
b8669191 GKH |
1576 | } |
1577 | if ($2 ne "") { | |
9b434de1 KS |
1578 | if (defined(getgrnam($2))) { |
1579 | $groupid = int(getgrnam($2)); | |
1580 | } else { | |
1581 | $groupid = $2; | |
1582 | } | |
1583 | if ($gid != $groupid) { $wrong = 1; } | |
b8669191 GKH |
1584 | } |
1585 | if ($3 ne "") { | |
1586 | if (($mode & 07777) != oct($3)) { $wrong = 1; }; | |
1587 | } | |
1588 | if ($wrong == 0) { | |
9b434de1 | 1589 | print "permissions: ok\n"; |
b8669191 | 1590 | } else { |
9b434de1 KS |
1591 | printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3); |
1592 | printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; | |
1593 | print "permissions: error\n"; | |
b8669191 GKH |
1594 | $error++; |
1595 | } | |
1596 | } | |
1597 | ||
1598 | sub major_minor_test { | |
65005a7f | 1599 | my($rules, $rdev) = @_; |
b8669191 GKH |
1600 | |
1601 | my $major = ($rdev >> 8) & 0xfff; | |
1602 | my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); | |
1603 | my $wrong = 0; | |
1604 | ||
65005a7f | 1605 | $rules->{exp_majorminor} =~ m/^(.*):(.*)$/; |
b8669191 GKH |
1606 | if ($1 ne "") { |
1607 | if ($major != $1) { $wrong = 1; }; | |
1608 | } | |
1609 | if ($2 ne "") { | |
1610 | if ($minor != $2) { $wrong = 1; }; | |
1611 | } | |
1612 | if ($wrong == 0) { | |
9b434de1 | 1613 | print "major:minor: ok\n"; |
b8669191 | 1614 | } else { |
9b434de1 KS |
1615 | printf " expected major:minor is: %i:%i\n", $1, $2; |
1616 | printf " created major:minor is : %i:%i\n", $major, $minor; | |
1617 | print "major:minor: error\n"; | |
b8669191 GKH |
1618 | $error++; |
1619 | } | |
1620 | } | |
1621 | ||
1622 | sub symlink_test { | |
65005a7f | 1623 | my ($rules) = @_; |
b8669191 | 1624 | |
65005a7f | 1625 | my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`; |
b8669191 GKH |
1626 | |
1627 | if ($output =~ m/(.*)-> (.*)/) { | |
65005a7f | 1628 | if ($2 eq $rules->{exp_target}) { |
9b434de1 | 1629 | print "symlink: ok\n"; |
b8669191 | 1630 | } else { |
65005a7f KS |
1631 | print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n"; |
1632 | print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n"; | |
9b434de1 | 1633 | print "symlink: error"; |
65005a7f | 1634 | if ($rules->{exp_add_error}) { |
9b434de1 | 1635 | print " as expected\n"; |
b8669191 | 1636 | } else { |
9b434de1 | 1637 | print "\n"; |
b8669191 GKH |
1638 | $error++; |
1639 | } | |
1640 | } | |
1641 | } else { | |
65005a7f | 1642 | print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n"; |
9b434de1 | 1643 | print "symlink: not created"; |
65005a7f | 1644 | if ($rules->{exp_add_error}) { |
9b434de1 | 1645 | print " as expected\n"; |
b8669191 | 1646 | } else { |
9b434de1 | 1647 | print "\n"; |
b8669191 GKH |
1648 | $error++; |
1649 | } | |
1650 | } | |
1651 | } | |
1652 | ||
2e317184 | 1653 | sub run_test { |
65005a7f | 1654 | my ($rules, $number) = @_; |
fa19f181 | 1655 | |
65005a7f | 1656 | print "TEST $number: $rules->{desc}\n"; |
b8669191 | 1657 | |
65005a7f KS |
1658 | if ($rules->{exp_target}) { |
1659 | print "device \'$rules->{devpath}\' expecting symlink '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n"; | |
b8669191 | 1660 | } else { |
65005a7f | 1661 | print "device \'$rules->{devpath}\' expecting node \'$rules->{exp_name}\'\n"; |
b8669191 GKH |
1662 | } |
1663 | ||
a367f04e | 1664 | |
65005a7f KS |
1665 | udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules}); |
1666 | if ((-e "$PWD/$udev_root$rules->{exp_name}") || | |
1667 | (-l "$PWD/$udev_root$rules->{exp_name}")) { | |
fa19f181 KS |
1668 | |
1669 | my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, | |
65005a7f | 1670 | $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}"); |
fa19f181 | 1671 | |
995aec87 KS |
1672 | if (defined($rules->{not_exp_name})) { |
1673 | if ((-e "$PWD/$udev_root$rules->{not_exp_name}") || | |
1674 | (-l "$PWD/$udev_root$rules->{not_exp_name}")) { | |
1675 | print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; | |
1676 | $error++ | |
1677 | } | |
1678 | } | |
65005a7f KS |
1679 | if (defined($rules->{exp_perms})) { |
1680 | permissions_test($rules, $uid, $gid, $mode); | |
c612a0ac | 1681 | } |
65005a7f KS |
1682 | if (defined($rules->{exp_majorminor})) { |
1683 | major_minor_test($rules, $rdev); | |
b8669191 | 1684 | } |
65005a7f KS |
1685 | if (defined($rules->{exp_target})) { |
1686 | symlink_test($rules); | |
fa19f181 | 1687 | } |
9b434de1 | 1688 | print "add: ok\n"; |
a367f04e | 1689 | } else { |
9b434de1 | 1690 | print "add: error"; |
65005a7f | 1691 | if ($rules->{exp_add_error}) { |
9b434de1 | 1692 | print " as expected\n"; |
b8669191 | 1693 | } else { |
9b434de1 | 1694 | print "\n"; |
b8669191 GKH |
1695 | system("tree $udev_root"); |
1696 | print "\n"; | |
1697 | $error++; | |
1698 | } | |
a367f04e GKH |
1699 | } |
1700 | ||
65005a7f | 1701 | if (defined($rules->{option}) && $rules->{option} eq "keep") { |
0345b862 KS |
1702 | print "\n\n"; |
1703 | return; | |
1704 | } | |
1705 | ||
65005a7f KS |
1706 | udev("remove", $rules->{subsys}, $rules->{devpath}, \$rules->{rules}); |
1707 | if ((-e "$PWD/$udev_root$rules->{exp_name}") || | |
1708 | (-l "$PWD/$udev_root$rules->{exp_name}")) { | |
9b434de1 | 1709 | print "remove: error"; |
65005a7f | 1710 | if ($rules->{exp_rem_error}) { |
9b434de1 | 1711 | print " as expected\n"; |
b8669191 | 1712 | } else { |
9b434de1 | 1713 | print "\n"; |
b8669191 GKH |
1714 | system("tree $udev_root"); |
1715 | print "\n"; | |
1716 | $error++; | |
1717 | } | |
a367f04e | 1718 | } else { |
9b434de1 | 1719 | print "remove: ok\n"; |
a367f04e | 1720 | } |
0345b862 | 1721 | |
9b434de1 KS |
1722 | print "\n"; |
1723 | ||
db949b02 | 1724 | if (defined($rules->{option}) && $rules->{option} eq "clean") { |
2b41e68a | 1725 | system("rm -rf $udev_db"); |
0345b862 KS |
1726 | system("rm -rf $udev_root"); |
1727 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1728 | } | |
1729 | ||
a367f04e GKH |
1730 | } |
1731 | ||
800ab95b GKH |
1732 | # only run if we have root permissions |
1733 | # due to mknod restrictions | |
1734 | if (!($<==0)) { | |
1735 | print "Must have root permissions to run properly.\n"; | |
1736 | exit; | |
1737 | } | |
1738 | ||
2e317184 GKH |
1739 | # prepare |
1740 | system("rm -rf $udev_root"); | |
1741 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1742 | ||
65005a7f KS |
1743 | # create config file |
1744 | open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; | |
2e317184 GKH |
1745 | print CONF "udev_root=\"$udev_root\"\n"; |
1746 | print CONF "udev_db=\"$udev_db\"\n"; | |
65005a7f | 1747 | print CONF "udev_rules=\"$udev_rules\"\n"; |
2e317184 GKH |
1748 | close CONF; |
1749 | ||
1750 | my $test_num = 1; | |
1751 | ||
1752 | if ($ARGV[0]) { | |
1753 | # only run one test | |
1754 | $test_num = $ARGV[0]; | |
2e317184 | 1755 | |
0345b862 KS |
1756 | if (defined($tests[$test_num-1]->{desc})) { |
1757 | print "udev-test will run test number $test_num only:\n\n"; | |
1758 | run_test($tests[$test_num-1], $test_num); | |
1759 | } else { | |
1760 | print "test does not exist.\n"; | |
1761 | } | |
2e317184 GKH |
1762 | } else { |
1763 | # test all | |
1764 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; | |
1765 | ||
65005a7f KS |
1766 | foreach my $rules (@tests) { |
1767 | run_test($rules, $test_num); | |
2e317184 | 1768 | $test_num++; |
2e317184 GKH |
1769 | } |
1770 | } | |
1771 | ||
a367f04e GKH |
1772 | print "$error errors occured\n\n"; |
1773 | ||
1774 | # cleanup | |
2b41e68a | 1775 | system("rm -rf $udev_db"); |
a367f04e | 1776 | system("rm -rf $udev_root"); |
65005a7f KS |
1777 | unlink($udev_rules); |
1778 | unlink($udev_conf); | |
a367f04e | 1779 |