linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Test script for udevd binary, Request for Comments!
@ 2004-04-07 10:53 Yin, Hu
  2004-04-08 14:16 ` Kay Sievers
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: Yin, Hu @ 2004-04-07 10:53 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Hi, All,

I have written a test script for udevd binary. As you know there have been some good test scripts for udev binary but we didn't write the corresponding test scripts for the new udev's binaries since udev is split into several binary program. Moreover, I think the work is necessary, especially for udevd and udevsend binaries.

Now I focus on the validation of udev as a Intel's intern student, so wrote this test script for udevd and send it to all. I know this script is not very good and enough for udevd's test but I believe we can do better with the help from all of you. So please just take a look at this script and give me some advises and suggestions in order that we can improve it together.

Thank you in advance!

Best Regards,
 
Yin Hu ( Nick )

The content of this email message solely contains my own personal views,
and not those of my employer.

[-- Attachment #2: udevd-test.pl --]
[-- Type: application/octet-stream, Size: 11850 bytes --]

#!/usr/bin/perl
#
# udevd-test
#
# Copyright (C) Intel Corp, 2004
#
# Author: Yin Hu <hu.yin@intel.com> 
#
# Provides automated testing of the udevd binary.
# This test will remove /udev directory so the contect of /udev directory will loss.
# Before you run this script please modify $sysfs to locate your sysfs filesystem, 
# modify $udev_bin to locate your udevsend binary,
# and modify $time_out to decide the time out for events first.
#
# 
#	This program is free software; you can redistribute it and/or modify it
# 	under the terms of the GNU General Public License as published by the
# 	Free Software Foundation version 2 of the License.
#  
# 	This program is distributed in the hope that it will be useful, but
# 	WITHOUT ANY WARRANTY; without even the implied warranty of
# 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# 	General Public License for more details.
#  
#	You should have received a copy of the GNU General Public License along
# 	with this program; if not, write to the Free Software Foundation, Inc.,
# 	675 Mass Ave, Cambridge, MA 02139, USA.
#

use warnings;
use strict;

# modifiable settings
my $sysfs     = "/sys";
my $udev_bin  = "/sbin/udevsend";
my $udev_root = "/udev/";
my $time_out  = 5;

# global variables
my $new_process_num = 0;
my $old_process_num = 0;
my $test_case = 0;

# common functions
sub udevsend {
	my ($seqnum, $devpath, $action, $subsystem) = @_;

        $ENV{DEVPATH} = $devpath;
        $ENV{ACTION} = $action;
	if ( $seqnum != -1) {
        	$ENV{SEQNUM} = $seqnum;
	}
        return system("$udev_bin $subsystem");
}

sub get_udev_dev_count {
	my $count;

	system("rm -f output");
	system("ls -l $udev_root|wc -l > output");
	open(OF, "output");
	$count = <OF>;
	close(OF);
	return $count;
}

sub get_process_num {
	my $num;

	system("ps -ef|grep udev|wc -l > output");
	open(OF, "output");
	$num = <OF>;
	close(OF);
	return $num;
}

sub check_sysfs_device_exist {
	my @dev_list = @_;
	my $dev;

	# check if the designated devices exist
	foreach $dev (@dev_list) {
		if (! -e $dev) {
			print "the designated device $dev doesn't exist. please change a device!\n";
			exit 1;
		}
	}
}

sub check_udev_instance { 
	$old_process_num = $new_process_num;
	$new_process_num = get_process_num();
	if ( ($old_process_num != 0) && ($new_process_num != $old_process_num) ) {
		print "test failed. there are more than one udev instances running for a single device at the same time\n";
		exit 1;
	}
}

sub show_result {
	my $i;

	for ($i=1; $i<=$time_out+1; $i++) {
        	sleep 1;
        	print "\n$i second passing...\n";
        	system("ls $udev_root");
	}
}

# test cases functions
sub run_no_seq_test {
	print "udevd-test is running no sequence number test case,\n";
	print "the expected result is: \n";
	print "   Device /udev/hda is created at once, \n";
	print "   and then the device is removed \n\n";

	system("killall udevd");
	system("rm -rf $udev_root/*");
	# check if device /sys/block/hda exist
	system("ls $sysfs/block/hda > /dev/null 2>&1");
	if ( $? == 0 ) {
        	udevsend(-1, "/block/hda", "add", "block");

        	# check if execution is successful in time, that is, if device /udev/hda has been created at once
		sleep 1;
               	system("ls -lrt $udev_root/hda > /dev/null 2>&1");
	        if ($? == 0) {
			print "   device /udev/udev has been created successfully.\n";
        		udevsend(-1, "/block/hda", "remove", "block");
                        if ($? == 0) {
        	                # check if device /udev/hda has been removed at once
				sleep 1;
               			system("ls -lrt $udev_root/hda > /dev/null 2>&1");
               			if ($? == 0) {
                			# remove failed
					print "remove: error\n\n";
				} else {
					print "   device /udev/udev has been removed successfully.\n";
					print "this case is ok\n\n";
                        	}
			} else {
				print "remove: failed\n\n";
			}
      		} else {
			print "add: error\n\n";
		}
	}
}

sub run_normal_seq_test {
	print "udevd-test is running normal sequence number test case,\n";
	print "the expected result is: \n";
	print "   We can see all the deviceis in $sysfs/block are populated into $udev_root directory,\n";
	print "   and then we can see all the devices are removed.\n\n";

	system("killall udevd");
	system("rm -rf $udev_root/*");

	my @file_list;
	my $file;
	my $seq=1;

	@file_list = glob "$sysfs/block/*"; 

	# add devices
	foreach $file (@file_list) {
        	udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "add", "block");
                # check if execution is successful
                if ($? == 0) {
                        $seq++;
                } else {
                        print "add: error\n\n";
                        exit 1;
                }
        }
	
	# we'd better wait the udev to create all the device for a few seconds
	print "   waiting for udev creating devices...\n";
	sleep 6;

	if ( $seq != get_udev_dev_count()) {
		print "   add: failed. some device fail to create.\n\n";
		exit 1;
	} else {
		print "   $seq pieces of devices have been added.\n";
	}

        # remove devices
	system("killall udevd");
	@file_list = glob "$sysfs/block/*"; 
	$seq = 1;
        foreach $file (@file_list) {
        	udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "remove", "block");
                # check if execution is successful
                if ($? == 0) {
                        $seq++;
                } else {
                        print "remove: error\n\n";
                        exit 1;
                }
        }
	print "   waiting for udev removing devices...\n";
	sleep 6;
	if (get_udev_dev_count() > 1) {
		print "   remove: failed. some device fail to remove.\n\n";
		exit 1;
	} else {
		print "   $seq pieces of devices have been removed.\n";
		print "this case is ok.\n\n";
	}
}

sub run_random_seq_test {
	print "udevd-test is running random sequence number test case,\n";
	print "the expected result is:\n";
	print "   Within 5 seconds there should be no device to been created,\n";
	print "   after 5 seconds device sda should be created first, then the loop1 and loop2,\n";
	print "   removing devices is the same as above.\n\n";

	# check if devices /sys/block/hda, loop1, loop2 exist
	check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");

	# add devices
	print "add devices: \n";
	system("killall udevd");
	# parameters: 1 sequence number, 2 device, 3 action, 4 subsystem
        udevsend(3, "/block/loop2", "add", "block");
        udevsend(1, "/block/hda", "add", "block");
        udevsend(2, "/block/loop1", "add", "block");
	show_result();

	# remove devices
	system("killall udevd");
	print "\nremove devices: \n";
        udevsend(5, "/block/hda", "remove", "block");
        udevsend(4, "/block/loop1", "remove", "block");
        udevsend(6, "/block/loop2", "remove", "block");
	show_result();
	print "this case is ok.\n\n";
}

sub run_expected_seq_test {
        print "udevd-test is running random sequence number test case,\n";
        print "the expected result is:\n";
        print "   We can see a device loop2 has been added first,\n";
        print "   and then loop2 was removed\n\n";

        # check if devices /sys/block/hda, loop1, loop2 exist
	check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");

        system("killall udevd");
        # parameters: 1 sequence number, 2 device, 3 action, 4 subsystem
        udevsend(3, "/block/loop2", "add", "block");
        udevsend(1, "/block/hda", "add", "block");
        udevsend(2, "/block/loop1", "add", "block");
	print "   udevd is polling the events, please wait...\n\n";
	sleep 5;
        udevsend(4, "/block/hda", "remove", "block");
        udevsend(5, "/block/loop1", "remove", "block");
        udevsend(6, "/block/loop2", "remove", "block");
	sleep 1;
        # system("ls -lrt $udev_root");
	print "   add device loop2 at once\n";
        if ( udevsend(7, "/block/loop2", "add", "block") == 0 ) {
		# we'd better wait udev program to add the device loop2 for a little while
		sleep 1;
        	system("ls -lrt $udev_root");
	}
	print "\n   remove device loop2 at once\n";
        if ( udevsend(8, "/block/loop2", "remove", "block") == 0 ) {
		# we'd better wait udev program to remove the device loop2 for a little while
		sleep 1;
        	system("ls -lrt $udev_root");
	}
        print "this case is ok.\n\n";
}

sub run_single_instance_test { 
	print "udevd-test is running single instance running for a single device test case,\n";
	print "the expected result is: \n";
	print "   For each event a udev instance is executed in the background. All\n";
	print "   further events for the same device are delayed until the execution is\n";
	print "   finished. This way there will never be more than one instance running\n";
	print "   for a single device at the same time.\n\n";

	system("killall udevd");
	system("rm -rf $udev_root/*");
	$new_process_num = 0;

	# check if device /sys/block/hda exists
	check_sysfs_device_exist("$sysfs/block/hda");

        udevsend(-1, "/block/hda", "add", "block");
	# we'd better wait for udevd to startup for a second
	sleep 1;
	check_udev_instance();
        udevsend(-1, "/block/hda", "remove", "block");
	check_udev_instance();
        udevsend(-1, "/block/hda", "add", "block");
	check_udev_instance();
        udevsend(-1, "/block/hda", "remove", "block");
	check_udev_instance();
	print "this case is ok\n\n";
}

sub run_same_events_test { 
	print "udevd-test is running event sequence number overlap test case,\n";
	print "the expected result is: \n";
	print "   Udev can execute properly. \n\n";

        system("killall udevd");
        system("rm -rf $udev_root/*");

        # check if device /sys/block/hda exist
	check_sysfs_device_exist("$sysfs/block/hda");

        udevsend(1, "/block/hda", "add", "block");
        udevsend(1, "/block/hda", "remove", "block");
        udevsend(1, "/block/hda", "add", "block");
        udevsend(1, "/block/hda", "remove", "block");
        print "this case is ok\n\n";
}

sub run_all_cases_test { 
	run_no_seq_test();
	run_normal_seq_test();
	run_random_seq_test();
	run_expected_seq_test();
	run_same_events_test();
	run_single_instance_test();
}

# prepare
system("rm -rf $udev_root");
mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";

# main program
if ($ARGV[0]) {
	$test_case = $ARGV[0];

        if ($test_case == 1) {
		run_no_seq_test();
        } elsif ($test_case == 2) {
		run_normal_seq_test();
        } elsif ($test_case == 3) {
		run_random_seq_test();
        } elsif ($test_case == 4) {
		run_expected_seq_test();
        } elsif ($test_case == 5) {
		run_single_instance_test();
	} elsif ($test_case == 6) {
		run_same_events_test();
        } else {
		run_all_cases_test();
        }
} else {
	# echo usage
	print "command format: perl udevd-test.pl <case number>\n";
	print "   test case:\n";
	print "           1: no event sequence number\n";
	print "           2: sequential event sequence number\n";
	print "           3: random event sequence number\n";
	print "           4: the incoming event sequence number is right the expected sequence number\n";
	print "           5: single udev instance on a single device at the same time\n";
	print "           6: test event sequence number overlap\n";
	print "           9: all the cases\n\n";
}

# cleanup
system("rm -f output");

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2004-04-15  1:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
2004-04-08 14:16 ` Kay Sievers
2004-04-08 16:22 ` Sabharwal, Atul
2004-04-08 20:49 ` Kay Sievers
2004-04-09 10:45 ` Nick Yin
2004-04-09 20:52 ` Kay Sievers
2004-04-10  4:39 ` Nick Yin
2004-04-10 14:04 ` Kay Sievers
2004-04-10 14:48 ` Nick Yin
2004-04-13 10:34 ` Yin, Hu
2004-04-13 13:25 ` Kay Sievers
2004-04-13 13:51 ` Nick Yin
2004-04-14  3:11 ` Yin, Hu
2004-04-14 12:18 ` Kay Sievers
2004-04-14 15:24 ` Nick Yin
2004-04-14 15:33 ` Kay Sievers
2004-04-15  1:03 ` Yin, Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).