]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/udev-test.pl
[PATCH] tweak udev-test.pl to report '0' errors if that's what happened.
[thirdparty/systemd.git] / test / udev-test.pl
CommitLineData
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
21use warnings;
22use strict;
23
24my $PWD = `pwd`;
25chomp($PWD);
26
27my $sysfs = "sys/";
28my $udev_bin = "../udev";
29my $udev_root = "udev-root/"; # !!! directory will be removed !!!
30my $udev_db = "udev.tdb";
31my $perm = "udev.permissions";
32my $conf_tmp = "udev-test.config";
33
34
35my @tests = (
36 {
37 desc => "label test of scsi disc",
38 subsys => "block",
39 devpath => "block/sda",
40 expected => "boot_disk" ,
41 conf => <<EOF
42LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
43REPLACE, KERNEL="ttyUSB0", NAME="visor""
44EOF
45 },
46 {
47 desc => "label test of scsi partition",
48 subsys => "block",
49 devpath => "block/sda/sda1",
50 expected => "boot_disk1" ,
51 conf => <<EOF
52LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
53EOF
54 },
55 {
56 desc => "replace kernel name",
57 subsys => "tty",
58 devpath => "class/tty/ttyUSB0",
59 expected => "visor" ,
60 conf => <<EOF
61REPLACE, KERNEL="ttyUSB0", NAME="visor"
62EOF
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
70TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
71EOF
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
79TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
80EOF
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
88CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="-special-*", NAME="%c-1-%n"
89CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAME="%c-2-%n"
90CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
91CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
92CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
93EOF
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
106sub 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
123system("rm -rf $udev_root");
124mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
125
126# test
e5fbfe0a 127my $error = 0;
a367f04e
GKH
128print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
129
130foreach 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
158print "$error errors occured\n\n";
159
160# cleanup
161system("rm -rf $udev_root");
162unlink($conf_tmp);
163unlink($udev_db);
164