]>
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
=> "catch device by *",
57 devpath
=> "class/tty/ttyUSB0",
58 expected
=> "visor/0" ,
60 REPLACE, KERNEL="ttyUSB*", NAME="visor/%n"
64 desc
=> "catch device by ?",
66 devpath
=> "class/tty/ttyUSB0",
67 expected
=> "visor/0" ,
69 REPLACE, KERNEL="ttyUSB??*", NAME="visor/%n-1"
70 REPLACE, KERNEL="ttyUSB??", NAME="visor/%n-2"
71 REPLACE, KERNEL="ttyUSB?", NAME="visor/%n"
75 desc
=> "catch device by character class",
77 devpath
=> "class/tty/ttyUSB0",
78 expected
=> "visor/0" ,
80 REPLACE, KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1"
81 REPLACE, KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2"
82 REPLACE, KERNEL="ttyUSB[0-9]*", NAME="visor/%n"
86 desc
=> "replace kernel name",
88 devpath
=> "class/tty/ttyUSB0",
91 REPLACE, KERNEL="ttyUSB0", NAME="visor"
95 desc
=> "subdirectory handling",
97 devpath
=> "class/tty/ttyUSB0",
98 expected
=> "sub/direct/ory/visor" ,
100 REPLACE, KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
104 desc
=> "place on bus of scsi partition",
106 devpath
=> "block/sda/sda3",
107 expected
=> "first_disk3" ,
109 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
113 desc
=> "test NAME substitution chars",
115 devpath
=> "block/sda/sda3",
116 expected
=> "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
118 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
122 desc
=> "callout result substitution",
124 devpath
=> "block/sda/sda3",
125 expected
=> "special-device-3" ,
127 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="-special-*", NAME="%c-1-%n"
128 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAME="%c-2-%n"
129 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
130 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
131 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
135 desc
=> "callout program substitution",
137 devpath
=> "block/sda/sda3",
138 expected
=> "test-0:0:0:0" ,
140 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
144 desc
=> "devfs disk naming substitution",
146 devpath
=> "block/sda",
147 expected
=> "lun0/disk" ,
149 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
153 desc
=> "devfs disk naming substitution",
155 devpath
=> "block/sda/sda2",
156 expected
=> "lun0/part2" ,
158 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
162 desc
=> "callout bus type",
164 devpath
=> "block/sda",
165 expected
=> "scsi-0:0:0:0" ,
167 CALLOUT, BUS="usb", PROGRAM="/bin/echo -n usb-%b", ID="*", NAME="%c"
168 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", ID="*", NAME="%c"
169 CALLOUT, BUS="foo", PROGRAM="/bin/echo -n foo-%b", ID="*", NAME="%c"
175 $ENV{UDEV_TEST
} = "yes";
176 $ENV{SYSFS_PATH
} = $sysfs;
177 $ENV{UDEV_CONFIG_FILE
} = $main_conf;
181 my ($action, $subsys, $devpath, $config) = @_;
183 $ENV{DEVPATH
} = $devpath;
185 # create temporary config
186 open CONF
, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
190 $ENV{ACTION
} = $action;
191 system("$udev_bin $subsys");
196 system("rm -rf $udev_root");
197 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
201 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
203 # create initial config file
204 open CONF
, ">$main_conf" || die "unable to create config file: $main_conf";
205 print CONF
"udev_root=\"$udev_root\"\n";
206 print CONF
"udev_db=\"$udev_db\"\n";
207 print CONF
"udev_rules=\"$conf_tmp\"\n";
208 print CONF
"udev_permissions=\"$perm\"\n";
211 foreach my $config (@tests) {
212 $config->{conf
} =~ m/^([A-Z]*).*/;
215 print "TEST: $config->{desc}\n";
216 print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
218 udev
("add", $config->{subsys
}, $config->{devpath
}, \
$config->{conf
});
219 if (-e
"$PWD/$udev_root$config->{expected}") {
222 print "add: error\n";
223 system("tree $udev_root");
228 udev
("remove", $config->{subsys
}, $config->{devpath
}, \
$config->{conf
});
229 if (-e
"$PWD/$udev_root$config->{expected}") {
230 print "remove: error\n\n";
231 system("tree $udev_root");
234 print "remove: ok\n\n";
238 print "$error errors occured\n\n";
242 system("rm -rf $udev_root");