]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/udev-test.pl
[PATCH] fix problems using scsi_id with udevstart
[thirdparty/systemd.git] / test / udev-test.pl
CommitLineData
a367f04e
GKH
1#!/usr/bin/perl
2
3# udev-test
4#
5# Provides automated testing of the udev binary.
6# The whole test is self contained in this file, except the matching sysfs tree.
7# Simply extend the @tests array, to add a new test variant.
8#
9# Every test is driven by its own temporary config file.
10# This program prepares the environment, creates the config and calls udev.
11#
12# udev reads the config, looks at the provided sysfs and
13# first creates and then removes the device node.
14# After creation and removal the result is checked against the
15# expected value and the result is printed.
16#
17# happy testing,
18# Kay Sievers <kay.sievers@vrfy.org>, 2003
b8669191
GKH
19#
20# Modified April 9, 2004 by Leann Ogasawara <ogasawara@osdl.org>
21# - expanded @tests array to add more symlinks and permissions tests
22# - some of the symlinks tests also test lack of node creation
23# - added symlink_test() function
24# - moved permissions and major_minor tests into their own functions
a367f04e
GKH
25
26use warnings;
27use strict;
28
f8f00338 29my $PWD = $ENV{PWD};
a367f04e
GKH
30my $sysfs = "sys/";
31my $udev_bin = "../udev";
32my $udev_root = "udev-root/"; # !!! directory will be removed !!!
36043f84 33my $udev_db = ".udev.tdb";
a367f04e 34my $perm = "udev.permissions";
72ffa78d
GKH
35my $main_conf = "udev-test.conf";
36my $conf_tmp = "udev-test.rules";
a367f04e
GKH
37
38
39my @tests = (
40 {
fa19f181
KS
41 desc => "label test of scsi disc",
42 subsys => "block",
f61d732a 43 devpath => "/block/sda",
c013b034 44 exp_name => "boot_disk" ,
fa19f181 45 conf => <<EOF
16378373 46BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n"
ac28b86d 47KERNEL="ttyUSB0", NAME="visor"
a367f04e
GKH
48EOF
49 },
50 {
fa19f181
KS
51 desc => "label test of scsi partition",
52 subsys => "block",
f61d732a 53 devpath => "/block/sda/sda1",
c013b034 54 exp_name => "boot_disk1" ,
fa19f181 55 conf => <<EOF
16378373 56BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n"
83be97ba
KS
57EOF
58 },
59 {
fa19f181
KS
60 desc => "label test of pattern match",
61 subsys => "block",
f61d732a 62 devpath => "/block/sda/sda1",
c013b034 63 exp_name => "boot_disk1" ,
fa19f181 64 conf => <<EOF
16378373
KS
65BUS="scsi", SYSFS{vendor}="?IBM-ESXS", NAME="boot_disk%n-1"
66BUS="scsi", SYSFS{vendor}="IBM-ESXS?", NAME="boot_disk%n-2"
67BUS="scsi", SYSFS{vendor}="IBM-ES??", NAME="boot_disk%n"
68BUS="scsi", SYSFS{vendor}="IBM-ESXSS", NAME="boot_disk%n-3"
358c8c20
GKH
69EOF
70 },
71 {
fa19f181
KS
72 desc => "label test of multiple sysfs files",
73 subsys => "block",
f61d732a 74 devpath => "/block/sda/sda1",
fa19f181
KS
75 exp_name => "boot_disk1" ,
76 conf => <<EOF
16378373
KS
77BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_diskX%n"
78BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_disk%n"
358c8c20
GKH
79EOF
80 },
81 {
fa19f181
KS
82 desc => "label test of max sysfs files",
83 subsys => "block",
f61d732a 84 devpath => "/block/sda/sda1",
fa19f181
KS
85 exp_name => "boot_disk1" ,
86 conf => <<EOF
16378373
KS
87BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="2", SYSFS{queue_depth}="32", NAME="boot_diskXX%n"
88BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="0", NAME="boot_disk%n"
0db6d4cc
KS
89EOF
90 },
91 {
fa19f181
KS
92 desc => "catch device by *",
93 subsys => "tty",
f61d732a 94 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
95 exp_name => "visor/0" ,
96 conf => <<EOF
ac28b86d 97KERNEL="ttyUSB*", NAME="visor/%n"
2e317184
GKH
98EOF
99 },
100 {
fa19f181
KS
101 desc => "catch device by * - take 2",
102 subsys => "tty",
f61d732a 103 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
104 exp_name => "visor/0" ,
105 conf => <<EOF
2e317184
GKH
106KERNEL="*USB1", NAME="bad"
107KERNEL="*USB0", NAME="visor/%n"
9f1da361
KS
108EOF
109 },
110 {
fa19f181
KS
111 desc => "catch device by ?",
112 subsys => "tty",
f61d732a 113 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
114 exp_name => "visor/0" ,
115 conf => <<EOF
ac28b86d
KS
116KERNEL="ttyUSB??*", NAME="visor/%n-1"
117KERNEL="ttyUSB??", NAME="visor/%n-2"
118KERNEL="ttyUSB?", NAME="visor/%n"
9f1da361
KS
119EOF
120 },
121 {
fa19f181
KS
122 desc => "catch device by character class",
123 subsys => "tty",
f61d732a 124 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
125 exp_name => "visor/0" ,
126 conf => <<EOF
ac28b86d
KS
127KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1"
128KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2"
129KERNEL="ttyUSB[0-9]*", NAME="visor/%n"
a367f04e
GKH
130EOF
131 },
132 {
fa19f181
KS
133 desc => "replace kernel name",
134 subsys => "tty",
f61d732a 135 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
136 exp_name => "visor" ,
137 conf => <<EOF
ac28b86d 138KERNEL="ttyUSB0", NAME="visor"
281ff00a
GKH
139EOF
140 },
141 {
fa19f181
KS
142 desc => "Handle comment lines in config file (and replace kernel name)",
143 subsys => "tty",
f61d732a 144 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
145 exp_name => "visor" ,
146 conf => <<EOF
281ff00a 147# this is a comment
ac28b86d 148KERNEL="ttyUSB0", NAME="visor"
281ff00a
GKH
149
150EOF
151 },
152 {
fa19f181
KS
153 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
154 subsys => "tty",
f61d732a 155 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
156 exp_name => "visor" ,
157 conf => <<EOF
281ff00a 158 # this is a comment with whitespace before the comment
ac28b86d 159KERNEL="ttyUSB0", NAME="visor"
281ff00a 160
3db7fa27
KS
161EOF
162 },
163 {
164 desc => "Handle whitespace only lines (and replace kernel name)",
165 subsys => "tty",
166 devpath => "/class/tty/ttyUSB0",
167 exp_name => "whitespace" ,
168 conf => <<EOF
169
170
171
172 # this is a comment with whitespace before the comment
173KERNEL="ttyUSB0", NAME="whitespace"
174
175
176
281ff00a
GKH
177EOF
178 },
179 {
fa19f181
KS
180 desc => "Handle empty lines in config file (and replace kernel name)",
181 subsys => "tty",
f61d732a 182 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
183 exp_name => "visor" ,
184 conf => <<EOF
281ff00a 185
ac28b86d 186KERNEL="ttyUSB0", NAME="visor"
281ff00a 187
5499d319
KS
188EOF
189 },
190 {
fa19f181
KS
191 desc => "subdirectory handling",
192 subsys => "tty",
f61d732a 193 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
194 exp_name => "sub/direct/ory/visor" ,
195 conf => <<EOF
ac28b86d 196KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
a367f04e
GKH
197EOF
198 },
199 {
fa19f181
KS
200 desc => "place on bus of scsi partition",
201 subsys => "block",
f61d732a 202 devpath => "/block/sda/sda3",
fa19f181
KS
203 exp_name => "first_disk3" ,
204 conf => <<EOF
ac28b86d 205BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
a367f04e
GKH
206EOF
207 },
208 {
fa19f181
KS
209 desc => "test NAME substitution chars",
210 subsys => "block",
f61d732a 211 devpath => "/block/sda/sda3",
fa19f181
KS
212 exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
213 conf => <<EOF
ac28b86d 214BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
63ead27c
KS
215EOF
216 },
217 {
fa19f181
KS
218 desc => "test NAME substitution chars (with length limit)",
219 subsys => "block",
f61d732a 220 devpath => "/block/sda/sda3",
fa19f181
KS
221 exp_name => "M8-m3-n3-b0:0-sIBM" ,
222 conf => <<EOF
63ead27c 223BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
59525115
GKH
224EOF
225 },
226 {
fa19f181
KS
227 desc => "old style SYSFS_ attribute",
228 subsys => "block",
f61d732a 229 devpath => "/block/sda",
fa19f181
KS
230 exp_name => "good" ,
231 conf => <<EOF
59525115 232BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="good"
a27cd06c
KS
233EOF
234 },
235 {
fa19f181
KS
236 desc => "sustitution of sysfs value (%s{file})",
237 subsys => "block",
f61d732a 238 devpath => "/block/sda",
fa19f181
KS
239 exp_name => "disk-IBM-ESXS-sda" ,
240 conf => <<EOF
16378373 241BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k"
a27cd06c 242KERNEL="ttyUSB0", NAME="visor"
a367f04e
GKH
243EOF
244 },
245 {
fa19f181
KS
246 desc => "program result substitution",
247 subsys => "block",
f61d732a 248 devpath => "/block/sda/sda3",
fa19f181
KS
249 exp_name => "special-device-3" ,
250 conf => <<EOF
ac28b86d
KS
251BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="-special-*", NAME="%c-1-%n"
252BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c-2-%n"
253BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n"
254BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n"
255BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n"
f608f8ac
KS
256EOF
257 },
258 {
259 desc => "program result substitution (no argument should be subsystem)",
260 subsys => "block",
261 devpath => "/block/sda/sda3",
262 exp_name => "subsys_block" ,
263 conf => <<EOF
264BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block"
bbbe503e
KS
265EOF
266 },
267 {
268 desc => "program result substitution (newline removal)",
269 subsys => "block",
270 devpath => "/block/sda/sda3",
271 exp_name => "newline_removed" ,
272 conf => <<EOF
273BUS="scsi", PROGRAM="/bin/echo test", RESULT="test", NAME="newline_removed"
f3b04a2e
GKH
274EOF
275 },
276 {
fa19f181
KS
277 desc => "program result substitution",
278 subsys => "block",
f61d732a 279 devpath => "/block/sda/sda3",
fa19f181
KS
280 exp_name => "test-0:0:0:0" ,
281 conf => <<EOF
ac28b86d 282BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c"
8ffb636f
KS
283EOF
284 },
285 {
fa19f181
KS
286 desc => "program with escaped format char (tricky: callout returns format char!)",
287 subsys => "block",
f61d732a 288 devpath => "/block/sda/sda3",
fa19f181
KS
289 exp_name => "escape-3" ,
290 conf => <<EOF
8ffb636f 291BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c"
dde05ccb
GKH
292EOF
293 },
294 {
fa19f181
KS
295 desc => "program with lots of arguments",
296 subsys => "block",
f61d732a 297 devpath => "/block/sda/sda3",
fa19f181
KS
298 exp_name => "foo9" ,
299 conf => <<EOF
dde05ccb 300BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}"
35b38379
KS
301EOF
302 },
303 {
fa19f181
KS
304 desc => "program with subshell",
305 subsys => "block",
f61d732a 306 devpath => "/block/sda/sda3",
fa19f181
KS
307 exp_name => "bar9" ,
308 conf => <<EOF
35b38379
KS
309BUS="scsi", PROGRAM="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL="sda3", NAME="%c{7}"
310EOF
311 },
312 {
fa19f181
KS
313 desc => "program arguments combined with apostrophes",
314 subsys => "block",
f61d732a 315 devpath => "/block/sda/sda3",
fa19f181
KS
316 exp_name => "foo7" ,
317 conf => <<EOF
35b38379 318BUS="scsi", PROGRAM="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL="sda3", NAME="%c{5}"
56c963dc
PM
319EOF
320 },
321 {
fa19f181
KS
322 desc => "characters before the %c{N} substitution",
323 subsys => "block",
f61d732a 324 devpath => "/block/sda/sda3",
fa19f181
KS
325 exp_name => "my-foo9" ,
326 conf => <<EOF
56c963dc
PM
327BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}"
328EOF
329 },
330 {
fa19f181
KS
331 desc => "substitute the second to last argument",
332 subsys => "block",
f61d732a 333 devpath => "/block/sda/sda3",
fa19f181
KS
334 exp_name => "my-foo8" ,
335 conf => <<EOF
56c963dc 336BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}"
8ff8bbba
GKH
337EOF
338 },
339 {
fa19f181
KS
340 desc => "invalid program for device with no bus",
341 subsys => "tty",
f61d732a 342 devpath => "/class/tty/console",
fa19f181
KS
343 exp_name => "TTY" ,
344 conf => <<EOF
ac28b86d
KS
345BUS="scsi", PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo"
346KERNEL="console", NAME="TTY"
1d936fbc
GKH
347EOF
348 },
349 {
fa19f181
KS
350 desc => "valid program for device with no bus",
351 subsys => "tty",
f61d732a 352 devpath => "/class/tty/console",
fa19f181
KS
353 exp_name => "foo" ,
354 conf => <<EOF
ac28b86d
KS
355PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo"
356KERNEL="console", NAME="TTY"
64682333
GKH
357EOF
358 },
359 {
fa19f181
KS
360 desc => "invalid label for device with no bus",
361 subsys => "tty",
f61d732a 362 devpath => "/class/tty/console",
fa19f181
KS
363 exp_name => "TTY" ,
364 conf => <<EOF
16378373 365BUS="foo", SYSFS{dev}="5:1", NAME="foo"
ac28b86d 366KERNEL="console", NAME="TTY"
64682333
GKH
367EOF
368 },
369 {
fa19f181
KS
370 desc => "valid label for device with no bus",
371 subsys => "tty",
f61d732a 372 devpath => "/class/tty/console",
fa19f181
KS
373 exp_name => "foo" ,
374 conf => <<EOF
16378373 375SYSFS{dev}="5:1", NAME="foo"
ac28b86d 376KERNEL="console", NAME="TTY"
772558f4
GKH
377EOF
378 },
379 {
fa19f181
KS
380 desc => "program and bus type match",
381 subsys => "block",
f61d732a 382 devpath => "/block/sda",
fa19f181
KS
383 exp_name => "scsi-0:0:0:0" ,
384 conf => <<EOF
ac28b86d
KS
385BUS="usb", PROGRAM="/bin/echo -n usb-%b", NAME="%c"
386BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", NAME="%c"
387BUS="foo", PROGRAM="/bin/echo -n foo-%b", NAME="%c"
724257d9
GKH
388EOF
389 },
390 {
fa19f181
KS
391 desc => "create all possible partitions",
392 subsys => "block",
f61d732a 393 devpath => "/block/sda",
fa19f181
KS
394 exp_name => "boot_disk15" ,
395 conf => <<EOF
16378373 396BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME{all_partitions}="boot_disk"
50e5de03
KS
397EOF
398 },
399 {
fa19f181
KS
400 desc => "sysfs parent hierarchy",
401 subsys => "tty",
f61d732a 402 devpath => "/class/tty/ttyUSB0",
fa19f181
KS
403 exp_name => "visor" ,
404 conf => <<EOF
16378373 405SYSFS{idProduct}="2008", NAME="visor"
f0142622
GKH
406EOF
407 },
408 {
fa19f181
KS
409 desc => "name test with ! in the name",
410 subsys => "block",
f61d732a 411 devpath => "/block/rd!c0d0",
fa19f181
KS
412 exp_name => "rd/c0d0" ,
413 conf => <<EOF
f0142622
GKH
414BUS="scsi", NAME="%k"
415KERNEL="ttyUSB0", NAME="visor"
b9fc973b
GKH
416EOF
417 },
418 {
fa19f181
KS
419 desc => "name test with ! in the name, but no matching rule",
420 subsys => "block",
f61d732a 421 devpath => "/block/rd!c0d0",
fa19f181
KS
422 exp_name => "rd/c0d0" ,
423 conf => <<EOF
b9fc973b 424KERNEL="ttyUSB0", NAME="visor"
0f36e68e
GKH
425EOF
426 },
427 {
428 desc => "name test with ! in the name for a partition",
429 subsys => "block",
430 devpath => "/block/cciss!c0d0/cciss!c0d0p1",
431 exp_name => "cciss/c0d0p1" ,
432 conf => <<EOF
433BUS="scsi", NAME="%k"
434KERNEL="ttyUSB0", NAME="visor"
93656247
PM
435EOF
436 },
437 {
fa19f181
KS
438 desc => "ID rule",
439 subsys => "block",
f61d732a 440 devpath => "/block/sda",
fa19f181
KS
441 exp_name => "scsi-0:0:0:0",
442 conf => <<EOF
93656247
PM
443BUS="usb", ID="0:0:0:0", NAME="not-scsi"
444BUS="scsi", ID="0:0:0:1", NAME="no-match"
445BUS="scsi", ID=":0", NAME="short-id"
446BUS="scsi", ID="/0:0:0:0", NAME="no-match"
447BUS="scsi", ID="0:0:0:0", NAME="scsi-0:0:0:0"
448EOF
449 },
450 {
fa19f181
KS
451 desc => "ID wildcard all",
452 subsys => "block",
f61d732a 453 devpath => "/block/sda",
fa19f181
KS
454 exp_name => "scsi-0:0:0:0",
455 conf => <<EOF
93656247
PM
456BUS="scsi", ID="*:1", NAME="no-match"
457BUS="scsi", ID="*:0:1", NAME="no-match"
458BUS="scsi", ID="*:0:0:1", NAME="no-match"
459BUS="scsi", ID="*", NAME="scsi-0:0:0:0"
460BUS="scsi", ID="0:0:0:0", NAME="bad"
461EOF
462 },
463 {
fa19f181
KS
464 desc => "ID wildcard partial",
465 subsys => "block",
f61d732a 466 devpath => "/block/sda",
fa19f181
KS
467 exp_name => "scsi-0:0:0:0",
468 conf => <<EOF
93656247
PM
469BUS="scsi", ID="*:0", NAME="scsi-0:0:0:0"
470BUS="scsi", ID="0:0:0:0", NAME="bad"
471EOF
472 },
473 {
fa19f181
KS
474 desc => "ID wildcard partial 2",
475 subsys => "block",
f61d732a 476 devpath => "/block/sda",
fa19f181
KS
477 exp_name => "scsi-0:0:0:0",
478 conf => <<EOF
93656247
PM
479BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0"
480BUS="scsi", ID="0:0:0:0", NAME="bad"
d5f91372
KS
481EOF
482 },
483 {
fa19f181
KS
484 desc => "ignore SYSFS attribute whitespace",
485 subsys => "block",
f61d732a 486 devpath => "/block/sda",
fa19f181
KS
487 exp_name => "ignored",
488 conf => <<EOF
d5f91372
KS
489BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE", NAME="ignored"
490EOF
491 },
492 {
fa19f181
KS
493 desc => "do not ignore SYSFS attribute whitespace",
494 subsys => "block",
f61d732a 495 devpath => "/block/sda",
fa19f181
KS
496 exp_name => "matched-with-space",
497 conf => <<EOF
d5f91372
KS
498BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="wrong-to-ignore"
499BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="matched-with-space"
0a5417a0
KS
500EOF
501 },
502 {
b8669191 503 desc => "permissions test",
fa19f181 504 subsys => "block",
f61d732a 505 devpath => "/block/sda",
b8669191
GKH
506 exp_name => "node",
507 exp_perms => "5000::0444",
fa19f181 508 conf => <<EOF
b8669191 509BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", MODE="0444"
c612a0ac
KS
510EOF
511 },
512 {
b8669191
GKH
513 desc => "permissions ttyUSB0:root:uucp:0660",
514 subsys => "tty",
515 devpath => "/class/tty/ttyUSB0",
516 exp_name => "ttyUSB0",
517 exp_perms => "0:14:0660",
518 conf => <<EOF
519KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n"
520EOF
521 },
522 {
523 desc => "permissions tty0::root:0444",
524 subsys => "tty",
525 devpath => "/class/tty/tty0",
526 exp_name => "tty0",
527 exp_perms => "0:0:0444",
528 conf => <<EOF
529KERNEL="tty0", NAME="tty0"
530EOF
531 },
532 {
533 desc => "permissions tty1:root::0555",
534 subsys => "tty",
535 devpath => "/class/tty/tty1",
536 exp_name => "tty1",
537 exp_perms => "0:0:0555",
538 conf => <<EOF
539KERNEL="tty1", NAME="tty1"
540EOF
541 },
542 {
543 desc => "permissions tty2:::0777",
544 subsys => "tty",
545 devpath => "/class/tty/tty2",
546 exp_name => "tty2",
547 exp_perms => "0:0:0777",
548 conf => <<EOF
549KERNEL="tty2", NAME="tty2"
550EOF
551 },
552 {
553 desc => "permissions tty3:::",
554 subsys => "tty",
555 devpath => "/class/tty/tty3",
556 exp_name => "tty3",
557 exp_perms => "0:0:0",
558 conf => <<EOF
559KERNEL="tty3", NAME="tty3"
560EOF
561 },
562 {
563 desc => "permissions i2c-300:root:sys:0744",
564 subsys => "i2c-dev",
565 devpath => "/class/i2c-dev/i2c-300",
566 exp_name => "i2c-300",
567 exp_perms => "0:3:0744",
568 conf => <<EOF
569KERNEL="i2c-300", NAME="i2c-300"
570EOF
571 },
572 {
573 desc => "permissions i2c-fake1:root:7:0007",
574 subsys => "i2c-dev",
575 devpath => "/class/i2c-dev/i2c-fake1",
576 exp_name => "i2c-fake1",
577 exp_perms => "0:7:0007",
578 conf => <<EOF
579KERNEL="i2c-fake1", NAME="i2c-fake1"
580EOF
581 },
582 {
583 desc => "permissions ttyS[01]:0:5:0700",
584 subsys => "tty",
585 devpath => "/class/tty/ttyS1",
586 exp_name => "ttyS1",
587 exp_perms => "0:5:0700",
588 conf => <<EOF
589KERNEL="ttyS1", NAME="ttyS1"
590EOF
591 },
592 {
593 desc => "permissions ttyS[4-9]:tty:5:0060",
594 subsys => "tty",
595 devpath => "/class/tty/ttyS7",
596 exp_name => "ttyS7",
597 exp_perms => "0:5:0060",
598 conf => <<EOF
599KERNEL="ttyS7", NAME="ttyS7"
600EOF
601 },
602 {
603 desc => "permissions tty4:0:5:0707",
604 subsys => "ttyS4",
605 devpath => "/class/tty/tty4",
606 exp_name => "tty4",
607 exp_perms => "0:5:0707",
608 conf => <<EOF
609KERNEL="tty4", NAME="tty4"
610EOF
611 },
612 {
613 desc => "permissions tty4?:0:5:0007",
614 subsys => "tty",
615 devpath => "/class/tty/tty44",
616 exp_name => "tty44",
617 exp_perms => "0:5:0007",
618 conf => <<EOF
619KERNEL="tty44", NAME="tty44"
620EOF
621 },
622 {
623 desc => "permissions tty3[!3]:::0467",
624 subsys => "tty",
625 devpath => "/class/tty/tty35",
626 exp_name => "tty35",
627 exp_perms => "0:0:0467",
628 conf => <<EOF
629KERNEL="tty35", NAME="tty35"
630EOF
631 },
632 {
633 desc => "permissions tty33:bad:name:0500",
634 subsys => "tty",
635 devpath => "/class/tty/tty33",
636 exp_name => "tty33",
637 exp_perms => "0:0:0500",
638 conf => <<EOF
639KERNEL="tty33", NAME="tty33"
640EOF
641 },
642 {
643 desc => "permissions rtc:0:users:0600",
644 subsys => "misc",
645 devpath => "/class/misc/rtc",
646 exp_name => "misc/rtc",
647 exp_perms => "0:100:0600",
648 conf => <<EOF
649KERNEL="rtc", NAME="misc/rtc"
650EOF
651 },
652 {
653 desc => "permissions misc:0:users:0600",
654 subsys => "misc",
655 devpath => "/class/misc/psaux",
656 exp_name => "misc/psaux",
657 exp_perms => "0:100:0600",
658 conf => <<EOF
659KERNEL="psaux", NAME="misc/psaux"
660EOF
661 },
662 {
663 desc => "permissions set OWNER=5000",
fa19f181 664 subsys => "block",
f61d732a 665 devpath => "/block/sda",
fa19f181 666 exp_name => "node",
b8669191 667 exp_perms => "5000::0600",
fa19f181 668 conf => <<EOF
b8669191
GKH
669BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000"
670EOF
671 },
672 {
673 desc => "permissions set GROUP=100",
674 subsys => "block",
675 devpath => "/block/sda",
676 exp_name => "node",
677 exp_perms => ":100:0600",
678 conf => <<EOF
679BUS="scsi", KERNEL="sda", NAME="node", GROUP="100"
680EOF
681 },
682 {
683 desc => "permissions set mode=0777",
684 subsys => "block",
685 devpath => "/block/sda",
686 exp_name => "node",
687 exp_perms => "::0777",
688 conf => <<EOF
689BUS="scsi", KERNEL="sda", NAME="node", MODE="0777"
690EOF
691 },
692 {
693 desc => "permissions set OWNER=5000 GROUP=100 MODE=0777",
694 subsys => "block",
695 devpath => "/block/sda",
696 exp_name => "node",
697 exp_perms => "5000:100:0777",
698 conf => <<EOF
699BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777"
700EOF
701 },
702 {
703 desc => "permissions override OWNER to 5000",
704 subsys => "tty",
705 devpath => "/class/tty/ttyUSB0",
706 exp_name => "ttyUSB0",
707 exp_perms => "5000:14:0660",
708 conf => <<EOF
709KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000"
710EOF
711 },
712 {
713 desc => "permissions override GROUP to 100",
714 subsys => "tty",
715 devpath => "/class/tty/ttyUSB0",
716 exp_name => "ttyUSB0",
717 exp_perms => ":100:0660",
718 conf => <<EOF
719KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100"
720EOF
721 },
722 {
723 desc => "permissions override MODE to 0060",
724 subsys => "tty",
725 devpath => "/class/tty/ttyUSB0",
726 exp_name => "ttyUSB0",
727 exp_perms => ":14:0060",
728 conf => <<EOF
729KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060"
730EOF
731 },
732 {
733 desc => "permissions override OWNER, GROUP, MODE",
734 subsys => "tty",
735 devpath => "/class/tty/ttyUSB0",
736 exp_name => "ttyUSB0",
737 exp_perms => "5000:100:0777",
738 conf => <<EOF
739KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777"
fa19f181
KS
740EOF
741 },
742 {
743 desc => "major/minor number test",
744 subsys => "block",
f61d732a 745 devpath => "/block/sda",
fa19f181 746 exp_name => "node",
fa19f181
KS
747 exp_majorminor => "8:0",
748 conf => <<EOF
7ddb6f47 749BUS="scsi", KERNEL="sda", NAME="node"
a5e8d2b4
GKH
750EOF
751 },
752 {
753 desc => "big minor number test",
754 subsys => "i2c-dev",
f61d732a 755 devpath => "/class/i2c-dev/i2c-300",
a5e8d2b4
GKH
756 exp_name => "node",
757 exp_majorminor => "89:300",
758 conf => <<EOF
759KERNEL="i2c-300", NAME="node"
7d12d4e1
GKH
760EOF
761 },
762 {
763 desc => "big major number test",
764 subsys => "i2c-dev",
f61d732a 765 devpath => "/class/i2c-dev/i2c-fake1",
7d12d4e1
GKH
766 exp_name => "node",
767 exp_majorminor => "4095:1",
768 conf => <<EOF
769KERNEL="i2c-fake1", NAME="node"
770EOF
771 },
772 {
773 desc => "big major and big minor number test",
774 subsys => "i2c-dev",
f61d732a 775 devpath => "/class/i2c-dev/i2c-fake2",
7d12d4e1
GKH
776 exp_name => "node",
777 exp_majorminor => "4094:89999",
778 conf => <<EOF
779KERNEL="i2c-fake2", NAME="node"
b8669191
GKH
780EOF
781 },
782 {
783 desc => "symlink creation (same directory)",
784 subsys => "tty",
785 devpath => "/class/tty/ttyUSB0",
786 exp_name => "visor0",
787 exp_target => "ttyUSB0",
788 conf => <<EOF
789KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n"
790EOF
791 },
792 {
793 desc => "symlink creation (relative link forward)",
794 subsys => "block",
795 devpath => "/block/sda/sda2",
796 exp_name => "1/2/symlink" ,
797 exp_target => "a/b/node",
798 conf => <<EOF
799BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
800EOF
801 },
802 {
803 desc => "symlink creation (relative link back and forward)",
804 subsys => "block",
805 devpath => "/block/sda/sda2",
806 exp_name => "1/2/c/d/symlink" ,
807 exp_target => "../../a/b/node",
808 conf => <<EOF
809BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
810EOF
811 },
812 {
813 desc => "multiple symlinks",
814 subsys => "tty",
815 devpath => "/class/tty/ttyUSB0",
816 exp_name => "second-0" ,
817 exp_target => "visor" ,
818 conf => <<EOF
819KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
820EOF
821 },
822 {
823 desc => "symlink only rule",
824 subsys => "block",
825 devpath => "/block/sda",
826 exp_name => "symlink-only2",
827 exp_target => "link",
828 conf => <<EOF
829BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1"
830BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2"
831BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
832EOF
833 },
834 {
835 desc => "symlink name empty",
836 subsys => "block",
837 devpath => "/block/sda",
838 exp_name => "",
839 exp_target => "link",
840 exp_error => "yes",
841 conf => <<EOF
842BUS="scsi", KERNEL="sda", NAME="link", SYMLINK=""
843EOF
844 },
845 {
846 desc => "symlink name '.'",
847 subsys => "block",
848 devpath => "/block/sda",
849 exp_name => ".",
850 exp_target => "link",
851 exp_error => "yes",
852 conf => <<EOF
853BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="."
854EOF
855 },
856 {
857 desc => "symlink to empty name",
858 subsys => "block",
859 devpath => "/block/sda",
860 exp_name => "symlink",
861 exp_target => "",
862 exp_error => "yes",
863 conf => <<EOF
864BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink"
865EOF
866 },
867 {
868 desc => "symlink and name empty",
869 subsys => "block",
870 devpath => "/block/sda",
871 exp_name => "",
872 exp_target => "",
873 exp_error => "yes",
874 conf => <<EOF
875BUS="scsi", KERNEL="sda", NAME="", SYMLINK=""
876EOF
877 },
878 {
879 desc => "symlink node to itself",
880 subsys => "tty",
881 devpath => "/class/tty/tty0",
882 exp_name => "link",
883 exp_target => "link",
884 conf => <<EOF
885KERNEL="tty0", NAME="link", SYMLINK="link"
886EOF
887 },
888 {
889 desc => "symlink %n substitution",
890 subsys => "tty",
891 devpath => "/class/tty/ttyUSB0",
892 exp_name => "symlink0",
893 exp_target => "ttyUSB0",
894 conf => <<EOF
895KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink%n"
896EOF
897 },
898 {
899 desc => "symlink %k substitution",
900 subsys => "tty",
901 devpath => "/class/tty/ttyUSB0",
902 exp_name => "symlink-ttyUSB0",
903 exp_target => "ttyUSB0",
904 conf => <<EOF
905KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink-%k"
906EOF
907 },
908 {
909 desc => "symlink %M:%m substitution",
910 subsys => "tty",
911 devpath => "/class/tty/ttyUSB0",
912 exp_name => "major-188:0",
913 exp_target => "ttyUSB0",
914 conf => <<EOF
915KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="major-%M:%m"
916EOF
917 },
918 {
919 desc => "symlink %b substitution",
920 subsys => "block",
921 devpath => "/block/sda",
922 exp_name => "symlink-0:0:0:0",
923 exp_target => "node",
924 conf => <<EOF
925BUS="scsi", KERNEL="sda", NAME="node", SYMLINK="symlink-%b"
926EOF
927 },
928 {
929 desc => "symlink %c substitution",
930 subsys => "tty",
931 devpath => "/class/tty/ttyUSB0",
932 exp_name => "test",
933 exp_target => "ttyUSB0",
934 conf => <<EOF
935KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo test" NAME="ttyUSB%n", SYMLINK="%c"
936EOF
937 },
938 {
939 desc => "symlink %c{N} substitution",
940 subsys => "tty",
941 devpath => "/class/tty/ttyUSB0",
942 exp_name => "test",
943 exp_target => "ttyUSB0",
944 conf => <<EOF
945KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2}"
946EOF
947 },
948 {
949 desc => "symlink %c{N+} substitution",
950 subsys => "tty",
951 devpath => "/class/tty/ttyUSB0",
952 exp_name => "this",
953 exp_target => "ttyUSB0",
954 conf => <<EOF
955KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2+}"
956EOF
957 },
958 {
959 desc => "symlink only rule with %c{N+}",
960 subsys => "block",
961 devpath => "/block/sda",
962 exp_name => "test",
963 exp_target => "link",
964 conf => <<EOF
965BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo link test this" SYMLINK="%c{2+}"
966BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
967EOF
968 },
969 {
970 desc => "symlink %s{filename} substitution",
971 subsys => "tty",
972 devpath => "/class/tty/ttyUSB0",
973 exp_name => "188:0",
974 exp_target => "ttyUSB0",
975 conf => <<EOF
976KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%s{dev}"
977EOF
978 },
979 {
980 desc => "symlink %Ns{filename} substitution",
981 subsys => "tty",
982 devpath => "/class/tty/ttyUSB0",
983 exp_name => "188",
984 exp_target => "ttyUSB0",
985 conf => <<EOF
986KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%3s{dev}"
987EOF
988 },
989 {
990 desc => "symlink with '%' in name",
991 subsys => "tty",
992 devpath => "/class/tty/ttyUSB0",
993 exp_name => "percent%sign",
994 exp_target => "ttyUSB0",
995 conf => <<EOF
996KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="percent%%sign"
997EOF
998 },
999 {
1000 desc => "symlink with '%' in name",
1001 subsys => "tty",
1002 devpath => "/class/tty/ttyUSB0",
1003 exp_name => "%ttyUSB0_name",
1004 exp_target => "ttyUSB0",
1005 conf => <<EOF
1006KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%%%k_name"
1007EOF
1008 },
1009 {
1010 desc => "program result substitution (numbered part of)",
1011 subsys => "block",
1012 devpath => "/block/sda/sda3",
1013 exp_name => "link1",
1014 exp_target => "node",
1015 conf => <<EOF
1016BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}"
1017EOF
1018 },
1019 {
1020 desc => "program result substitution (numbered part of+)",
1021 subsys => "block",
1022 devpath => "/block/sda/sda3",
1023 exp_name => "link4",
1024 exp_target => "node",
1025 conf => <<EOF
1026BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}"
0345b862
KS
1027EOF
1028 },
1029 {
1030 desc => "enumeration char test (single test)",
1031 subsys => "block",
1032 devpath => "/block/sda",
1033 exp_name => "cdrom",
1034 conf => <<EOF
1035KERNEL="sda", NAME="cdrom%e"
1036EOF
1037 },
1038 {
1039 desc => "enumeration char test sequence (1/5 keep)",
1040 subsys => "block",
1041 devpath => "/block/sda",
1042 exp_name => "cdrom",
1043 option => "keep",
1044 conf => <<EOF
1045KERNEL="sda", NAME="cdrom%e"
1046EOF
1047 },
1048 {
1049 desc => "enumeration char test sequence 2/5 (keep)",
1050 subsys => "block",
1051 devpath => "/block/sda/sda1",
1052 exp_name => "enum",
1053 option => "keep",
1054 conf => <<EOF
1055KERNEL="sda1", NAME="enum%e"
1056EOF
1057 },
1058 {
1059 desc => "enumeration char test sequence 3/5 (keep)",
1060 subsys => "block",
1061 devpath => "/block/sda/sda2",
1062 exp_name => "cdrom1",
1063 option => "keep",
1064 conf => <<EOF
1065KERNEL="sda2", NAME="cdrom%e"
1066EOF
1067 },
1068 {
1069 desc => "enumeration char test sequence 4/5 (keep)",
1070 subsys => "block",
1071 devpath => "/block/sda/sda3",
1072 exp_name => "enum1",
1073 option => "keep",
1074 conf => <<EOF
1075KERNEL="sda3", NAME="enum%e"
1076EOF
1077 },
1078 {
1079 desc => "enumeration char test sequence 5/5 (clean)",
1080 subsys => "block",
1081 devpath => "/block/sda/sda4",
1082 exp_name => "cdrom2",
1083 option => "clear",
1084 conf => <<EOF
1085KERNEL="sda4", NAME="cdrom%e"
1086EOF
1087 },
1088 {
1089 desc => "enumeration char test after cleanup (single test)",
1090 subsys => "block",
1091 devpath => "/block/sda",
1092 exp_name => "cdrom",
1093 conf => <<EOF
1094KERNEL="sda", NAME="cdrom%e"
a367f04e
GKH
1095EOF
1096 },
1097);
1098
1099# set env
1100$ENV{UDEV_TEST} = "yes";
1101$ENV{SYSFS_PATH} = $sysfs;
72ffa78d 1102$ENV{UDEV_CONFIG_FILE} = $main_conf;
bbbe503e
KS
1103$ENV{UDEV_NO_SLEEP} = "yes";
1104$ENV{UDEV_NO_DEVD} = "yes";
a367f04e
GKH
1105
1106
1107sub udev {
1108 my ($action, $subsys, $devpath, $config) = @_;
1109
1110 $ENV{DEVPATH} = $devpath;
a367f04e
GKH
1111
1112 # create temporary config
1113 open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
1114 print CONF $$config;
1115 close CONF;
1116
1117 $ENV{ACTION} = $action;
1118 system("$udev_bin $subsys");
1119}
1120
e5fbfe0a 1121my $error = 0;
72ffa78d 1122
b8669191
GKH
1123sub permissions_test {
1124 my($config, $uid, $gid, $mode) = @_;
1125
1126 my $wrong = 0;
1127 $config->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1128 if ($1 ne "") {
1129 if ($uid != $1) { $wrong = 1; };
1130 }
1131 if ($2 ne "") {
1132 if ($gid != $2) { $wrong = 1; };
1133 }
1134 if ($3 ne "") {
1135 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1136 }
1137 if ($wrong == 0) {
1138 print "permissions: ok ";
1139 } else {
1140 printf "expected permissions are: %i:%i:%#o\n", $1, $2, oct($3);
1141 printf "created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1142 $error++;
1143 }
1144}
1145
1146sub major_minor_test {
1147 my($config, $rdev) = @_;
1148
1149 my $major = ($rdev >> 8) & 0xfff;
1150 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1151 my $wrong = 0;
1152
1153 $config->{exp_majorminor} =~ m/^(.*):(.*)$/;
1154 if ($1 ne "") {
1155 if ($major != $1) { $wrong = 1; };
1156 }
1157 if ($2 ne "") {
1158 if ($minor != $2) { $wrong = 1; };
1159 }
1160 if ($wrong == 0) {
1161 print "major:minor: ok ";
1162 } else {
1163 printf "expected major:minor is: %i:%i\n", $1, $2;
1164 printf "created major:minor is : %i:%i\n", $major, $minor;
1165 print "major:minor: error ";
1166 $error++;
1167 }
1168}
1169
1170sub symlink_test {
1171 my ($config) = @_;
1172
1173 my $output = `ls -l $PWD/$udev_root$config->{exp_name}`;
1174
1175 if ($output =~ m/(.*)-> (.*)/) {
1176 if ($2 eq $config->{exp_target}) {
1177 print "symlink: ok ";
1178 } else {
1179 print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
1180 print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n";
1181 if ($config->{exp_error}) {
1182 print "as expected ";
1183 } else {
1184 $error++;
1185 }
1186 }
1187 } else {
1188 print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
1189 print "symlink: not created ";
1190 if ($config->{exp_error}) {
1191 print "as expected ";
1192 } else {
1193 $error++;
1194 }
1195 }
1196}
1197
2e317184
GKH
1198sub run_test {
1199 my ($config, $number) = @_;
fa19f181 1200
2e317184 1201 print "TEST $number: $config->{desc}\n";
b8669191
GKH
1202
1203 if ($config->{exp_target}) {
1204 print "device \'$config->{devpath}\' expecting symlink '$config->{exp_name}' to node \'$config->{exp_target}\'\n";
1205 } else {
1206 print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n";
1207 }
1208
a367f04e
GKH
1209
1210 udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
b8669191
GKH
1211
1212 if ((-e "$PWD/$udev_root$config->{exp_name}") ||
1213 (-l "$PWD/$udev_root$config->{exp_name}")) {
fa19f181
KS
1214
1215 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1216 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$config->{exp_name}");
1217
c013b034 1218 if (defined($config->{exp_perms})) {
b8669191 1219 permissions_test($config, $uid, $gid, $mode);
c612a0ac 1220 }
fa19f181 1221 if (defined($config->{exp_majorminor})) {
b8669191
GKH
1222 major_minor_test($config, $rdev);
1223 }
1224 if (defined($config->{exp_target})) {
1225 symlink_test($config);
fa19f181 1226 }
a367f04e
GKH
1227 print "add: ok ";
1228 } else {
b8669191
GKH
1229 print "add: error ";
1230 if ($config->{exp_error}) {
1231 print "as expected ";
1232 } else {
1233 print "\n\n";
1234 system("tree $udev_root");
1235 print "\n";
1236 $error++;
1237 }
a367f04e
GKH
1238 }
1239
0345b862
KS
1240 if (defined($config->{option}) && $config->{option} eq "keep") {
1241 print "\n\n";
1242 return;
1243 }
1244
a367f04e 1245 udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
fa19f181
KS
1246 if ((-e "$PWD/$udev_root$config->{exp_name}") ||
1247 (-l "$PWD/$udev_root$config->{exp_name}")) {
b8669191
GKH
1248 print "remove: error ";
1249 if ($config->{exp_error}) {
1250 print "as expected\n\n";
1251 } else {
1252 print "\n\n";
1253 system("tree $udev_root");
1254 print "\n";
1255 $error++;
1256 }
a367f04e
GKH
1257 } else {
1258 print "remove: ok\n\n";
1259 }
0345b862
KS
1260
1261 if (defined($config->{option}) && $config->{option} eq "clear") {
1262 unlink($udev_db);
1263 system("rm -rf $udev_root");
1264 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1265 }
1266
a367f04e
GKH
1267}
1268
2e317184
GKH
1269# prepare
1270system("rm -rf $udev_root");
1271mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1272
1273# create initial config file
1274open CONF, ">$main_conf" || die "unable to create config file: $main_conf";
1275print CONF "udev_root=\"$udev_root\"\n";
1276print CONF "udev_db=\"$udev_db\"\n";
1277print CONF "udev_rules=\"$conf_tmp\"\n";
1278print CONF "udev_permissions=\"$perm\"\n";
1279close CONF;
1280
1281my $test_num = 1;
1282
1283if ($ARGV[0]) {
1284 # only run one test
1285 $test_num = $ARGV[0];
2e317184 1286
0345b862
KS
1287 if (defined($tests[$test_num-1]->{desc})) {
1288 print "udev-test will run test number $test_num only:\n\n";
1289 run_test($tests[$test_num-1], $test_num);
1290 } else {
1291 print "test does not exist.\n";
1292 }
2e317184
GKH
1293} else {
1294 # test all
1295 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1296
1297 foreach my $config (@tests) {
1298 run_test($config, $test_num);
1299 $test_num++;
2e317184
GKH
1300 }
1301}
1302
a367f04e
GKH
1303print "$error errors occured\n\n";
1304
1305# cleanup
36043f84 1306unlink($udev_db);
a367f04e
GKH
1307system("rm -rf $udev_root");
1308unlink($conf_tmp);
72ffa78d 1309unlink($main_conf);
a367f04e 1310