From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Sat, 22 Nov 2003 14:41:10 +0000 Subject: [udev] udev-test.pl - automatic testing script MIME-Version: 1 Content-Type: multipart/mixed; boundary="GvXjxJ+pjyke8COw" Message-Id: List-Id: To: linux-hotplug@vger.kernel.org --GvXjxJ+pjyke8COw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, here is a automatic udev test script. To test place it in the test/ directory of the current tree to find the sysfs tree copy and run it. The whole test is self contained, it only needs a matching sysfs tree. To extend the test add a hash to the @tests array inside the script. The script checks the created node and prints a summary of all tests. Please don't change $udev_root to something useful, its a temorary directory and will be removed after the test run. thanks, Kay pim:/home/kay/src/udev.kay/test# ./udev-test.pl udev-test will run 6 tests: LABEL: for 'block/sda' add 'udev-root/boot_disk': ok LABEL: for 'block/sda' remove 'udev-root/boot_disk': ok LABEL: for 'block/sda/sda1' add 'udev-root/boot_disk1': ok LABEL: for 'block/sda/sda1' remove 'udev-root/boot_disk1': ok REPLACE: for 'class/tty/ttyUSB0' add 'udev-root/visor': ok REPLACE: for 'class/tty/ttyUSB0' remove 'udev-root/visor': ok TOPOLOGY: for 'block/sda/sda3' add 'udev-root/first_disk3': ok TOPOLOGY: for 'block/sda/sda3' remove 'udev-root/first_disk3': ok TOPOLOGY: for 'block/sda/sda3' add 'udev-root/Major:8:minor:3:kernelnumber:3:bus:0:0:0:0': ok TOPOLOGY: for 'block/sda/sda3' remove 'udev-root/Major:8:minor:3:kernelnumber:3:bus:0:0:0:0': ok CALLOUT: for 'block/sda/sda3' add 'udev-root/special-device-3': ok CALLOUT: for 'block/sda/sda3' remove 'udev-root/special-device-3': ok 0 errors occured --GvXjxJ+pjyke8COw Content-Type: application/x-perl Content-Disposition: inline; filename="udev-test.pl" Content-Transfer-Encoding: quoted-printable #!/usr/bin/perl=0A=0A# udev-test=0A#=0A# Provides automated testing of the = udev binary.=0A# The whole test is self contained in this file, except the = matching sysfs tree.=0A# Simply extend the @tests array, to add a new test = variant.=0A#=0A# Every test is driven by its own temporary config file.=0A#= This program prepares the environment, creates the config and calls udev.= =0A#=0A# udev reads the config, looks at the provided sysfs and=0A# first c= reates and then removes the device node.=0A# After creation and removal the= result is checked against the=0A# expected value and the result is printed= =2E=0A#=0A# happy testing,=0A# Kay Sievers , 2003=0A= =0A=0Ause warnings;=0Ause strict;=0A=0Amy $PWD =3D `pwd`;=0Achomp($PWD);=0A= =0Amy $sysfs =3D "sys/";=0Amy $udev_bin =3D "../udev";=0Amy $udev_root= =3D "udev-root/"; # !!! will be removed !!!=0Amy $udev_db =3D "udev.tdb"= ;=0Amy $perm =3D "udev.permissions";=0Amy $conf_tmp =3D "udev-test.co= nfig";=0A=0A=0Amy @tests =3D (=0A# label test of scsi disc=0A {=0A subsys = =3D> "block",=0A devpath =3D> "block/sda",=0A expected =3D> "boot_disk= " ,=0A conf =3D> < "block",=0A devp= ath =3D> "block/sda/sda1",=0A expected =3D> "boot_disk1" ,=0A conf = =3D> < "tty",=0A devp= ath =3D> "class/tty/ttyUSB0",=0A expected =3D> "visor" ,=0A conf =3D= > < "block",=0A devpath =3D>= "block/sda/sda3",=0A expected =3D> "first_disk3" ,=0A conf =3D> < "block",=0A = devpath =3D> "block/sda/sda3",=0A expected =3D> "Major:8:minor:3:kerneln= umber:3:bus:0:0:0:0" ,=0A conf =3D> < "block",=0A devpath =3D> "block/sda/sda3",=0A expected =3D> "spec= ial-device-3" ,=0A conf =3D> <$conf_tmp" || die "unable to = create config file: $conf_tmp";=0A print CONF $$config;=0A close CONF;=0A= =0A # add action=0A $ENV{ACTION} =3D "add";=0A print "$method: for \'$devpa= th\' add \'$udev_root$expected_node\': ";=0A system("$udev_bin $subsys");= =0A if (-e "$PWD/$udev_root$expected_node") {=0A print "ok\n";=0A } else {= =0A print "error\n";=0A system("ls -la $udev_root");=0A return -1;=0A }= =0A=0A # remove action=0A $ENV{ACTION} =3D "remove";=0A print "$method: for= \'$devpath\' remove \'$udev_root$expected_node\': ";=0A system("$udev_bin = $subsys");=0A if (-e "$PWD/$udev_root$expected_node") {=0A print "error\n"= ;=0A return -1=0A } else {=0A print "ok\n";=0A }=0A return 0;=0A}=0A=0A= =0A# prepare=0Asystem("rm -rf $udev_root");=0Amkdir($udev_root) || die "una= ble to create udev_root: $udev_root\n";=0A=0A# test=0Amy $error =3D 0;=0Apr= int "\nudev-test will run ".($#tests + 1)." tests:\n\n";=0A=0Aforeach my $c= onfig (@tests) {=0A if (test($config->{subsys}, $config->{devpath}, $config= ->{expected}, \$config->{conf}) !=3D 0) {=0A $error++;=0A }=0A print "\n";= =0A}=0A=0Aprint "$error errors occured\n\n";=0A=0A# cleanup=0Asystem("rm -r= f $udev_root");=0Aunlink($conf_tmp);=0Aunlink($udev_db);=0A=0A --GvXjxJ+pjyke8COw-- ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel