]>
Commit | Line | Data |
---|---|---|
2a5fcfae | 1 | #!/usr/bin/env perl |
8f5bcd61 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
a367f04e | 3 | |
438d4c3c | 4 | # udev test |
a367f04e GKH |
5 | # |
6 | # Provides automated testing of the udev binary. | |
7 | # The whole test is self contained in this file, except the matching sysfs tree. | |
8 | # Simply extend the @tests array, to add a new test variant. | |
9 | # | |
10 | # Every test is driven by its own temporary config file. | |
11 | # This program prepares the environment, creates the config and calls udev. | |
12 | # | |
65005a7f | 13 | # udev parses the rules, looks at the provided sysfs and |
a367f04e GKH |
14 | # first creates and then removes the device node. |
15 | # After creation and removal the result is checked against the | |
16 | # expected value and the result is printed. | |
17 | # | |
810adae9 | 18 | # Copyright © 2004 Leann Ogasawara <ogasawara@osdl.org> |
a367f04e GKH |
19 | |
20 | use warnings; | |
21 | use strict; | |
d4076383 ZJS |
22 | |
23 | BEGIN { | |
24 | my $EXIT_TEST_SKIP = 77; | |
25 | ||
26 | unless (eval "use POSIX qw(WIFEXITED WEXITSTATUS); | |
27 | use Cwd qw(getcwd abs_path); | |
28 | use IPC::Semaphore; | |
29 | use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT); | |
30 | use Time::HiRes qw(usleep); 1") { | |
31 | warn "Failed to import dependencies, skipping the test: $@"; | |
32 | exit($EXIT_TEST_SKIP); | |
33 | } | |
34 | } | |
a367f04e | 35 | |
a7910612 LP |
36 | # Relax sd-device's sysfs verification, since we want to provide a fake sysfs |
37 | # here that actually is a tmpfs. | |
38 | $ENV{"SYSTEMD_DEVICE_VERIFY_SYSFS"}="0"; | |
39 | ||
9b80f05f | 40 | my $udev_bin = "./test-udev"; |
912541b0 | 41 | my $valgrind = 0; |
333e07b7 | 42 | my $gdb = 0; |
587751eb | 43 | my $strace = 0; |
b3f24900 | 44 | my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --track-origins=yes --quiet $udev_bin"; |
333e07b7 | 45 | my $udev_bin_gdb = "gdb --args $udev_bin"; |
587751eb | 46 | my $udev_bin_strace = "strace -efile $udev_bin"; |
6ada823a | 47 | my $udev_run = "test/run"; |
2ce8d27b | 48 | my $udev_tmpfs = "test/tmpfs"; |
21d9e3f3 EV |
49 | my $udev_sys = "${udev_tmpfs}/sys"; |
50 | my $udev_dev = "${udev_tmpfs}/dev"; | |
6ada823a KS |
51 | my $udev_rules_dir = "$udev_run/udev/rules.d"; |
52 | my $udev_rules = "$udev_rules_dir/udev-test.rules"; | |
0eb3cc88 | 53 | my $EXIT_TEST_SKIP = 77; |
a367f04e | 54 | |
bf8f7583 MP |
55 | my $rules_10k_tags = ""; |
56 | for (my $i = 1; $i <= 10000; ++$i) { | |
d3fc8bf4 | 57 | $rules_10k_tags .= 'KERNEL=="sda", TAG+="test' . $i . "\"\n"; |
bf8f7583 MP |
58 | } |
59 | ||
e37a5d90 YW |
60 | my $rules_10k_tags_continuation = "KERNEL==\"sda\", \\\n"; |
61 | for (my $i = 1; $i < 10000; ++$i) { | |
62 | $rules_10k_tags_continuation .= 'TAG+="test' . $i . "\",\\\n"; | |
1e797cf5 | 63 | } |
e37a5d90 | 64 | $rules_10k_tags_continuation .= "TAG+=\"test10000\"\\n"; |
1e797cf5 | 65 | |
eb44d715 MW |
66 | # Create a device list with all block devices under /sys |
67 | # (except virtual devices and cd-roms) | |
68 | # the optional argument exp_func returns expected and non-expected | |
69 | # symlinks for the device. | |
70 | sub all_block_devs { | |
71 | my ($exp_func) = @_; | |
72 | my @devices; | |
73 | ||
74 | foreach my $bd (glob "$udev_sys/dev/block/*") { | |
75 | my $tgt = readlink($bd); | |
76 | my ($exp, $notexp) = (undef, undef); | |
77 | ||
78 | next if ($tgt =~ m!/virtual/! || $tgt =~ m!/sr[0-9]*$!); | |
79 | ||
80 | $tgt =~ s!^\.\./\.\.!!; | |
81 | ($exp, $notexp) = $exp_func->($tgt) if defined($exp_func); | |
82 | my $device = { | |
83 | devpath => $tgt, | |
84 | exp_links => $exp, | |
85 | not_exp_links => $notexp, | |
86 | }; | |
87 | push(@devices, $device); | |
88 | } | |
89 | return \@devices; | |
90 | } | |
91 | ||
92 | # This generator returns a suitable exp_func for use with | |
93 | # all_block_devs(). | |
94 | sub expect_for_some { | |
95 | my ($pattern, $links, $donot) = @_; | |
96 | my $_expect = sub { | |
97 | my ($name) = @_; | |
98 | ||
99 | if ($name =~ /$pattern/) { | |
100 | return ($links, undef); | |
101 | } elsif ($donot) { | |
102 | return (undef, $links); | |
103 | } else { | |
104 | return (undef, undef); | |
105 | } | |
106 | }; | |
107 | return $_expect; | |
108 | } | |
109 | ||
a367f04e | 110 | my @tests = ( |
912541b0 KS |
111 | { |
112 | desc => "no rules", | |
255c05b7 MW |
113 | devices => [ |
114 | { | |
115 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
255c05b7 MW |
116 | exp_rem_error => "yes", |
117 | }, | |
118 | { | |
119 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
255c05b7 MW |
120 | exp_rem_error => "yes", |
121 | }], | |
912541b0 | 122 | rules => <<EOF |
5754e74c | 123 | # |
bcf44d55 | 124 | EOF |
912541b0 KS |
125 | }, |
126 | { | |
127 | desc => "label test of scsi disc", | |
255c05b7 MW |
128 | devices => [ |
129 | { | |
130 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 131 | exp_links => ["boot_disk"], |
255c05b7 | 132 | }], |
912541b0 | 133 | rules => <<EOF |
0f52fdee | 134 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n" |
5754e74c | 135 | KERNEL=="ttyACM0", SYMLINK+="modem" |
c4edd0ad | 136 | EOF |
912541b0 KS |
137 | }, |
138 | { | |
139 | desc => "label test of scsi disc", | |
255c05b7 MW |
140 | devices => [ |
141 | { | |
142 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 143 | exp_links => ["boot_disk"], |
255c05b7 | 144 | }], |
912541b0 | 145 | rules => <<EOF |
5754e74c KS |
146 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n" |
147 | KERNEL=="ttyACM0", SYMLINK+="modem" | |
c4edd0ad | 148 | EOF |
912541b0 KS |
149 | }, |
150 | { | |
151 | desc => "label test of scsi disc", | |
255c05b7 MW |
152 | devices => [ |
153 | { | |
154 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 155 | exp_links => ["boot_disk"], |
255c05b7 | 156 | }], |
912541b0 | 157 | rules => <<EOF |
5754e74c KS |
158 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n" |
159 | KERNEL=="ttyACM0", SYMLINK+="modem" | |
a367f04e | 160 | EOF |
912541b0 KS |
161 | }, |
162 | { | |
163 | desc => "label test of scsi partition", | |
255c05b7 MW |
164 | devices => [ |
165 | { | |
166 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 167 | exp_links => ["boot_disk1"], |
255c05b7 | 168 | }], |
912541b0 | 169 | rules => <<EOF |
5754e74c | 170 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n" |
83be97ba | 171 | EOF |
912541b0 KS |
172 | }, |
173 | { | |
174 | desc => "label test of pattern match", | |
255c05b7 MW |
175 | devices => [ |
176 | { | |
177 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 178 | exp_links => ["boot_disk1", "boot_disk1-4", "boot_disk1-5"], |
d94802e9 | 179 | not_exp_links => ["boot_disk1-1", "boot_disk1-2", "boot_disk1-3", "boot_disk1-6", "boot_disk1-7"] |
255c05b7 | 180 | }], |
912541b0 | 181 | rules => <<EOF |
5754e74c KS |
182 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1" |
183 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2" | |
184 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n" | |
185 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3" | |
e62acc31 MW |
186 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="AT?", SYMLINK+="boot_disk%n-4" |
187 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="??A", SYMLINK+="boot_disk%n-5" | |
d94802e9 YW |
188 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", GOTO="skip-6" |
189 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n-6" | |
190 | LABEL="skip-6" | |
191 | SUBSYSTEMS=="scsi", GOTO="skip-7" | |
192 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n-7" | |
193 | LABEL="skip-7" | |
358c8c20 | 194 | EOF |
912541b0 KS |
195 | }, |
196 | { | |
197 | desc => "label test of multiple sysfs files", | |
255c05b7 MW |
198 | devices => [ |
199 | { | |
200 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
201 | exp_links => ["boot_disk1"], |
202 | not_exp_links => ["boot_diskX1"], | |
255c05b7 | 203 | }], |
912541b0 | 204 | rules => <<EOF |
5754e74c KS |
205 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n" |
206 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n" | |
358c8c20 | 207 | EOF |
912541b0 KS |
208 | }, |
209 | { | |
210 | desc => "label test of max sysfs files (skip invalid rule)", | |
255c05b7 MW |
211 | devices => [ |
212 | { | |
213 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 214 | exp_links => ["boot_disk1", "boot_diskXY1"], |
d314345a | 215 | not_exp_links => ["boot_diskXX1", "hoge"], |
255c05b7 | 216 | }], |
912541b0 | 217 | rules => <<EOF |
5754e74c | 218 | 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" |
e62acc31 | 219 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", ATTRS{queue_depth}=="1", SYMLINK+="boot_diskXY%n" |
d314345a YW |
220 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n", SYMLINK+="hoge" |
221 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK-="hoge" | |
0db6d4cc | 222 | EOF |
912541b0 KS |
223 | }, |
224 | { | |
225 | desc => "catch device by *", | |
255c05b7 MW |
226 | devices => [ |
227 | { | |
228 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 229 | exp_links => ["modem/0", "catch-all"], |
255c05b7 | 230 | }], |
912541b0 | 231 | rules => <<EOF |
5754e74c | 232 | KERNEL=="ttyACM*", SYMLINK+="modem/%n" |
e62acc31 | 233 | KERNEL=="*", SYMLINK+="catch-all" |
2e317184 | 234 | EOF |
912541b0 | 235 | }, |
e62acc31 | 236 | # 10 |
912541b0 KS |
237 | { |
238 | desc => "catch device by * - take 2", | |
255c05b7 MW |
239 | devices => [ |
240 | { | |
241 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
242 | exp_links => ["modem/0"], |
243 | not_exp_links => ["bad"], | |
255c05b7 | 244 | }], |
912541b0 | 245 | rules => <<EOF |
5754e74c KS |
246 | KERNEL=="*ACM1", SYMLINK+="bad" |
247 | KERNEL=="*ACM0", SYMLINK+="modem/%n" | |
9f1da361 | 248 | EOF |
912541b0 KS |
249 | }, |
250 | { | |
251 | desc => "catch device by ?", | |
255c05b7 MW |
252 | devices => [ |
253 | { | |
254 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
255 | exp_links => ["modem/0"], |
256 | not_exp_links => ["modem/0-1", "modem/0-2"], | |
255c05b7 | 257 | }], |
912541b0 | 258 | rules => <<EOF |
5754e74c KS |
259 | KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1" |
260 | KERNEL=="ttyACM??", SYMLINK+="modem/%n-2" | |
261 | KERNEL=="ttyACM?", SYMLINK+="modem/%n" | |
9f1da361 | 262 | EOF |
912541b0 KS |
263 | }, |
264 | { | |
265 | desc => "catch device by character class", | |
255c05b7 MW |
266 | devices => [ |
267 | { | |
268 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
269 | exp_links => ["modem/0"], |
270 | not_exp_links => ["modem/0-1", "modem/0-2"], | |
255c05b7 | 271 | }], |
912541b0 | 272 | rules => <<EOF |
5754e74c KS |
273 | KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1" |
274 | KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2" | |
275 | KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n" | |
a367f04e | 276 | EOF |
912541b0 KS |
277 | }, |
278 | { | |
46bc71b2 | 279 | desc => "don't replace kernel name", |
255c05b7 MW |
280 | devices => [ |
281 | { | |
282 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 283 | exp_links => ["modem"], |
255c05b7 | 284 | }], |
912541b0 | 285 | rules => <<EOF |
5754e74c | 286 | KERNEL=="ttyACM0", SYMLINK+="modem" |
281ff00a | 287 | EOF |
912541b0 KS |
288 | }, |
289 | { | |
46bc71b2 | 290 | desc => "Handle comment lines in config file (and don't replace kernel name)", |
255c05b7 MW |
291 | devices => [ |
292 | { | |
293 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 294 | exp_links => ["modem"], |
255c05b7 | 295 | }], |
912541b0 | 296 | rules => <<EOF |
281ff00a | 297 | # this is a comment |
5754e74c | 298 | KERNEL=="ttyACM0", SYMLINK+="modem" |
281ff00a GKH |
299 | |
300 | EOF | |
912541b0 KS |
301 | }, |
302 | { | |
46bc71b2 | 303 | desc => "Handle comment lines in config file with whitespace (and don't replace kernel name)", |
255c05b7 MW |
304 | devices => [ |
305 | { | |
306 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 307 | exp_links => ["modem"], |
255c05b7 | 308 | }], |
912541b0 | 309 | rules => <<EOF |
d914e445 | 310 | # this is a comment with whitespace before the comment |
5754e74c | 311 | KERNEL=="ttyACM0", SYMLINK+="modem" |
281ff00a | 312 | |
3db7fa27 | 313 | EOF |
912541b0 KS |
314 | }, |
315 | { | |
46bc71b2 | 316 | desc => "Handle whitespace only lines (and don't replace kernel name)", |
255c05b7 MW |
317 | devices => [ |
318 | { | |
319 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 320 | exp_links => ["whitespace"], |
255c05b7 | 321 | }], |
912541b0 | 322 | rules => <<EOF |
3db7fa27 | 323 | |
3db7fa27 | 324 | |
d914e445 KS |
325 | |
326 | # this is a comment with whitespace before the comment | |
5754e74c | 327 | KERNEL=="ttyACM0", SYMLINK+="whitespace" |
3db7fa27 | 328 | |
d914e445 | 329 | |
3db7fa27 | 330 | |
281ff00a | 331 | EOF |
912541b0 KS |
332 | }, |
333 | { | |
46bc71b2 | 334 | desc => "Handle empty lines in config file (and don't replace kernel name)", |
255c05b7 MW |
335 | devices => [ |
336 | { | |
337 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 338 | exp_links => ["modem"], |
255c05b7 | 339 | }], |
912541b0 | 340 | rules => <<EOF |
281ff00a | 341 | |
5754e74c | 342 | KERNEL=="ttyACM0", SYMLINK+="modem" |
281ff00a | 343 | |
9f8dfa19 | 344 | EOF |
912541b0 KS |
345 | }, |
346 | { | |
46bc71b2 | 347 | desc => "Handle backslashed multi lines in config file (and don't replace kernel name)", |
255c05b7 MW |
348 | devices => [ |
349 | { | |
350 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 351 | exp_links => ["modem"], |
255c05b7 | 352 | }], |
912541b0 | 353 | rules => <<EOF |
c7fcba1b | 354 | KERNEL=="ttyACM0", \\ |
5754e74c | 355 | SYMLINK+="modem" |
9f8dfa19 | 356 | |
77313cd0 | 357 | EOF |
912541b0 KS |
358 | }, |
359 | { | |
360 | desc => "preserve backslashes, if they are not for a newline", | |
255c05b7 MW |
361 | devices => [ |
362 | { | |
363 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 364 | exp_links => ["aaa"], |
255c05b7 | 365 | }], |
912541b0 | 366 | rules => <<EOF |
d914e445 | 367 | KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa" |
9f8dfa19 | 368 | EOF |
912541b0 | 369 | }, |
46bc71b2 | 370 | # 20 |
912541b0 | 371 | { |
46bc71b2 | 372 | desc => "Handle stupid backslashed multi lines in config file (and don't replace kernel name)", |
255c05b7 MW |
373 | devices => [ |
374 | { | |
375 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 376 | exp_links => ["modem"], |
255c05b7 | 377 | }], |
912541b0 | 378 | rules => <<EOF |
9f8dfa19 KS |
379 | |
380 | # | |
381 | \\ | |
382 | ||
d960ad15 | 383 | \\ |
9f8dfa19 KS |
384 | |
385 | #\\ | |
386 | ||
c7fcba1b | 387 | KERNEL=="ttyACM0", \\ |
912541b0 | 388 | SYMLINK+="modem" |
9f8dfa19 | 389 | |
5499d319 | 390 | EOF |
912541b0 KS |
391 | }, |
392 | { | |
393 | desc => "subdirectory handling", | |
255c05b7 MW |
394 | devices => [ |
395 | { | |
396 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 397 | exp_links => ["sub/direct/ory/modem"], |
255c05b7 | 398 | }], |
912541b0 | 399 | rules => <<EOF |
5754e74c | 400 | KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem" |
a367f04e | 401 | EOF |
912541b0 KS |
402 | }, |
403 | { | |
404 | desc => "parent device name match of scsi partition", | |
255c05b7 MW |
405 | devices => [ |
406 | { | |
407 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 408 | exp_links => ["first_disk5"], |
255c05b7 | 409 | }], |
912541b0 | 410 | rules => <<EOF |
5754e74c | 411 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n" |
c4edd0ad | 412 | EOF |
912541b0 KS |
413 | }, |
414 | { | |
415 | desc => "test substitution chars", | |
255c05b7 MW |
416 | devices => [ |
417 | { | |
418 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 419 | exp_links => ["Major:8:minor:5:kernelnumber:5:id:0:0:0:0"], |
255c05b7 | 420 | }], |
912541b0 | 421 | rules => <<EOF |
5754e74c | 422 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b" |
319c6700 | 423 | EOF |
912541b0 KS |
424 | }, |
425 | { | |
426 | desc => "import of shell-value returned from program", | |
255c05b7 MW |
427 | devices => [ |
428 | { | |
429 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 430 | exp_links => ["node12345678"], |
255c05b7 | 431 | }], |
912541b0 | 432 | rules => <<EOF |
d914e445 | 433 | SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}" |
5754e74c | 434 | KERNEL=="ttyACM0", SYMLINK+="modem" |
a27cd06c | 435 | EOF |
912541b0 KS |
436 | }, |
437 | { | |
d3f044dd | 438 | desc => "substitution of sysfs value (%s{file})", |
255c05b7 MW |
439 | devices => [ |
440 | { | |
441 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
442 | exp_links => ["disk-ATA-sda"], |
443 | not_exp_links => ["modem"], | |
255c05b7 | 444 | }], |
912541b0 | 445 | rules => <<EOF |
5754e74c KS |
446 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k" |
447 | KERNEL=="ttyACM0", SYMLINK+="modem" | |
a367f04e | 448 | EOF |
912541b0 KS |
449 | }, |
450 | { | |
451 | desc => "program result substitution", | |
255c05b7 MW |
452 | devices => [ |
453 | { | |
454 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
455 | exp_links => ["special-device-5"], |
456 | not_exp_links => ["not"], | |
255c05b7 | 457 | }], |
912541b0 | 458 | rules => <<EOF |
d914e445 KS |
459 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not" |
460 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n" | |
bbbe503e | 461 | EOF |
912541b0 KS |
462 | }, |
463 | { | |
464 | desc => "program result substitution (newline removal)", | |
255c05b7 MW |
465 | devices => [ |
466 | { | |
467 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 468 | exp_links => ["newline_removed"], |
255c05b7 | 469 | }], |
912541b0 | 470 | rules => <<EOF |
d914e445 | 471 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed" |
f3b04a2e | 472 | EOF |
912541b0 KS |
473 | }, |
474 | { | |
475 | desc => "program result substitution", | |
255c05b7 MW |
476 | devices => [ |
477 | { | |
478 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 479 | exp_links => ["test-0:0:0:0"], |
255c05b7 | 480 | }], |
912541b0 | 481 | rules => <<EOF |
d914e445 | 482 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c" |
dde05ccb | 483 | EOF |
912541b0 KS |
484 | }, |
485 | { | |
486 | desc => "program with lots of arguments", | |
255c05b7 MW |
487 | devices => [ |
488 | { | |
489 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
490 | exp_links => ["foo9"], |
491 | not_exp_links => ["foo3", "foo4", "foo5", "foo6", "foo7", "foo8"], | |
255c05b7 | 492 | }], |
912541b0 | 493 | rules => <<EOF |
d914e445 | 494 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}" |
35b38379 | 495 | EOF |
912541b0 KS |
496 | }, |
497 | { | |
498 | desc => "program with subshell", | |
255c05b7 MW |
499 | devices => [ |
500 | { | |
501 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
502 | exp_links => ["bar9"], |
503 | not_exp_links => ["foo3", "foo4", "foo5", "foo6", "foo7", "foo8"], | |
255c05b7 | 504 | }], |
912541b0 | 505 | rules => <<EOF |
d914e445 | 506 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}" |
35b38379 | 507 | EOF |
912541b0 KS |
508 | }, |
509 | { | |
510 | desc => "program arguments combined with apostrophes", | |
255c05b7 MW |
511 | devices => [ |
512 | { | |
513 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
514 | exp_links => ["foo7"], |
515 | not_exp_links => ["foo3", "foo4", "foo5", "foo6", "foo8"], | |
255c05b7 | 516 | }], |
912541b0 | 517 | rules => <<EOF |
d914e445 | 518 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}" |
7e760b79 FB |
519 | EOF |
520 | }, | |
521 | { | |
522 | desc => "program arguments combined with escaped double quotes, part 1", | |
255c05b7 MW |
523 | devices => [ |
524 | { | |
525 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
526 | exp_links => ["foo2"], |
527 | not_exp_links => ["foo1"], | |
255c05b7 | 528 | }], |
7e760b79 FB |
529 | rules => <<EOF |
530 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}" | |
531 | EOF | |
532 | }, | |
533 | { | |
534 | desc => "program arguments combined with escaped double quotes, part 2", | |
255c05b7 MW |
535 | devices => [ |
536 | { | |
537 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
538 | exp_links => ["foo2"], |
539 | not_exp_links => ["foo1"], | |
255c05b7 | 540 | }], |
7e760b79 FB |
541 | rules => <<EOF |
542 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}" | |
543 | EOF | |
544 | }, | |
545 | { | |
546 | desc => "program arguments combined with escaped double quotes, part 3", | |
255c05b7 MW |
547 | devices => [ |
548 | { | |
549 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
550 | exp_links => ["foo2"], |
551 | not_exp_links => ["foo1", "foo3"], | |
255c05b7 | 552 | }], |
7e760b79 FB |
553 | rules => <<EOF |
554 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}" | |
56c963dc | 555 | EOF |
912541b0 KS |
556 | }, |
557 | { | |
558 | desc => "characters before the %c{N} substitution", | |
255c05b7 MW |
559 | devices => [ |
560 | { | |
561 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 562 | exp_links => ["my-foo9"], |
255c05b7 | 563 | }], |
912541b0 | 564 | rules => <<EOF |
d914e445 | 565 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}" |
56c963dc | 566 | EOF |
912541b0 KS |
567 | }, |
568 | { | |
569 | desc => "substitute the second to last argument", | |
255c05b7 MW |
570 | devices => [ |
571 | { | |
572 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
573 | exp_links => ["my-foo8"], |
574 | not_exp_links => ["my-foo3", "my-foo4", "my-foo5", "my-foo6", "my-foo7", "my-foo9"], | |
255c05b7 | 575 | }], |
912541b0 | 576 | rules => <<EOF |
d914e445 | 577 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}" |
bf5d2964 | 578 | EOF |
912541b0 KS |
579 | }, |
580 | { | |
581 | desc => "test substitution by variable name", | |
255c05b7 MW |
582 | devices => [ |
583 | { | |
584 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 585 | exp_links => ["Major:8-minor:5-kernelnumber:5-id:0:0:0:0"], |
255c05b7 | 586 | }], |
912541b0 | 587 | rules => <<EOF |
5754e74c | 588 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id" |
bf5d2964 | 589 | EOF |
912541b0 KS |
590 | }, |
591 | { | |
592 | desc => "test substitution by variable name 2", | |
255c05b7 MW |
593 | devices => [ |
594 | { | |
595 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 596 | exp_links => ["Major:8-minor:5-kernelnumber:5-id:0:0:0:0"], |
255c05b7 | 597 | }], |
912541b0 | 598 | rules => <<EOF |
5754e74c | 599 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id" |
bf5d2964 | 600 | EOF |
912541b0 KS |
601 | }, |
602 | { | |
603 | desc => "test substitution by variable name 3", | |
255c05b7 MW |
604 | devices => [ |
605 | { | |
606 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 607 | exp_links => ["850:0:0:05"], |
255c05b7 | 608 | }], |
912541b0 | 609 | rules => <<EOF |
5754e74c | 610 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n" |
bf5d2964 | 611 | EOF |
912541b0 KS |
612 | }, |
613 | { | |
614 | desc => "test substitution by variable name 4", | |
255c05b7 MW |
615 | devices => [ |
616 | { | |
617 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 618 | exp_links => ["855"], |
255c05b7 | 619 | }], |
912541b0 | 620 | rules => <<EOF |
5754e74c | 621 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number" |
bf5d2964 | 622 | EOF |
912541b0 KS |
623 | }, |
624 | { | |
625 | desc => "test substitution by variable name 5", | |
255c05b7 MW |
626 | devices => [ |
627 | { | |
628 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 | 629 | exp_links => ["8550:0:0:0"], |
255c05b7 | 630 | }], |
912541b0 | 631 | rules => <<EOF |
5754e74c | 632 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id" |
8ff8bbba | 633 | EOF |
912541b0 KS |
634 | }, |
635 | { | |
636 | desc => "non matching SUBSYSTEMS for device with no parent", | |
255c05b7 MW |
637 | devices => [ |
638 | { | |
639 | devpath => "/devices/virtual/tty/console", | |
e62acc31 MW |
640 | exp_links => ["TTY"], |
641 | not_exp_links => ["foo"], | |
255c05b7 | 642 | }], |
912541b0 | 643 | rules => <<EOF |
d914e445 | 644 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo" |
5754e74c | 645 | KERNEL=="console", SYMLINK+="TTY" |
1d936fbc | 646 | EOF |
912541b0 KS |
647 | }, |
648 | { | |
649 | desc => "non matching SUBSYSTEMS", | |
255c05b7 MW |
650 | devices => [ |
651 | { | |
652 | devpath => "/devices/virtual/tty/console", | |
e62acc31 MW |
653 | exp_links => ["TTY"], |
654 | not_exp_links => ["foo"], | |
255c05b7 | 655 | }], |
912541b0 | 656 | rules => <<EOF |
5754e74c KS |
657 | SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo" |
658 | KERNEL=="console", SYMLINK+="TTY" | |
64682333 | 659 | EOF |
912541b0 KS |
660 | }, |
661 | { | |
662 | desc => "ATTRS match", | |
255c05b7 MW |
663 | devices => [ |
664 | { | |
665 | devpath => "/devices/virtual/tty/console", | |
e62acc31 | 666 | exp_links => ["foo", "TTY"], |
255c05b7 | 667 | }], |
912541b0 | 668 | rules => <<EOF |
5754e74c KS |
669 | KERNEL=="console", SYMLINK+="TTY" |
670 | ATTRS{dev}=="5:1", SYMLINK+="foo" | |
a402404f | 671 | EOF |
912541b0 KS |
672 | }, |
673 | { | |
674 | desc => "ATTR (empty file)", | |
255c05b7 MW |
675 | devices => [ |
676 | { | |
677 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
678 | exp_links => ["empty", "not-something"], |
679 | not_exp_links => ["something", "not-empty"], | |
255c05b7 | 680 | }], |
912541b0 | 681 | rules => <<EOF |
5754e74c KS |
682 | KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something" |
683 | KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty" | |
684 | KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty" | |
685 | KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something" | |
a402404f | 686 | EOF |
912541b0 KS |
687 | }, |
688 | { | |
689 | desc => "ATTR (non-existent file)", | |
255c05b7 MW |
690 | devices => [ |
691 | { | |
692 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
693 | exp_links => ["non-existent", "wrong"], |
694 | not_exp_links => ["something", "empty", "not-empty", | |
695 | "not-something", "something"], | |
255c05b7 | 696 | }], |
912541b0 | 697 | rules => <<EOF |
5754e74c KS |
698 | KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something" |
699 | KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty" | |
700 | KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty" | |
701 | KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something" | |
702 | KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent" | |
703 | KERNEL=="sda", SYMLINK+="wrong" | |
772558f4 | 704 | EOF |
912541b0 KS |
705 | }, |
706 | { | |
707 | desc => "program and bus type match", | |
255c05b7 MW |
708 | devices => [ |
709 | { | |
710 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 711 | exp_links => ["scsi-0:0:0:0"], |
255c05b7 | 712 | }], |
912541b0 | 713 | rules => <<EOF |
d914e445 KS |
714 | SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c" |
715 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c" | |
716 | SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c" | |
50e5de03 | 717 | EOF |
912541b0 KS |
718 | }, |
719 | { | |
720 | desc => "sysfs parent hierarchy", | |
255c05b7 MW |
721 | devices => [ |
722 | { | |
723 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 724 | exp_links => ["modem"], |
255c05b7 | 725 | }], |
912541b0 | 726 | rules => <<EOF |
5754e74c | 727 | ATTRS{idProduct}=="007b", SYMLINK+="modem" |
f0142622 | 728 | EOF |
912541b0 KS |
729 | }, |
730 | { | |
731 | desc => "name test with ! in the name", | |
255c05b7 MW |
732 | devices => [ |
733 | { | |
734 | devpath => "/devices/virtual/block/fake!blockdev0", | |
f0dccf01 | 735 | devnode => "fake/blockdev0", |
e62acc31 MW |
736 | exp_links => ["is/a/fake/blockdev0"], |
737 | not_exp_links => ["is/not/a/fake/blockdev0", "modem"], | |
255c05b7 | 738 | }], |
912541b0 | 739 | rules => <<EOF |
5754e74c KS |
740 | SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k" |
741 | SUBSYSTEM=="block", SYMLINK+="is/a/%k" | |
742 | KERNEL=="ttyACM0", SYMLINK+="modem" | |
b9fc973b | 743 | EOF |
912541b0 KS |
744 | }, |
745 | { | |
746 | desc => "name test with ! in the name, but no matching rule", | |
255c05b7 MW |
747 | devices => [ |
748 | { | |
749 | devpath => "/devices/virtual/block/fake!blockdev0", | |
f0dccf01 | 750 | devnode => "fake/blockdev0", |
e62acc31 | 751 | not_exp_links => ["modem"], |
255c05b7 | 752 | }], |
912541b0 | 753 | rules => <<EOF |
5754e74c | 754 | KERNEL=="ttyACM0", SYMLINK+="modem" |
93656247 | 755 | EOF |
912541b0 KS |
756 | }, |
757 | { | |
758 | desc => "KERNELS rule", | |
255c05b7 MW |
759 | devices => [ |
760 | { | |
761 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
762 | exp_links => ["scsi-0:0:0:0"], |
763 | not_exp_links => ["no-match", "short-id", "not-scsi"], | |
255c05b7 | 764 | }], |
912541b0 | 765 | rules => <<EOF |
5754e74c KS |
766 | SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi" |
767 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match" | |
768 | SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id" | |
769 | SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match" | |
770 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0" | |
93656247 | 771 | EOF |
912541b0 KS |
772 | }, |
773 | { | |
774 | desc => "KERNELS wildcard all", | |
255c05b7 MW |
775 | devices => [ |
776 | { | |
777 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
778 | exp_links => ["scsi-0:0:0:0"], |
779 | not_exp_links => ["no-match", "before"], | |
255c05b7 | 780 | }], |
912541b0 | 781 | rules => <<EOF |
5754e74c KS |
782 | SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match" |
783 | SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match" | |
784 | SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match" | |
785 | SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before" | |
786 | SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0" | |
93656247 | 787 | EOF |
912541b0 KS |
788 | }, |
789 | { | |
790 | desc => "KERNELS wildcard partial", | |
255c05b7 MW |
791 | devices => [ |
792 | { | |
793 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 794 | exp_links => ["scsi-0:0:0:0", "before"], |
255c05b7 | 795 | }], |
912541b0 | 796 | rules => <<EOF |
5754e74c KS |
797 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before" |
798 | SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0" | |
93656247 | 799 | EOF |
912541b0 KS |
800 | }, |
801 | { | |
802 | desc => "KERNELS wildcard partial 2", | |
255c05b7 MW |
803 | devices => [ |
804 | { | |
805 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 806 | exp_links => ["scsi-0:0:0:0", "before"], |
255c05b7 MW |
807 | }], |
808 | rules => <<EOF | |
5754e74c KS |
809 | SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before" |
810 | SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0" | |
eef54479 | 811 | EOF |
912541b0 KS |
812 | }, |
813 | { | |
814 | desc => "substitute attr with link target value (first match)", | |
255c05b7 MW |
815 | devices => [ |
816 | { | |
817 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 818 | exp_links => ["driver-is-sd"], |
255c05b7 | 819 | }], |
912541b0 | 820 | rules => <<EOF |
5754e74c | 821 | SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}" |
eef54479 | 822 | EOF |
912541b0 KS |
823 | }, |
824 | { | |
825 | desc => "substitute attr with link target value (currently selected device)", | |
255c05b7 MW |
826 | devices => [ |
827 | { | |
828 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 829 | exp_links => ["driver-is-ahci"], |
255c05b7 | 830 | }], |
912541b0 | 831 | rules => <<EOF |
5754e74c | 832 | SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}" |
d5f91372 | 833 | EOF |
912541b0 KS |
834 | }, |
835 | { | |
836 | desc => "ignore ATTRS attribute whitespace", | |
255c05b7 MW |
837 | devices => [ |
838 | { | |
839 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 840 | exp_links => ["ignored"], |
255c05b7 | 841 | }], |
912541b0 | 842 | rules => <<EOF |
5754e74c | 843 | SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored" |
d5f91372 | 844 | EOF |
912541b0 KS |
845 | }, |
846 | { | |
847 | desc => "do not ignore ATTRS attribute whitespace", | |
255c05b7 MW |
848 | devices => [ |
849 | { | |
850 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
851 | exp_links => ["matched-with-space"], |
852 | not_exp_links => ["wrong-to-ignore"], | |
255c05b7 | 853 | }], |
912541b0 | 854 | rules => <<EOF |
5754e74c KS |
855 | SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore" |
856 | SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space" | |
0a5417a0 | 857 | EOF |
912541b0 KS |
858 | }, |
859 | { | |
860 | desc => "permissions USER=bad GROUP=name", | |
255c05b7 MW |
861 | devices => [ |
862 | { | |
863 | devpath => "/devices/virtual/tty/tty33", | |
255c05b7 MW |
864 | exp_perms => "0:0:0600", |
865 | }], | |
912541b0 | 866 | rules => <<EOF |
6ada823a | 867 | KERNEL=="tty33", OWNER="bad", GROUP="name" |
b8669191 | 868 | EOF |
912541b0 KS |
869 | }, |
870 | { | |
9158d03e | 871 | desc => "permissions OWNER=1", |
255c05b7 MW |
872 | devices => [ |
873 | { | |
874 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 875 | exp_links => ["node"], |
255c05b7 MW |
876 | exp_perms => "1::0600", |
877 | }], | |
912541b0 | 878 | rules => <<EOF |
9158d03e | 879 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1" |
b8669191 | 880 | EOF |
912541b0 KS |
881 | }, |
882 | { | |
9158d03e | 883 | desc => "permissions GROUP=1", |
255c05b7 MW |
884 | devices => [ |
885 | { | |
886 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 887 | exp_links => ["node"], |
255c05b7 MW |
888 | exp_perms => ":1:0660", |
889 | }], | |
912541b0 | 890 | rules => <<EOF |
9158d03e | 891 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1" |
9b434de1 | 892 | EOF |
912541b0 KS |
893 | }, |
894 | { | |
895 | desc => "textual user id", | |
255c05b7 MW |
896 | devices => [ |
897 | { | |
898 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 899 | exp_links => ["node"], |
255c05b7 MW |
900 | exp_perms => "daemon::0600", |
901 | }], | |
912541b0 | 902 | rules => <<EOF |
24a01950 | 903 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="daemon" |
9b434de1 | 904 | EOF |
912541b0 KS |
905 | }, |
906 | { | |
907 | desc => "textual group id", | |
255c05b7 MW |
908 | devices => [ |
909 | { | |
910 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 911 | exp_links => ["node"], |
255c05b7 MW |
912 | exp_perms => ":daemon:0660", |
913 | }], | |
912541b0 | 914 | rules => <<EOF |
5754e74c | 915 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon" |
c8278763 | 916 | EOF |
912541b0 KS |
917 | }, |
918 | { | |
919 | desc => "textual user/group id", | |
255c05b7 MW |
920 | devices => [ |
921 | { | |
922 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 923 | exp_links => ["node"], |
255c05b7 MW |
924 | exp_perms => "root:audio:0660", |
925 | }], | |
912541b0 | 926 | rules => <<EOF |
a9030b81 | 927 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="audio" |
b8669191 | 928 | EOF |
912541b0 KS |
929 | }, |
930 | { | |
931 | desc => "permissions MODE=0777", | |
255c05b7 MW |
932 | devices => [ |
933 | { | |
934 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 935 | exp_links => ["node"], |
255c05b7 MW |
936 | exp_perms => "::0777", |
937 | }], | |
912541b0 | 938 | rules => <<EOF |
5754e74c | 939 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777" |
b8669191 | 940 | EOF |
912541b0 KS |
941 | }, |
942 | { | |
9158d03e | 943 | desc => "permissions OWNER=1 GROUP=1 MODE=0777", |
255c05b7 MW |
944 | devices => [ |
945 | { | |
946 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 947 | exp_links => ["node"], |
255c05b7 MW |
948 | exp_perms => "1:1:0777", |
949 | }], | |
912541b0 | 950 | rules => <<EOF |
9158d03e | 951 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777" |
b8669191 | 952 | EOF |
912541b0 KS |
953 | }, |
954 | { | |
9158d03e | 955 | desc => "permissions OWNER to 1", |
255c05b7 MW |
956 | devices => [ |
957 | { | |
958 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
959 | exp_perms => "1::", |
960 | }], | |
912541b0 | 961 | rules => <<EOF |
9158d03e | 962 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1" |
b8669191 | 963 | EOF |
912541b0 KS |
964 | }, |
965 | { | |
9158d03e | 966 | desc => "permissions GROUP to 1", |
255c05b7 MW |
967 | devices => [ |
968 | { | |
969 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
970 | exp_perms => ":1:0660", |
971 | }], | |
912541b0 | 972 | rules => <<EOF |
9158d03e | 973 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1" |
b8669191 | 974 | EOF |
912541b0 KS |
975 | }, |
976 | { | |
977 | desc => "permissions MODE to 0060", | |
255c05b7 MW |
978 | devices => [ |
979 | { | |
980 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
981 | exp_perms => "::0060", |
982 | }], | |
912541b0 | 983 | rules => <<EOF |
5754e74c | 984 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060" |
b8669191 | 985 | EOF |
912541b0 KS |
986 | }, |
987 | { | |
988 | desc => "permissions OWNER, GROUP, MODE", | |
255c05b7 MW |
989 | devices => [ |
990 | { | |
991 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
992 | exp_perms => "1:1:0777", |
993 | }], | |
912541b0 | 994 | rules => <<EOF |
9158d03e | 995 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777" |
e9390146 | 996 | EOF |
912541b0 KS |
997 | }, |
998 | { | |
999 | desc => "permissions only rule", | |
255c05b7 MW |
1000 | devices => [ |
1001 | { | |
1002 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
1003 | exp_perms => "1:1:0777", |
1004 | }], | |
912541b0 | 1005 | rules => <<EOF |
9158d03e TG |
1006 | KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777" |
1007 | KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444" | |
5754e74c | 1008 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n" |
eb870090 | 1009 | EOF |
912541b0 KS |
1010 | }, |
1011 | { | |
1012 | desc => "multiple permissions only rule", | |
255c05b7 MW |
1013 | devices => [ |
1014 | { | |
1015 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
1016 | exp_perms => "1:1:0777", |
1017 | }], | |
912541b0 | 1018 | rules => <<EOF |
9158d03e TG |
1019 | SUBSYSTEM=="tty", OWNER="1" |
1020 | SUBSYSTEM=="tty", GROUP="1" | |
28ce66de | 1021 | SUBSYSTEM=="tty", MODE="0777" |
9158d03e | 1022 | KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444" |
5754e74c | 1023 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n" |
eb870090 | 1024 | EOF |
912541b0 KS |
1025 | }, |
1026 | { | |
1027 | desc => "permissions only rule with override at SYMLINK+ rule", | |
255c05b7 MW |
1028 | devices => [ |
1029 | { | |
1030 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
255c05b7 MW |
1031 | exp_perms => "1:2:0777", |
1032 | }], | |
912541b0 | 1033 | rules => <<EOF |
9158d03e TG |
1034 | SUBSYSTEM=="tty", OWNER="1" |
1035 | SUBSYSTEM=="tty", GROUP="1" | |
28ce66de | 1036 | SUBSYSTEM=="tty", MODE="0777" |
9158d03e TG |
1037 | KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444" |
1038 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2" | |
fa19f181 | 1039 | EOF |
912541b0 KS |
1040 | }, |
1041 | { | |
1042 | desc => "major/minor number test", | |
255c05b7 MW |
1043 | devices => [ |
1044 | { | |
1045 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1046 | exp_links => ["node"], |
255c05b7 MW |
1047 | exp_majorminor => "8:0", |
1048 | }], | |
912541b0 | 1049 | rules => <<EOF |
5754e74c | 1050 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node" |
7d12d4e1 | 1051 | EOF |
912541b0 KS |
1052 | }, |
1053 | { | |
1054 | desc => "big major number test", | |
255c05b7 MW |
1055 | devices => [ |
1056 | { | |
1057 | devpath => "/devices/virtual/misc/misc-fake1", | |
e62acc31 | 1058 | exp_links => ["node"], |
255c05b7 MW |
1059 | exp_majorminor => "4095:1", |
1060 | }], | |
1061 | rules => <<EOF | |
5754e74c | 1062 | KERNEL=="misc-fake1", SYMLINK+="node" |
7d12d4e1 | 1063 | EOF |
912541b0 KS |
1064 | }, |
1065 | { | |
1066 | desc => "big major and big minor number test", | |
255c05b7 MW |
1067 | devices => [ |
1068 | { | |
1069 | devpath => "/devices/virtual/misc/misc-fake89999", | |
e62acc31 | 1070 | exp_links => ["node"], |
255c05b7 MW |
1071 | exp_majorminor => "4095:89999", |
1072 | }], | |
912541b0 | 1073 | rules => <<EOF |
5754e74c | 1074 | KERNEL=="misc-fake89999", SYMLINK+="node" |
2b0f835c | 1075 | EOF |
912541b0 KS |
1076 | }, |
1077 | { | |
1078 | desc => "multiple symlinks with format char", | |
255c05b7 MW |
1079 | devices => [ |
1080 | { | |
1081 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1082 | exp_links => ["symlink1-0", "symlink2-ttyACM0", "symlink3-"], |
255c05b7 | 1083 | }], |
912541b0 | 1084 | rules => <<EOF |
5754e74c | 1085 | KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b" |
7b2bdb4b | 1086 | EOF |
912541b0 KS |
1087 | }, |
1088 | { | |
1089 | desc => "multiple symlinks with a lot of s p a c e s", | |
255c05b7 MW |
1090 | devices => [ |
1091 | { | |
1092 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1093 | exp_links => ["one", "two"], |
1094 | not_exp_links => [" "], | |
255c05b7 | 1095 | }], |
912541b0 | 1096 | rules => <<EOF |
5754e74c | 1097 | KERNEL=="ttyACM[0-9]*", SYMLINK=" one two " |
9cd7b128 DS |
1098 | EOF |
1099 | }, | |
1100 | { | |
1101 | desc => "symlink with spaces in substituted variable", | |
255c05b7 MW |
1102 | devices => [ |
1103 | { | |
1104 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1105 | exp_links => ["name-one_two_three-end"], |
1106 | not_exp_links => [" "], | |
255c05b7 | 1107 | }], |
9cd7b128 DS |
1108 | rules => <<EOF |
1109 | ENV{WITH_WS}="one two three" | |
1110 | SYMLINK="name-\$env{WITH_WS}-end" | |
1111 | EOF | |
1112 | }, | |
1113 | { | |
1114 | desc => "symlink with leading space in substituted variable", | |
255c05b7 MW |
1115 | devices => [ |
1116 | { | |
1117 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1118 | exp_links => ["name-one_two_three-end"], |
1119 | not_exp_links => [" "], | |
255c05b7 | 1120 | }], |
9cd7b128 DS |
1121 | rules => <<EOF |
1122 | ENV{WITH_WS}=" one two three" | |
1123 | SYMLINK="name-\$env{WITH_WS}-end" | |
1124 | EOF | |
1125 | }, | |
1126 | { | |
1127 | desc => "symlink with trailing space in substituted variable", | |
255c05b7 MW |
1128 | devices => [ |
1129 | { | |
1130 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1131 | exp_links => ["name-one_two_three-end"], |
1132 | not_exp_links => [" "], | |
255c05b7 | 1133 | }], |
9cd7b128 DS |
1134 | rules => <<EOF |
1135 | ENV{WITH_WS}="one two three " | |
1136 | SYMLINK="name-\$env{WITH_WS}-end" | |
1137 | EOF | |
1138 | }, | |
1139 | { | |
1140 | desc => "symlink with lots of space in substituted variable", | |
255c05b7 MW |
1141 | devices => [ |
1142 | { | |
1143 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1144 | exp_links => ["name-one_two_three-end"], |
1145 | not_exp_links => [" "], | |
255c05b7 | 1146 | }], |
9cd7b128 DS |
1147 | rules => <<EOF |
1148 | ENV{WITH_WS}=" one two three " | |
1149 | SYMLINK="name-\$env{WITH_WS}-end" | |
1150 | EOF | |
1151 | }, | |
1152 | { | |
1153 | desc => "symlink with multiple spaces in substituted variable", | |
255c05b7 MW |
1154 | devices => [ |
1155 | { | |
1156 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1157 | exp_links => ["name-one_two_three-end"], |
1158 | not_exp_links => [" "], | |
255c05b7 | 1159 | }], |
9cd7b128 DS |
1160 | rules => <<EOF |
1161 | ENV{WITH_WS}=" one two three " | |
1162 | SYMLINK="name-\$env{WITH_WS}-end" | |
1163 | EOF | |
1164 | }, | |
1165 | { | |
e62acc31 | 1166 | desc => "symlink with space and var with space", |
255c05b7 MW |
1167 | devices => [ |
1168 | { | |
1169 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
2084fe0d MW |
1170 | exp_links => ["first", "name-one_two_three-end", |
1171 | "another_symlink", "a", "b", "c"], | |
1172 | not_exp_links => [" "], | |
255c05b7 | 1173 | }], |
9cd7b128 DS |
1174 | rules => <<EOF |
1175 | ENV{WITH_WS}=" one two three " | |
1176 | SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c " | |
33989b96 YW |
1177 | EOF |
1178 | }, | |
1179 | { | |
1180 | desc => "symlink with env which contain slash (see #19309)", | |
1181 | devices => [ | |
1182 | { | |
1183 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
1184 | exp_links => ["first", "name-aaa_bbb_ccc-end", | |
1185 | "another_symlink", "a", "b", "c"], | |
1186 | not_exp_links => ["ame-aaa/bbb/ccc-end"], | |
1187 | }], | |
1188 | rules => <<EOF | |
1189 | ENV{WITH_SLASH}="aaa/bbb/ccc" | |
1190 | OPTIONS="string_escape=replace", ENV{REPLACED}="\$env{WITH_SLASH}" | |
1191 | SYMLINK=" first name-\$env{REPLACED}-end another_symlink a b c " | |
b8669191 | 1192 | EOF |
912541b0 KS |
1193 | }, |
1194 | { | |
1195 | desc => "symlink creation (same directory)", | |
255c05b7 MW |
1196 | devices => [ |
1197 | { | |
1198 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1199 | exp_links => ["modem0"], |
255c05b7 | 1200 | }], |
912541b0 | 1201 | rules => <<EOF |
5754e74c | 1202 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n" |
b8669191 | 1203 | EOF |
912541b0 KS |
1204 | }, |
1205 | { | |
1206 | desc => "multiple symlinks", | |
255c05b7 MW |
1207 | devices => [ |
1208 | { | |
1209 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1210 | exp_links => ["first-0", "second-0", "third-0"], |
255c05b7 | 1211 | }], |
912541b0 | 1212 | rules => <<EOF |
5754e74c | 1213 | KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n" |
b8669191 | 1214 | EOF |
912541b0 KS |
1215 | }, |
1216 | { | |
1217 | desc => "symlink name '.'", | |
255c05b7 MW |
1218 | devices => [ |
1219 | { | |
1220 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1221 | exp_links => ["."], |
255c05b7 MW |
1222 | exp_add_error => "yes", |
1223 | exp_rem_error => "yes", | |
1224 | }], | |
912541b0 | 1225 | rules => <<EOF |
5754e74c | 1226 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="." |
b8669191 | 1227 | EOF |
912541b0 KS |
1228 | }, |
1229 | { | |
1230 | desc => "symlink node to itself", | |
255c05b7 MW |
1231 | devices => [ |
1232 | { | |
1233 | devpath => "/devices/virtual/tty/tty0", | |
e62acc31 | 1234 | exp_links => ["link"], |
255c05b7 MW |
1235 | exp_add_error => "yes", |
1236 | exp_rem_error => "yes", | |
1237 | }], | |
1238 | option => "clean", | |
912541b0 | 1239 | rules => <<EOF |
5754e74c | 1240 | KERNEL=="tty0", SYMLINK+="tty0" |
b8669191 | 1241 | EOF |
912541b0 KS |
1242 | }, |
1243 | { | |
1244 | desc => "symlink %n substitution", | |
255c05b7 MW |
1245 | devices => [ |
1246 | { | |
1247 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1248 | exp_links => ["symlink0"], |
255c05b7 | 1249 | }], |
912541b0 | 1250 | rules => <<EOF |
5754e74c | 1251 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n" |
b8669191 | 1252 | EOF |
912541b0 KS |
1253 | }, |
1254 | { | |
1255 | desc => "symlink %k substitution", | |
255c05b7 MW |
1256 | devices => [ |
1257 | { | |
1258 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1259 | exp_links => ["symlink-ttyACM0"], |
255c05b7 | 1260 | }], |
912541b0 | 1261 | rules => <<EOF |
5754e74c | 1262 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k" |
b8669191 | 1263 | EOF |
912541b0 KS |
1264 | }, |
1265 | { | |
1266 | desc => "symlink %M:%m substitution", | |
255c05b7 MW |
1267 | devices => [ |
1268 | { | |
1269 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1270 | exp_links => ["major-166:0"], |
255c05b7 | 1271 | }], |
912541b0 | 1272 | rules => <<EOF |
5754e74c | 1273 | KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m" |
b8669191 | 1274 | EOF |
912541b0 KS |
1275 | }, |
1276 | { | |
1277 | desc => "symlink %b substitution", | |
255c05b7 MW |
1278 | devices => [ |
1279 | { | |
1280 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1281 | exp_links => ["symlink-0:0:0:0"], |
255c05b7 | 1282 | }], |
912541b0 | 1283 | rules => <<EOF |
220893b3 | 1284 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b" |
b8669191 | 1285 | EOF |
912541b0 KS |
1286 | }, |
1287 | { | |
1288 | desc => "symlink %c substitution", | |
255c05b7 MW |
1289 | devices => [ |
1290 | { | |
1291 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1292 | exp_links => ["test"], |
255c05b7 | 1293 | }], |
912541b0 | 1294 | rules => <<EOF |
d914e445 | 1295 | KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c" |
b8669191 | 1296 | EOF |
912541b0 KS |
1297 | }, |
1298 | { | |
1299 | desc => "symlink %c{N} substitution", | |
255c05b7 MW |
1300 | devices => [ |
1301 | { | |
1302 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1303 | exp_links => ["test"], |
1304 | not_exp_links => ["symlink", "this"], | |
255c05b7 | 1305 | }], |
912541b0 | 1306 | rules => <<EOF |
d914e445 | 1307 | KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}" |
b8669191 | 1308 | EOF |
912541b0 KS |
1309 | }, |
1310 | { | |
1311 | desc => "symlink %c{N+} substitution", | |
255c05b7 MW |
1312 | devices => [ |
1313 | { | |
1314 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1315 | exp_links => ["test", "this"], |
1316 | not_exp_links => ["symlink"], | |
255c05b7 | 1317 | }], |
912541b0 | 1318 | rules => <<EOF |
d914e445 | 1319 | KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}" |
b8669191 | 1320 | EOF |
912541b0 KS |
1321 | }, |
1322 | { | |
1323 | desc => "symlink only rule with %c{N+}", | |
255c05b7 MW |
1324 | devices => [ |
1325 | { | |
1326 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
1327 | exp_links => ["test", "this"], |
1328 | not_exp_links => ["symlink"], | |
255c05b7 | 1329 | }], |
912541b0 | 1330 | rules => <<EOF |
d914e445 | 1331 | SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}" |
b8669191 | 1332 | EOF |
912541b0 KS |
1333 | }, |
1334 | { | |
1335 | desc => "symlink %s{filename} substitution", | |
255c05b7 MW |
1336 | devices => [ |
1337 | { | |
1338 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1339 | exp_links => ["166:0"], |
255c05b7 | 1340 | }], |
912541b0 | 1341 | rules => <<EOF |
5754e74c | 1342 | KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}" |
b8669191 | 1343 | EOF |
912541b0 KS |
1344 | }, |
1345 | { | |
1346 | desc => "program result substitution (numbered part of)", | |
255c05b7 MW |
1347 | devices => [ |
1348 | { | |
1349 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
1350 | exp_links => ["link1", "link2"], |
1351 | not_exp_links => ["node"], | |
255c05b7 | 1352 | }], |
912541b0 | 1353 | rules => <<EOF |
d914e445 | 1354 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}" |
b8669191 | 1355 | EOF |
912541b0 KS |
1356 | }, |
1357 | { | |
1358 | desc => "program result substitution (numbered part of+)", | |
255c05b7 MW |
1359 | devices => [ |
1360 | { | |
1361 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
e62acc31 MW |
1362 | exp_links => ["link1", "link2", "link3", "link4"], |
1363 | not_exp_links => ["node"], | |
255c05b7 | 1364 | }], |
912541b0 | 1365 | rules => <<EOF |
d914e445 | 1366 | SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}" |
7efa217d | 1367 | EOF |
912541b0 KS |
1368 | }, |
1369 | { | |
1370 | desc => "SUBSYSTEM match test", | |
255c05b7 MW |
1371 | devices => [ |
1372 | { | |
1373 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
1374 | exp_links => ["node"], |
1375 | not_exp_links => ["should_not_match", "should_not_match2"], | |
255c05b7 | 1376 | }], |
912541b0 | 1377 | rules => <<EOF |
5754e74c KS |
1378 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc" |
1379 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block" | |
1380 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc" | |
2092fbcd | 1381 | EOF |
912541b0 KS |
1382 | }, |
1383 | { | |
1384 | desc => "DRIVERS match test", | |
255c05b7 MW |
1385 | devices => [ |
1386 | { | |
1387 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
1388 | exp_links => ["node"], |
1389 | not_exp_links => ["should_not_match"] | |
255c05b7 | 1390 | }], |
912541b0 | 1391 | rules => <<EOF |
5754e74c KS |
1392 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong" |
1393 | SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd" | |
c1ab0461 | 1394 | EOF |
912541b0 KS |
1395 | }, |
1396 | { | |
1397 | desc => "devnode substitution test", | |
255c05b7 MW |
1398 | devices => [ |
1399 | { | |
1400 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1401 | exp_links => ["node"], |
255c05b7 | 1402 | }], |
912541b0 | 1403 | rules => <<EOF |
220893b3 | 1404 | SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node" |
69aa6dfb | 1405 | EOF |
912541b0 KS |
1406 | }, |
1407 | { | |
1408 | desc => "parent node name substitution test", | |
255c05b7 MW |
1409 | devices => [ |
1410 | { | |
1411 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1412 | exp_links => ["sda-part-1"], |
255c05b7 | 1413 | }], |
912541b0 | 1414 | rules => <<EOF |
06d4d4e2 | 1415 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-%n" |
69aa6dfb | 1416 | EOF |
912541b0 KS |
1417 | }, |
1418 | { | |
1419 | desc => "udev_root substitution", | |
255c05b7 MW |
1420 | devices => [ |
1421 | { | |
1422 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1423 | exp_links => ["start-/dev-end"], |
255c05b7 | 1424 | }], |
912541b0 | 1425 | rules => <<EOF |
5754e74c | 1426 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end" |
3b6ed8bb | 1427 | EOF |
912541b0 KS |
1428 | }, |
1429 | { | |
17cce031 | 1430 | # This is not supported any more |
912541b0 | 1431 | desc => "last_rule option", |
255c05b7 MW |
1432 | devices => [ |
1433 | { | |
1434 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1435 | exp_links => ["last"], |
17cce031 MW |
1436 | not_exp_links => ["very-last"], |
1437 | exp_nodev_error => "yes", | |
255c05b7 | 1438 | }], |
912541b0 | 1439 | rules => <<EOF |
c4edd0ad | 1440 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule" |
5754e74c | 1441 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last" |
28ce66de | 1442 | EOF |
912541b0 KS |
1443 | }, |
1444 | { | |
1445 | desc => "negation KERNEL!=", | |
255c05b7 MW |
1446 | devices => [ |
1447 | { | |
1448 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1449 | exp_links => ["match", "before"], |
1450 | not_exp_links => ["matches-but-is-negated"], | |
255c05b7 | 1451 | }], |
912541b0 | 1452 | rules => <<EOF |
5754e74c KS |
1453 | SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated" |
1454 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before" | |
1455 | SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match" | |
28ce66de | 1456 | EOF |
912541b0 KS |
1457 | }, |
1458 | { | |
1459 | desc => "negation SUBSYSTEM!=", | |
255c05b7 MW |
1460 | devices => [ |
1461 | { | |
1462 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1463 | exp_links => ["before", "not-anything"], |
1464 | not_exp_links => ["matches-but-is-negated"], | |
255c05b7 | 1465 | }], |
912541b0 | 1466 | rules => <<EOF |
5754e74c KS |
1467 | SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated" |
1468 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before" | |
1469 | SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything" | |
28ce66de | 1470 | EOF |
912541b0 KS |
1471 | }, |
1472 | { | |
1473 | desc => "negation PROGRAM!= exit code", | |
255c05b7 MW |
1474 | devices => [ |
1475 | { | |
1476 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1477 | exp_links => ["before", "nonzero-program"], |
255c05b7 | 1478 | }], |
912541b0 | 1479 | rules => <<EOF |
5754e74c | 1480 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before" |
d914e445 | 1481 | KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program" |
3e5958de | 1482 | EOF |
912541b0 KS |
1483 | }, |
1484 | { | |
1485 | desc => "ENV{} test", | |
255c05b7 MW |
1486 | devices => [ |
1487 | { | |
1488 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1489 | exp_links => ["true"], |
1490 | not_exp_links => ["bad", "wrong"], | |
255c05b7 | 1491 | }], |
912541b0 | 1492 | rules => <<EOF |
a1af6b04 | 1493 | ENV{ENV_KEY_TEST}="test" |
5754e74c KS |
1494 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong" |
1495 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true" | |
1496 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad" | |
3e5958de | 1497 | EOF |
912541b0 KS |
1498 | }, |
1499 | { | |
1500 | desc => "ENV{} test", | |
255c05b7 MW |
1501 | devices => [ |
1502 | { | |
1503 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1504 | exp_links => ["true"], |
1505 | not_exp_links => ["bad", "wrong", "no"], | |
255c05b7 | 1506 | }], |
912541b0 | 1507 | rules => <<EOF |
a1af6b04 | 1508 | ENV{ENV_KEY_TEST}="test" |
5754e74c KS |
1509 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong" |
1510 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no" | |
1511 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true" | |
1512 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad" | |
5618b561 | 1513 | EOF |
912541b0 KS |
1514 | }, |
1515 | { | |
1516 | desc => "ENV{} test (assign)", | |
255c05b7 MW |
1517 | devices => [ |
1518 | { | |
1519 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1520 | exp_links => ["true", "before"], |
1521 | not_exp_links => ["no"], | |
255c05b7 | 1522 | }], |
912541b0 | 1523 | rules => <<EOF |
c4edd0ad | 1524 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true" |
5754e74c KS |
1525 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no" |
1526 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before" | |
1527 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true" | |
ac528431 | 1528 | EOF |
912541b0 KS |
1529 | }, |
1530 | { | |
1531 | desc => "ENV{} test (assign 2 times)", | |
255c05b7 MW |
1532 | devices => [ |
1533 | { | |
1534 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1535 | exp_links => ["true", "before"], |
1536 | not_exp_links => ["no", "bad"], | |
255c05b7 | 1537 | }], |
912541b0 | 1538 | rules => <<EOF |
ac528431 KS |
1539 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true" |
1540 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}" | |
5754e74c KS |
1541 | SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before" |
1542 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no" | |
06d4d4e2 | 1543 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="bad" |
5754e74c | 1544 | SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true" |
5618b561 | 1545 | EOF |
912541b0 KS |
1546 | }, |
1547 | { | |
1548 | desc => "ENV{} test (assign2)", | |
255c05b7 MW |
1549 | devices => [ |
1550 | { | |
1551 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1552 | exp_links => ["part"], |
1553 | not_exp_links => ["disk"], | |
1554 | }, | |
06d4d4e2 MW |
1555 | { |
1556 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
1557 | exp_links => ["disk"], | |
1558 | not_exp_links => ["part"], | |
1559 | }, | |
e62acc31 | 1560 | ], |
912541b0 | 1561 | rules => <<EOF |
d59c84ef KS |
1562 | SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false" |
1563 | SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true" | |
5754e74c KS |
1564 | ENV{MAINDEVICE}=="true", SYMLINK+="disk" |
1565 | SUBSYSTEM=="block", SYMLINK+="before" | |
1566 | ENV{PARTITION}=="true", SYMLINK+="part" | |
18614ab2 | 1567 | EOF |
912541b0 KS |
1568 | }, |
1569 | { | |
1570 | desc => "untrusted string sanitize", | |
255c05b7 MW |
1571 | devices => [ |
1572 | { | |
1573 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1574 | exp_links => ["sane"], |
255c05b7 | 1575 | }], |
912541b0 | 1576 | rules => <<EOF |
d914e445 | 1577 | SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane" |
764ce7f2 | 1578 | EOF |
912541b0 KS |
1579 | }, |
1580 | { | |
1581 | desc => "untrusted string sanitize (don't replace utf8)", | |
255c05b7 MW |
1582 | devices => [ |
1583 | { | |
1584 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1585 | exp_links => ["uber"], |
255c05b7 | 1586 | }], |
912541b0 | 1587 | rules => <<EOF |
d914e445 | 1588 | SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber" |
764ce7f2 | 1589 | EOF |
912541b0 KS |
1590 | }, |
1591 | { | |
1592 | desc => "untrusted string sanitize (replace invalid utf8)", | |
255c05b7 MW |
1593 | devices => [ |
1594 | { | |
1595 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1596 | exp_links => ["replaced"], |
255c05b7 | 1597 | }], |
912541b0 | 1598 | rules => <<EOF |
d914e445 | 1599 | SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced" |
98bbc835 | 1600 | EOF |
912541b0 KS |
1601 | }, |
1602 | { | |
1603 | desc => "read sysfs value from parent device", | |
255c05b7 MW |
1604 | devices => [ |
1605 | { | |
1606 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1607 | exp_links => ["serial-354172020305000"], |
255c05b7 | 1608 | }], |
912541b0 | 1609 | rules => <<EOF |
5754e74c | 1610 | KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}" |
db949b02 | 1611 | EOF |
912541b0 KS |
1612 | }, |
1613 | { | |
1614 | desc => "match against empty key string", | |
255c05b7 MW |
1615 | devices => [ |
1616 | { | |
1617 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
1618 | exp_links => ["ok"], |
1619 | not_exp_links => ["not-1-ok", "not-2-ok", "not-3-ok"], | |
255c05b7 | 1620 | }], |
912541b0 | 1621 | rules => <<EOF |
5754e74c KS |
1622 | KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok" |
1623 | KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok" | |
1624 | KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok" | |
1625 | KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok" | |
821d0ec8 | 1626 | EOF |
912541b0 KS |
1627 | }, |
1628 | { | |
1629 | desc => "check ACTION value", | |
255c05b7 MW |
1630 | devices => [ |
1631 | { | |
1632 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
1633 | exp_links => ["ok"], |
1634 | not_exp_links => ["unknown-not-ok"], | |
255c05b7 | 1635 | }], |
912541b0 | 1636 | rules => <<EOF |
5754e74c KS |
1637 | ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok" |
1638 | ACTION=="add", KERNEL=="sda", SYMLINK+="ok" | |
c974742b | 1639 | EOF |
912541b0 KS |
1640 | }, |
1641 | { | |
1642 | desc => "final assignment", | |
255c05b7 MW |
1643 | devices => [ |
1644 | { | |
1645 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1646 | exp_links => ["ok"], |
255c05b7 MW |
1647 | exp_perms => "root:tty:0640", |
1648 | }], | |
912541b0 | 1649 | rules => <<EOF |
d960ad15 | 1650 | KERNEL=="sda", GROUP:="tty" |
06d4d4e2 | 1651 | KERNEL=="sda", GROUP="root", MODE="0640", SYMLINK+="ok" |
c974742b | 1652 | EOF |
912541b0 KS |
1653 | }, |
1654 | { | |
1655 | desc => "final assignment 2", | |
255c05b7 MW |
1656 | devices => [ |
1657 | { | |
1658 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1659 | exp_links => ["ok"], |
255c05b7 MW |
1660 | exp_perms => "root:tty:0640", |
1661 | }], | |
912541b0 | 1662 | rules => <<EOF |
d960ad15 | 1663 | KERNEL=="sda", GROUP:="tty" |
c974742b | 1664 | SUBSYSTEM=="block", MODE:="640" |
06d4d4e2 | 1665 | KERNEL=="sda", GROUP="root", MODE="0666", SYMLINK+="ok" |
bd0ed2ff | 1666 | EOF |
912541b0 KS |
1667 | }, |
1668 | { | |
1669 | desc => "env substitution", | |
255c05b7 MW |
1670 | devices => [ |
1671 | { | |
1672 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1673 | exp_links => ["node-add-me"], |
255c05b7 | 1674 | }], |
912541b0 | 1675 | rules => <<EOF |
5754e74c | 1676 | KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me" |
995aec87 | 1677 | EOF |
912541b0 KS |
1678 | }, |
1679 | { | |
1680 | desc => "reset list to current value", | |
255c05b7 MW |
1681 | devices => [ |
1682 | { | |
1683 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1684 | exp_links => ["three"], |
1685 | not_exp_links => ["two", "one"], | |
255c05b7 | 1686 | }], |
912541b0 | 1687 | rules => <<EOF |
c7fcba1b KS |
1688 | KERNEL=="ttyACM[0-9]*", SYMLINK+="one" |
1689 | KERNEL=="ttyACM[0-9]*", SYMLINK+="two" | |
1690 | KERNEL=="ttyACM[0-9]*", SYMLINK="three" | |
647f7c49 | 1691 | EOF |
912541b0 KS |
1692 | }, |
1693 | { | |
1694 | desc => "test empty SYMLINK+ (empty override)", | |
255c05b7 MW |
1695 | devices => [ |
1696 | { | |
1697 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1698 | exp_links => ["right"], |
1699 | not_exp_links => ["wrong"], | |
255c05b7 | 1700 | }], |
912541b0 | 1701 | rules => <<EOF |
5754e74c KS |
1702 | KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong" |
1703 | KERNEL=="ttyACM[0-9]*", SYMLINK="" | |
1704 | KERNEL=="ttyACM[0-9]*", SYMLINK+="right" | |
0cd4ac47 | 1705 | EOF |
912541b0 KS |
1706 | }, |
1707 | { | |
1708 | desc => "test multi matches", | |
255c05b7 MW |
1709 | devices => [ |
1710 | { | |
1711 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 | 1712 | exp_links => ["right", "before"], |
255c05b7 | 1713 | }], |
912541b0 | 1714 | rules => <<EOF |
5754e74c KS |
1715 | KERNEL=="ttyACM*", SYMLINK+="before" |
1716 | KERNEL=="ttyACM*|nothing", SYMLINK+="right" | |
0cd4ac47 | 1717 | EOF |
912541b0 KS |
1718 | }, |
1719 | { | |
1720 | desc => "test multi matches 2", | |
255c05b7 MW |
1721 | devices => [ |
1722 | { | |
1723 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1724 | exp_links => ["right", "before"], |
1725 | not_exp_links => ["nomatch"], | |
255c05b7 | 1726 | }], |
912541b0 | 1727 | rules => <<EOF |
5754e74c KS |
1728 | KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch" |
1729 | KERNEL=="ttyACM*", SYMLINK+="before" | |
1730 | KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right" | |
91a75e4a | 1731 | EOF |
912541b0 KS |
1732 | }, |
1733 | { | |
1734 | desc => "test multi matches 3", | |
255c05b7 MW |
1735 | devices => [ |
1736 | { | |
1737 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1738 | exp_links => ["right"], |
1739 | not_exp_links => ["nomatch", "wrong1", "wrong2"], | |
255c05b7 | 1740 | }], |
912541b0 | 1741 | rules => <<EOF |
5754e74c KS |
1742 | KERNEL=="dontknow|nothing", SYMLINK+="nomatch" |
1743 | KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1" | |
1744 | KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2" | |
1745 | KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right" | |
91a75e4a | 1746 | EOF |
912541b0 KS |
1747 | }, |
1748 | { | |
1749 | desc => "test multi matches 4", | |
255c05b7 MW |
1750 | devices => [ |
1751 | { | |
1752 | devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", | |
e62acc31 MW |
1753 | exp_links => ["right"], |
1754 | not_exp_links => ["nomatch", "wrong1", "wrong2", "wrong3"], | |
255c05b7 | 1755 | }], |
912541b0 | 1756 | rules => <<EOF |
5754e74c KS |
1757 | KERNEL=="dontknow|nothing", SYMLINK+="nomatch" |
1758 | KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1" | |
1759 | KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2" | |
1760 | KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right" | |
1761 | KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3" | |
48d26c90 YW |
1762 | EOF |
1763 | }, | |
1764 | { | |
255c05b7 MW |
1765 | desc => "test multi matches 5", |
1766 | devices => [ | |
1767 | { | |
1768 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1769 | exp_links => ["found"], |
255c05b7 MW |
1770 | not_exp_name => "bad", |
1771 | }], | |
48d26c90 YW |
1772 | rules => <<EOF |
1773 | KERNEL=="sda", TAG="foo" | |
1774 | TAGS=="|foo", SYMLINK+="found" | |
1775 | TAGS=="|aaa", SYMLINK+="bad" | |
1776 | EOF | |
1777 | }, | |
1778 | { | |
1779 | desc => "test multi matches 6", | |
255c05b7 MW |
1780 | devices => [ |
1781 | { | |
1782 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1783 | exp_links => ["found"], |
255c05b7 MW |
1784 | not_exp_name => "bad", |
1785 | }], | |
48d26c90 YW |
1786 | rules => <<EOF |
1787 | KERNEL=="sda", TAG="" | |
1788 | TAGS=="|foo", SYMLINK+="found" | |
1789 | TAGS=="aaa|bbb", SYMLINK+="bad" | |
1790 | EOF | |
1791 | }, | |
1792 | { | |
1793 | desc => "test multi matches 7", | |
255c05b7 MW |
1794 | devices => [ |
1795 | { | |
1796 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1797 | exp_links => ["found"], |
255c05b7 MW |
1798 | not_exp_name => "bad", |
1799 | }], | |
48d26c90 YW |
1800 | rules => <<EOF |
1801 | KERNEL=="sda", TAG="foo" | |
1802 | TAGS=="foo||bar", SYMLINK+="found" | |
1803 | TAGS=="aaa||bbb", SYMLINK+="bad" | |
1804 | EOF | |
1805 | }, | |
1806 | { | |
1807 | desc => "test multi matches 8", | |
255c05b7 MW |
1808 | devices => [ |
1809 | { | |
1810 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1811 | exp_links => ["found"], |
255c05b7 MW |
1812 | not_exp_name => "bad", |
1813 | }], | |
48d26c90 YW |
1814 | rules => <<EOF |
1815 | KERNEL=="sda", TAG="" | |
1816 | TAGS=="foo||bar", SYMLINK+="found" | |
1817 | TAGS=="aaa|bbb", SYMLINK+="bad" | |
1818 | EOF | |
1819 | }, | |
1820 | { | |
1821 | desc => "test multi matches 9", | |
255c05b7 MW |
1822 | devices => [ |
1823 | { | |
1824 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1825 | exp_links => ["found"], |
255c05b7 MW |
1826 | not_exp_name => "bad", |
1827 | }], | |
48d26c90 YW |
1828 | rules => <<EOF |
1829 | KERNEL=="sda", TAG="foo" | |
1830 | TAGS=="foo|", SYMLINK+="found" | |
1831 | TAGS=="aaa|", SYMLINK+="bad" | |
1832 | EOF | |
1833 | }, | |
1834 | { | |
1835 | desc => "test multi matches 10", | |
255c05b7 MW |
1836 | devices => [ |
1837 | { | |
1838 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1839 | exp_links => ["found"], |
255c05b7 MW |
1840 | not_exp_name => "bad", |
1841 | }], | |
48d26c90 YW |
1842 | rules => <<EOF |
1843 | KERNEL=="sda", TAG="" | |
1844 | TAGS=="foo|", SYMLINK+="found" | |
1845 | TAGS=="aaa|bbb", SYMLINK+="bad" | |
0d3a8bc7 YG |
1846 | EOF |
1847 | }, | |
1848 | { | |
1849 | desc => "test multi matches 11", | |
255c05b7 MW |
1850 | devices => [ |
1851 | { | |
1852 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1853 | exp_links => ["found"], |
255c05b7 MW |
1854 | not_exp_name => "bad", |
1855 | }], | |
0d3a8bc7 YG |
1856 | rules => <<EOF |
1857 | KERNEL=="sda", TAG="c" | |
1858 | TAGS=="foo||bar||c", SYMLINK+="found" | |
1859 | TAGS=="aaa||bbb||ccc", SYMLINK+="bad" | |
0bfb84e1 | 1860 | EOF |
912541b0 KS |
1861 | }, |
1862 | { | |
a96cd21d | 1863 | desc => "IMPORT parent test", |
255c05b7 MW |
1864 | devices => [ |
1865 | { | |
1866 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1867 | exp_links => ["parent"], |
a96cd21d | 1868 | }, |
255c05b7 MW |
1869 | { |
1870 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1871 | exp_links => ["parentenv-parent_right"], |
255c05b7 | 1872 | }], |
a96cd21d | 1873 | sleep_us => 500000, # Serialized! We need to sleep here after adding sda |
912541b0 | 1874 | rules => <<EOF |
5754e74c | 1875 | KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}" |
a96cd21d MW |
1876 | KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'" |
1877 | KERNEL=="sda", SYMLINK+="parent" | |
594dd610 | 1878 | EOF |
912541b0 KS |
1879 | }, |
1880 | { | |
1881 | desc => "GOTO test", | |
255c05b7 MW |
1882 | devices => [ |
1883 | { | |
1884 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1885 | exp_links => ["right"], |
1886 | not_exp_test => ["wrong", "wrong2"], | |
255c05b7 | 1887 | }], |
912541b0 | 1888 | rules => <<EOF |
594dd610 | 1889 | KERNEL=="sda1", GOTO="TEST" |
5754e74c | 1890 | KERNEL=="sda1", SYMLINK+="wrong" |
6880b25d | 1891 | KERNEL=="sda1", GOTO="BAD" |
5754e74c KS |
1892 | KERNEL=="sda1", SYMLINK+="", LABEL="NO" |
1893 | KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end" | |
1894 | KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD" | |
9dae0e89 | 1895 | LABEL="end" |
0c377989 | 1896 | EOF |
912541b0 KS |
1897 | }, |
1898 | { | |
1899 | desc => "GOTO label does not exist", | |
255c05b7 MW |
1900 | devices => [ |
1901 | { | |
1902 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 | 1903 | exp_links => ["right"], |
255c05b7 | 1904 | }], |
912541b0 | 1905 | rules => <<EOF |
0c377989 | 1906 | KERNEL=="sda1", GOTO="does-not-exist" |
5754e74c | 1907 | KERNEL=="sda1", SYMLINK+="right", |
0c377989 | 1908 | LABEL="exists" |
d59c84ef | 1909 | EOF |
912541b0 KS |
1910 | }, |
1911 | { | |
1912 | desc => "SYMLINK+ compare test", | |
255c05b7 MW |
1913 | devices => [ |
1914 | { | |
1915 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1916 | exp_links => ["right", "link"], |
1917 | not_exp_links => ["wrong"], | |
255c05b7 | 1918 | }], |
912541b0 | 1919 | rules => <<EOF |
5754e74c KS |
1920 | KERNEL=="sda1", SYMLINK+="link" |
1921 | KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right" | |
1922 | KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong" | |
d59c84ef | 1923 | EOF |
912541b0 KS |
1924 | }, |
1925 | { | |
1926 | desc => "invalid key operation", | |
255c05b7 MW |
1927 | devices => [ |
1928 | { | |
1929 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1930 | exp_links => ["yes"], |
1931 | not_exp_links => ["no"], | |
255c05b7 | 1932 | }], |
912541b0 | 1933 | rules => <<EOF |
5754e74c KS |
1934 | KERNEL="sda1", SYMLINK+="no" |
1935 | KERNEL=="sda1", SYMLINK+="yes" | |
864b9b5e | 1936 | EOF |
912541b0 KS |
1937 | }, |
1938 | { | |
1939 | desc => "operator chars in attribute", | |
255c05b7 MW |
1940 | devices => [ |
1941 | { | |
1942 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1943 | exp_links => ["yes"], |
255c05b7 | 1944 | }], |
912541b0 | 1945 | rules => <<EOF |
5754e74c | 1946 | KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes" |
d4ae9925 | 1947 | EOF |
912541b0 KS |
1948 | }, |
1949 | { | |
1950 | desc => "overlong comment line", | |
255c05b7 MW |
1951 | devices => [ |
1952 | { | |
1953 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
e62acc31 MW |
1954 | exp_links => ["yes"], |
1955 | not_exp_links => ["no"], | |
255c05b7 | 1956 | }], |
912541b0 | 1957 | rules => <<EOF |
d4ae9925 | 1958 | # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 |
d960ad15 | 1959 | # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 |
5754e74c KS |
1960 | KERNEL=="sda1", SYMLINK+=="no" |
1961 | KERNEL=="sda1", SYMLINK+="yes" | |
4ad47b2d | 1962 | EOF |
912541b0 KS |
1963 | }, |
1964 | { | |
1965 | desc => "magic subsys/kernel lookup", | |
255c05b7 MW |
1966 | devices => [ |
1967 | { | |
1968 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1969 | exp_links => ["00:16:41:e2:8d:ff"], |
255c05b7 | 1970 | }], |
912541b0 | 1971 | rules => <<EOF |
5754e74c | 1972 | KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}" |
03f65fe6 | 1973 | EOF |
912541b0 KS |
1974 | }, |
1975 | { | |
1976 | desc => "TEST absolute path", | |
255c05b7 MW |
1977 | devices => [ |
1978 | { | |
1979 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
1980 | exp_links => ["there"], |
1981 | not_exp_links => ["notthere"], | |
255c05b7 | 1982 | }], |
912541b0 | 1983 | rules => <<EOF |
f0289577 LB |
1984 | TEST=="/etc/passwd", SYMLINK+="there" |
1985 | TEST!="/etc/passwd", SYMLINK+="notthere" | |
03f65fe6 | 1986 | EOF |
912541b0 KS |
1987 | }, |
1988 | { | |
1989 | desc => "TEST subsys/kernel lookup", | |
255c05b7 MW |
1990 | devices => [ |
1991 | { | |
1992 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 1993 | exp_links => ["yes"], |
255c05b7 | 1994 | }], |
912541b0 | 1995 | rules => <<EOF |
5754e74c | 1996 | KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes" |
03f65fe6 | 1997 | EOF |
912541b0 KS |
1998 | }, |
1999 | { | |
2000 | desc => "TEST relative path", | |
255c05b7 MW |
2001 | devices => [ |
2002 | { | |
2003 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2004 | exp_links => ["relative"], |
255c05b7 | 2005 | }], |
912541b0 | 2006 | rules => <<EOF |
5754e74c | 2007 | KERNEL=="sda", TEST=="size", SYMLINK+="relative" |
0ea5e96e | 2008 | EOF |
912541b0 KS |
2009 | }, |
2010 | { | |
2011 | desc => "TEST wildcard substitution (find queue/nr_requests)", | |
255c05b7 MW |
2012 | devices => [ |
2013 | { | |
2014 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2015 | exp_links => ["found-subdir"], |
255c05b7 | 2016 | }], |
912541b0 | 2017 | rules => <<EOF |
5754e74c | 2018 | KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir" |
cf100ca7 | 2019 | EOF |
912541b0 KS |
2020 | }, |
2021 | { | |
2022 | desc => "TEST MODE=0000", | |
255c05b7 MW |
2023 | devices => [ |
2024 | { | |
2025 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
255c05b7 MW |
2026 | exp_perms => "0:0:0000", |
2027 | exp_rem_error => "yes", | |
2028 | }], | |
912541b0 | 2029 | rules => <<EOF |
cf100ca7 | 2030 | KERNEL=="sda", MODE="0000" |
a367f04e | 2031 | EOF |
912541b0 KS |
2032 | }, |
2033 | { | |
2034 | desc => "TEST PROGRAM feeds OWNER, GROUP, MODE", | |
255c05b7 MW |
2035 | devices => [ |
2036 | { | |
2037 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
255c05b7 | 2038 | exp_perms => "1:1:0400", |
255c05b7 | 2039 | }], |
912541b0 | 2040 | rules => <<EOF |
6880b25d | 2041 | KERNEL=="sda", MODE="666" |
9158d03e | 2042 | KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}" |
ff94cec3 | 2043 | EOF |
912541b0 KS |
2044 | }, |
2045 | { | |
2046 | desc => "TEST PROGRAM feeds MODE with overflow", | |
255c05b7 MW |
2047 | devices => [ |
2048 | { | |
2049 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
255c05b7 MW |
2050 | exp_perms => "0:0:0440", |
2051 | exp_rem_error => "yes", | |
2052 | }], | |
912541b0 | 2053 | rules => <<EOF |
6880b25d | 2054 | KERNEL=="sda", MODE="440" |
d914e445 | 2055 | KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}" |
dc4c7e46 | 2056 | EOF |
912541b0 KS |
2057 | }, |
2058 | { | |
2059 | desc => "magic [subsys/sysname] attribute substitution", | |
255c05b7 MW |
2060 | devices => [ |
2061 | { | |
2062 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2063 | exp_links => ["sda-8741C4G-end"], |
255c05b7 MW |
2064 | exp_perms => "0:0:0600", |
2065 | }], | |
912541b0 | 2066 | rules => <<EOF |
0f52fdee | 2067 | KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end" |
d7867b31 | 2068 | EOF |
912541b0 KS |
2069 | }, |
2070 | { | |
2071 | desc => "builtin path_id", | |
255c05b7 MW |
2072 | devices => [ |
2073 | { | |
2074 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2075 | exp_links => ["disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0"], |
255c05b7 | 2076 | }], |
912541b0 | 2077 | rules => <<EOF |
d7867b31 KS |
2078 | KERNEL=="sda", IMPORT{builtin}="path_id" |
2079 | KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}" | |
bf8f7583 MP |
2080 | EOF |
2081 | }, | |
2082 | { | |
2083 | desc => "add and match tag", | |
255c05b7 MW |
2084 | devices => [ |
2085 | { | |
2086 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 MW |
2087 | exp_links => ["found"], |
2088 | not_exp_links => ["bad"], | |
255c05b7 | 2089 | }], |
bf8f7583 MP |
2090 | rules => <<EOF |
2091 | SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green" | |
2092 | TAGS=="green", SYMLINK+="found" | |
2093 | TAGS=="blue", SYMLINK+="bad" | |
2094 | EOF | |
2095 | }, | |
2096 | { | |
2097 | desc => "don't crash with lots of tags", | |
255c05b7 MW |
2098 | devices => [ |
2099 | { | |
2100 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2101 | exp_links => ["found"], |
255c05b7 | 2102 | }], |
bf8f7583 MP |
2103 | rules => $rules_10k_tags . <<EOF |
2104 | TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found" | |
1e797cf5 YW |
2105 | EOF |
2106 | }, | |
2107 | { | |
d35976c6 | 2108 | desc => "continuations", |
255c05b7 MW |
2109 | devices => [ |
2110 | { | |
2111 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2112 | exp_links => ["found"], |
255c05b7 MW |
2113 | not_exp_name => "bad", |
2114 | }], | |
1e797cf5 YW |
2115 | rules => $rules_10k_tags_continuation . <<EOF |
2116 | TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="bad" | |
d35976c6 YW |
2117 | KERNEL=="sda",\\ |
2118 | # comment in continuation | |
2119 | TAG+="hoge1",\\ | |
2120 | # space before comment | |
2121 | TAG+="hoge2",\\ | |
2122 | # spaces before and after token are dropped | |
2123 | TAG+="hoge3", \\ | |
84a0819c YW |
2124 | \\ |
2125 | \\ | |
d35976c6 YW |
2126 | TAG+="hoge4" |
2127 | TAGS=="hoge1", TAGS=="hoge2", TAGS=="hoge3", TAGS=="hoge4", SYMLINK+="found" | |
84a0819c YW |
2128 | EOF |
2129 | }, | |
2130 | { | |
2131 | desc => "continuations with empty line", | |
255c05b7 MW |
2132 | devices => [ |
2133 | { | |
2134 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2135 | exp_links => ["found"], |
255c05b7 MW |
2136 | not_exp_name => "bad", |
2137 | ||
2138 | }], | |
84a0819c YW |
2139 | rules => <<EOF |
2140 | # empty line finishes continuation | |
2141 | KERNEL=="sda", TAG+="foo" \\ | |
2142 | ||
2143 | KERNEL=="sdb", TAG+="hoge" | |
2144 | KERNEL=="sda", TAG+="aaa" \\ | |
2145 | KERNEL=="sdb", TAG+="bbb" | |
2146 | TAGS=="foo", SYMLINK+="found" | |
2147 | TAGS=="aaa", SYMLINK+="bad" | |
255c05b7 | 2148 | EOF |
84a0819c YW |
2149 | }, |
2150 | { | |
2151 | desc => "continuations with white only line", | |
255c05b7 MW |
2152 | devices => [ |
2153 | { | |
2154 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda", | |
e62acc31 | 2155 | exp_links => ["found"], |
255c05b7 MW |
2156 | not_exp_name => "bad", |
2157 | }], | |
84a0819c YW |
2158 | rules => <<EOF |
2159 | # space only line finishes continuation | |
2160 | KERNEL=="sda", TAG+="foo" \\ | |
2161 | \t | |
2162 | KERNEL=="sdb", TAG+="hoge" | |
2163 | KERNEL=="sda", TAG+="aaa" \\ | |
2164 | KERNEL=="sdb", TAG+="bbb" | |
2165 | TAGS=="foo", SYMLINK+="found" | |
2166 | TAGS=="aaa", SYMLINK+="bad" | |
4a0ec82d MW |
2167 | EOF |
2168 | }, | |
2169 | { | |
2170 | desc => "multiple devices", | |
2171 | devices => [ | |
2172 | { | |
2173 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
2174 | exp_links => ["part-1"], | |
2175 | }, | |
2176 | { | |
2177 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
2178 | exp_links => ["part-5"], | |
2179 | }, | |
2180 | { | |
2181 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6", | |
2182 | exp_links => ["part-6"], | |
2183 | }, | |
2184 | { | |
2185 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7", | |
2186 | exp_links => ["part-7"], | |
2187 | }, | |
2188 | { | |
2189 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8", | |
2190 | exp_links => ["part-8"], | |
2191 | }, | |
2192 | { | |
2193 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9", | |
2194 | exp_links => ["part-9"], | |
2195 | }, | |
2196 | { | |
2197 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10", | |
2198 | exp_links => ["part-10"], | |
2199 | }, | |
2200 | ], | |
2201 | rules => <<EOF | |
2202 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n" | |
2203 | EOF | |
2204 | }, | |
2205 | { | |
2206 | desc => "multiple devices, same link name, positive prio", | |
2ab0a8d0 | 2207 | repeat => 100, |
4a0ec82d MW |
2208 | devices => [ |
2209 | { | |
2210 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
2211 | exp_links => ["part-1"], | |
2212 | not_exp_links => ["partition"], | |
2213 | }, | |
2214 | { | |
2215 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
2216 | exp_links => ["part-5"], | |
2217 | not_exp_links => ["partition"], | |
2218 | }, | |
2219 | { | |
2220 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6", | |
2221 | not_exp_links => ["partition"], | |
2222 | exp_links => ["part-6"], | |
2223 | }, | |
2224 | { | |
2225 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7", | |
2226 | exp_links => ["part-7", "partition"], | |
2227 | }, | |
2228 | { | |
2229 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8", | |
2230 | not_exp_links => ["partition"], | |
2231 | exp_links => ["part-8"], | |
2232 | }, | |
2233 | { | |
2234 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9", | |
2235 | not_exp_links => ["partition"], | |
2236 | exp_links => ["part-9"], | |
2237 | }, | |
2238 | { | |
2239 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10", | |
2240 | not_exp_links => ["partition"], | |
2241 | exp_links => ["part-10"], | |
2242 | }, | |
2243 | ], | |
2244 | rules => <<EOF | |
2245 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n" | |
2246 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="partition" | |
2247 | KERNEL=="*7", OPTIONS+="link_priority=10" | |
2248 | EOF | |
2249 | }, | |
2250 | { | |
2251 | desc => "multiple devices, same link name, negative prio", | |
2252 | devices => [ | |
2253 | { | |
2254 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
2255 | exp_links => ["part-1"], | |
2256 | not_exp_links => ["partition"], | |
2257 | }, | |
2258 | { | |
2259 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
2260 | exp_links => ["part-5"], | |
2261 | not_exp_links => ["partition"], | |
2262 | }, | |
2263 | { | |
2264 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6", | |
2265 | not_exp_links => ["partition"], | |
2266 | exp_links => ["part-6"], | |
2267 | }, | |
2268 | { | |
2269 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7", | |
2270 | exp_links => ["part-7", "partition"], | |
2271 | }, | |
2272 | { | |
2273 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8", | |
2274 | not_exp_links => ["partition"], | |
2275 | exp_links => ["part-8"], | |
2276 | }, | |
2277 | { | |
2278 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9", | |
2279 | not_exp_links => ["partition"], | |
2280 | exp_links => ["part-9"], | |
2281 | }, | |
2282 | { | |
2283 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10", | |
2284 | not_exp_links => ["partition"], | |
2285 | exp_links => ["part-10"], | |
2286 | }, | |
2287 | ], | |
2288 | rules => <<EOF | |
2289 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n" | |
2290 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="partition" | |
2291 | KERNEL!="*7", OPTIONS+="link_priority=-10" | |
2292 | EOF | |
2293 | }, | |
2294 | { | |
2295 | desc => "multiple devices, same link name, positive prio, sleep", | |
2296 | devices => [ | |
2297 | { | |
2298 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", | |
2299 | exp_links => ["part-1"], | |
2300 | not_exp_links => ["partition"], | |
2301 | }, | |
2302 | { | |
2303 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5", | |
2304 | exp_links => ["part-5"], | |
2305 | not_exp_links => ["partition"], | |
2306 | }, | |
2307 | { | |
2308 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6", | |
2309 | not_exp_links => ["partition"], | |
2310 | exp_links => ["part-6"], | |
2311 | }, | |
2312 | { | |
2313 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7", | |
2314 | exp_links => ["part-7", "partition"], | |
2315 | }, | |
2316 | { | |
2317 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8", | |
2318 | not_exp_links => ["partition"], | |
2319 | exp_links => ["part-8"], | |
2320 | }, | |
2321 | { | |
2322 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9", | |
2323 | not_exp_links => ["partition"], | |
2324 | exp_links => ["part-9"], | |
2325 | }, | |
2326 | { | |
2327 | devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10", | |
2328 | not_exp_links => ["partition"], | |
2329 | exp_links => ["part-10"], | |
2330 | }, | |
2331 | ], | |
2332 | sleep_us => 10000, | |
2333 | rules => <<EOF | |
2334 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n" | |
2335 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="partition" | |
2336 | KERNEL=="*7", OPTIONS+="link_priority=10" | |
ff94cec3 | 2337 | EOF |
912541b0 | 2338 | }, |
eb44d715 MW |
2339 | { |
2340 | desc => 'all_block_devs', | |
2341 | generator => expect_for_some("\\/sda6\$", ["blockdev"]), | |
2342 | repeat => 10, | |
2343 | rules => <<EOF | |
2344 | SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sd*", SYMLINK+="blockdev" | |
2345 | KERNEL=="sda6", OPTIONS+="link_priority=10" | |
2346 | EOF | |
2347 | } | |
a367f04e GKH |
2348 | ); |
2349 | ||
af7ee3ea MW |
2350 | sub create_rules { |
2351 | my ($rules) = @_; | |
a367f04e | 2352 | |
912541b0 | 2353 | # create temporary rules |
6ada823a | 2354 | system("mkdir", "-p", "$udev_rules_dir"); |
912541b0 KS |
2355 | open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules"; |
2356 | print CONF $$rules; | |
2357 | close CONF; | |
af7ee3ea MW |
2358 | } |
2359 | ||
2360 | sub udev { | |
2361 | my ($action, $devpath) = @_; | |
a367f04e | 2362 | |
912541b0 | 2363 | if ($valgrind > 0) { |
efc9f703 | 2364 | return system("$udev_bin_valgrind $action $devpath"); |
333e07b7 | 2365 | } elsif ($gdb > 0) { |
efc9f703 | 2366 | return system("$udev_bin_gdb $action $devpath"); |
587751eb | 2367 | } elsif ($strace > 0) { |
efc9f703 | 2368 | return system("$udev_bin_strace $action $devpath"); |
912541b0 | 2369 | } else { |
efc9f703 | 2370 | return system("$udev_bin", "$action", "$devpath"); |
912541b0 | 2371 | } |
a367f04e GKH |
2372 | } |
2373 | ||
e5fbfe0a | 2374 | my $error = 0; |
b95c4398 | 2375 | my $good = 0; |
cbeb23d8 | 2376 | my $exp_good = 0; |
72ffa78d | 2377 | |
b8669191 | 2378 | sub permissions_test { |
912541b0 | 2379 | my($rules, $uid, $gid, $mode) = @_; |
b8669191 | 2380 | |
912541b0 KS |
2381 | my $wrong = 0; |
2382 | my $userid; | |
2383 | my $groupid; | |
9b434de1 | 2384 | |
912541b0 KS |
2385 | $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/; |
2386 | if ($1 ne "") { | |
2387 | if (defined(getpwnam($1))) { | |
2388 | $userid = int(getpwnam($1)); | |
2389 | } else { | |
2390 | $userid = $1; | |
2391 | } | |
2392 | if ($uid != $userid) { $wrong = 1; } | |
2393 | } | |
2394 | if ($2 ne "") { | |
2395 | if (defined(getgrnam($2))) { | |
2396 | $groupid = int(getgrnam($2)); | |
2397 | } else { | |
2398 | $groupid = $2; | |
2399 | } | |
2400 | if ($gid != $groupid) { $wrong = 1; } | |
2401 | } | |
2402 | if ($3 ne "") { | |
2403 | if (($mode & 07777) != oct($3)) { $wrong = 1; }; | |
2404 | } | |
2405 | if ($wrong == 0) { | |
2406 | print "permissions: ok\n"; | |
b95c4398 | 2407 | $good++; |
912541b0 KS |
2408 | } else { |
2409 | printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3); | |
2410 | printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; | |
2411 | print "permissions: error\n"; | |
2412 | $error++; | |
2413 | sleep(1); | |
2414 | } | |
b8669191 GKH |
2415 | } |
2416 | ||
2417 | sub major_minor_test { | |
912541b0 | 2418 | my($rules, $rdev) = @_; |
b8669191 | 2419 | |
912541b0 KS |
2420 | my $major = ($rdev >> 8) & 0xfff; |
2421 | my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); | |
2422 | my $wrong = 0; | |
b8669191 | 2423 | |
912541b0 KS |
2424 | $rules->{exp_majorminor} =~ m/^(.*):(.*)$/; |
2425 | if ($1 ne "") { | |
2426 | if ($major != $1) { $wrong = 1; }; | |
2427 | } | |
2428 | if ($2 ne "") { | |
2429 | if ($minor != $2) { $wrong = 1; }; | |
2430 | } | |
2431 | if ($wrong == 0) { | |
2432 | print "major:minor: ok\n"; | |
b95c4398 | 2433 | $good++; |
912541b0 KS |
2434 | } else { |
2435 | printf " expected major:minor is: %i:%i\n", $1, $2; | |
2436 | printf " created major:minor is : %i:%i\n", $major, $minor; | |
2437 | print "major:minor: error\n"; | |
2438 | $error++; | |
2439 | sleep(1); | |
2440 | } | |
b8669191 GKH |
2441 | } |
2442 | ||
6ada823a | 2443 | sub udev_setup { |
f1cb0860 | 2444 | system("umount \"$udev_tmpfs\" 2>/dev/null"); |
21d9e3f3 EV |
2445 | rmdir($udev_tmpfs); |
2446 | mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n"; | |
110a1320 | 2447 | |
9f563f27 | 2448 | if (system("mount", "-o", "rw,mode=0755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs)) { |
110a1320 EV |
2449 | warn "unable to mount tmpfs"; |
2450 | return 0; | |
2451 | } | |
21d9e3f3 | 2452 | |
6ada823a KS |
2453 | mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n"; |
2454 | # setting group and mode of udev_dev ensures the tests work | |
912541b0 | 2455 | # even if the parent directory has setgid bit enabled. |
6ada823a KS |
2456 | chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n"; |
2457 | chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n"; | |
110a1320 EV |
2458 | |
2459 | if (system("mknod", $udev_dev . "/null", "c", "1", "3")) { | |
2460 | warn "unable to create $udev_dev/null"; | |
2461 | return 0; | |
2462 | } | |
6ada823a | 2463 | |
dbfbc6c4 AB |
2464 | # check if we are permitted to create block device nodes |
2465 | my $block_device_filename = $udev_dev . "/sda"; | |
2466 | if (system("mknod", $block_device_filename, "b", "8", "0")) { | |
2467 | warn "unable to create $block_device_filename"; | |
2468 | return 0; | |
2469 | } | |
2470 | unlink $block_device_filename; | |
2471 | ||
21d9e3f3 | 2472 | system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys"; |
2ce8d27b | 2473 | |
6ada823a | 2474 | system("rm", "-rf", "$udev_run"); |
110a1320 | 2475 | |
1e5548c0 AB |
2476 | if (!mkdir($udev_run)) { |
2477 | warn "unable to create directory $udev_run"; | |
2478 | return 0; | |
2479 | } | |
2480 | ||
110a1320 | 2481 | return 1; |
ff94cec3 EK |
2482 | } |
2483 | ||
f0dccf01 MW |
2484 | sub get_devnode { |
2485 | my ($device) = @_; | |
2486 | my $devnode; | |
2487 | ||
2488 | if (defined($device->{devnode})) { | |
2489 | $devnode = "$udev_dev/$device->{devnode}"; | |
2490 | } else { | |
2491 | $devnode = "$device->{devpath}"; | |
2492 | $devnode =~ s!.*/!$udev_dev/!; | |
2493 | } | |
2494 | return $devnode; | |
2495 | } | |
2496 | ||
2497 | sub check_devnode { | |
2498 | my ($device) = @_; | |
2499 | my $devnode = get_devnode($device); | |
2500 | ||
2501 | my @st = lstat("$devnode"); | |
2502 | if (! (-b _ || -c _)) { | |
2503 | print "add $devnode: error\n"; | |
2504 | system("tree", "$udev_dev"); | |
2505 | $error++; | |
2506 | return undef; | |
2507 | } | |
2508 | ||
2509 | my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, | |
2510 | $atime, $mtime, $ctime, $blksize, $blocks) = @st; | |
2511 | ||
2512 | if (defined($device->{exp_perms})) { | |
2513 | permissions_test($device, $uid, $gid, $mode); | |
2514 | } | |
2515 | if (defined($device->{exp_majorminor})) { | |
2516 | major_minor_test($device, $rdev); | |
2517 | } | |
2518 | print "add $devnode: ok\n"; | |
b95c4398 | 2519 | $good++; |
f0dccf01 MW |
2520 | return $devnode; |
2521 | } | |
2522 | ||
e62acc31 MW |
2523 | sub get_link_target { |
2524 | my ($link) = @_; | |
09a4062d | 2525 | |
e62acc31 MW |
2526 | my $cwd = getcwd(); |
2527 | my $dir = "$udev_dev/$link"; | |
2528 | my $tgt = readlink("$udev_dev/$link"); | |
2529 | $dir =~ s!/[^/]*$!!; | |
2530 | $tgt = abs_path("$dir/$tgt"); | |
2531 | $tgt =~ s!^$cwd/!!; | |
2532 | return $tgt; | |
2533 | } | |
f0dccf01 | 2534 | |
e62acc31 MW |
2535 | sub check_link_add { |
2536 | my ($link, $devnode, $err_expected) = @_; | |
f0dccf01 | 2537 | |
e62acc31 | 2538 | my @st = lstat("$udev_dev/$link"); |
997683c8 | 2539 | if (-l _) { |
e62acc31 | 2540 | my $tgt = get_link_target($link); |
997683c8 MW |
2541 | |
2542 | if ($tgt ne $devnode) { | |
e62acc31 | 2543 | print "symlink $link: error, found -> $tgt\n"; |
997683c8 MW |
2544 | $error++; |
2545 | system("tree", "$udev_dev"); | |
2546 | } else { | |
e62acc31 | 2547 | print "symlink $link: ok\n"; |
b95c4398 | 2548 | $good++; |
997683c8 | 2549 | } |
912541b0 | 2550 | } else { |
e62acc31 MW |
2551 | print "symlink $link: error"; |
2552 | if ($err_expected) { | |
912541b0 | 2553 | print " as expected\n"; |
b95c4398 | 2554 | $good++; |
912541b0 KS |
2555 | } else { |
2556 | print "\n"; | |
6ada823a | 2557 | system("tree", "$udev_dev"); |
912541b0 KS |
2558 | print "\n"; |
2559 | $error++; | |
2560 | sleep(1); | |
2561 | } | |
2562 | } | |
255c05b7 | 2563 | } |
a367f04e | 2564 | |
e62acc31 MW |
2565 | sub check_link_nonexistent { |
2566 | my ($link, $devnode, $err_expected) = @_; | |
2567 | ||
2568 | if ((-e "$udev_dev/$link") || (-l "$udev_dev/$link")) { | |
2569 | my $tgt = get_link_target($link); | |
2570 | ||
2571 | if ($tgt ne $devnode) { | |
2572 | print "nonexistent: '$link' points to other device (ok)\n"; | |
b95c4398 | 2573 | $good++; |
e62acc31 MW |
2574 | } else { |
2575 | print "nonexistent: error \'$link\' should not be there"; | |
2576 | if ($err_expected) { | |
2577 | print " (as expected)\n"; | |
b95c4398 | 2578 | $good++; |
e62acc31 MW |
2579 | } else { |
2580 | print "\n"; | |
2581 | system("tree", "$udev_dev"); | |
2582 | print "\n"; | |
2583 | $error++; | |
2584 | sleep(1); | |
2585 | } | |
2586 | } | |
2587 | } else { | |
2588 | print "nonexistent $link: ok\n"; | |
b95c4398 | 2589 | $good++; |
e62acc31 MW |
2590 | } |
2591 | } | |
2592 | ||
2593 | sub check_add { | |
2594 | my ($device) = @_; | |
2595 | my $devnode = check_devnode($device); | |
2596 | ||
2597 | if (defined($device->{exp_links})) { | |
2598 | foreach my $link (@{$device->{exp_links}}) { | |
2599 | check_link_add($link, $devnode, | |
2600 | $device->{exp_add_error}); | |
2601 | } | |
2602 | } | |
2603 | if (defined $device->{not_exp_links}) { | |
2604 | foreach my $link (@{$device->{not_exp_links}}) { | |
2605 | check_link_nonexistent($link, $devnode, | |
2606 | $device->{exp_nodev_error}); | |
2607 | } | |
2608 | } | |
2609 | } | |
2610 | ||
f0dccf01 MW |
2611 | sub check_remove_devnode { |
2612 | my ($device) = @_; | |
2613 | my $devnode = get_devnode($device); | |
2614 | ||
2615 | if (-e "$devnode") { | |
2616 | print "remove $devnode: error"; | |
2617 | print "\n"; | |
2618 | system("tree", "$udev_dev"); | |
2619 | print "\n"; | |
2620 | $error++; | |
2621 | sleep(1); | |
2622 | } else { | |
2623 | print "remove $devnode: ok\n"; | |
b95c4398 | 2624 | $good++; |
f0dccf01 MW |
2625 | } |
2626 | } | |
2627 | ||
e62acc31 MW |
2628 | sub check_link_remove { |
2629 | my ($link, $err_expected) = @_; | |
f0dccf01 | 2630 | |
e62acc31 MW |
2631 | if ((-e "$udev_dev/$link") || |
2632 | (-l "$udev_dev/$link")) { | |
2633 | print "remove $link: error"; | |
2634 | if ($err_expected) { | |
912541b0 | 2635 | print " as expected\n"; |
b95c4398 | 2636 | $good++; |
912541b0 KS |
2637 | } else { |
2638 | print "\n"; | |
6ada823a | 2639 | system("tree", "$udev_dev"); |
912541b0 KS |
2640 | print "\n"; |
2641 | $error++; | |
2642 | sleep(1); | |
2643 | } | |
2644 | } else { | |
e62acc31 | 2645 | print "remove $link: ok\n"; |
b95c4398 | 2646 | $good++; |
e62acc31 MW |
2647 | } |
2648 | } | |
2649 | ||
2650 | sub check_remove { | |
2651 | my ($device) = @_; | |
2652 | ||
2653 | check_remove_devnode($device); | |
2654 | ||
2655 | return if (!defined($device->{exp_links})); | |
2656 | ||
2657 | foreach my $link (@{$device->{exp_links}}) { | |
2658 | check_link_remove($link, $device->{exp_rem_error}); | |
255c05b7 MW |
2659 | } |
2660 | } | |
2661 | ||
09a4062d MW |
2662 | sub run_udev { |
2663 | my ($action, $dev, $sleep_us, $sema) = @_; | |
2664 | ||
2665 | # Notify main process that this worker has started | |
2666 | $sema->op(0, 1, 0); | |
2667 | ||
2668 | # Wait for start | |
2669 | $sema->op(0, 0, 0); | |
2670 | usleep($sleep_us) if defined ($sleep_us); | |
2671 | my $rc = udev($action, $dev->{devpath}); | |
2672 | exit $rc; | |
2673 | } | |
2674 | ||
2675 | sub fork_and_run_udev { | |
2676 | my ($action, $rules, $sema) = @_; | |
2677 | my @devices = @{$rules->{devices}}; | |
2678 | my $dev; | |
2679 | my $k = 0; | |
2680 | ||
2681 | $sema->setval(0, 1); | |
2682 | foreach $dev (@devices) { | |
2683 | my $pid = fork(); | |
2684 | ||
2685 | if (!$pid) { | |
2686 | run_udev($action, $dev, | |
2687 | defined($rules->{sleep_us}) ? $k * $rules->{sleep_us} : undef, | |
2688 | $sema); | |
2689 | } else { | |
2690 | $dev->{pid} = $pid; | |
2691 | } | |
2692 | $k++; | |
2693 | } | |
2694 | ||
2695 | # This operation waits for all workers to become ready, and | |
2696 | # starts them off when that's the case. | |
2697 | $sema->op(0, -($#devices + 2), 0); | |
2698 | ||
2699 | foreach $dev (@devices) { | |
2700 | my $rc; | |
2701 | my $pid; | |
2702 | ||
2703 | $pid = waitpid($dev->{pid}, 0); | |
2704 | if ($pid == -1) { | |
2705 | print "error waiting for pid dev->{pid}\n"; | |
09a4062d MW |
2706 | } |
2707 | if (WIFEXITED($?)) { | |
2708 | $rc = WEXITSTATUS($?); | |
2709 | ||
2710 | if ($rc) { | |
2711 | print "$udev_bin $action for $dev->{devpath} failed with code $rc\n"; | |
2712 | $error += 1; | |
b95c4398 MW |
2713 | } else { |
2714 | $good++; | |
09a4062d MW |
2715 | } |
2716 | } | |
2717 | } | |
2718 | } | |
2719 | ||
255c05b7 | 2720 | sub run_test { |
09a4062d | 2721 | my ($rules, $number, $sema) = @_; |
255c05b7 | 2722 | my $rc; |
eb44d715 | 2723 | my @devices; |
cbeb23d8 MW |
2724 | my $ntests; |
2725 | my $cur_good = $good; | |
2726 | my $cur_error = $error; | |
eb44d715 MW |
2727 | |
2728 | if (!defined $rules->{devices}) { | |
2729 | $rules->{devices} = all_block_devs($rules->{generator}); | |
2730 | } | |
2731 | @devices = @{$rules->{devices}}; | |
cbeb23d8 MW |
2732 | # For each device: exit status and devnode test for add & remove |
2733 | $ntests += 4 * ($#devices + 1); | |
255c05b7 | 2734 | |
cbeb23d8 MW |
2735 | foreach my $dev (@devices) { |
2736 | $ntests += 2 * ($#{$dev->{exp_links}} + 1) | |
2737 | + ($#{$dev->{not_exp_links}} + 1) | |
2738 | + (defined $dev->{exp_perms} ? 1 : 0) | |
2739 | + (defined $dev->{exp_majorminor} ? 1 : 0); | |
2740 | } | |
2741 | if (defined $rules->{repeat}) { | |
2742 | $ntests *= $rules->{repeat}; | |
2743 | } | |
2744 | $exp_good += $ntests; | |
255c05b7 | 2745 | print "TEST $number: $rules->{desc}\n"; |
af7ee3ea | 2746 | create_rules(\$rules->{rules}); |
09a4062d | 2747 | |
2ab0a8d0 | 2748 | REPEAT: |
09a4062d | 2749 | fork_and_run_udev("add", $rules, $sema); |
255c05b7 MW |
2750 | |
2751 | foreach my $dev (@devices) { | |
2752 | check_add($dev); | |
2753 | } | |
2754 | ||
2755 | if (defined($rules->{option}) && $rules->{option} eq "keep") { | |
2756 | print "\n\n"; | |
2757 | return; | |
2758 | } | |
2759 | ||
09a4062d MW |
2760 | fork_and_run_udev("remove", $rules, $sema); |
2761 | ||
255c05b7 MW |
2762 | foreach my $dev (@devices) { |
2763 | check_remove($dev); | |
912541b0 | 2764 | } |
0345b862 | 2765 | |
2ab0a8d0 MW |
2766 | if (defined($rules->{repeat}) && --($rules->{repeat}) > 0) { |
2767 | goto REPEAT; | |
2768 | } | |
cbeb23d8 MW |
2769 | printf "TEST $number: errors: %d good: %d/%d\n\n", $error-$cur_error, |
2770 | $good-$cur_good, $ntests; | |
9b434de1 | 2771 | |
912541b0 | 2772 | if (defined($rules->{option}) && $rules->{option} eq "clean") { |
6ada823a | 2773 | udev_setup(); |
912541b0 | 2774 | } |
0345b862 | 2775 | |
a367f04e GKH |
2776 | } |
2777 | ||
abb9cc50 DS |
2778 | sub cleanup { |
2779 | system("rm", "-rf", "$udev_run"); | |
2780 | system("umount", "$udev_tmpfs"); | |
2781 | rmdir($udev_tmpfs); | |
2782 | } | |
2783 | ||
800ab95b GKH |
2784 | # only run if we have root permissions |
2785 | # due to mknod restrictions | |
2786 | if (!($<==0)) { | |
912541b0 | 2787 | print "Must have root permissions to run properly.\n"; |
4d55fc5b | 2788 | exit($EXIT_TEST_SKIP); |
800ab95b GKH |
2789 | } |
2790 | ||
e4d214ef DC |
2791 | # skip the test when running in a chroot |
2792 | system("systemd-detect-virt", "-r", "-q"); | |
2793 | if ($? >> 8 == 0) { | |
ce5fcc69 ZJS |
2794 | print "Running in a chroot, skipping the test.\n"; |
2795 | exit($EXIT_TEST_SKIP); | |
e4d214ef DC |
2796 | } |
2797 | ||
110a1320 EV |
2798 | if (!udev_setup()) { |
2799 | warn "Failed to set up the environment, skipping the test"; | |
abb9cc50 | 2800 | cleanup(); |
110a1320 EV |
2801 | exit($EXIT_TEST_SKIP); |
2802 | } | |
2803 | ||
7935dae5 | 2804 | if (system($udev_bin, "check")) { |
110a1320 | 2805 | warn "$udev_bin failed to set up the environment, skipping the test"; |
abb9cc50 | 2806 | cleanup(); |
110a1320 EV |
2807 | exit($EXIT_TEST_SKIP); |
2808 | } | |
2e317184 GKH |
2809 | |
2810 | my $test_num = 1; | |
e08109cb | 2811 | my @list; |
2e317184 | 2812 | |
e08109cb | 2813 | foreach my $arg (@ARGV) { |
912541b0 KS |
2814 | if ($arg =~ m/--valgrind/) { |
2815 | $valgrind = 1; | |
2816 | printf("using valgrind\n"); | |
333e07b7 TG |
2817 | } elsif ($arg =~ m/--gdb/) { |
2818 | $gdb = 1; | |
2819 | printf("using gdb\n"); | |
587751eb ZJS |
2820 | } elsif ($arg =~ m/--strace/) { |
2821 | $strace = 1; | |
2822 | printf("using strace\n"); | |
912541b0 KS |
2823 | } else { |
2824 | push(@list, $arg); | |
2825 | } | |
e08109cb | 2826 | } |
09a4062d | 2827 | my $sema = IPC::Semaphore->new(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR | IPC_CREAT); |
e08109cb KS |
2828 | |
2829 | if ($list[0]) { | |
912541b0 KS |
2830 | foreach my $arg (@list) { |
2831 | if (defined($tests[$arg-1]->{desc})) { | |
2832 | print "udev-test will run test number $arg:\n\n"; | |
09a4062d | 2833 | run_test($tests[$arg-1], $arg, $sema); |
912541b0 KS |
2834 | } else { |
2835 | print "test does not exist.\n"; | |
2836 | } | |
2837 | } | |
2e317184 | 2838 | } else { |
912541b0 KS |
2839 | # test all |
2840 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; | |
2e317184 | 2841 | |
912541b0 | 2842 | foreach my $rules (@tests) { |
09a4062d | 2843 | run_test($rules, $test_num, $sema); |
912541b0 KS |
2844 | $test_num++; |
2845 | } | |
2e317184 GKH |
2846 | } |
2847 | ||
09a4062d | 2848 | $sema->remove; |
cbeb23d8 | 2849 | print "$error errors occurred. $good/$exp_good good results.\n\n"; |
a367f04e | 2850 | |
abb9cc50 | 2851 | cleanup(); |
a367f04e | 2852 | |
034b37c8 | 2853 | if ($error > 0) { |
d3fc8bf4 | 2854 | exit(1); |
034b37c8 AJ |
2855 | } |
2856 | exit(0); |