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