chiark / gitweb /
EXTRAS: cleanup and sync all Makefiles
[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 $ENV{UDEV_NO_DEVD} = "yes";
26 $ENV{UDEV_NO_HOTPLUGD} = "yes";
27
28 # due to mknod restrictions
29 if (!($<==0)) {
30         print "Must have root permissions to run properly.\n";
31         exit;
32 }
33
34 # prepare
35 system("rm -rf $udev_root");
36 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
37
38 # create config file
39 open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
40 print CONF "udev_root=\"$udev_root\"\n";
41 print CONF "udev_db=\"$udev_db\"\n";
42 print CONF "udev_rules=\"$udev_rules\"\n";
43 close CONF;
44
45 # create rules file
46 open RULES, ">$udev_rules" || die "unable to create rules file: $udev_rules";
47 print RULES "\n";
48 close RULES;
49
50 system("$udevstart_bin");
51 my $block = int(`find $udev_root -type b -print | wc -l`);
52 my $char  = int(`find $udev_root -type c -print | wc -l`);
53
54 print "block devices: $block/10\n";
55 print "char devices: $char/91\n";
56 print "\n";
57
58 # cleanup
59 system("rm -rf $udev_db");
60 system("rm -rf $udev_root");
61 unlink($udev_rules);
62 unlink($udev_conf);
63