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.
9 # Every test is driven by its own temporary config file.
10 # This program prepares the environment, creates the config and calls udev.
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.
18 # Kay Sievers <kay.sievers@vrfy.org>, 2003
26 my $udev_bin = "../udev";
27 my $udev_root = "udev-root/"; # !!! directory will be removed !!!
28 my $udev_db = ".udev.tdb";
29 my $perm = "udev.permissions";
30 my $conf_tmp = "udev-test.config";
35 desc => "label test of scsi disc",
37 devpath => "block/sda",
38 expected => "boot_disk" ,
40 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
41 REPLACE, KERNEL="ttyUSB0", NAME="visor""
45 desc => "label test of scsi partition",
47 devpath => "block/sda/sda1",
48 expected => "boot_disk1" ,
50 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
54 desc => "catch device by *",
56 devpath => "class/tty/ttyUSB0",
57 expected => "visor/0" ,
59 REPLACE, KERNEL="ttyUSB*", NAME="visor/%n"
63 desc => "catch device by ?",
65 devpath => "class/tty/ttyUSB0",
66 expected => "visor/0" ,
68 REPLACE, KERNEL="ttyUSB??*", NAME="visor/%n-1"
69 REPLACE, KERNEL="ttyUSB??", NAME="visor/%n-2"
70 REPLACE, KERNEL="ttyUSB?", NAME="visor/%n"
74 desc => "catch device by character class",
76 devpath => "class/tty/ttyUSB0",
77 expected => "visor/0" ,
79 REPLACE, KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1"
80 REPLACE, KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2"
81 REPLACE, KERNEL="ttyUSB[0-9]*", NAME="visor/%n"
85 desc => "replace kernel name",
87 devpath => "class/tty/ttyUSB0",
90 REPLACE, KERNEL="ttyUSB0", NAME="visor"
94 desc => "subdirectory handling",
96 devpath => "class/tty/ttyUSB0",
97 expected => "sub/direct/ory/visor" ,
99 REPLACE, KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
103 desc => "place on bus of scsi partition",
105 devpath => "block/sda/sda3",
106 expected => "first_disk3" ,
108 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
112 desc => "test NAME substitution chars",
114 devpath => "block/sda/sda3",
115 expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
117 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
121 desc => "callout result substitution",
123 devpath => "block/sda/sda3",
124 expected => "special-device-3" ,
126 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="-special-*", NAME="%c-1-%n"
127 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAME="%c-2-%n"
128 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
129 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
130 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
134 desc => "callout program substitution",
136 devpath => "block/sda/sda3",
137 expected => "test-0:0:0:0" ,
139 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
143 desc => "devfs disk naming substitution",
145 devpath => "block/sda",
146 expected => "lun0/disk" ,
148 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
152 desc => "devfs disk naming substitution",
154 devpath => "block/sda/sda2",
155 expected => "lun0/part2" ,
157 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
161 desc => "callout bus type",
163 devpath => "block/sda",
164 expected => "scsi-0:0:0:0" ,
166 CALLOUT, BUS="usb", PROGRAM="/bin/echo -n usb-%b", ID="*", NAME="%c"
167 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", ID="*", NAME="%c"
168 CALLOUT, BUS="foo", PROGRAM="/bin/echo -n foo-%b", ID="*", NAME="%c"
174 $ENV{UDEV_TEST} = "yes";
175 $ENV{SYSFS_PATH} = $sysfs;
176 $ENV{UDEV_CONFIG_DIR} = "./";
177 $ENV{UDEV_ROOT} = $udev_root;
178 $ENV{UDEV_DB} = $udev_db;
179 $ENV{UDEV_PERMISSION_FILE} = $perm;
183 my ($action, $subsys, $devpath, $config) = @_;
185 $ENV{DEVPATH} = $devpath;
186 $ENV{UDEV_RULES_FILE} = $conf_tmp;
188 # create temporary config
189 open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
193 $ENV{ACTION} = $action;
194 system("$udev_bin $subsys");
199 system("rm -rf $udev_root");
200 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
204 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
206 foreach my $config (@tests) {
207 $config->{conf} =~ m/^([A-Z]*).*/;
210 print "TEST: $config->{desc}\n";
211 print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
213 udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
214 if (-e "$PWD/$udev_root$config->{expected}") {
217 print "add: error\n";
218 system("tree $udev_root");
223 udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
224 if (-e "$PWD/$udev_root$config->{expected}") {
225 print "remove: error\n\n";
226 system("tree $udev_root");
229 print "remove: ok\n\n";
233 print "$error errors occured\n\n";
237 system("rm -rf $udev_root");