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 => "replace kernel name",
56 devpath => "class/tty/ttyUSB0",
59 REPLACE, KERNEL="ttyUSB0", NAME="visor"
63 desc => "subdirectory handling",
65 devpath => "class/tty/ttyUSB0",
66 expected => "sub/direct/ory/visor" ,
68 REPLACE, KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
72 desc => "place on bus of scsi partition",
74 devpath => "block/sda/sda3",
75 expected => "first_disk3" ,
77 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
81 desc => "test NAME substitution chars",
83 devpath => "block/sda/sda3",
84 expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
86 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
90 desc => "callout result substitution, only last should match",
92 devpath => "block/sda/sda3",
93 expected => "special-device-3" ,
95 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="-special-*", NAME="%c-1-%n"
96 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAME="%c-2-%n"
97 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
98 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
99 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
103 desc => "callout program substitution",
105 devpath => "block/sda/sda3",
106 expected => "test-0:0:0:0" ,
108 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
112 desc => "devfs disk naming substitution",
114 devpath => "block/sda",
115 expected => "lun0/disk" ,
117 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
121 desc => "devfs disk naming substitution",
123 devpath => "block/sda/sda2",
124 expected => "lun0/part2" ,
126 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
130 desc => "callout bus type",
132 devpath => "block/sda",
133 expected => "scsi-0:0:0:0" ,
135 CALLOUT, BUS="usb", PROGRAM="/bin/echo -n usb-%b", ID="*", NAME="%c"
136 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", ID="*", NAME="%c"
137 CALLOUT, BUS="foo", PROGRAM="/bin/echo -n foo-%b", ID="*", NAME="%c"
143 $ENV{UDEV_TEST} = "yes";
144 $ENV{SYSFS_PATH} = $sysfs;
145 $ENV{UDEV_CONFIG_DIR} = "./";
146 $ENV{UDEV_ROOT} = $udev_root;
147 $ENV{UDEV_DB} = $udev_db;
148 $ENV{UDEV_PERMISSION_FILE} = $perm;
152 my ($action, $subsys, $devpath, $config) = @_;
154 $ENV{DEVPATH} = $devpath;
155 $ENV{UDEV_CONFIG_FILE} = $conf_tmp;
157 # create temporary config
158 open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
162 $ENV{ACTION} = $action;
163 system("$udev_bin $subsys");
168 system("rm -rf $udev_root");
169 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
173 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
175 foreach my $config (@tests) {
176 $config->{conf} =~ m/^([A-Z]*).*/;
179 print "TEST: $config->{desc}\n";
180 print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
182 udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
183 if (-e "$PWD/$udev_root$config->{expected}") {
186 print "add: error\n";
187 system("tree $udev_root");
192 udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
193 if (-e "$PWD/$udev_root$config->{expected}") {
194 print "remove: error\n\n";
195 system("tree $udev_root");
198 print "remove: ok\n\n";
202 print "$error errors occured\n\n";
206 system("rm -rf $udev_root");