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
28 my $udev_bin = "../udev";
29 my $udev_root = "udev-root/"; # !!! directory will be removed !!!
30 my $udev_db = "udev.tdb";
31 my $perm = "udev.permissions";
32 my $conf_tmp = "udev-test.config";
37 desc => "label test of scsi disc",
39 devpath => "block/sda",
40 expected => "boot_disk" ,
42 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
43 REPLACE, KERNEL="ttyUSB0", NAME="visor""
47 desc => "label test of scsi partition",
49 devpath => "block/sda/sda1",
50 expected => "boot_disk1" ,
52 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
56 desc => "replace kernel name",
58 devpath => "class/tty/ttyUSB0",
61 REPLACE, KERNEL="ttyUSB0", NAME="visor"
65 desc => "place on bus of scsi partition",
67 devpath => "block/sda/sda3",
68 expected => "first_disk3" ,
70 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
74 desc => "test NAME substitution chars",
76 devpath => "block/sda/sda3",
77 expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
79 TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
83 desc => "callout result subtitution, only last should match",
85 devpath => "block/sda/sda3",
86 expected => "special-device-3" ,
88 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="-special-*", NAME="%c-1-%n"
89 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAME="%c-2-%n"
90 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
91 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
92 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
96 desc => "callout program subtitution",
98 devpath => "block/sda/sda3",
99 expected => "test-0:0:0:0" ,
101 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
107 $ENV{UDEV_TEST} = "yes";
108 $ENV{SYSFS_PATH} = $sysfs;
109 $ENV{UDEV_CONFIG_DIR} = "./";
110 $ENV{UDEV_ROOT} = $udev_root;
111 $ENV{UDEV_DB} = $udev_db;
112 $ENV{UDEV_PERMISSION_FILE} = $perm;
116 my ($action, $subsys, $devpath, $config) = @_;
118 $ENV{DEVPATH} = $devpath;
119 $ENV{UDEV_CONFIG_FILE} = $conf_tmp;
121 # create temporary config
122 open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
126 $ENV{ACTION} = $action;
127 system("$udev_bin $subsys");
132 system("rm -rf $udev_root");
133 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
137 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
139 foreach my $config (@tests) {
140 $config->{conf} =~ m/^([A-Z]*).*/;
143 print "TEST: $config->{desc}\n";
144 print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
146 udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
147 if (-e "$PWD/$udev_root$config->{expected}") {
150 print "add: error\n";
151 system("tree $udev_root");
157 udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
158 if (-e "$PWD/$udev_root$config->{expected}") {
159 print "remove: error\n\n";
160 system("tree $udev_root");
163 print "remove: ok\n\n";
167 print "$error errors occured\n\n";
170 system("rm -rf $udev_root");