chiark / gitweb /
[PATCH] add dumb script to show all sysfs devices in the system.
[elogind.git] / test / udev-test.pl
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
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
25
26 use warnings;
27 use strict;
28
29 my $PWD = $ENV{PWD};
30 my $sysfs     = "sys/";
31 my $udev_bin  = "../udev";
32 my $udev_root = "udev-root/"; # !!! directory will be removed !!!
33 my $udev_db   = ".udev.tdb";
34 my $perm      = "udev.permissions";
35 my $main_conf = "udev-test.conf";
36 my $conf_tmp  = "udev-test.rules";
37
38
39 my @tests = (
40         {
41                 desc            => "label test of scsi disc",
42                 subsys          => "block",
43                 devpath         => "/block/sda",
44                 exp_name        => "boot_disk" ,
45                 conf            => <<EOF
46 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n"
47 KERNEL="ttyUSB0", NAME="visor"
48 EOF
49         },
50         {
51                 desc            => "label test of scsi partition",
52                 subsys          => "block",
53                 devpath         => "/block/sda/sda1",
54                 exp_name        => "boot_disk1" ,
55                 conf            => <<EOF
56 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n"
57 EOF
58         },
59         {
60                 desc            => "label test of pattern match",
61                 subsys          => "block",
62                 devpath         => "/block/sda/sda1",
63                 exp_name        => "boot_disk1" ,
64                 conf            => <<EOF
65 BUS="scsi", SYSFS{vendor}="?IBM-ESXS", NAME="boot_disk%n-1"
66 BUS="scsi", SYSFS{vendor}="IBM-ESXS?", NAME="boot_disk%n-2"
67 BUS="scsi", SYSFS{vendor}="IBM-ES??", NAME="boot_disk%n"
68 BUS="scsi", SYSFS{vendor}="IBM-ESXSS", NAME="boot_disk%n-3"
69 EOF
70         },
71         {
72                 desc            => "label test of multiple sysfs files",
73                 subsys          => "block",
74                 devpath         => "/block/sda/sda1",
75                 exp_name        => "boot_disk1" ,
76                 conf            => <<EOF
77 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW   !#", NAME="boot_diskX%n"
78 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW    !#", NAME="boot_disk%n"
79 EOF
80         },
81         {
82                 desc            => "label test of max sysfs files",
83                 subsys          => "block",
84                 devpath         => "/block/sda/sda1",
85                 exp_name        => "boot_disk1" ,
86                 conf            => <<EOF
87 BUS="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"
88 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW    !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="0", NAME="boot_disk%n"
89 EOF
90         },
91         {
92                 desc            => "catch device by *",
93                 subsys          => "tty",
94                 devpath         => "/class/tty/ttyUSB0",
95                 exp_name        => "visor/0" ,
96                 conf            => <<EOF
97 KERNEL="ttyUSB*", NAME="visor/%n"
98 EOF
99         },
100         {
101                 desc            => "catch device by * - take 2",
102                 subsys          => "tty",
103                 devpath         => "/class/tty/ttyUSB0",
104                 exp_name        => "visor/0" ,
105                 conf            => <<EOF
106 KERNEL="*USB1", NAME="bad"
107 KERNEL="*USB0", NAME="visor/%n"
108 EOF
109         },
110         {
111                 desc            => "catch device by ?",
112                 subsys          => "tty",
113                 devpath         => "/class/tty/ttyUSB0",
114                 exp_name        => "visor/0" ,
115                 conf            => <<EOF
116 KERNEL="ttyUSB??*", NAME="visor/%n-1"
117 KERNEL="ttyUSB??", NAME="visor/%n-2"
118 KERNEL="ttyUSB?", NAME="visor/%n"
119 EOF
120         },
121         {
122                 desc            => "catch device by character class",
123                 subsys          => "tty",
124                 devpath         => "/class/tty/ttyUSB0",
125                 exp_name        => "visor/0" ,
126                 conf            => <<EOF
127 KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1"
128 KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2"
129 KERNEL="ttyUSB[0-9]*", NAME="visor/%n"
130 EOF
131         },
132         {
133                 desc            => "replace kernel name",
134                 subsys          => "tty",
135                 devpath         => "/class/tty/ttyUSB0",
136                 exp_name        => "visor" ,
137                 conf            => <<EOF
138 KERNEL="ttyUSB0", NAME="visor"
139 EOF
140         },
141         {
142                 desc            => "Handle comment lines in config file (and replace kernel name)",
143                 subsys          => "tty",
144                 devpath         => "/class/tty/ttyUSB0",
145                 exp_name        => "visor" ,
146                 conf            => <<EOF
147 # this is a comment
148 KERNEL="ttyUSB0", NAME="visor"
149
150 EOF
151         },
152         {
153                 desc            => "Handle comment lines in config file with whitespace (and replace kernel name)",
154                 subsys          => "tty",
155                 devpath         => "/class/tty/ttyUSB0",
156                 exp_name        => "visor" ,
157                 conf            => <<EOF
158  # this is a comment with whitespace before the comment 
159 KERNEL="ttyUSB0", NAME="visor"
160
161 EOF
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 
173 KERNEL="ttyUSB0", NAME="whitespace"
174
175  
176
177 EOF
178         },
179         {
180                 desc            => "Handle empty lines in config file (and replace kernel name)",
181                 subsys          => "tty",
182                 devpath         => "/class/tty/ttyUSB0",
183                 exp_name        => "visor" ,
184                 conf            => <<EOF
185
186 KERNEL="ttyUSB0", NAME="visor"
187
188 EOF
189         },
190         {
191                 desc            => "subdirectory handling",
192                 subsys          => "tty",
193                 devpath         => "/class/tty/ttyUSB0",
194                 exp_name        => "sub/direct/ory/visor" ,
195                 conf            => <<EOF
196 KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
197 EOF
198         },
199         {
200                 desc            => "place on bus of scsi partition",
201                 subsys          => "block",
202                 devpath         => "/block/sda/sda3",
203                 exp_name        => "first_disk3" ,
204                 conf            => <<EOF
205 BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
206 EOF
207         },
208         {
209                 desc            => "test NAME substitution chars",
210                 subsys          => "block",
211                 devpath         => "/block/sda/sda3",
212                 exp_name        => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
213                 conf            => <<EOF
214 BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
215 EOF
216         },
217         {
218                 desc            => "test NAME substitution chars (with length limit)",
219                 subsys          => "block",
220                 devpath         => "/block/sda/sda3",
221                 exp_name        => "M8-m3-n3-b0:0-sIBM" ,
222                 conf            => <<EOF
223 BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
224 EOF
225         },
226         {
227                 desc            => "old style SYSFS_ attribute",
228                 subsys          => "block",
229                 devpath         => "/block/sda",
230                 exp_name        => "good" ,
231                 conf            => <<EOF
232 BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="good"
233 EOF
234         },
235         {
236                 desc            => "sustitution of sysfs value (%s{file})",
237                 subsys          => "block",
238                 devpath         => "/block/sda",
239                 exp_name        => "disk-IBM-ESXS-sda" ,
240                 conf            => <<EOF
241 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k"
242 KERNEL="ttyUSB0", NAME="visor"
243 EOF
244         },
245         {
246                 desc            => "program result substitution",
247                 subsys          => "block",
248                 devpath         => "/block/sda/sda3",
249                 exp_name        => "special-device-3" ,
250                 conf            => <<EOF
251 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="-special-*", NAME="%c-1-%n"
252 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c-2-%n"
253 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n"
254 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n"
255 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n"
256 EOF
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
264 BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block"
265 EOF
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
273 BUS="scsi", PROGRAM="/bin/echo test", RESULT="test", NAME="newline_removed"
274 EOF
275         },
276         {
277                 desc            => "program result substitution",
278                 subsys          => "block",
279                 devpath         => "/block/sda/sda3",
280                 exp_name        => "test-0:0:0:0" ,
281                 conf            => <<EOF
282 BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c"
283 EOF
284         },
285         {
286                 desc            => "program with escaped format char (tricky: callout returns format char!)",
287                 subsys          => "block",
288                 devpath         => "/block/sda/sda3",
289                 exp_name        => "escape-3" ,
290                 conf            => <<EOF
291 BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c"
292 EOF
293         },
294         {
295                 desc            => "program with lots of arguments",
296                 subsys          => "block",
297                 devpath         => "/block/sda/sda3",
298                 exp_name        => "foo9" ,
299                 conf            => <<EOF
300 BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}"
301 EOF
302         },
303         {
304                 desc            => "program with subshell",
305                 subsys          => "block",
306                 devpath         => "/block/sda/sda3",
307                 exp_name        => "bar9" ,
308                 conf            => <<EOF
309 BUS="scsi", PROGRAM="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed  s/foo9/bar9/'", KERNEL="sda3", NAME="%c{7}"
310 EOF
311         },
312         {
313                 desc            => "program arguments combined with apostrophes",
314                 subsys          => "block",
315                 devpath         => "/block/sda/sda3",
316                 exp_name        => "foo7" ,
317                 conf            => <<EOF
318 BUS="scsi", PROGRAM="/bin/echo -n 'foo3 foo4'   'foo5   foo6   foo7 foo8'", KERNEL="sda3", NAME="%c{5}"
319 EOF
320         },
321         {
322                 desc            => "characters before the %c{N} substitution",
323                 subsys          => "block",
324                 devpath         => "/block/sda/sda3",
325                 exp_name        => "my-foo9" ,
326                 conf            => <<EOF
327 BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}"
328 EOF
329         },
330         {
331                 desc            => "substitute the second to last argument",
332                 subsys          => "block",
333                 devpath         => "/block/sda/sda3",
334                 exp_name        => "my-foo8" ,
335                 conf            => <<EOF
336 BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}"
337 EOF
338         },
339         {
340                 desc            => "invalid program for device with no bus",
341                 subsys          => "tty",
342                 devpath         => "/class/tty/console",
343                 exp_name        => "TTY" ,
344                 conf            => <<EOF
345 BUS="scsi", PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo"
346 KERNEL="console", NAME="TTY"
347 EOF
348         },
349         {
350                 desc            => "valid program for device with no bus",
351                 subsys          => "tty",
352                 devpath         => "/class/tty/console",
353                 exp_name        => "foo" ,
354                 conf            => <<EOF
355 PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo"
356 KERNEL="console", NAME="TTY"
357 EOF
358         },
359         {
360                 desc            => "invalid label for device with no bus",
361                 subsys          => "tty",
362                 devpath         => "/class/tty/console",
363                 exp_name        => "TTY" ,
364                 conf            => <<EOF
365 BUS="foo", SYSFS{dev}="5:1", NAME="foo"
366 KERNEL="console", NAME="TTY"
367 EOF
368         },
369         {
370                 desc            => "valid label for device with no bus",
371                 subsys          => "tty",
372                 devpath         => "/class/tty/console",
373                 exp_name        => "foo" ,
374                 conf            => <<EOF
375 SYSFS{dev}="5:1", NAME="foo"
376 KERNEL="console", NAME="TTY"
377 EOF
378         },
379         {
380                 desc            => "program and bus type match",
381                 subsys          => "block",
382                 devpath         => "/block/sda",
383                 exp_name        => "scsi-0:0:0:0" ,
384                 conf            => <<EOF
385 BUS="usb", PROGRAM="/bin/echo -n usb-%b", NAME="%c"
386 BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", NAME="%c"
387 BUS="foo", PROGRAM="/bin/echo -n foo-%b", NAME="%c"
388 EOF
389         },
390         {
391                 desc            => "create all possible partitions",
392                 subsys          => "block",
393                 devpath         => "/block/sda",
394                 exp_name        => "boot_disk15" ,
395                 conf            => <<EOF
396 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME{all_partitions}="boot_disk"
397 EOF
398         },
399         {
400                 desc            => "sysfs parent hierarchy",
401                 subsys          => "tty",
402                 devpath         => "/class/tty/ttyUSB0",
403                 exp_name        => "visor" ,
404                 conf            => <<EOF
405 SYSFS{idProduct}="2008", NAME="visor"
406 EOF
407         },
408         {
409                 desc            => "name test with ! in the name",
410                 subsys          => "block",
411                 devpath         => "/block/rd!c0d0",
412                 exp_name        => "rd/c0d0" ,
413                 conf            => <<EOF
414 BUS="scsi", NAME="%k"
415 KERNEL="ttyUSB0", NAME="visor"
416 EOF
417         },
418         {
419                 desc            => "name test with ! in the name, but no matching rule",
420                 subsys          => "block",
421                 devpath         => "/block/rd!c0d0",
422                 exp_name        => "rd/c0d0" ,
423                 conf            => <<EOF
424 KERNEL="ttyUSB0", NAME="visor"
425 EOF
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
433 BUS="scsi", NAME="%k"
434 KERNEL="ttyUSB0", NAME="visor"
435 EOF
436         },
437         {
438                 desc            => "ID rule",
439                 subsys          => "block",
440                 devpath         => "/block/sda",
441                 exp_name        => "scsi-0:0:0:0",
442                 conf            => <<EOF
443 BUS="usb", ID="0:0:0:0", NAME="not-scsi"
444 BUS="scsi", ID="0:0:0:1", NAME="no-match"
445 BUS="scsi", ID=":0", NAME="short-id"
446 BUS="scsi", ID="/0:0:0:0", NAME="no-match"
447 BUS="scsi", ID="0:0:0:0", NAME="scsi-0:0:0:0"
448 EOF
449         },
450         {
451                 desc            => "ID wildcard all",
452                 subsys          => "block",
453                 devpath         => "/block/sda",
454                 exp_name        => "scsi-0:0:0:0",
455                 conf            => <<EOF
456 BUS="scsi", ID="*:1", NAME="no-match"
457 BUS="scsi", ID="*:0:1", NAME="no-match"
458 BUS="scsi", ID="*:0:0:1", NAME="no-match"
459 BUS="scsi", ID="*", NAME="scsi-0:0:0:0"
460 BUS="scsi", ID="0:0:0:0", NAME="bad"
461 EOF
462         },
463         {
464                 desc            => "ID wildcard partial",
465                 subsys          => "block",
466                 devpath         => "/block/sda",
467                 exp_name        => "scsi-0:0:0:0",
468                 conf            => <<EOF
469 BUS="scsi", ID="*:0", NAME="scsi-0:0:0:0"
470 BUS="scsi", ID="0:0:0:0", NAME="bad"
471 EOF
472         },
473         {
474                 desc            => "ID wildcard partial 2",
475                 subsys          => "block",
476                 devpath         => "/block/sda",
477                 exp_name        => "scsi-0:0:0:0",
478                 conf            => <<EOF
479 BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0"
480 BUS="scsi", ID="0:0:0:0", NAME="bad"
481 EOF
482         },
483         {
484                 desc            => "ignore SYSFS attribute whitespace",
485                 subsys          => "block",
486                 devpath         => "/block/sda",
487                 exp_name        => "ignored",
488                 conf            => <<EOF
489 BUS="scsi", SYSFS{whitespace_test}="WHITE  SPACE", NAME="ignored"
490 EOF
491         },
492         {
493                 desc            => "do not ignore SYSFS attribute whitespace",
494                 subsys          => "block",
495                 devpath         => "/block/sda",
496                 exp_name        => "matched-with-space",
497                 conf            => <<EOF
498 BUS="scsi", SYSFS{whitespace_test}="WHITE  SPACE ", NAME="wrong-to-ignore"
499 BUS="scsi", SYSFS{whitespace_test}="WHITE  SPACE   ", NAME="matched-with-space"
500 EOF
501         },
502         {
503                 desc            => "permissions test",
504                 subsys          => "block",
505                 devpath         => "/block/sda",
506                 exp_name        => "node",
507                 exp_perms       => "5000::0444",
508                 conf            => <<EOF
509 BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", MODE="0444"
510 EOF
511         },
512         {
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
519 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n"
520 EOF
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
529 KERNEL="tty0", NAME="tty0"
530 EOF
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
539 KERNEL="tty1", NAME="tty1"
540 EOF
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
549 KERNEL="tty2", NAME="tty2"
550 EOF
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
559 KERNEL="tty3", NAME="tty3"
560 EOF
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
569 KERNEL="i2c-300", NAME="i2c-300"
570 EOF
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
579 KERNEL="i2c-fake1", NAME="i2c-fake1"
580 EOF
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
589 KERNEL="ttyS1", NAME="ttyS1"
590 EOF
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
599 KERNEL="ttyS7", NAME="ttyS7"
600 EOF
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
609 KERNEL="tty4", NAME="tty4"
610 EOF
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
619 KERNEL="tty44", NAME="tty44"
620 EOF
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
629 KERNEL="tty35", NAME="tty35"
630 EOF
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
639 KERNEL="tty33", NAME="tty33"
640 EOF
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
649 KERNEL="rtc", NAME="misc/rtc"
650 EOF
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
659 KERNEL="psaux", NAME="misc/psaux"
660 EOF
661         },
662         {
663                 desc            => "permissions set OWNER=5000",
664                 subsys          => "block",
665                 devpath         => "/block/sda",
666                 exp_name        => "node",
667                 exp_perms       => "5000::0600",
668                 conf            => <<EOF
669 BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000"
670 EOF
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
679 BUS="scsi", KERNEL="sda", NAME="node", GROUP="100"
680 EOF
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
689 BUS="scsi", KERNEL="sda", NAME="node", MODE="0777"
690 EOF
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
699 BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777"
700 EOF
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
709 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000"
710 EOF
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
719 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100"
720 EOF
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
729 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060"
730 EOF
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
739 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777"
740 EOF
741         },
742         {
743                 desc            => "major/minor number test",
744                 subsys          => "block",
745                 devpath         => "/block/sda",
746                 exp_name        => "node",
747                 exp_majorminor  => "8:0",
748                 conf            => <<EOF
749 BUS="scsi", KERNEL="sda", NAME="node"
750 EOF
751         },
752         {
753                 desc            => "big minor number test",
754                 subsys          => "i2c-dev",
755                 devpath         => "/class/i2c-dev/i2c-300",
756                 exp_name        => "node",
757                 exp_majorminor  => "89:300",
758                 conf            => <<EOF
759 KERNEL="i2c-300", NAME="node"
760 EOF
761         },
762         {
763                 desc            => "big major number test",
764                 subsys          => "i2c-dev",
765                 devpath         => "/class/i2c-dev/i2c-fake1",
766                 exp_name        => "node",
767                 exp_majorminor  => "4095:1",
768                 conf            => <<EOF
769 KERNEL="i2c-fake1", NAME="node"
770 EOF
771         },
772         {
773                 desc            => "big major and big minor number test",
774                 subsys          => "i2c-dev",
775                 devpath         => "/class/i2c-dev/i2c-fake2",
776                 exp_name        => "node",
777                 exp_majorminor  => "4094:89999",
778                 conf            => <<EOF
779 KERNEL="i2c-fake2", NAME="node"
780 EOF
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
789 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n"
790 EOF
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
799 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
800 EOF
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
809 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
810 EOF
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
819 KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
820 EOF
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
829 BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1"
830 BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2"
831 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
832 EOF
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
842 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK=""
843 EOF
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
853 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="."
854 EOF
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
864 BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink"
865 EOF
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
875 BUS="scsi", KERNEL="sda", NAME="", SYMLINK=""
876 EOF
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
885 KERNEL="tty0", NAME="link", SYMLINK="link"
886 EOF
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
895 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink%n"
896 EOF
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
905 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink-%k"
906 EOF
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
915 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="major-%M:%m"
916 EOF
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
925 BUS="scsi", KERNEL="sda", NAME="node", SYMLINK="symlink-%b"
926 EOF
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
935 KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo test" NAME="ttyUSB%n", SYMLINK="%c"
936 EOF
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
945 KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2}"
946 EOF
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
955 KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2+}"
956 EOF
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
965 BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo link test this" SYMLINK="%c{2+}"
966 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
967 EOF
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
976 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%s{dev}"
977 EOF
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
986 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%3s{dev}"
987 EOF
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
996 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="percent%%sign"
997 EOF
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
1006 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%%%k_name"
1007 EOF
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
1016 BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}"
1017 EOF
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
1026 BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}"
1027 EOF
1028         },
1029         {
1030                 desc            => "enumeration char test (single test)",
1031                 subsys          => "block",
1032                 devpath         => "/block/sda",
1033                 exp_name        => "cdrom",
1034                 conf            => <<EOF
1035 KERNEL="sda", NAME="cdrom%e"
1036 EOF
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
1045 KERNEL="sda", NAME="cdrom%e"
1046 EOF
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
1055 KERNEL="sda1", NAME="enum%e"
1056 EOF
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
1065 KERNEL="sda2", NAME="cdrom%e"
1066 EOF
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
1075 KERNEL="sda3", NAME="enum%e"
1076 EOF
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
1085 KERNEL="sda4", NAME="cdrom%e"
1086 EOF
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
1094 KERNEL="sda", NAME="cdrom%e"
1095 EOF
1096         },
1097 );
1098
1099 # set env
1100 $ENV{UDEV_TEST} = "yes";
1101 $ENV{SYSFS_PATH} = $sysfs;
1102 $ENV{UDEV_CONFIG_FILE} = $main_conf;
1103 $ENV{UDEV_NO_DEVD} = "yes";
1104
1105
1106 sub udev {
1107         my ($action, $subsys, $devpath, $config) = @_;
1108
1109         $ENV{DEVPATH} = $devpath;
1110
1111         # create temporary config
1112         open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
1113         print CONF $$config;
1114         close CONF;
1115
1116         $ENV{ACTION} = $action;
1117         system("$udev_bin $subsys");
1118 }
1119
1120 my $error = 0;
1121
1122 sub permissions_test {
1123         my($config, $uid, $gid, $mode) = @_;
1124
1125         my $wrong = 0;
1126         $config->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1127         if ($1 ne "") {
1128                 if ($uid != $1) { $wrong = 1; };
1129         }
1130         if ($2 ne "") {
1131                 if ($gid != $2) { $wrong = 1; };
1132         }
1133         if ($3 ne "") {
1134                 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1135         }
1136         if ($wrong == 0) {
1137                 print "permissions: ok    ";
1138         } else {
1139                 printf "expected permissions are: %i:%i:%#o\n", $1, $2, oct($3);
1140                 printf "created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1141                 $error++;
1142         }
1143 }
1144
1145 sub major_minor_test {
1146         my($config, $rdev) = @_;
1147
1148         my $major = ($rdev >> 8) & 0xfff;
1149         my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1150         my $wrong = 0;
1151
1152         $config->{exp_majorminor} =~ m/^(.*):(.*)$/;
1153         if ($1 ne "") {
1154                 if ($major != $1) { $wrong = 1; };
1155         }
1156         if ($2 ne "") {
1157                 if ($minor != $2) { $wrong = 1; };
1158         }
1159         if ($wrong == 0) {
1160                 print "major:minor: ok    ";
1161         } else {
1162                 printf "expected major:minor is: %i:%i\n", $1, $2;
1163                 printf "created major:minor is : %i:%i\n", $major, $minor;
1164                 print "major:minor: error    ";
1165                 $error++;
1166         }
1167 }
1168
1169 sub symlink_test {
1170         my ($config) = @_;
1171
1172         my $output = `ls -l $PWD/$udev_root$config->{exp_name}`;
1173
1174         if ($output =~ m/(.*)-> (.*)/) {
1175                 if ($2 eq $config->{exp_target}) {
1176                         print "symlink: ok    ";
1177                 } else {
1178                         print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
1179                         print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n";
1180                         if ($config->{exp_error}) {
1181                                 print "as expected    ";
1182                         } else {
1183                                 $error++;
1184                         }
1185                 }
1186         } else {
1187                 print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
1188                 print "symlink: not created ";
1189                 if ($config->{exp_error}) {
1190                         print "as expected    ";
1191                 } else {
1192                         $error++;
1193                 }
1194         }
1195 }
1196
1197 sub run_test {
1198         my ($config, $number) = @_;
1199
1200         print "TEST $number: $config->{desc}\n";
1201
1202         if ($config->{exp_target}) {
1203                 print "device \'$config->{devpath}\' expecting symlink '$config->{exp_name}' to node \'$config->{exp_target}\'\n";
1204         } else {
1205                 print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n";
1206         }
1207
1208
1209         udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
1210
1211         if ((-e "$PWD/$udev_root$config->{exp_name}") ||
1212             (-l "$PWD/$udev_root$config->{exp_name}")) {
1213
1214                 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1215                     $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$config->{exp_name}");
1216
1217                 if (defined($config->{exp_perms})) {
1218                         permissions_test($config, $uid, $gid, $mode);
1219                 }
1220                 if (defined($config->{exp_majorminor})) {
1221                         major_minor_test($config, $rdev);
1222                 }
1223                 if (defined($config->{exp_target})) {
1224                         symlink_test($config);
1225                 }
1226                 print "add: ok    ";
1227         } else {
1228                 print "add: error ";
1229                 if ($config->{exp_error}) {
1230                         print "as expected    ";
1231                 } else {
1232                         print "\n\n";
1233                         system("tree $udev_root");
1234                         print "\n";
1235                         $error++;
1236                 }
1237         }
1238
1239         if (defined($config->{option}) && $config->{option} eq "keep") {
1240                 print "\n\n";
1241                 return;
1242         }
1243
1244         udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
1245         if ((-e "$PWD/$udev_root$config->{exp_name}") ||
1246             (-l "$PWD/$udev_root$config->{exp_name}")) {
1247                 print "remove: error ";
1248                 if ($config->{exp_error}) {
1249                         print "as expected\n\n";
1250                 } else {
1251                         print "\n\n";
1252                         system("tree $udev_root");
1253                         print "\n";
1254                         $error++;
1255                 }
1256         } else {
1257                 print "remove: ok\n\n";
1258         }
1259
1260         if (defined($config->{option}) && $config->{option} eq "clear") {
1261                 unlink($udev_db);
1262                 system("rm -rf $udev_root");
1263                 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1264         }
1265
1266 }
1267
1268 # prepare
1269 system("rm -rf $udev_root");
1270 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1271
1272 # create initial config file
1273 open CONF, ">$main_conf" || die "unable to create config file: $main_conf";
1274 print CONF "udev_root=\"$udev_root\"\n";
1275 print CONF "udev_db=\"$udev_db\"\n";
1276 print CONF "udev_rules=\"$conf_tmp\"\n";
1277 print CONF "udev_permissions=\"$perm\"\n";
1278 close CONF;
1279
1280 my $test_num = 1;
1281
1282 if ($ARGV[0]) {
1283         # only run one test
1284         $test_num = $ARGV[0];
1285
1286         if (defined($tests[$test_num-1]->{desc})) {
1287                 print "udev-test will run test number $test_num only:\n\n";
1288                 run_test($tests[$test_num-1], $test_num);
1289         } else {
1290                 print "test does not exist.\n";
1291         }
1292 } else {
1293         # test all
1294         print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1295
1296         foreach my $config (@tests) {
1297                 run_test($config, $test_num);
1298                 $test_num++;
1299         }
1300 }
1301
1302 print "$error errors occured\n\n";
1303
1304 # cleanup
1305 unlink($udev_db);
1306 system("rm -rf $udev_root");
1307 unlink($conf_tmp);
1308 unlink($main_conf);
1309