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