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