2005-02-10 20:26:09 +03:00
#!/usr/bin/perl
# udevstart-test
#
# runs udevstart in a temporary directory with our test sysfs-tree
# and counts the created nodes to compare it with the expected numbers.
#
# Kay Sievers <kay.sievers@vrfy.org>, 2005
#
use warnings ;
use strict ;
my $ PWD = $ ENV { PWD } ;
my $ sysfs = "sys/" ;
2005-03-27 03:10:03 +04:00
my $ udevstart_bin = "../udevstart" ;
2005-02-10 20:26:09 +03:00
my $ udev_root = "udev-root/" ; # !!! directory will be removed !!!
my $ udev_db = ".udevdb" ;
2005-03-27 03:10:03 +04:00
my $ udev_conf = "udev-test.conf" ;
my $ udev_rules = "udev-test.rules" ;
2005-02-10 20:26:09 +03:00
# set env
$ ENV { SYSFS_PATH } = $ sysfs ;
2005-03-27 03:10:03 +04:00
$ ENV { UDEV_CONFIG_FILE } = $ udev_conf ;
2005-02-10 20:26:09 +03:00
$ ENV { UDEV_NO_DEVD } = "yes" ;
$ ENV { UDEV_NO_HOTPLUGD } = "yes" ;
# due to mknod restrictions
if ( ! ( $< == 0 ) ) {
print "Must have root permissions to run properly.\n" ;
exit ;
}
# prepare
system ( "rm -rf $udev_root" ) ;
mkdir ( $ udev_root ) || die "unable to create udev_root: $udev_root\n" ;
2005-03-27 03:10:03 +04:00
# create config file
open CONF , ">$udev_conf" || die "unable to create config file: $udev_conf" ;
2005-02-10 20:26:09 +03:00
print CONF "udev_root=\"$udev_root\"\n" ;
print CONF "udev_db=\"$udev_db\"\n" ;
2005-03-27 03:10:03 +04:00
print CONF "udev_rules=\"$udev_rules\"\n" ;
2005-02-10 20:26:09 +03:00
close CONF ;
2005-03-27 03:10:03 +04:00
# create rules file
open RULES , ">$udev_rules" || die "unable to create rules file: $udev_rules" ;
print RULES "\n" ;
close RULES ;
system ( "$udevstart_bin" ) ;
my $ block = int ( `find $udev_root -type b -print | wc -l` ) ;
my $ char = int ( `find $udev_root -type c -print | wc -l` ) ;
2005-02-10 20:26:09 +03:00
print "block devices: $block/10\n" ;
print "char devices: $char/91\n" ;
2005-03-27 03:10:03 +04:00
print "\n" ;
2005-02-10 20:26:09 +03:00
# cleanup
system ( "rm -rf $udev_db" ) ;
system ( "rm -rf $udev_root" ) ;
2005-03-27 03:10:03 +04:00
unlink ( $ udev_rules ) ;
unlink ( $ udev_conf ) ;
2005-02-10 20:26:09 +03:00