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
11use warnings;
12use strict;
13
14my $PWD = $ENV{PWD};
15my $sysfs     = "sys/";
16my $udevstart_bin  = "../udevstart";
17my $udev_root = "udev-root/"; # !!! directory will be removed !!!
18my $udev_db   = ".udevdb";
19my $udev_conf = "udev-test.conf";
20my $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
27if (!($<==0)) {
28	print "Must have root permissions to run properly.\n";
29	exit;
30}
31
32# prepare
33system("rm -rf $udev_root");
34mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
35
36# create config file
37open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
38print CONF "udev_root=\"$udev_root\"\n";
39print CONF "udev_db=\"$udev_db\"\n";
40print CONF "udev_rules=\"$udev_rules\"\n";
41close CONF;
42
43# create rules file
44open RULES, ">$udev_rules" || die "unable to create rules file: $udev_rules";
45print RULES "\n";
46close RULES;
47
48system("$udevstart_bin");
49my $block = int(`find $udev_root -type b -print | wc -l`);
50my $char  = int(`find $udev_root -type c -print | wc -l`);
51
52print "block devices: $block/10\n";
53print "char devices: $char/91\n";
54print "\n";
55
56# cleanup
57system("rm -rf $udev_db");
58system("rm -rf $udev_root");
59unlink($udev_rules);
60unlink($udev_conf);
61