From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Sun, 23 Nov 2003 03:54:09 +0000 Subject: Re: [udev] udev-test.pl - automatic testing script MIME-Version: 1 Content-Type: multipart/mixed; boundary="T4sUOijqQbZv57TR" Message-Id: List-Id: To: linux-hotplug@vger.kernel.org --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Nov 22, 2003 at 03:41:10PM +0100, Kay Sievers wrote: > 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. Here is a slightly better version that runs 'tree' on error and prints a description for every test. thanks, Kay pim:/home/kay/src/udev.kay/test# ./udev-test.pl udev-test will run 6 tests: TEST: label test of scsi disc method 'LABEL' for 'block/sda' expecting node 'boot_disk' add: ok remove: ok TEST: label test of scsi partition method 'LABEL' for 'block/sda/sda1' expecting node 'boot_disk1' add: ok remove: ok TEST: replace kernel name method 'REPLACE' for 'class/tty/ttyUSB0' expecting node 'visor' add: ok remove: ok TEST: place on bus of scsi partition method 'TOPOLOGY' for 'block/sda/sda3' expecting node 'first_disk2' add: error udev-root/ `-- first_disk3 0 directories, 1 file TEST: test NAME substitution chars method 'TOPOLOGY' for 'block/sda/sda3' expecting node 'Major:8:minor:3:kernelnumber:3:bus:0:0:0:0' add: ok remove: ok TEST: callout result subtitution, only last should match method 'CALLOUT' for 'block/sda/sda3' expecting node 'special-device-3' add: ok remove: ok 1 errors occured --T4sUOijqQbZv57TR 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/"; # !!! directory will be removed !!!=0Amy $udev_db =3D = "udev.tdb";=0Amy $perm =3D "udev.permissions";=0Amy $conf_tmp =3D "ud= ev-test.config";=0A=0A=0Amy @tests =3D (=0A {=0A desc =3D> "label test= of scsi disc",=0A subsys =3D> "block",=0A devpath =3D> "block/sda",= =0A expected =3D> "boot_disk" ,=0A conf =3D> < "label test of scsi p= artition",=0A subsys =3D> "block",=0A devpath =3D> "block/sda/sda1",= =0A expected =3D> "boot_disk1" ,=0A conf =3D> < "replace kernel name",=0A subsys =3D> "tty",=0A devpath =3D> "= class/tty/ttyUSB0",=0A expected =3D> "visor" ,=0A conf =3D> < "place on bus of scsi partition",=0A subsys =3D> "block",=0A devpa= th =3D> "block/sda/sda3",=0A expected =3D> "first_disk3" ,=0A conf = =3D> < "test NAME substitution chars",=0A s= ubsys =3D> "block",=0A devpath =3D> "block/sda/sda3",=0A expected =3D>= "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,=0A conf =3D> < "callout result subtitu= tion, only last should match",=0A subsys =3D> "block",=0A devpath =3D>= "block/sda/sda3",=0A expected =3D> "special-device-3" ,=0A conf =3D>= <$conf_tmp" || die "unable to = create config file: $conf_tmp";=0A print CONF $$config;=0A close CONF;=0A= =0A $ENV{ACTION} =3D $action;=0A system("$udev_bin $subsys");=0A}=0A=0A=0A#= prepare=0Asystem("rm -rf $udev_root");=0Amkdir($udev_root) || die "unable = to create udev_root: $udev_root\n";=0A=0A# test=0Amy $error;=0Aprint "\nude= v-test will run ".($#tests + 1)." tests:\n\n";=0A=0Aforeach my $config (@te= sts) {=0A $config->{conf} =3D~ m/^([A-Z]*).*/;=0A my $method =3D $1;=0A=0A= print "TEST: $config->{desc}\n";=0A print "method \'$method\' for \'$confi= g->{devpath}\' expecting node \'$config->{expected}\'\n";=0A=0A udev("add",= $config->{subsys}, $config->{devpath}, \$config->{conf});=0A if (-e "$PWD/= $udev_root$config->{expected}") {=0A print "add: ok ";=0A } else {=0A = print "add: error\n";=0A system("tree $udev_root");=0A print "\n";=0A $e= rror++;=0A next;=0A }=0A=0A udev("remove", $config->{subsys}, $config->{de= vpath}, \$config->{conf});=0A if (-e "$PWD/$udev_root$config->{expected}") = {=0A print "remove: error\n\n";=0A system("tree $udev_root");=0A $error+= +;=0A } else {=0A print "remove: ok\n\n";=0A }=0A}=0A=0Aprint "$error erro= rs occured\n\n";=0A=0A# cleanup=0Asystem("rm -rf $udev_root");=0Aunlink($co= nf_tmp);=0Aunlink($udev_db);=0A=0A --T4sUOijqQbZv57TR-- ------------------------------------------------------- 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