]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/udev-test.pl
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 $main_conf = "udev-test.conf";
31 my $conf_tmp = "udev-test.rules";
36 desc
=> "label test of scsi disc",
38 devpath
=> "block/sda",
39 expected
=> "boot_disk" ,
41 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
42 REPLACE, KERNEL="ttyUSB0", NAME="visor"
46 desc
=> "label test of scsi partition",
48 devpath
=> "block/sda/sda1",
49 expected
=> "boot_disk1" ,
51 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
55 desc
=> "label test of pattern match",
57 devpath
=> "block/sda/sda1",
58 expected
=> "boot_disk1" ,
60 LABEL, BUS="scsi", vendor="?IBM-ESXS", NAME="boot_disk%n-1"
61 LABEL, BUS="scsi", vendor="IBM-ESXS?", NAME="boot_disk%n-2"
62 LABEL, BUS="scsi", vendor="IBM-ES??", NAME="boot_disk%n"
63 LABEL, BUS="scsi", vendor="IBM-ESXSS", NAME="boot_disk%n-3"
67 desc
=> "catch device by *",
69 devpath
=> "class/tty/ttyUSB0",
70 expected
=> "visor/0" ,
72 REPLACE, KERNEL="ttyUSB*", NAME="visor/%n"
76 desc
=> "catch device by ?",
78 devpath
=> "class/tty/ttyUSB0",
79 expected
=> "visor/0" ,
81 REPLACE, KERNEL="ttyUSB??*", NAME="visor/%n-1"
82 REPLACE, KERNEL="ttyUSB??", NAME="visor/%n-2"
83 REPLACE, KERNEL="ttyUSB?", NAME="visor/%n"
87 desc
=> "catch device by character class",
89 devpath
=> "class/tty/ttyUSB0",
90 expected
=> "visor/0" ,
92 REPLACE, KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1"
93 REPLACE, KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2"
94 REPLACE, KERNEL="ttyUSB[0-9]*", NAME="visor/%n"
98 desc
=> "replace kernel name",
100 devpath
=> "class/tty/ttyUSB0",
101 expected
=> "visor" ,
103 REPLACE, KERNEL="ttyUSB0", NAME="visor"
107 desc
=> "subdirectory handling",
109 devpath
=> "class/tty/ttyUSB0",
110 expected
=> "sub/direct/ory/visor" ,
112 REPLACE, KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
116 desc
=> "place on bus of scsi partition",
118 devpath
=> "block/sda/sda3",
119 expected
=> "first_disk3" ,
121 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
125 desc
=> "test NAME substitution chars",
127 devpath
=> "block/sda/sda3",
128 expected
=> "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
130 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
134 desc
=> "callout result substitution",
136 devpath
=> "block/sda/sda3",
137 expected
=> "special-device-3" ,
139 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="-special-*", NAME="%c-1-%n"
140 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAME="%c-2-%n"
141 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
142 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
143 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
147 desc
=> "callout program substitution",
149 devpath
=> "block/sda/sda3",
150 expected
=> "test-0:0:0:0" ,
152 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
156 desc
=> "devfs disk naming substitution",
158 devpath
=> "block/sda",
159 expected
=> "lun0/disk" ,
161 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
165 desc
=> "devfs disk naming substitution",
167 devpath
=> "block/sda/sda2",
168 expected
=> "lun0/part2" ,
170 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
174 desc
=> "callout bus type",
176 devpath
=> "block/sda",
177 expected
=> "scsi-0:0:0:0" ,
179 CALLOUT, BUS="usb", PROGRAM="/bin/echo -n usb-%b", ID="*", NAME="%c"
180 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", ID="*", NAME="%c"
181 CALLOUT, BUS="foo", PROGRAM="/bin/echo -n foo-%b", ID="*", NAME="%c"
185 desc
=> "symlink creation (same directory)",
187 devpath
=> "class/tty/ttyUSB0",
188 expected
=> "visor0" ,
190 REPLACE, KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n"
194 desc
=> "symlink creation (relative link back)",
196 devpath
=> "block/sda/sda2",
197 expected
=> "1/2/a/b/symlink" ,
199 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/node", SYMLINK="1/2/a/b/symlink"
203 desc
=> "symlink creation (relative link forward)",
205 devpath
=> "block/sda/sda2",
206 expected
=> "1/2/symlink" ,
208 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
212 desc
=> "symlink creation (relative link back and forward)",
214 devpath
=> "block/sda/sda2",
215 expected
=> "1/2/c/d/symlink" ,
217 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
221 desc
=> "multiple symlinks",
223 devpath
=> "class/tty/ttyUSB0",
224 expected
=> "second-0" ,
226 REPLACE, KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
232 $ENV{UDEV_TEST
} = "yes";
233 $ENV{SYSFS_PATH
} = $sysfs;
234 $ENV{UDEV_CONFIG_FILE
} = $main_conf;
238 my ($action, $subsys, $devpath, $config) = @_;
240 $ENV{DEVPATH
} = $devpath;
242 # create temporary config
243 open CONF
, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
247 $ENV{ACTION
} = $action;
248 system("$udev_bin $subsys");
253 system("rm -rf $udev_root");
254 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
258 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
260 # create initial config file
261 open CONF
, ">$main_conf" || die "unable to create config file: $main_conf";
262 print CONF
"udev_root=\"$udev_root\"\n";
263 print CONF
"udev_db=\"$udev_db\"\n";
264 print CONF
"udev_rules=\"$conf_tmp\"\n";
265 print CONF
"udev_permissions=\"$perm\"\n";
268 foreach my $config (@tests) {
269 $config->{conf
} =~ m/^([A-Z]*).*/;
272 print "TEST: $config->{desc}\n";
273 print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
275 udev
("add", $config->{subsys
}, $config->{devpath
}, \
$config->{conf
});
276 if (-e
"$PWD/$udev_root$config->{expected}") {
279 print "add: error\n";
280 system("tree $udev_root");
285 udev
("remove", $config->{subsys
}, $config->{devpath
}, \
$config->{conf
});
286 if ((-e
"$PWD/$udev_root$config->{expected}") ||
287 (-l
"$PWD/$udev_root$config->{expected}")) {
288 print "remove: error\n\n";
289 system("tree $udev_root");
292 print "remove: ok\n\n";
296 print "$error errors occured\n\n";
300 system("rm -rf $udev_root");