chiark / gitweb /
add "[$SUBSYSTEM/$KERNEL]<attribute>" lookup
[elogind.git] / test / udevstart-test.pl
1 #!/usr/bin/perl
2
3 # udevstart-test
4 #
5 # runs udevstart in a temporary directory with our test sysfs-tree
6 # and counts the created nodes to compare it with the expected numbers.
7 #
8 # Kay Sievers <kay.sievers@vrfy.org>, 2005
9 #
10
11 use warnings;
12 use strict;
13
14 my $PWD = $ENV{PWD};
15 my $sysfs     = "sys/";
16 my $udevstart_bin  = "../udevstart";
17 my $udev_root = "udev-root/"; # !!! directory will be removed !!!
18 my $udev_db   = ".udevdb";
19 my $udev_conf = "udev-test.conf";
20 my $udev_rules  = "udev-test.rules";
21
22 # set env
23 $ENV{SYSFS_PATH} = $sysfs;
24 $ENV{UDEV_CONFIG_FILE} = $udev_conf;
25
26 # due to mknod restrictions
27 if (!($<==0)) {
28         print "Must have root permissions to run properly.\n";
29         exit;
30 }
31
32 # prepare
33 system("rm -rf $udev_root");
34 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
35
36 # create config file
37 open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
38 print CONF "udev_root=\"$udev_root\"\n";
39 print CONF "udev_db=\"$udev_db\"\n";
40 print CONF "udev_rules=\"$udev_rules\"\n";
41 close CONF;
42
43 # create rules file
44 open RULES, ">$udev_rules" || die "unable to create rules file: $udev_rules";
45 print RULES "\n";
46 close RULES;
47
48 system("$udevstart_bin");
49 my $block = int(`find $udev_root -type b -print | wc -l`);
50 my $char  = int(`find $udev_root -type c -print | wc -l`);
51
52 print "block devices: $block/10\n";
53 print "char devices: $char/91\n";
54 print "\n";
55
56 # cleanup
57 system("rm -rf $udev_db");
58 system("rm -rf $udev_root");
59 unlink($udev_rules);
60 unlink($udev_conf);
61