]>
Commit | Line | Data |
---|---|---|
a367f04e GKH |
1 | #!/usr/bin/perl |
2 | ||
3 | # udev-test | |
4 | # | |
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. | |
8 | # | |
9 | # Every test is driven by its own temporary config file. | |
10 | # This program prepares the environment, creates the config and calls udev. | |
11 | # | |
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. | |
16 | # | |
17 | # happy testing, | |
18 | # Kay Sievers <kay.sievers@vrfy.org>, 2003 | |
19 | ||
20 | ||
21 | use warnings; | |
22 | use strict; | |
23 | ||
24 | my $PWD = `pwd`; | |
25 | chomp($PWD); | |
26 | ||
27 | my $sysfs = "sys/"; | |
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"; | |
33 | ||
34 | ||
35 | my @tests = ( | |
36 | { | |
37 | desc => "label test of scsi disc", | |
38 | subsys => "block", | |
39 | devpath => "block/sda", | |
40 | expected => "boot_disk" , | |
41 | conf => <<EOF | |
42 | LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n" | |
43 | REPLACE, KERNEL="ttyUSB0", NAME="visor"" | |
44 | EOF | |
45 | }, | |
46 | { | |
47 | desc => "label test of scsi partition", | |
48 | subsys => "block", | |
49 | devpath => "block/sda/sda1", | |
50 | expected => "boot_disk1" , | |
51 | conf => <<EOF | |
52 | LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n" | |
53 | EOF | |
54 | }, | |
55 | { | |
56 | desc => "replace kernel name", | |
57 | subsys => "tty", | |
58 | devpath => "class/tty/ttyUSB0", | |
59 | expected => "visor" , | |
60 | conf => <<EOF | |
61 | REPLACE, KERNEL="ttyUSB0", NAME="visor" | |
62 | EOF | |
63 | }, | |
64 | { | |
65 | desc => "place on bus of scsi partition", | |
66 | subsys => "block", | |
67 | devpath => "block/sda/sda3", | |
68 | expected => "first_disk3" , | |
69 | conf => <<EOF | |
70 | TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n" | |
71 | EOF | |
72 | }, | |
73 | { | |
74 | desc => "test NAME substitution chars", | |
75 | subsys => "block", | |
76 | devpath => "block/sda/sda3", | |
77 | expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , | |
78 | conf => <<EOF | |
79 | TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b" | |
80 | EOF | |
81 | }, | |
82 | { | |
83 | desc => "callout result subtitution, only last should match", | |
84 | subsys => "block", | |
85 | devpath => "block/sda/sda3", | |
86 | expected => "special-device-3" , | |
87 | conf => <<EOF | |
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" | |
93 | EOF | |
94 | }, | |
95 | ); | |
96 | ||
97 | # set env | |
98 | $ENV{UDEV_TEST} = "yes"; | |
99 | $ENV{SYSFS_PATH} = $sysfs; | |
100 | $ENV{UDEV_CONFIG_DIR} = "./"; | |
101 | $ENV{UDEV_ROOT} = $udev_root; | |
102 | $ENV{UDEV_DB} = $udev_db; | |
103 | $ENV{UDEV_PERMISSION_FILE} = $perm; | |
104 | ||
105 | ||
106 | sub udev { | |
107 | my ($action, $subsys, $devpath, $config) = @_; | |
108 | ||
109 | $ENV{DEVPATH} = $devpath; | |
110 | $ENV{UDEV_CONFIG_FILE} = $conf_tmp; | |
111 | ||
112 | # create temporary config | |
113 | open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp"; | |
114 | print CONF $$config; | |
115 | close CONF; | |
116 | ||
117 | $ENV{ACTION} = $action; | |
118 | system("$udev_bin $subsys"); | |
119 | } | |
120 | ||
121 | ||
122 | # prepare | |
123 | system("rm -rf $udev_root"); | |
124 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
125 | ||
126 | # test | |
e5fbfe0a | 127 | my $error = 0; |
a367f04e GKH |
128 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; |
129 | ||
130 | foreach my $config (@tests) { | |
131 | $config->{conf} =~ m/^([A-Z]*).*/; | |
132 | my $method = $1; | |
133 | ||
134 | print "TEST: $config->{desc}\n"; | |
135 | print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n"; | |
136 | ||
137 | udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf}); | |
138 | if (-e "$PWD/$udev_root$config->{expected}") { | |
139 | print "add: ok "; | |
140 | } else { | |
141 | print "add: error\n"; | |
142 | system("tree $udev_root"); | |
143 | print "\n"; | |
144 | $error++; | |
145 | # next; | |
146 | } | |
147 | ||
148 | udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf}); | |
149 | if (-e "$PWD/$udev_root$config->{expected}") { | |
150 | print "remove: error\n\n"; | |
151 | system("tree $udev_root"); | |
152 | $error++; | |
153 | } else { | |
154 | print "remove: ok\n\n"; | |
155 | } | |
156 | } | |
157 | ||
158 | print "$error errors occured\n\n"; | |
159 | ||
160 | # cleanup | |
161 | system("rm -rf $udev_root"); | |
162 | unlink($conf_tmp); | |
163 | unlink($udev_db); | |
164 |