* 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
* Re: Test script for udevd binary, Request for Comments!
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
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-08 14:16 UTC (permalink / raw)
To: linux-hotplug
On Wed, Apr 07, 2004 at 06:53:21PM +0800, Yin, Hu wrote:
> 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.
The timout is 10 seconds now.
It is not acceptable for a test like this, to work on the "real" $udev_root.
It may render your system unusable!
I prefer a test for udevsend/udevd only, not calling the real udev. You may
change udevd to look on startup in the environment for the key UDEV_BIN and
take this value instead of the real udev. Then you replace the real udev by
a call to a small test program, which maybe writes a log file to be analyzed
by your test script.
This way you test the daemon only, not udev and udevd together and you are
able to check if the logic for holding back events for the same device and
execute different devices in parallel, works too.
And a second time: Two events with the same sequence number are not a
case we need to handle differently than a missing sequence number. A
test for it is nice, but a timeout is the expected behavior.
What do you think?
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: Test script for udevd binary, Request for Comments!
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
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Sabharwal, Atul @ 2004-04-08 16:22 UTC (permalink / raw)
To: linux-hotplug
Where is the timeout happening ?
--
Atul
-------------------------------------------------------------
P.S: All opinions are my personal opinion(s) & responsibility and do
not represent the view of my employer ( Intel Corporation ).
-----Original Message-----
From: linux-hotplug-devel-admin@lists.sourceforge.net
[mailto:linux-hotplug-devel-admin@lists.sourceforge.net] On Behalf Of
Kay Sievers
Sent: Thursday, April 08, 2004 7:16 AM
To: Yin, Hu
Cc: linux-hotplug-devel@lists.sourceforge.net; Fu, Michael; Guo, Min
Subject: Re: Test script for udevd binary, Request for Comments!
On Wed, Apr 07, 2004 at 06:53:21PM +0800, Yin, Hu wrote:
> 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.
The timout is 10 seconds now.
It is not acceptable for a test like this, to work on the "real"
$udev_root.
It may render your system unusable!
I prefer a test for udevsend/udevd only, not calling the real udev. You
may
change udevd to look on startup in the environment for the key UDEV_BIN
and
take this value instead of the real udev. Then you replace the real udev
by
a call to a small test program, which maybe writes a log file to be
analyzed
by your test script.
This way you test the daemon only, not udev and udevd together and you
are
able to check if the logic for holding back events for the same device
and
execute different devices in parallel, works too.
And a second time: Two events with the same sequence number are not a
case we need to handle differently than a missing sequence number. A
test for it is nice, but a timeout is the expected behavior.
What do you think?
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&opÌk
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
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
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-08 20:49 UTC (permalink / raw)
To: linux-hotplug
On Thu, Apr 08, 2004 at 09:22:25AM -0700, Sabharwal, Atul wrote:
> Where is the timeout happening ?
The timeout happens if a sequence number is missing and udevd will
wait for the missing events until the timout happens and we skip the
missing sequences, you may look at 'man udevd' for a short description.
Kay
> On Wed, Apr 07, 2004 at 06:53:21PM +0800, Yin, Hu wrote:
> > 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.
>
> The timout is 10 seconds now.
>
> It is not acceptable for a test like this, to work on the "real"
> $udev_root.
> It may render your system unusable!
>
> I prefer a test for udevsend/udevd only, not calling the real udev. You
> may
> change udevd to look on startup in the environment for the key UDEV_BIN
> and
> take this value instead of the real udev. Then you replace the real udev
> by
> a call to a small test program, which maybe writes a log file to be
> analyzed
> by your test script.
> This way you test the daemon only, not udev and udevd together and you
> are
> able to check if the logic for holding back events for the same device
> and
> execute different devices in parallel, works too.
>
> And a second time: Two events with the same sequence number are not a
> case we need to handle differently than a missing sequence number. A
> test for it is nice, but a timeout is the expected behavior.
>
> What do you think?
>
> thanks,
> Kay
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
> _______________________________________________
> 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
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
> _______________________________________________
> 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
>
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&opÌk
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (2 preceding siblings ...)
2004-04-08 20:49 ` Kay Sievers
@ 2004-04-09 10:45 ` Nick Yin
2004-04-09 20:52 ` Kay Sievers
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Nick Yin @ 2004-04-09 10:45 UTC (permalink / raw)
To: linux-hotplug
Kay,
Thank you very much for giving me so much suggestion. I will modify this
test script following your suggestion. :-)
BTW, now i'm on campus, not in Intel's office, so i just can reply you by
this email account.
Have a nice weekend!
Best Regards,
Yin Hu ( Nick )
>From: Kay Sievers <kay.sievers@vrfy.org>
>To: "Sabharwal, Atul" <atul.sabharwal@intel.com>
>CC: "Yin, Hu"
><hu.yin@intel.com>,linux-hotplug-devel@lists.sourceforge.net,"Fu, Michael"
><michael.fu@intel.com>, "Guo, Min" <min.guo@intel.com>
>Subject: Re: Test script for udevd binary, Request for Comments!
>Date: Thu, 8 Apr 2004 22:49:34 +0200
>
>On Thu, Apr 08, 2004 at 09:22:25AM -0700, Sabharwal, Atul wrote:
> > Where is the timeout happening ?
>
>The timeout happens if a sequence number is missing and udevd will
>wait for the missing events until the timout happens and we skip the
>missing sequences, you may look at 'man udevd' for a short description.
>
>Kay
>
> > On Wed, Apr 07, 2004 at 06:53:21PM +0800, Yin, Hu wrote:
> > > 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.
> >
> > The timout is 10 seconds now.
> >
> > It is not acceptable for a test like this, to work on the "real"
> > $udev_root.
> > It may render your system unusable!
> >
> > I prefer a test for udevsend/udevd only, not calling the real udev. You
> > may
> > change udevd to look on startup in the environment for the key UDEV_BIN
> > and
> > take this value instead of the real udev. Then you replace the real udev
> > by
> > a call to a small test program, which maybe writes a log file to be
> > analyzed
> > by your test script.
> > This way you test the daemon only, not udev and udevd together and you
> > are
> > able to check if the logic for holding back events for the same device
> > and
> > execute different devices in parallel, works too.
> >
> > And a second time: Two events with the same sequence number are not a
> > case we need to handle differently than a missing sequence number. A
> > test for it is nice, but a timeout is the expected behavior.
> >
> > What do you think?
> >
> > thanks,
> > Kay
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
> > _______________________________________________
> > 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
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
> > _______________________________________________
> > 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
> >
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: IBM Linux Tutorials
>Free Linux tutorial presented by Daniel Robbins, President and CEO of
>GenToo technologies. Learn everything from fundamentals to system
>administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
>_______________________________________________
>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
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?pageþatures/junkmail
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (3 preceding siblings ...)
2004-04-09 10:45 ` Nick Yin
@ 2004-04-09 20:52 ` Kay Sievers
2004-04-10 4:39 ` Nick Yin
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-09 20:52 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 438 bytes --]
On Fri, Apr 09, 2004 at 10:45:40AM +0000, Nick Yin wrote:
> Kay,
>
> Thank you very much for giving me so much suggestion. I will modify this
> test script following your suggestion. :-)
Nick,
here is the needed change for udevd. You can start udevd in your test
script with a specified UDEV_BIN in the environment. If we get a nice
udevd test script, we can merge the change in the main tree along with
your script :)
good luck,
Kay
[-- Attachment #2: 01-udev_bin-override.patch --]
[-- Type: text/plain, Size: 1092 bytes --]
===== udevd.c 1.30 vs edited =====
--- 1.30/udevd.c Fri Apr 2 22:48:21 2004
+++ edited/udevd.c Fri Apr 9 22:12:22 2004
@@ -60,6 +60,7 @@
static void msg_queue_manager(void);
static void user_sighandler(void);
static void reap_kids(void);
+char *udev_bin;
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
@@ -146,7 +147,7 @@
switch (pid) {
case 0:
/* child */
- execle(UDEV_BIN, "udev", msg->subsystem, NULL, env);
+ execle(udev_bin, "udev", msg->subsystem, NULL, env);
dbg("exec of child failed");
exit(1);
break;
@@ -399,6 +400,7 @@
const int on = 1;
struct sigaction act;
fd_set readfds;
+ char *s;
init_logging("udevd");
dbg("version %s", UDEV_VERSION);
@@ -457,6 +459,15 @@
/* enable receiving of the sender credentials */
setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
+
+ /* possible override of udev binary, used for testing */
+ s = getenv("UDEV_BIN");
+ if (s != NULL) {
+ udev_bin = s;
+ dbg("udev binary is set to '%s'", udev_bin);
+ } else {
+ udev_bin = UDEV_BIN;
+ }
FD_ZERO(&readfds);
FD_SET(ssock, &readfds);
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (4 preceding siblings ...)
2004-04-09 20:52 ` Kay Sievers
@ 2004-04-10 4:39 ` Nick Yin
2004-04-10 14:04 ` Kay Sievers
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Nick Yin @ 2004-04-10 4:39 UTC (permalink / raw)
To: linux-hotplug
Kay,
I understand your idea. Thank you for changing udevd program to meet the
test. I intend to write a small udevd test program called udevdtest.c to log
what event udevd has sent and modify that test script to analyze the log
file output by udevdtest in order to judge whether udevd has executed as we
expected. How do you think of this? If you think it's feasible I will do
this as soon as possible.
Have a nice weekend!
Nick ( Yin Hu)
>From: Kay Sievers <kay.sievers@vrfy.org>
>To: Nick Yin <nickyin@hotmail.com>
>CC: atul.sabharwal@intel.com,
>hu.yin@intel.com,linux-hotplug-devel@lists.sourceforge.net,
>michael.fu@intel.com,min.guo@intel.com
>Subject: Re: Test script for udevd binary, Request for Comments!
>Date: Fri, 9 Apr 2004 22:52:24 +0200
>
>On Fri, Apr 09, 2004 at 10:45:40AM +0000, Nick Yin wrote:
> > Kay,
> >
> > Thank you very much for giving me so much suggestion. I will modify this
> > test script following your suggestion. :-)
>
>Nick,
>here is the needed change for udevd. You can start udevd in your test
>script with a specified UDEV_BIN in the environment. If we get a nice
>udevd test script, we can merge the change in the main tree along with
>your script :)
>
>good luck,
>Kay
>=== udevd.c 1.30 vs edited ==>--- 1.30/udevd.c Fri Apr 2 22:48:21 2004
>+++ edited/udevd.c Fri Apr 9 22:12:22 2004
>@@ -60,6 +60,7 @@
> static void msg_queue_manager(void);
> static void user_sighandler(void);
> static void reap_kids(void);
>+char *udev_bin;
>
> #ifdef LOG
> unsigned char logname[LOGNAME_SIZE];
>@@ -146,7 +147,7 @@
> switch (pid) {
> case 0:
> /* child */
>- execle(UDEV_BIN, "udev", msg->subsystem, NULL, env);
>+ execle(udev_bin, "udev", msg->subsystem, NULL, env);
> dbg("exec of child failed");
> exit(1);
> break;
>@@ -399,6 +400,7 @@
> const int on = 1;
> struct sigaction act;
> fd_set readfds;
>+ char *s;
>
> init_logging("udevd");
> dbg("version %s", UDEV_VERSION);
>@@ -457,6 +459,15 @@
>
> /* enable receiving of the sender credentials */
> setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
>+
>+ /* possible override of udev binary, used for testing */
>+ s = getenv("UDEV_BIN");
>+ if (s != NULL) {
>+ udev_bin = s;
>+ dbg("udev binary is set to '%s'", udev_bin);
>+ } else {
>+ udev_bin = UDEV_BIN;
>+ }
>
> FD_ZERO(&readfds);
> FD_SET(ssock, &readfds);
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?pageþatures/junkmail
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (5 preceding siblings ...)
2004-04-10 4:39 ` Nick Yin
@ 2004-04-10 14:04 ` Kay Sievers
2004-04-10 14:48 ` Nick Yin
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-10 14:04 UTC (permalink / raw)
To: linux-hotplug
On Sat, Apr 10, 2004 at 04:39:29AM +0000, Nick Yin wrote:
> I intend to write a small udevd test program called udevdtest.c to
> log what event udevd has sent and modify that test script to analyze the
> log file output by udevdtest in order to judge whether udevd has executed
> as we expected. How do you think of this? If you think it's feasible I will
> do this as soon as possible.
A simple shell script or perl will also be executed by udevd.
So you don't need to compile anything.
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (6 preceding siblings ...)
2004-04-10 14:04 ` Kay Sievers
@ 2004-04-10 14:48 ` Nick Yin
2004-04-13 10:34 ` Yin, Hu
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Nick Yin @ 2004-04-10 14:48 UTC (permalink / raw)
To: linux-hotplug
Kay,
I got it. I will do it ASAP.
Thanks!
Nick
>From: Kay Sievers <kay.sievers@vrfy.org>
>To: Nick Yin <nickyin@hotmail.com>
>CC: atul.sabharwal@intel.com,
>hu.yin@intel.com,linux-hotplug-devel@lists.sourceforge.net,
>michael.fu@intel.com,min.guo@intel.com
>Subject: Re: Test script for udevd binary, Request for Comments!
>Date: Sat, 10 Apr 2004 16:04:55 +0200
>
>On Sat, Apr 10, 2004 at 04:39:29AM +0000, Nick Yin wrote:
> > I intend to write a small udevd test program called udevdtest.c to
> > log what event udevd has sent and modify that test script to analyze the
> > log file output by udevdtest in order to judge whether udevd has
>executed
> > as we expected. How do you think of this? If you think it's feasible I
>will
> > do this as soon as possible.
>
>A simple shell script or perl will also be executed by udevd.
>So you don't need to compile anything.
>
>Kay
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: IBM Linux Tutorials
>Free Linux tutorial presented by Daniel Robbins, President and CEO of
>GenToo technologies. Learn everything from fundamentals to system
>administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
>_______________________________________________
>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
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?pageþatures/virus
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (7 preceding siblings ...)
2004-04-10 14:48 ` Nick Yin
@ 2004-04-13 10:34 ` Yin, Hu
2004-04-13 13:25 ` Kay Sievers
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Yin, Hu @ 2004-04-13 10:34 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]
Kay,
I have written three scripts, that is, udevd-test.pl,
udev-log-script.pl, udev-log-amplify.pl. where udevd-test.pl is main
test script, udev-log-script.pl is a replace for udev binary for general
test case, udev-log-amplify.pl is another replace for udev binary for
"only one udev instance for a single device at the same time" test case,
which amplifies the execution time (sleep 5) in order for convenience of
test.
Would you like to help me check them? Thank you very much!
Of course any suggestion from anybody is also welcome.
I will improve them according to your suggestion. Thanks!
Nick
-----Original Message-----
From: Kay Sievers [mailto:kay.sievers@vrfy.org]
Sent: Saturday, April 10, 2004 4:52 AM
To: Nick Yin
Cc: Sabharwal, Atul; Yin, Hu; linux-hotplug-devel@lists.sourceforge.net;
Fu, Michael; Guo, Min
Subject: Re: Test script for udevd binary, Request for Comments!
On Fri, Apr 09, 2004 at 10:45:40AM +0000, Nick Yin wrote:
> Kay,
>
> Thank you very much for giving me so much suggestion. I will modify
this
> test script following your suggestion. :-)
Nick,
here is the needed change for udevd. You can start udevd in your test
script with a specified UDEV_BIN in the environment. If we get a nice
udevd test script, we can merge the change in the main tree along with
your script :)
good luck,
Kay
[-- Attachment #2: udev-log-amplify.pl --]
[-- Type: application/octet-stream, Size: 2352 bytes --]
#!/usr/bin/perl -w
#
# udev-log-amplify
#
# Copyright (C) Intel Corp, 2004
#
# Author: Yin Hu <hu.yin@intel.com>
#
# This is a script for replacing udev binary during udevsend/udevd testing.
# It first amplifies the execution time ( sleep 5 ) and then logs the event
# information sent by udved in order that test script udevd-test.pl can
# analyze whether udved execute as we expected.
# You should not execute this script directly because it will be invoked by
# udevd automatically.
#
# Before you run your test please modify $log_file to designate where the udev
# log file should be placed, in fact, the default value is ok.
#
#
# 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 $udev_exe_time = 5;
my $log_file = "/var/log/udev_log.txt";
# global variables
my $devpath;
my $action;
my $subsystem;
# common functions
sub getDate {
# Get current date/time
# If we want GTM time, simply pass GMT as first argument to this function.
my $format = @_;
my $date;
if( $format =~ /GMT/i ) {
$date = gmtime() . " GMT";
} else {
$date = localtime();
}
return $date;
}
# main program
if ($ARGV[0]) {
$subsystem = $ARGV[0];
$devpath = $ENV{DEVPATH};
$action = $ENV{ACTION};
# Get current system date
my $time = getDate();
# Logging
if (open(LOGF, ">>$log_file")) {
print LOGF "$devpath,$action,$subsystem,$time\n";
} else {
print "File open failed. \n";
exit 1;
}
close(LOGF);
# Amplify the execution time of udev
sleep 5;
exit 0;
} else {
print "Too less argument count.\n";
exit 1;
}
[-- Attachment #3: udevd-test.pl --]
[-- Type: application/octet-stream, Size: 21480 bytes --]
#!/usr/bin/perl -w
#
# udevd-test
#
# Copyright (C) Intel Corp, 2004
#
# Author: Yin Hu <hu.yin@intel.com>
#
# Provides automated testing of the udevd binary.This test script is self-contained.
# Before you run this script please modify $sysfs to locate your sysfs filesystem,
# modify $udevd_bin to locate your udevsend binary,
# modify $udev_bin to locate dummy udev script,
# modify $udev_bin2 to locate another dummy udev script ( amplify the execution time for test),
# modify $log_file to locate where udev script have placed the log file,
# modify $time_out to decide the time out for events,
# modify $udev_exe_time to decide the execution time for dummy udev script.
#
# Detail information of each test case please refer to the header of corresponding
# test case function.
#
#
# 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 $udevd_bin = "../udevsend";
my $udev_bin = "$ENV{PWD}/udev-log-script.pl";
my $udev_bin2 = "$ENV{PWD}/udev-log-amplify.pl";
my $log_file = "/var/log/udev_log.txt";
my $time_out = 10;
my $udev_exe_time = 5;
# global variables
my $test_case = 0;
# common functions
sub udevsend {
# This function prepares corresponding environment variables
# and then call $udevd_bin to send event.
my ($seqnum, $devpath, $action, $subsystem, $udev_bin_tmp) = @_;
$ENV{DEVPATH} = $devpath;
$ENV{ACTION} = $action;
$udev_bin_tmp = $udev_bin if ( not $udev_bin_tmp );
$ENV{UDEV_BIN} = $udev_bin_tmp;
if ( $seqnum != -1) {
$ENV{SEQNUM} = $seqnum;
}
return system("$udevd_bin $subsystem");
}
sub getDate {
# Get current date function
# If we want GTM time, simply pass GMT as first argument to this function.
my $format = @_;
my $date;
if( $format =~ /GMT/i ) {
$date = gmtime() . " GMT";
} else {
$date = localtime();
}
return $date;
}
sub cmpDate {
# This function should return a difference betweent date1 and date2
my ($date1, $date2) = @_;
my @monList = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec" );
my ( $m1, $m2, $tmp );
$date1 =~ s/([\D]*)$//g;
$date2 =~ s/([\D]*)$//g;
return if( (not $date1) or (not $date2) );
my $mon = 0;
my ( @T1 ) =
( $date1 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
my ( @T2 ) =
( $date2 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
foreach $tmp (@monList) {
$m1 = sprintf("%2.2d",$mon) if( $date1 =~ /$tmp/i );
$m2 = sprintf("%2.2d",$mon) if( $date2 =~ /$tmp/i );
$mon++;
}
my $dt1 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T1[4], $m1, $T1[0],
$T1[1], $T1[2], $T1[3]);
my $dt2 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T2[4], $m2, $T2[0],
$T2[1], $T2[2], $T2[3]);
my $ret = $dt1 - $dt2;
if ( $ret > 40 ) {
$ret = abs($ret-40);
}
return $ret;
}
sub check_count_and_time {
my $event_recv_time;
my $udev_fork_time;
my $log_ln_count = 0;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
if ( $diff > $time_out ) {
print " the delay time is: $diff \n";
print " udevd doesn't act properly. \n";
exit 1;
}
$log_ln_count++;
}
close(LOGF);
return $log_ln_count;
}
sub check_sysfs_device_exist {
# check if the designated devices exist
my @dev_list = @_;
my $dev;
foreach $dev (@dev_list) {
if (! -e $dev) {
print "the designated device $dev doesn't exist. please change a device!\n";
exit 1;
}
}
}
sub show_result {
my $event_recv_time;
my $udev_fork_time;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
}
close(LOGF);
}
sub show_result_tm_out {
my $event_recv_time;
my $udev_fork_time;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
if ( $diff < $time_out ) {
print " the delay time is: $diff \n";
print " udevd doesn't act properly. \n";
exit 1;
}
}
close(LOGF);
}
sub show_result_immediate {
my $event_recv_time;
my $udev_fork_time;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
if ( $diff > $time_out ) {
print " the delay time is: $diff \n";
print " udevd doesn't act properly. \n";
exit 1;
}
}
close(LOGF);
}
sub check_exe_time {
my @exe_time;
my $i = 0;
my $line;
my @content;
my @line_items;
my $diff;
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
close(LOGF);
foreach $line ( @content ) {
@line_items = split(/,/,$line);
$exe_time[$i] = $line_items[-1];
$i++;
}
$diff = cmpDate($exe_time[1], $exe_time[0]);
if ( $diff < $udev_exe_time ) {
print " there are more than one udev instance for a single device at the same time. \n";
exit 1;
} else {
print " there is just one udev instance for a single device at the same time. \n";
}
}
# test case functions
sub run_no_seq_test {
print "Test case name: no sequence number test\n";
print "Test case purpose: check whether udevd forks udev immediately when environment variable SEQNUM is null.\n";
print "Test expected visible results: \n";
print " the delay time between event receiving and forking udev for udevd should be negligible, \n";
print " that is, udev should be forked at once. please notice the following time...\n\n";
# local variables
my $time;
#
# add devices event test
#
system("killall udevd");
system("rm -rf $log_file");
# check if devices /sys/block/hda, loop1, loop2 exist
check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
# log current system date/time
$time = getDate();
# fork udevd
udevsend(-1, "/block/hda", "add", "block");
# check if execution is successful in time
sleep 1;
show_result_immediate($time);
print " fork udev (add device) at once successfully.\n\n";
#
# remove devices event test
#
system("rm -rf $log_file");
# log current system date/time
$time = getDate();
# fork udevd
udevsend(-1, "/block/hda", "remove", "block");
# check if execution is successful in time
sleep 1;
show_result_immediate($time);
print " fork udev (remove device) at once successfully.\n\n";
print "this case is ok\n\n";
}
sub run_normal_seq_test {
print "Test case name: normal sequence number stress test\n";
print "Test case purpose: check whether udevd can fork massive udev instances for \n";
print " massive sequential events successfully. \n";
print "Test expected visible results: \n";
print " Populate all the devices in directory $sysfs/block, fork udved to send add/remove \n";
print " event to udev for each device. \n";
print " We can see the delay time for each device should be negligible. \n\n";
# local variables
my @file_list;
my $file;
my $seq=0;
my $time;
my $ret_seq;
# prepare
system("killall udevd");
system("rm -rf $log_file");
@file_list = glob "$sysfs/block/*";
# log current system date/time for device add events
$time = getDate();
#
# add devices event test
#
print "add device events test: \n";
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 event: error\n\n";
exit 1;
}
}
# we'd better wait the udev to create all the device for a few seconds
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out;
$ret_seq = check_count_and_time($time);
if ( $ret_seq != $seq ) {
print " add event: failed. some device-adding events fail to execute.\n\n";
exit 1;
} else {
print " $seq pieces of device-adding events have executed successfully.\n\n";
}
# log current system date/time for device remove events
$time = getDate();
#
# remove devices event test
#
print "remove device events test: \n";
system("killall udevd");
system("rm -rf $log_file");
@file_list = glob "$sysfs/block/*";
$seq = 0;
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 event: error\n\n";
exit 1;
}
}
# we'd better wait the udev to create all the device for a few seconds
print " waiting for udev removing devices (about $time_out s)...\n";
sleep $time_out;
# show results
$ret_seq = check_count_and_time($time);
if ( $ret_seq != $seq ) {
print " remove event: failed. some device-removing events fail to execute.\n\n";
exit 1;
} else {
print " $seq pieces of device-removing events have executed successfully.\n\n";
print "this case is ok.\n\n";
}
}
sub run_random_seq_test {
print "Test case name: random sequence number test case,\n";
print "Test case purpose: check whether udevd can order the events with random sequence number \n";
print " and fork udev correctly. \n";
print "Test expected visible results: \n";
print " We have disordered the events sent to udevd, if udevd can order them correctly, the devices' \n";
print " add/remove sequence should be hda, loop1, loop2. \n\n";
# local variables
my $time;
# check if devices /sys/block/hda, loop1, loop2 exist
check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
#
# add device events test
#
print "add device events test: \n";
system("killall udevd");
system("rm -rf $log_file");
# log current system date/time for device remove events
$time = getDate();
# 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 " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result_tm_out($time);
#
# remove device events test
#
system("killall udevd");
print "\nremove device events test: \n";
system("rm -rf $log_file");
# log current system date/time for device remove events
$time = getDate();
# fork udevd
udevsend(3, "/block/loop2", "remove", "block");
udevsend(2, "/block/loop1", "remove", "block");
udevsend(1, "/block/hda", "remove", "block");
# show results
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result_tm_out($time);
print "this case is ok.\n\n";
}
sub run_expected_seq_test {
print "Test case name: expected sequence number test \n";
print "Test case purpose: check whether udevd fork udev immediately when the incoming event\n";
print " is exactly the expected event sequence number.\n";
print "Test expected visible results:\n";
print " first, udevd disposes disorder events(sequence number is 3,1,2,5,4,6),\n";
print " thus after disposed the expected event number for udevd is 7, when incoming event is 7, udevd\n";
print " should fork udev immediately, the delay time should be negligible. \n";
print " where: event 7 is (add device /block/loop2) \n\n";
# local variables
my $time;
# check if devices /sys/block/hda, loop1, loop2 exist
check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
# prepare
system("killall udevd");
system("rm -rf $log_file");
# 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");
udevsend(5, "/block/loop1", "remove", "block");
udevsend(4, "/block/hda", "remove", "block");
udevsend(6, "/block/loop2", "remove", "block");
print " wait for udevd timing out for disorder events (about $time_out s) \n\n";
sleep $time_out+1;
system("rm -rf $log_file");
# log current system date/time for device remove events
$time = getDate();
# show results
udevsend(7, "/block/loop2", "add", "block");
sleep 1;
print " event sequence number: 7 \n";
show_result_immediate($time);
print "this case is ok.\n\n";
}
sub run_single_instance_test {
print "Test case name: single instance running for a single device test \n";
print "Test case purpose: check whether udevd only fork one udev instance for a single\n";
print " device at the same time. For each event a udev instance is \n";
print " executed in the background. All further events for the same \n";
print " device are delayed until the execution is finished. This way \n";
print " there will never be more than one instance running for a single \n";
print " device at the same time.\n";
print "Test expected visible results:\n";
print " In this test we amplify the execution time of udev (about 5 seconds), first, \n";
print " we send a add event for device /block/hda, and then we send a remove event, so the \n";
print " execution of remove event should be delayed until add is finished. \n\n";
# local variables
my $time;
# prepare
system("killall udevd");
system("rm -rf $log_file");
# check if device exists
check_sysfs_device_exist("$sysfs/block/hda");
# log current system date/time
$time = getDate();
# fork udved
udevsend(-1, "/block/hda", "add", "block", $udev_bin2);
udevsend(-1, "/block/hda", "remove", "block", $udev_bin2);
# show results
print " wait for udevd processing about $udev_exe_time s... \n\n";
sleep $udev_exe_time+1;
show_result_immediate($time);
check_exe_time();
print "this case is ok\n\n";
}
sub run_same_events_test {
print "Test case name: event sequence number overlap test \n";
print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
print " when encountering a event with sequence number same as the pevious event. \n";
print "Test expected visible results:\n";
print " event ( add device /block/hda ) should be no delay, \n";
print " event ( add device /block/loop1 ) should be delayed for $time_out s than its previous \n";
print " event ( remove device /block/hda ) \n\n";
# local variables
my $time;
# prepare
system("killall udevd");
system("rm -rf $log_file");
# check if device exist
check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
# fork udevd
udevsend(0, "/block/hda", "add", "block");
# log current system date/time
sleep 1;
$time = getDate();
system("rm -rf $log_file");
# fork udevd
udevsend(1, "/block/hda", "remove", "block");
udevsend(1, "/block/loop1", "add", "block");
# show results
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result($time);
print "this case is ok\n\n";
}
sub run_missing_seq_test {
print "Test case name: missing sequence number test \n";
print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
print " when certain event sequence number is missing.\n";
print "Test expected visible results:\n";
print " the delay time for event(add device /block/hda) should be about $time_out s.\n\n";
# local variables
my $time;
# prepare
system("killall udevd");
system("rm -rf $log_file");
# check if device exist
check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
# fork udevd
udevsend(0, "/block/loop1", "add", "block");
udevsend(1, "/block/loop1", "remove", "block");
sleep 1;
# log current system date/time
$time = getDate();
system("rm -rf $log_file");
# fork udevd
udevsend(3, "/block/hda", "add", "block");
# show results
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result($time);
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_missing_seq_test();
run_expected_seq_test();
run_same_events_test();
run_single_instance_test();
}
# 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_missing_seq_test();
} elsif ($test_case == 5) {
run_expected_seq_test();
} elsif ($test_case == 6) {
run_single_instance_test();
} elsif ($test_case == 7) {
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: missing event sequence number\n";
print " 5: the incoming event sequence number is right the expected sequence number\n";
print " 6: single udev instance on a single device at the same time\n";
print " 7: test event sequence number overlap\n";
print " 9: all the cases\n\n";
}
[-- Attachment #4: udev-log-script.pl --]
[-- Type: application/octet-stream, Size: 2243 bytes --]
#!/usr/bin/perl -w
#
# udev-log-script
#
# Copyright (C) Intel Corp, 2004
#
# Author: Yin Hu <hu.yin@intel.com>
#
# This is a script for replacing udev binary during udevsend/udevd testing.
# It just simply logs the event information sent by udved in order to
# test script udevd-test.pl can analyze whether udved execute as we expected.
# You should not execute this script directly because it will be invoked by
# udevd automatically.
#
# Before you run your test please modify $log_file to designate where the udev
# log file should be placed, in fact, the default value is ok.
#
#
# 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 $log_file = "/var/log/udev_log.txt";
# global variables
my $devpath;
my $action;
my $subsystem;
# common functions
sub getDate {
# Get current date/time
# If we want GTM time, simply pass GMT as first argument to this function.
my $format = @_;
my $date;
if( $format =~ /GMT/i ) {
$date = gmtime() . " GMT";
} else {
$date = localtime();
}
return $date;
}
# main program
if ($ARGV[0]) {
# prepare
$subsystem = $ARGV[0];
$devpath = $ENV{DEVPATH};
$action = $ENV{ACTION};
# Get current system date
my $time = getDate();
# Logging
if (open(LOGF, ">>$log_file")) {
print LOGF "$devpath,$action,$subsystem,$time\n";
} else {
print "File open failed. \n";
exit 1;
}
close(LOGF);
exit 0;
} else {
print "Too less argument count.\n";
exit 1;
}
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (8 preceding siblings ...)
2004-04-13 10:34 ` Yin, Hu
@ 2004-04-13 13:25 ` Kay Sievers
2004-04-13 13:51 ` Nick Yin
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-13 13:25 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1350 bytes --]
On Tue, Apr 13, 2004 at 06:34:27PM +0800, Yin, Hu wrote:
> I have written three scripts, that is, udevd-test.pl,
> udev-log-script.pl, udev-log-amplify.pl. where udevd-test.pl is main
> test script, udev-log-script.pl is a replace for udev binary for general
> test case, udev-log-amplify.pl is another replace for udev binary for
> "only one udev instance for a single device at the same time" test case,
> which amplifies the execution time (sleep 5) in order for convenience of
> test.
>
> Would you like to help me check them? Thank you very much!
Looks promising. I've made it a big patch, also containing the udevd.c
change. Please send all future changes as a incremental patch on top of
this one, so we both can track the changes. I've changed a few things:
o placed the scripts in test/udevd-test/ subdir
o replaced 'rm -rf' by 'rm -f'
o place the logfile into /tmp/
o wait 1 second after killing the daemon, cause the kernel needs
to cleanup the old socket, otherwise the first two events sent for the
new daemon are lost on my machine
o unset SEQNUM in udevsend(), otherwise test #6 will fail by sending
the SEQNUM from test #5
o substituted spaces by tabs
Can we switch to our test/sys/ tree and use the files in there, instead of
the real /sys, cause some machines don't have /block/hda or /block/loop?
Kay
[-- Attachment #2: 99-udevd-test.patch --]
[-- Type: text/plain, Size: 25690 bytes --]
diff -Nru a/test/udevd-test/udev-log-amplify.pl b/test/udevd-test/udev-log-amplify.pl
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/test/udevd-test/udev-log-amplify.pl Tue Apr 13 15:21:43 2004
@@ -0,0 +1,87 @@
+#!/usr/bin/perl -w
+#
+# udev-log-amplify
+#
+# Copyright (C) Intel Corp, 2004
+#
+# Author: Yin Hu <hu.yin@intel.com>
+#
+# This is a script for replacing udev binary during udevsend/udevd testing.
+# It first amplifies the execution time ( sleep 5 ) and then logs the event
+# information sent by udved in order that test script udevd-test.pl can
+# analyze whether udved execute as we expected.
+# You should not execute this script directly because it will be invoked by
+# udevd automatically.
+#
+# Before you run your test please modify $log_file to designate where the udev
+# log file should be placed, in fact, the default value is ok.
+#
+#
+# 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 $udev_exe_time = 5;
+my $log_file = "/tmp/udev_log.txt";
+
+# global variables
+my $devpath;
+my $action;
+my $subsystem;
+
+# common functions
+sub getDate {
+ # Get current date/time
+ # If we want GTM time, simply pass GMT as first argument to this function.
+
+ my $format = @_;
+ my $date;
+
+ if( $format =~ /GMT/i ) {
+ $date = gmtime() . " GMT";
+ } else {
+ $date = localtime();
+ }
+ return $date;
+}
+
+# main program
+if ($ARGV[0]) {
+ $subsystem = $ARGV[0];
+ $devpath = $ENV{DEVPATH};
+ $action = $ENV{ACTION};
+
+ # Get current system date
+ my $time = getDate();
+
+ # Logging
+ if (open(LOGF, ">>$log_file")) {
+ print LOGF "$devpath,$action,$subsystem,$time\n";
+ } else {
+ print "File open failed. \n";
+ exit 1;
+ }
+ close(LOGF);
+
+ # Amplify the execution time of udev
+ sleep 5;
+
+ exit 0;
+} else {
+ print "Too less argument count.\n";
+ exit 1;
+}
diff -Nru a/test/udevd-test/udev-log-script.pl b/test/udevd-test/udev-log-script.pl
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/test/udevd-test/udev-log-script.pl Tue Apr 13 15:21:43 2004
@@ -0,0 +1,82 @@
+#!/usr/bin/perl -w
+#
+# udev-log-script
+#
+# Copyright (C) Intel Corp, 2004
+#
+# Author: Yin Hu <hu.yin@intel.com>
+#
+# This is a script for replacing udev binary during udevsend/udevd testing.
+# It just simply logs the event information sent by udved in order to
+# test script udevd-test.pl can analyze whether udved execute as we expected.
+# You should not execute this script directly because it will be invoked by
+# udevd automatically.
+#
+# Before you run your test please modify $log_file to designate where the udev
+# log file should be placed, in fact, the default value is ok.
+#
+#
+# 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 $log_file = "/tmp/udev_log.txt";
+
+# global variables
+my $devpath;
+my $action;
+my $subsystem;
+
+# common functions
+sub getDate {
+ # Get current date/time
+ # If we want GTM time, simply pass GMT as first argument to this function.
+ my $format = @_;
+ my $date;
+
+ if( $format =~ /GMT/i ) {
+ $date = gmtime() . " GMT";
+ } else {
+ $date = localtime();
+ }
+ return $date;
+}
+
+# main program
+if ($ARGV[0]) {
+ # prepare
+ $subsystem = $ARGV[0];
+ $devpath = $ENV{DEVPATH};
+ $action = $ENV{ACTION};
+
+ # Get current system date
+ my $time = getDate();
+
+ # Logging
+ if (open(LOGF, ">>$log_file")) {
+ print LOGF "$devpath,$action,$subsystem,$time\n";
+ } else {
+ print "File open failed. \n";
+ exit 1;
+ }
+ close(LOGF);
+
+ exit 0;
+} else {
+ print "Too less argument count.\n";
+ exit 1;
+}
diff -Nru a/test/udevd-test/udevd-test.pl b/test/udevd-test/udevd-test.pl
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/test/udevd-test/udevd-test.pl Tue Apr 13 15:21:43 2004
@@ -0,0 +1,668 @@
+#!/usr/bin/perl -w
+#
+# udevd-test
+#
+# Copyright (C) Intel Corp, 2004
+#
+# Author: Yin Hu <hu.yin@intel.com>
+#
+# Provides automated testing of the udevd binary.This test script is self-contained.
+# Before you run this script please modify $sysfs to locate your sysfs filesystem,
+# modify $udevd_bin to locate your udevsend binary,
+# modify $udev_bin to locate dummy udev script,
+# modify $udev_bin2 to locate another dummy udev script ( amplify the execution time for test),
+# modify $log_file to locate where udev script have placed the log file,
+# modify $time_out to decide the time out for events,
+# modify $udev_exe_time to decide the execution time for dummy udev script.
+#
+# Detail information of each test case please refer to the header of corresponding
+# test case function.
+#
+#
+# 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 $udevd_bin = "../../udevsend";
+my $udev_bin = "$ENV{PWD}/udev-log-script.pl";
+my $udev_bin2 = "$ENV{PWD}/udev-log-amplify.pl";
+my $log_file = "/tmp/udev_log.txt";
+my $time_out = 10;
+my $udev_exe_time = 5;
+
+# global variables
+my $test_case = 0;
+
+# common functions
+
+sub kill_daemon {
+ system("killall udevd");
+ system("rm -f $log_file");
+ sleep 1;
+}
+
+sub udevsend {
+ # This function prepares corresponding environment variables
+ # and then call $udevd_bin to send event.
+
+ my ($seqnum, $devpath, $action, $subsystem, $udev_bin_tmp) = @_;
+
+ $ENV{DEVPATH} = $devpath;
+ $ENV{ACTION} = $action;
+ $udev_bin_tmp = $udev_bin if ( not $udev_bin_tmp );
+ $ENV{UDEV_BIN} = $udev_bin_tmp;
+ if ( $seqnum != -1) {
+ $ENV{SEQNUM} = $seqnum;
+ } else {
+ delete $ENV{SEQNUM};
+ }
+
+ return system("$udevd_bin $subsystem");
+}
+
+sub getDate {
+ # Get current date function
+ # If we want GTM time, simply pass GMT as first argument to this function.
+
+ my $format = @_;
+ my $date;
+
+ if( $format =~ /GMT/i ) {
+ $date = gmtime() . " GMT";
+ } else {
+ $date = localtime();
+ }
+
+ return $date;
+}
+
+sub cmpDate {
+ # This function should return a difference betweent date1 and date2
+
+ my ($date1, $date2) = @_;
+ my @monList = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
+ "Aug", "Sep", "Oct", "Nov", "Dec" );
+ my ( $m1, $m2, $tmp );
+
+ $date1 =~ s/([\D]*)$//g;
+ $date2 =~ s/([\D]*)$//g;
+
+ return if( (not $date1) or (not $date2) );
+
+ my $mon = 0;
+
+ my ( @T1 ) =
+ ( $date1 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
+ my ( @T2 ) =
+ ( $date2 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
+
+ foreach $tmp (@monList) {
+ $m1 = sprintf("%2.2d",$mon) if( $date1 =~ /$tmp/i );
+ $m2 = sprintf("%2.2d",$mon) if( $date2 =~ /$tmp/i );
+ $mon++;
+ }
+
+ my $dt1 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T1[4], $m1, $T1[0],
+ $T1[1], $T1[2], $T1[3]);
+ my $dt2 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T2[4], $m2, $T2[0],
+ $T2[1], $T2[2], $T2[3]);
+
+ my $ret = $dt1 - $dt2;
+
+ if ( $ret > 40 ) {
+ $ret = abs($ret-40);
+ }
+
+ return $ret;
+}
+
+sub check_count_and_time {
+ my $event_recv_time;
+ my $udev_fork_time;
+ my $log_ln_count = 0;
+ my $line;
+ my @content;
+ my @line_items;
+ my $diff;
+
+ ($event_recv_time) = @_;
+
+ print " event receiving time: $event_recv_time\n\n";
+
+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
+ @content = <LOGF>;
+ foreach $line ( @content ) {
+ @line_items = split(/,/,$line);
+ print " device: $line_items[0], action: $line_items[1] \n";
+ print " forking udev time: $line_items[-1]";
+ $diff = cmpDate($line_items[-1], $event_recv_time);
+ print " the delay time is: $diff s \n\n";
+ if ( $diff > $time_out ) {
+ print " the delay time is: $diff \n";
+ print " udevd doesn't act properly. \n";
+ exit 1;
+ }
+ $log_ln_count++;
+ }
+ close(LOGF);
+
+ return $log_ln_count;
+}
+
+sub check_sysfs_device_exist {
+ # check if the designated devices exist
+ my @dev_list = @_;
+ my $dev;
+
+ foreach $dev (@dev_list) {
+ if (! -e $dev) {
+ print "the designated device $dev doesn't exist. please change a device!\n";
+ exit 1;
+ }
+ }
+}
+
+sub show_result {
+ my $event_recv_time;
+ my $udev_fork_time;
+ my $line;
+ my @content;
+ my @line_items;
+ my $diff;
+
+ ($event_recv_time) = @_;
+
+ print " event receiving time: $event_recv_time\n\n";
+
+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
+ @content = <LOGF>;
+ foreach $line ( @content ) {
+ @line_items = split(/,/,$line);
+ print " device: $line_items[0], action: $line_items[1] \n";
+ print " forking udev time: $line_items[-1]";
+ $diff = cmpDate($line_items[-1], $event_recv_time);
+ print " the delay time is: $diff s \n\n";
+ }
+ close(LOGF);
+}
+
+sub show_result_tm_out {
+ my $event_recv_time;
+ my $udev_fork_time;
+ my $line;
+ my @content;
+ my @line_items;
+ my $diff;
+
+ ($event_recv_time) = @_;
+
+ print " event receiving time: $event_recv_time\n\n";
+
+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
+ @content = <LOGF>;
+ foreach $line ( @content ) {
+ @line_items = split(/,/,$line);
+ print " device: $line_items[0], action: $line_items[1] \n";
+ print " forking udev time: $line_items[-1]";
+ $diff = cmpDate($line_items[-1], $event_recv_time);
+ print " the delay time is: $diff s \n\n";
+ if ( $diff < $time_out ) {
+ print " the delay time is: $diff \n";
+ print " udevd doesn't act properly. \n";
+ exit 1;
+ }
+ }
+ close(LOGF);
+}
+
+sub show_result_immediate {
+ my $event_recv_time;
+ my $udev_fork_time;
+ my $line;
+ my @content;
+ my @line_items;
+ my $diff;
+
+ ($event_recv_time) = @_;
+
+ print " event receiving time: $event_recv_time\n\n";
+
+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
+ @content = <LOGF>;
+ foreach $line ( @content ) {
+ @line_items = split(/,/,$line);
+ print " device: $line_items[0], action: $line_items[1] \n";
+ print " forking udev time: $line_items[-1]";
+ $diff = cmpDate($line_items[-1], $event_recv_time);
+ print " the delay time is: $diff s \n\n";
+ if ( $diff > $time_out ) {
+ print " the delay time is: $diff \n";
+ print " udevd doesn't act properly. \n";
+ exit 1;
+ }
+ }
+ close(LOGF);
+}
+
+sub check_exe_time {
+ my @exe_time;
+ my $i = 0;
+ my $line;
+ my @content;
+ my @line_items;
+ my $diff;
+
+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
+ @content = <LOGF>;
+ close(LOGF);
+ foreach $line ( @content ) {
+ @line_items = split(/,/,$line);
+ $exe_time[$i] = $line_items[-1];
+ $i++;
+ }
+ $diff = cmpDate($exe_time[1], $exe_time[0]);
+ if ( $diff < $udev_exe_time ) {
+ print " there are more than one udev instance for a single device at the same time. \n";
+ exit 1;
+ } else {
+ print " there is just one udev instance for a single device at the same time. \n";
+ }
+}
+
+# test case functions
+sub run_no_seq_test {
+ print "Test case name: no sequence number test\n";
+ print "Test case purpose: check whether udevd forks udev immediately when environment variable SEQNUM is null.\n";
+ print "Test expected visible results: \n";
+ print " the delay time between event receiving and forking udev for udevd should be negligible, \n";
+ print " that is, udev should be forked at once. please notice the following time...\n\n";
+
+ # local variables
+ my $time;
+
+ #
+ # add devices event test
+ #
+ kill_daemon();
+
+ # check if devices /sys/block/hda, loop1, loop2 exist
+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
+
+ # log current system date/time
+ $time = getDate();
+
+ # fork udevd
+ udevsend(-1, "/block/hda", "add", "block");
+
+ # check if execution is successful in time
+ sleep 1;
+ show_result_immediate($time);
+ print " fork udev (add device) at once successfully.\n\n";
+
+ #
+ # remove devices event test
+ #
+ system("rm -f $log_file");
+
+ # log current system date/time
+ $time = getDate();
+
+ # fork udevd
+ udevsend(-1, "/block/hda", "remove", "block");
+
+ # check if execution is successful in time
+ sleep 1;
+ show_result_immediate($time);
+ print " fork udev (remove device) at once successfully.\n\n";
+ print "this case is ok\n\n";
+}
+
+sub run_normal_seq_test {
+ print "Test case name: normal sequence number stress test\n";
+ print "Test case purpose: check whether udevd can fork massive udev instances for \n";
+ print " massive sequential events successfully. \n";
+ print "Test expected visible results: \n";
+ print " Populate all the devices in directory $sysfs/block, fork udved to send add/remove \n";
+ print " event to udev for each device. \n";
+ print " We can see the delay time for each device should be negligible. \n\n";
+
+ # local variables
+ my @file_list;
+ my $file;
+ my $seq = 0;
+ my $time;
+ my $ret_seq;
+
+ # prepare
+ kill_daemon();
+ @file_list = glob "$sysfs/block/*";
+
+ # log current system date/time for device add events
+ $time = getDate();
+
+ #
+ # add devices event test
+ #
+ print "add device events test: \n";
+ 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 event: error\n\n";
+ exit 1;
+ }
+ }
+
+ # we'd better wait the udev to create all the device for a few seconds
+ print " wait for udevd processing about $time_out s... \n\n";
+ sleep $time_out;
+
+ $ret_seq = check_count_and_time($time);
+ if ( $ret_seq != $seq ) {
+ print " add event: failed. some device-adding events fail to execute.\n\n";
+ exit 1;
+ } else {
+ print " $seq pieces of device-adding events have executed successfully.\n\n";
+ }
+
+ # log current system date/time for device remove events
+ $time = getDate();
+
+ #
+ # remove devices event test
+ #
+ print "remove device events test: \n";
+ kill_daemon();
+ @file_list = glob "$sysfs/block/*";
+ $seq = 0;
+ 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 event: error\n\n";
+ exit 1;
+ }
+ }
+
+ # we'd better wait the udev to create all the device for a few seconds
+ print " waiting for udev removing devices (about $time_out s)...\n";
+ sleep $time_out;
+
+ # show results
+ $ret_seq = check_count_and_time($time);
+ if ( $ret_seq != $seq ) {
+ print " remove event: failed. some device-removing events fail to execute.\n\n";
+ exit 1;
+ } else {
+ print " $seq pieces of device-removing events have executed successfully.\n\n";
+ print "this case is ok.\n\n";
+ }
+}
+
+sub run_random_seq_test {
+ print "Test case name: random sequence number test case,\n";
+ print "Test case purpose: check whether udevd can order the events with random sequence number \n";
+ print " and fork udev correctly. \n";
+ print "Test expected visible results: \n";
+ print " We have disordered the events sent to udevd, if udevd can order them correctly, the devices' \n";
+ print " add/remove sequence should be hda, loop1, loop2. \n\n";
+
+ # local variables
+ my $time;
+
+ # check if devices /sys/block/hda, loop1, loop2 exist
+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
+
+ #
+ # add device events test
+ #
+ print "add device events test: \n";
+ kill_daemon();
+
+ # log current system date/time for device remove events
+ $time = getDate();
+
+ # 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 " wait for udevd processing about $time_out s... \n\n";
+ sleep $time_out+1;
+ show_result_tm_out($time);
+
+ #
+ # remove device events test
+ #
+ print "\nremove device events test: \n";
+ kill_daemon();
+
+ # log current system date/time for device remove events
+ $time = getDate();
+
+ # fork udevd
+ udevsend(3, "/block/loop2", "remove", "block");
+ udevsend(2, "/block/loop1", "remove", "block");
+ udevsend(1, "/block/hda", "remove", "block");
+
+ # show results
+ print " wait for udevd processing about $time_out s... \n\n";
+ sleep $time_out+1;
+ show_result_tm_out($time);
+ print "this case is ok.\n\n";
+}
+
+sub run_expected_seq_test {
+ print "Test case name: expected sequence number test \n";
+ print "Test case purpose: check whether udevd fork udev immediately when the incoming event\n";
+ print " is exactly the expected event sequence number.\n";
+ print "Test expected visible results:\n";
+ print " first, udevd disposes disorder events(sequence number is 3,1,2,5,4,6),\n";
+ print " thus after disposed the expected event number for udevd is 7, when incoming event is 7, udevd\n";
+ print " should fork udev immediately, the delay time should be negligible. \n";
+ print " where: event 7 is (add device /block/loop2) \n\n";
+
+ # local variables
+ my $time;
+
+ # check if devices /sys/block/hda, loop1, loop2 exist
+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
+
+ # prepare
+ kill_daemon();
+
+ # 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");
+ udevsend(5, "/block/loop1", "remove", "block");
+ udevsend(4, "/block/hda", "remove", "block");
+ udevsend(6, "/block/loop2", "remove", "block");
+
+ print " wait for udevd timing out for disorder events (about $time_out s) \n\n";
+ sleep $time_out+1;
+ system("rm -f $log_file");
+
+ # log current system date/time for device remove events
+ $time = getDate();
+
+ # show results
+ udevsend(7, "/block/loop2", "add", "block");
+ sleep 1;
+ print " event sequence number: 7 \n";
+ show_result_immediate($time);
+
+ print "this case is ok.\n\n";
+}
+
+sub run_single_instance_test {
+ print "Test case name: single instance running for a single device test \n";
+ print "Test case purpose: check whether udevd only fork one udev instance for a single\n";
+ print " device at the same time. For each event a udev instance is \n";
+ print " executed in the background. All further events for the same \n";
+ print " device are delayed until the execution is finished. This way \n";
+ print " there will never be more than one instance running for a single \n";
+ print " device at the same time.\n";
+ print "Test expected visible results:\n";
+ print " In this test we amplify the execution time of udev (about 5 seconds), first, \n";
+ print " we send a add event for device /block/hda, and then we send a remove event, so the \n";
+ print " execution of remove event should be delayed until add is finished. \n\n";
+
+ # local variables
+ my $time;
+
+ # prepare
+ kill_daemon();
+
+ # check if device exists
+ check_sysfs_device_exist("$sysfs/block/hda");
+
+ # log current system date/time
+ $time = getDate();
+
+ # fork udved
+ udevsend(-1, "/block/hda", "add", "block", $udev_bin2);
+ udevsend(-1, "/block/hda", "remove", "block", $udev_bin2);
+
+ # show results
+ print " wait for udevd processing about $udev_exe_time s... \n\n";
+ sleep $udev_exe_time+1;
+ show_result_immediate($time);
+ check_exe_time();
+ print "this case is ok\n\n";
+}
+
+sub run_same_events_test {
+ print "Test case name: event sequence number overlap test \n";
+ print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
+ print " when encountering a event with sequence number same as the pevious event. \n";
+ print "Test expected visible results:\n";
+ print " event ( add device /block/hda ) should be no delay, \n";
+ print " event ( add device /block/loop1 ) should be delayed for $time_out s than its previous \n";
+ print " event ( remove device /block/hda ) \n\n";
+
+ # local variables
+ my $time;
+
+ # prepare
+ kill_daemon();
+
+ # check if device exist
+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
+
+ # fork udevd
+ udevsend(0, "/block/hda", "add", "block");
+
+ # log current system date/time
+ sleep 1;
+ $time = getDate();
+ system("rm -f $log_file");
+
+ # fork udevd
+ udevsend(1, "/block/hda", "remove", "block");
+ udevsend(1, "/block/loop1", "add", "block");
+
+ # show results
+ print " wait for udevd processing about $time_out s... \n\n";
+ sleep $time_out+1;
+ show_result($time);
+ print "this case is ok\n\n";
+}
+
+sub run_missing_seq_test {
+ print "Test case name: missing sequence number test \n";
+ print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
+ print " when certain event sequence number is missing.\n";
+ print "Test expected visible results:\n";
+ print " the delay time for event(add device /block/hda) should be about $time_out s.\n\n";
+
+ # local variables
+ my $time;
+
+ # prepare
+ kill_daemon();
+
+ # check if device exist
+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
+
+ # fork udevd
+ udevsend(0, "/block/loop1", "add", "block");
+ udevsend(1, "/block/loop1", "remove", "block");
+ sleep 1;
+
+ # log current system date/time
+ $time = getDate();
+ system("rm -f $log_file");
+
+ # fork udevd
+ udevsend(3, "/block/hda", "add", "block");
+
+ # show results
+ print " wait for udevd processing about $time_out s... \n\n";
+ sleep $time_out+1;
+ show_result($time);
+ 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_missing_seq_test();
+ run_expected_seq_test();
+ run_same_events_test();
+ run_single_instance_test();
+}
+
+# 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_missing_seq_test();
+ } elsif ($test_case == 5) {
+ run_expected_seq_test();
+ } elsif ($test_case == 6) {
+ run_single_instance_test();
+ } elsif ($test_case == 7) {
+ 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: missing event sequence number\n";
+ print " 5: the incoming event sequence number is right the expected sequence number\n";
+ print " 6: single udev instance on a single device at the same time\n";
+ print " 7: test event sequence number overlap\n";
+ print " 9: all the cases\n\n";
+}
diff -Nru a/udevd.c b/udevd.c
--- a/udevd.c Tue Apr 13 15:21:43 2004
+++ b/udevd.c Tue Apr 13 15:21:43 2004
@@ -60,6 +60,7 @@
static void msg_queue_manager(void);
static void user_sighandler(void);
static void reap_kids(void);
+char *udev_bin;
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
@@ -146,7 +147,7 @@
switch (pid) {
case 0:
/* child */
- execle(UDEV_BIN, "udev", msg->subsystem, NULL, env);
+ execle(udev_bin, "udev", msg->subsystem, NULL, env);
dbg("exec of child failed");
exit(1);
break;
@@ -457,6 +458,13 @@
/* enable receiving of the sender credentials */
setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
+
+ /* possible override of udev binary, used for testing */
+ udev_bin = getenv("UDEV_BIN");
+ if (udev_bin != NULL)
+ dbg("udev binary is set to '%s'", udev_bin);
+ else
+ udev_bin = UDEV_BIN;
FD_ZERO(&readfds);
FD_SET(ssock, &readfds);
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (9 preceding siblings ...)
2004-04-13 13:25 ` Kay Sievers
@ 2004-04-13 13:51 ` Nick Yin
2004-04-14 3:11 ` Yin, Hu
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Nick Yin @ 2004-04-13 13:51 UTC (permalink / raw)
To: linux-hotplug
Kay,
Thank you very very much!
Of course we can switch /sys to our test test/sys, i will modify and test it
tomorrow. Also, i will keep in tracking your change. hehe!
Have a nice day!
Nick ( Yin Hu )
>From: Kay Sievers <kay.sievers@vrfy.org>
>To: "Yin, Hu" <hu.yin@intel.com>
>CC: linux-hotplug-devel@lists.sourceforge.net
>Subject: Re: Test script for udevd binary, Request for Comments!
>Date: Tue, 13 Apr 2004 15:25:01 +0200
>
>On Tue, Apr 13, 2004 at 06:34:27PM +0800, Yin, Hu wrote:
> > I have written three scripts, that is, udevd-test.pl,
> > udev-log-script.pl, udev-log-amplify.pl. where udevd-test.pl is main
> > test script, udev-log-script.pl is a replace for udev binary for general
> > test case, udev-log-amplify.pl is another replace for udev binary for
> > "only one udev instance for a single device at the same time" test case,
> > which amplifies the execution time (sleep 5) in order for convenience of
> > test.
> >
> > Would you like to help me check them? Thank you very much!
>
>Looks promising. I've made it a big patch, also containing the udevd.c
>change. Please send all future changes as a incremental patch on top of
>this one, so we both can track the changes. I've changed a few things:
>
> o placed the scripts in test/udevd-test/ subdir
> o replaced 'rm -rf' by 'rm -f'
> o place the logfile into /tmp/
> o wait 1 second after killing the daemon, cause the kernel needs
> to cleanup the old socket, otherwise the first two events sent for the
> new daemon are lost on my machine
> o unset SEQNUM in udevsend(), otherwise test #6 will fail by sending
> the SEQNUM from test #5
> o substituted spaces by tabs
>
>
>Can we switch to our test/sys/ tree and use the files in there, instead of
>the real /sys, cause some machines don't have /block/hda or /block/loop?
>
>Kay
>diff -Nru a/test/udevd-test/udev-log-amplify.pl
>b/test/udevd-test/udev-log-amplify.pl
>--- /dev/null Wed Dec 31 16:00:00 1969
>+++ b/test/udevd-test/udev-log-amplify.pl Tue Apr 13 15:21:43 2004
>@@ -0,0 +1,87 @@
>+#!/usr/bin/perl -w
>+#
>+# udev-log-amplify
>+#
>+# Copyright (C) Intel Corp, 2004
>+#
>+# Author: Yin Hu <hu.yin@intel.com>
>+#
>+# This is a script for replacing udev binary during udevsend/udevd
>testing.
>+# It first amplifies the execution time ( sleep 5 ) and then logs the
>event
>+# information sent by udved in order that test script udevd-test.pl can
>+# analyze whether udved execute as we expected.
>+# You should not execute this script directly because it will be invoked
>by
>+# udevd automatically.
>+#
>+# Before you run your test please modify $log_file to designate where the
>udev
>+# log file should be placed, in fact, the default value is ok.
>+#
>+#
>+# 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 $udev_exe_time = 5;
>+my $log_file = "/tmp/udev_log.txt";
>+
>+# global variables
>+my $devpath;
>+my $action;
>+my $subsystem;
>+
>+# common functions
>+sub getDate {
>+ # Get current date/time
>+ # If we want GTM time, simply pass GMT as first argument to this
>function.
>+
>+ my $format = @_;
>+ my $date;
>+
>+ if( $format =~ /GMT/i ) {
>+ $date = gmtime() . " GMT";
>+ } else {
>+ $date = localtime();
>+ }
>+ return $date;
>+}
>+
>+# main program
>+if ($ARGV[0]) {
>+ $subsystem = $ARGV[0];
>+ $devpath = $ENV{DEVPATH};
>+ $action = $ENV{ACTION};
>+
>+ # Get current system date
>+ my $time = getDate();
>+
>+ # Logging
>+ if (open(LOGF, ">>$log_file")) {
>+ print LOGF "$devpath,$action,$subsystem,$time\n";
>+ } else {
>+ print "File open failed. \n";
>+ exit 1;
>+ }
>+ close(LOGF);
>+
>+ # Amplify the execution time of udev
>+ sleep 5;
>+
>+ exit 0;
>+} else {
>+ print "Too less argument count.\n";
>+ exit 1;
>+}
>diff -Nru a/test/udevd-test/udev-log-script.pl
>b/test/udevd-test/udev-log-script.pl
>--- /dev/null Wed Dec 31 16:00:00 1969
>+++ b/test/udevd-test/udev-log-script.pl Tue Apr 13 15:21:43 2004
>@@ -0,0 +1,82 @@
>+#!/usr/bin/perl -w
>+#
>+# udev-log-script
>+#
>+# Copyright (C) Intel Corp, 2004
>+#
>+# Author: Yin Hu <hu.yin@intel.com>
>+#
>+# This is a script for replacing udev binary during udevsend/udevd
>testing.
>+# It just simply logs the event information sent by udved in order to
>+# test script udevd-test.pl can analyze whether udved execute as we
>expected.
>+# You should not execute this script directly because it will be invoked
>by
>+# udevd automatically.
>+#
>+# Before you run your test please modify $log_file to designate where the
>udev
>+# log file should be placed, in fact, the default value is ok.
>+#
>+#
>+# 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 $log_file = "/tmp/udev_log.txt";
>+
>+# global variables
>+my $devpath;
>+my $action;
>+my $subsystem;
>+
>+# common functions
>+sub getDate {
>+ # Get current date/time
>+ # If we want GTM time, simply pass GMT as first argument to this
>function.
>+ my $format = @_;
>+ my $date;
>+
>+ if( $format =~ /GMT/i ) {
>+ $date = gmtime() . " GMT";
>+ } else {
>+ $date = localtime();
>+ }
>+ return $date;
>+}
>+
>+# main program
>+if ($ARGV[0]) {
>+ # prepare
>+ $subsystem = $ARGV[0];
>+ $devpath = $ENV{DEVPATH};
>+ $action = $ENV{ACTION};
>+
>+ # Get current system date
>+ my $time = getDate();
>+
>+ # Logging
>+ if (open(LOGF, ">>$log_file")) {
>+ print LOGF "$devpath,$action,$subsystem,$time\n";
>+ } else {
>+ print "File open failed. \n";
>+ exit 1;
>+ }
>+ close(LOGF);
>+
>+ exit 0;
>+} else {
>+ print "Too less argument count.\n";
>+ exit 1;
>+}
>diff -Nru a/test/udevd-test/udevd-test.pl b/test/udevd-test/udevd-test.pl
>--- /dev/null Wed Dec 31 16:00:00 1969
>+++ b/test/udevd-test/udevd-test.pl Tue Apr 13 15:21:43 2004
>@@ -0,0 +1,668 @@
>+#!/usr/bin/perl -w
>+#
>+# udevd-test
>+#
>+# Copyright (C) Intel Corp, 2004
>+#
>+# Author: Yin Hu <hu.yin@intel.com>
>+#
>+# Provides automated testing of the udevd binary.This test script is
>self-contained.
>+# Before you run this script please modify $sysfs to locate your sysfs
>filesystem,
>+# modify $udevd_bin to locate your udevsend binary,
>+# modify $udev_bin to locate dummy udev script,
>+# modify $udev_bin2 to locate another dummy udev script ( amplify the
>execution time for test),
>+# modify $log_file to locate where udev script have placed the log file,
>+# modify $time_out to decide the time out for events,
>+# modify $udev_exe_time to decide the execution time for dummy udev
>script.
>+#
>+# Detail information of each test case please refer to the header of
>corresponding
>+# test case function.
>+#
>+#
>+# 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 $udevd_bin = "../../udevsend";
>+my $udev_bin = "$ENV{PWD}/udev-log-script.pl";
>+my $udev_bin2 = "$ENV{PWD}/udev-log-amplify.pl";
>+my $log_file = "/tmp/udev_log.txt";
>+my $time_out = 10;
>+my $udev_exe_time = 5;
>+
>+# global variables
>+my $test_case = 0;
>+
>+# common functions
>+
>+sub kill_daemon {
>+ system("killall udevd");
>+ system("rm -f $log_file");
>+ sleep 1;
>+}
>+
>+sub udevsend {
>+ # This function prepares corresponding environment variables
>+ # and then call $udevd_bin to send event.
>+
>+ my ($seqnum, $devpath, $action, $subsystem, $udev_bin_tmp) = @_;
>+
>+ $ENV{DEVPATH} = $devpath;
>+ $ENV{ACTION} = $action;
>+ $udev_bin_tmp = $udev_bin if ( not $udev_bin_tmp );
>+ $ENV{UDEV_BIN} = $udev_bin_tmp;
>+ if ( $seqnum != -1) {
>+ $ENV{SEQNUM} = $seqnum;
>+ } else {
>+ delete $ENV{SEQNUM};
>+ }
>+
>+ return system("$udevd_bin $subsystem");
>+}
>+
>+sub getDate {
>+ # Get current date function
>+ # If we want GTM time, simply pass GMT as first argument to this
>function.
>+
>+ my $format = @_;
>+ my $date;
>+
>+ if( $format =~ /GMT/i ) {
>+ $date = gmtime() . " GMT";
>+ } else {
>+ $date = localtime();
>+ }
>+
>+ return $date;
>+}
>+
>+sub cmpDate {
>+ # This function should return a difference betweent date1 and date2
>+
>+ my ($date1, $date2) = @_;
>+ my @monList = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
>+ "Aug", "Sep", "Oct", "Nov", "Dec" );
>+ my ( $m1, $m2, $tmp );
>+
>+ $date1 =~ s/([\D]*)$//g;
>+ $date2 =~ s/([\D]*)$//g;
>+
>+ return if( (not $date1) or (not $date2) );
>+
>+ my $mon = 0;
>+
>+ my ( @T1 ) >+ ( $date1 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
>+ my ( @T2 ) >+ ( $date2 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
>+
>+ foreach $tmp (@monList) {
>+ $m1 = sprintf("%2.2d",$mon) if( $date1 =~ /$tmp/i );
>+ $m2 = sprintf("%2.2d",$mon) if( $date2 =~ /$tmp/i );
>+ $mon++;
>+ }
>+
>+ my $dt1 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T1[4], $m1, $T1[0],
>+ $T1[1], $T1[2], $T1[3]);
>+ my $dt2 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T2[4], $m2, $T2[0],
>+ $T2[1], $T2[2], $T2[3]);
>+
>+ my $ret = $dt1 - $dt2;
>+
>+ if ( $ret > 40 ) {
>+ $ret = abs($ret-40);
>+ }
>+
>+ return $ret;
>+}
>+
>+sub check_count_and_time {
>+ my $event_recv_time;
>+ my $udev_fork_time;
>+ my $log_ln_count = 0;
>+ my $line;
>+ my @content;
>+ my @line_items;
>+ my $diff;
>+
>+ ($event_recv_time) = @_;
>+
>+ print " event receiving time: $event_recv_time\n\n";
>+
>+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
>+ @content = <LOGF>;
>+ foreach $line ( @content ) {
>+ @line_items = split(/,/,$line);
>+ print " device: $line_items[0], action: $line_items[1] \n";
>+ print " forking udev time: $line_items[-1]";
>+ $diff = cmpDate($line_items[-1], $event_recv_time);
>+ print " the delay time is: $diff s \n\n";
>+ if ( $diff > $time_out ) {
>+ print " the delay time is: $diff \n";
>+ print " udevd doesn't act properly. \n";
>+ exit 1;
>+ }
>+ $log_ln_count++;
>+ }
>+ close(LOGF);
>+
>+ return $log_ln_count;
>+}
>+
>+sub check_sysfs_device_exist {
>+ # check if the designated devices exist
>+ my @dev_list = @_;
>+ my $dev;
>+
>+ foreach $dev (@dev_list) {
>+ if (! -e $dev) {
>+ print "the designated device $dev doesn't exist. please change a
>device!\n";
>+ exit 1;
>+ }
>+ }
>+}
>+
>+sub show_result {
>+ my $event_recv_time;
>+ my $udev_fork_time;
>+ my $line;
>+ my @content;
>+ my @line_items;
>+ my $diff;
>+
>+ ($event_recv_time) = @_;
>+
>+ print " event receiving time: $event_recv_time\n\n";
>+
>+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
>+ @content = <LOGF>;
>+ foreach $line ( @content ) {
>+ @line_items = split(/,/,$line);
>+ print " device: $line_items[0], action: $line_items[1] \n";
>+ print " forking udev time: $line_items[-1]";
>+ $diff = cmpDate($line_items[-1], $event_recv_time);
>+ print " the delay time is: $diff s \n\n";
>+ }
>+ close(LOGF);
>+}
>+
>+sub show_result_tm_out {
>+ my $event_recv_time;
>+ my $udev_fork_time;
>+ my $line;
>+ my @content;
>+ my @line_items;
>+ my $diff;
>+
>+ ($event_recv_time) = @_;
>+
>+ print " event receiving time: $event_recv_time\n\n";
>+
>+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
>+ @content = <LOGF>;
>+ foreach $line ( @content ) {
>+ @line_items = split(/,/,$line);
>+ print " device: $line_items[0], action: $line_items[1] \n";
>+ print " forking udev time: $line_items[-1]";
>+ $diff = cmpDate($line_items[-1], $event_recv_time);
>+ print " the delay time is: $diff s \n\n";
>+ if ( $diff < $time_out ) {
>+ print " the delay time is: $diff \n";
>+ print " udevd doesn't act properly. \n";
>+ exit 1;
>+ }
>+ }
>+ close(LOGF);
>+}
>+
>+sub show_result_immediate {
>+ my $event_recv_time;
>+ my $udev_fork_time;
>+ my $line;
>+ my @content;
>+ my @line_items;
>+ my $diff;
>+
>+ ($event_recv_time) = @_;
>+
>+ print " event receiving time: $event_recv_time\n\n";
>+
>+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
>+ @content = <LOGF>;
>+ foreach $line ( @content ) {
>+ @line_items = split(/,/,$line);
>+ print " device: $line_items[0], action: $line_items[1] \n";
>+ print " forking udev time: $line_items[-1]";
>+ $diff = cmpDate($line_items[-1], $event_recv_time);
>+ print " the delay time is: $diff s \n\n";
>+ if ( $diff > $time_out ) {
>+ print " the delay time is: $diff \n";
>+ print " udevd doesn't act properly. \n";
>+ exit 1;
>+ }
>+ }
>+ close(LOGF);
>+}
>+
>+sub check_exe_time {
>+ my @exe_time;
>+ my $i = 0;
>+ my $line;
>+ my @content;
>+ my @line_items;
>+ my $diff;
>+
>+ open(LOGF, $log_file) || die "Opening file $log_file: $!";
>+ @content = <LOGF>;
>+ close(LOGF);
>+ foreach $line ( @content ) {
>+ @line_items = split(/,/,$line);
>+ $exe_time[$i] = $line_items[-1];
>+ $i++;
>+ }
>+ $diff = cmpDate($exe_time[1], $exe_time[0]);
>+ if ( $diff < $udev_exe_time ) {
>+ print " there are more than one udev instance for a single device at
>the same time. \n";
>+ exit 1;
>+ } else {
>+ print " there is just one udev instance for a single device at the
>same time. \n";
>+ }
>+}
>+
>+# test case functions
>+sub run_no_seq_test {
>+ print "Test case name: no sequence number test\n";
>+ print "Test case purpose: check whether udevd forks udev immediately
>when environment variable SEQNUM is null.\n";
>+ print "Test expected visible results: \n";
>+ print " the delay time between event receiving and forking udev for
>udevd should be negligible, \n";
>+ print " that is, udev should be forked at once. please notice the
>following time...\n\n";
>+
>+ # local variables
>+ my $time;
>+
>+ #
>+ # add devices event test
>+ #
>+ kill_daemon();
>+
>+ # check if devices /sys/block/hda, loop1, loop2 exist
>+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1",
>"$sysfs/block/loop2");
>+
>+ # log current system date/time
>+ $time = getDate();
>+
>+ # fork udevd
>+ udevsend(-1, "/block/hda", "add", "block");
>+
>+ # check if execution is successful in time
>+ sleep 1;
>+ show_result_immediate($time);
>+ print " fork udev (add device) at once successfully.\n\n";
>+
>+ #
>+ # remove devices event test
>+ #
>+ system("rm -f $log_file");
>+
>+ # log current system date/time
>+ $time = getDate();
>+
>+ # fork udevd
>+ udevsend(-1, "/block/hda", "remove", "block");
>+
>+ # check if execution is successful in time
>+ sleep 1;
>+ show_result_immediate($time);
>+ print " fork udev (remove device) at once successfully.\n\n";
>+ print "this case is ok\n\n";
>+}
>+
>+sub run_normal_seq_test {
>+ print "Test case name: normal sequence number stress test\n";
>+ print "Test case purpose: check whether udevd can fork massive udev
>instances for \n";
>+ print " massive sequential events successfully. \n";
>+ print "Test expected visible results: \n";
>+ print " Populate all the devices in directory $sysfs/block, fork udved
>to send add/remove \n";
>+ print " event to udev for each device. \n";
>+ print " We can see the delay time for each device should be negligible.
>\n\n";
>+
>+ # local variables
>+ my @file_list;
>+ my $file;
>+ my $seq = 0;
>+ my $time;
>+ my $ret_seq;
>+
>+ # prepare
>+ kill_daemon();
>+ @file_list = glob "$sysfs/block/*";
>+
>+ # log current system date/time for device add events
>+ $time = getDate();
>+
>+ #
>+ # add devices event test
>+ #
>+ print "add device events test: \n";
>+ 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 event: error\n\n";
>+ exit 1;
>+ }
>+ }
>+
>+ # we'd better wait the udev to create all the device for a few seconds
>+ print " wait for udevd processing about $time_out s... \n\n";
>+ sleep $time_out;
>+
>+ $ret_seq = check_count_and_time($time);
>+ if ( $ret_seq != $seq ) {
>+ print " add event: failed. some device-adding events fail to
>execute.\n\n";
>+ exit 1;
>+ } else {
>+ print " $seq pieces of device-adding events have executed
>successfully.\n\n";
>+ }
>+
>+ # log current system date/time for device remove events
>+ $time = getDate();
>+
>+ #
>+ # remove devices event test
>+ #
>+ print "remove device events test: \n";
>+ kill_daemon();
>+ @file_list = glob "$sysfs/block/*";
>+ $seq = 0;
>+ 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 event: error\n\n";
>+ exit 1;
>+ }
>+ }
>+
>+ # we'd better wait the udev to create all the device for a few seconds
>+ print " waiting for udev removing devices (about $time_out s)...\n";
>+ sleep $time_out;
>+
>+ # show results
>+ $ret_seq = check_count_and_time($time);
>+ if ( $ret_seq != $seq ) {
>+ print " remove event: failed. some device-removing events fail to
>execute.\n\n";
>+ exit 1;
>+ } else {
>+ print " $seq pieces of device-removing events have executed
>successfully.\n\n";
>+ print "this case is ok.\n\n";
>+ }
>+}
>+
>+sub run_random_seq_test {
>+ print "Test case name: random sequence number test case,\n";
>+ print "Test case purpose: check whether udevd can order the events with
>random sequence number \n";
>+ print " and fork udev correctly. \n";
>+ print "Test expected visible results: \n";
>+ print " We have disordered the events sent to udevd, if udevd can order
>them correctly, the devices' \n";
>+ print " add/remove sequence should be hda, loop1, loop2. \n\n";
>+
>+ # local variables
>+ my $time;
>+
>+ # check if devices /sys/block/hda, loop1, loop2 exist
>+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1",
>"$sysfs/block/loop2");
>+
>+ #
>+ # add device events test
>+ #
>+ print "add device events test: \n";
>+ kill_daemon();
>+
>+ # log current system date/time for device remove events
>+ $time = getDate();
>+
>+ # 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 " wait for udevd processing about $time_out s... \n\n";
>+ sleep $time_out+1;
>+ show_result_tm_out($time);
>+
>+ #
>+ # remove device events test
>+ #
>+ print "\nremove device events test: \n";
>+ kill_daemon();
>+
>+ # log current system date/time for device remove events
>+ $time = getDate();
>+
>+ # fork udevd
>+ udevsend(3, "/block/loop2", "remove", "block");
>+ udevsend(2, "/block/loop1", "remove", "block");
>+ udevsend(1, "/block/hda", "remove", "block");
>+
>+ # show results
>+ print " wait for udevd processing about $time_out s... \n\n";
>+ sleep $time_out+1;
>+ show_result_tm_out($time);
>+ print "this case is ok.\n\n";
>+}
>+
>+sub run_expected_seq_test {
>+ print "Test case name: expected sequence number test \n";
>+ print "Test case purpose: check whether udevd fork udev immediately when
>the incoming event\n";
>+ print " is exactly the expected event sequence
>number.\n";
>+ print "Test expected visible results:\n";
>+ print " first, udevd disposes disorder events(sequence number is
>3,1,2,5,4,6),\n";
>+ print " thus after disposed the expected event number for udevd is 7,
>when incoming event is 7, udevd\n";
>+ print " should fork udev immediately, the delay time should be
>negligible. \n";
>+ print " where: event 7 is (add device /block/loop2) \n\n";
>+
>+ # local variables
>+ my $time;
>+
>+ # check if devices /sys/block/hda, loop1, loop2 exist
>+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1",
>"$sysfs/block/loop2");
>+
>+ # prepare
>+ kill_daemon();
>+
>+ # 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");
>+ udevsend(5, "/block/loop1", "remove", "block");
>+ udevsend(4, "/block/hda", "remove", "block");
>+ udevsend(6, "/block/loop2", "remove", "block");
>+
>+ print " wait for udevd timing out for disorder events (about $time_out
>s) \n\n";
>+ sleep $time_out+1;
>+ system("rm -f $log_file");
>+
>+ # log current system date/time for device remove events
>+ $time = getDate();
>+
>+ # show results
>+ udevsend(7, "/block/loop2", "add", "block");
>+ sleep 1;
>+ print " event sequence number: 7 \n";
>+ show_result_immediate($time);
>+
>+ print "this case is ok.\n\n";
>+}
>+
>+sub run_single_instance_test {
>+ print "Test case name: single instance running for a single device
>test \n";
>+ print "Test case purpose: check whether udevd only fork one udev instance
>for a single\n";
>+ print " device at the same time. For each event a udev
>instance is \n";
>+ print " executed in the background. All further events
>for the same \n";
>+ print " device are delayed until the execution is
>finished. This way \n";
>+ print " there will never be more than one instance
>running for a single \n";
>+ print " device at the same time.\n";
>+ print "Test expected visible results:\n";
>+ print " In this test we amplify the execution time of udev (about 5
>seconds), first, \n";
>+ print " we send a add event for device /block/hda, and then we send a
>remove event, so the \n";
>+ print " execution of remove event should be delayed until add is
>finished. \n\n";
>+
>+ # local variables
>+ my $time;
>+
>+ # prepare
>+ kill_daemon();
>+
>+ # check if device exists
>+ check_sysfs_device_exist("$sysfs/block/hda");
>+
>+ # log current system date/time
>+ $time = getDate();
>+
>+ # fork udved
>+ udevsend(-1, "/block/hda", "add", "block", $udev_bin2);
>+ udevsend(-1, "/block/hda", "remove", "block", $udev_bin2);
>+
>+ # show results
>+ print " wait for udevd processing about $udev_exe_time s... \n\n";
>+ sleep $udev_exe_time+1;
>+ show_result_immediate($time);
>+ check_exe_time();
>+ print "this case is ok\n\n";
>+}
>+
>+sub run_same_events_test {
>+ print "Test case name: event sequence number overlap test \n";
>+ print "Test case purpose: check whether udevd doesn't fork udev untill
>time out\n";
>+ print " when encountering a event with sequence number
>same as the pevious event. \n";
>+ print "Test expected visible results:\n";
>+ print " event ( add device /block/hda ) should be no delay, \n";
>+ print " event ( add device /block/loop1 ) should be delayed for
>$time_out s than its previous \n";
>+ print " event ( remove device /block/hda ) \n\n";
>+
>+ # local variables
>+ my $time;
>+
>+ # prepare
>+ kill_daemon();
>+
>+ # check if device exist
>+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
>+
>+ # fork udevd
>+ udevsend(0, "/block/hda", "add", "block");
>+
>+ # log current system date/time
>+ sleep 1;
>+ $time = getDate();
>+ system("rm -f $log_file");
>+
>+ # fork udevd
>+ udevsend(1, "/block/hda", "remove", "block");
>+ udevsend(1, "/block/loop1", "add", "block");
>+
>+ # show results
>+ print " wait for udevd processing about $time_out s... \n\n";
>+ sleep $time_out+1;
>+ show_result($time);
>+ print "this case is ok\n\n";
>+}
>+
>+sub run_missing_seq_test {
>+ print "Test case name: missing sequence number test \n";
>+ print "Test case purpose: check whether udevd doesn't fork udev untill
>time out\n";
>+ print " when certain event sequence number is
>missing.\n";
>+ print "Test expected visible results:\n";
>+ print " the delay time for event(add device /block/hda) should be about
>$time_out s.\n\n";
>+
>+ # local variables
>+ my $time;
>+
>+ # prepare
>+ kill_daemon();
>+
>+ # check if device exist
>+ check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
>+
>+ # fork udevd
>+ udevsend(0, "/block/loop1", "add", "block");
>+ udevsend(1, "/block/loop1", "remove", "block");
>+ sleep 1;
>+
>+ # log current system date/time
>+ $time = getDate();
>+ system("rm -f $log_file");
>+
>+ # fork udevd
>+ udevsend(3, "/block/hda", "add", "block");
>+
>+ # show results
>+ print " wait for udevd processing about $time_out s... \n\n";
>+ sleep $time_out+1;
>+ show_result($time);
>+ 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_missing_seq_test();
>+ run_expected_seq_test();
>+ run_same_events_test();
>+ run_single_instance_test();
>+}
>+
>+# 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_missing_seq_test();
>+ } elsif ($test_case = 5) {
>+ run_expected_seq_test();
>+ } elsif ($test_case = 6) {
>+ run_single_instance_test();
>+ } elsif ($test_case = 7) {
>+ 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: missing event sequence number\n";
>+ print " 5: the incoming event sequence number is right the
>expected sequence number\n";
>+ print " 6: single udev instance on a single device at the same
>time\n";
>+ print " 7: test event sequence number overlap\n";
>+ print " 9: all the cases\n\n";
>+}
>diff -Nru a/udevd.c b/udevd.c
>--- a/udevd.c Tue Apr 13 15:21:43 2004
>+++ b/udevd.c Tue Apr 13 15:21:43 2004
>@@ -60,6 +60,7 @@
> static void msg_queue_manager(void);
> static void user_sighandler(void);
> static void reap_kids(void);
>+char *udev_bin;
>
> #ifdef LOG
> unsigned char logname[LOGNAME_SIZE];
>@@ -146,7 +147,7 @@
> switch (pid) {
> case 0:
> /* child */
>- execle(UDEV_BIN, "udev", msg->subsystem, NULL, env);
>+ execle(udev_bin, "udev", msg->subsystem, NULL, env);
> dbg("exec of child failed");
> exit(1);
> break;
>@@ -457,6 +458,13 @@
>
> /* enable receiving of the sender credentials */
> setsockopt(ssock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
>+
>+ /* possible override of udev binary, used for testing */
>+ udev_bin = getenv("UDEV_BIN");
>+ if (udev_bin != NULL)
>+ dbg("udev binary is set to '%s'", udev_bin);
>+ else
>+ udev_bin = UDEV_BIN;
>
> FD_ZERO(&readfds);
> FD_SET(ssock, &readfds);
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?pageþatures/junkmail
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (10 preceding siblings ...)
2004-04-13 13:51 ` Nick Yin
@ 2004-04-14 3:11 ` Yin, Hu
2004-04-14 12:18 ` Kay Sievers
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Yin, Hu @ 2004-04-14 3:11 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 2001 bytes --]
Kay,
I'v changed the udevd-test.pl according to your suggestion and made a
incremental patch called 100-udevd-test.patch. I'm not sure the patch is
feasible so I also send the updated udevd-test.pl file to you.
The main changes lie in location of sysfs filesystem and devices we
choosed in our test.
Would you like to give me further suggestions?
Thanks!
Nick
-----Original Message-----
From: Kay Sievers [mailto:kay.sievers@vrfy.org]
Sent: Tuesday, April 13, 2004 9:25 PM
To: Yin, Hu
Cc: linux-hotplug-devel@lists.sourceforge.net
Subject: Re: Test script for udevd binary, Request for Comments!
On Tue, Apr 13, 2004 at 06:34:27PM +0800, Yin, Hu wrote:
> I have written three scripts, that is, udevd-test.pl,
> udev-log-script.pl, udev-log-amplify.pl. where udevd-test.pl is main
> test script, udev-log-script.pl is a replace for udev binary for
general
> test case, udev-log-amplify.pl is another replace for udev binary for
> "only one udev instance for a single device at the same time" test
case,
> which amplifies the execution time (sleep 5) in order for convenience
of
> test.
>
> Would you like to help me check them? Thank you very much!
Looks promising. I've made it a big patch, also containing the udevd.c
change. Please send all future changes as a incremental patch on top of
this one, so we both can track the changes. I've changed a few things:
o placed the scripts in test/udevd-test/ subdir
o replaced 'rm -rf' by 'rm -f'
o place the logfile into /tmp/
o wait 1 second after killing the daemon, cause the kernel needs
to cleanup the old socket, otherwise the first two events sent for
the
new daemon are lost on my machine
o unset SEQNUM in udevsend(), otherwise test #6 will fail by sending
the SEQNUM from test #5
o substituted spaces by tabs
Can we switch to our test/sys/ tree and use the files in there, instead
of
the real /sys, cause some machines don't have /block/hda or /block/loop?
Kay
[-- Attachment #2: 100-udevd-test.patch --]
[-- Type: application/octet-stream, Size: 9977 bytes --]
diff -Naru a/test/udevd-test/udevd-test.pl b/test/udevd-test/udevd-test.pl
--- a/test/udevd-test/udevd-test.pl 2004-04-14 10:28:16.921821872 +0800
+++ b/test/udevd-test/udevd-test.pl 2004-04-14 10:27:56.895866280 +0800
@@ -37,7 +37,7 @@
use strict;
# modifiable settings
-my $sysfs = "/sys";
+my $sysfs = "../sys";
my $udevd_bin = "../../udevsend";
my $udev_bin = "$ENV{PWD}/udev-log-script.pl";
my $udev_bin2 = "$ENV{PWD}/udev-log-amplify.pl";
@@ -300,14 +300,14 @@
#
kill_daemon();
- # check if devices /sys/block/hda, loop1, loop2 exist
- check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
+ # check if devices /block/sda exist
+ check_sysfs_device_exist("$sysfs/block/sda");
# log current system date/time
$time = getDate();
# fork udevd
- udevsend(-1, "/block/hda", "add", "block");
+ udevsend(-1, "/block/sda", "add", "block");
# check if execution is successful in time
sleep 1;
@@ -323,7 +323,7 @@
$time = getDate();
# fork udevd
- udevsend(-1, "/block/hda", "remove", "block");
+ udevsend(-1, "/block/sda", "remove", "block");
# check if execution is successful in time
sleep 1;
@@ -337,7 +337,7 @@
print "Test case purpose: check whether udevd can fork massive udev instances for \n";
print " massive sequential events successfully. \n";
print "Test expected visible results: \n";
- print " Populate all the devices in directory $sysfs/block, fork udved to send add/remove \n";
+ print " Populate all the devices in directory $sysfs/class/tty, fork udved to send add/remove \n";
print " event to udev for each device. \n";
print " We can see the delay time for each device should be negligible. \n\n";
@@ -350,7 +350,7 @@
# prepare
kill_daemon();
- @file_list = glob "$sysfs/block/*";
+ @file_list = glob "$sysfs/class/tty/*";
# log current system date/time for device add events
$time = getDate();
@@ -360,7 +360,7 @@
#
print "add device events test: \n";
foreach $file (@file_list) {
- udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "add", "block");
+ udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "add", "tty");
# check if execution is successful
if ($? == 0) {
$seq++;
@@ -390,10 +390,10 @@
#
print "remove device events test: \n";
kill_daemon();
- @file_list = glob "$sysfs/block/*";
+ @file_list = glob "$sysfs/class/tty/*";
$seq = 0;
foreach $file (@file_list) {
- udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "remove", "block");
+ udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "remove", "tty");
# check if execution is successful
if ($? == 0) {
$seq++;
@@ -424,13 +424,13 @@
print " and fork udev correctly. \n";
print "Test expected visible results: \n";
print " We have disordered the events sent to udevd, if udevd can order them correctly, the devices' \n";
- print " add/remove sequence should be hda, loop1, loop2. \n\n";
+ print " add/remove sequence should be tty0, tty1, tty2. \n\n";
# local variables
my $time;
- # check if devices /sys/block/hda, loop1, loop2 exist
- check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
+ # check if devices /class/tty/tty0, tty1, tty2 exist
+ check_sysfs_device_exist("$sysfs/class/tty/tty0", "$sysfs/class/tty/tty1", "$sysfs/class/tty/tty2");
#
# add device events test
@@ -442,9 +442,9 @@
$time = getDate();
# 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");
+ udevsend(3, "/class/tty/tty2", "add", "tty");
+ udevsend(1, "/class/tty/tty0", "add", "tty");
+ udevsend(2, "/class/tty/tty1", "add", "tty");
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result_tm_out($time);
@@ -459,9 +459,9 @@
$time = getDate();
# fork udevd
- udevsend(3, "/block/loop2", "remove", "block");
- udevsend(2, "/block/loop1", "remove", "block");
- udevsend(1, "/block/hda", "remove", "block");
+ udevsend(3, "/class/tty/tty2", "remove", "tty");
+ udevsend(2, "/class/tty/tty1", "remove", "tty");
+ udevsend(1, "/class/tty/tty0", "remove", "tty");
# show results
print " wait for udevd processing about $time_out s... \n\n";
@@ -478,24 +478,24 @@
print " first, udevd disposes disorder events(sequence number is 3,1,2,5,4,6),\n";
print " thus after disposed the expected event number for udevd is 7, when incoming event is 7, udevd\n";
print " should fork udev immediately, the delay time should be negligible. \n";
- print " where: event 7 is (add device /block/loop2) \n\n";
+ print " where: event 7 is (add device /class/tty/tty2) \n\n";
# local variables
my $time;
- # check if devices /sys/block/hda, loop1, loop2 exist
- check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1", "$sysfs/block/loop2");
+ # check if devices /class/tty0, tty1, tty2 exist
+ check_sysfs_device_exist("$sysfs/class/tty/tty0", "$sysfs/class/tty/tty1", "$sysfs/class/tty/tty2");
# prepare
kill_daemon();
# 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");
- udevsend(5, "/block/loop1", "remove", "block");
- udevsend(4, "/block/hda", "remove", "block");
- udevsend(6, "/block/loop2", "remove", "block");
+ udevsend(3, "/class/tty/tty2", "add", "tty");
+ udevsend(1, "/class/tty/tty0", "add", "tty");
+ udevsend(2, "/class/tty/tty1", "add", "tty");
+ udevsend(5, "/class/tty/tty1", "remove", "tty");
+ udevsend(4, "/class/tty/tty0", "remove", "tty");
+ udevsend(6, "/class/tty/tty2", "remove", "tty");
print " wait for udevd timing out for disorder events (about $time_out s) \n\n";
sleep $time_out+1;
@@ -505,7 +505,7 @@
$time = getDate();
# show results
- udevsend(7, "/block/loop2", "add", "block");
+ udevsend(7, "/class/tty/tty2", "add", "tty");
sleep 1;
print " event sequence number: 7 \n";
show_result_immediate($time);
@@ -523,7 +523,7 @@
print " device at the same time.\n";
print "Test expected visible results:\n";
print " In this test we amplify the execution time of udev (about 5 seconds), first, \n";
- print " we send a add event for device /block/hda, and then we send a remove event, so the \n";
+ print " we send a add event for device /block/sda, and then we send a remove event, so the \n";
print " execution of remove event should be delayed until add is finished. \n\n";
# local variables
@@ -533,14 +533,14 @@
kill_daemon();
# check if device exists
- check_sysfs_device_exist("$sysfs/block/hda");
+ check_sysfs_device_exist("$sysfs/block/sda");
# log current system date/time
$time = getDate();
# fork udved
- udevsend(-1, "/block/hda", "add", "block", $udev_bin2);
- udevsend(-1, "/block/hda", "remove", "block", $udev_bin2);
+ udevsend(-1, "/block/sda", "add", "block", $udev_bin2);
+ udevsend(-1, "/block/sda", "remove", "block", $udev_bin2);
# show results
print " wait for udevd processing about $udev_exe_time s... \n\n";
@@ -555,9 +555,9 @@
print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
print " when encountering a event with sequence number same as the pevious event. \n";
print "Test expected visible results:\n";
- print " event ( add device /block/hda ) should be no delay, \n";
- print " event ( add device /block/loop1 ) should be delayed for $time_out s than its previous \n";
- print " event ( remove device /block/hda ) \n\n";
+ print " event ( remove device /block/sda ) should be no delay, \n";
+ print " event ( add device /class/tty/tty1 ) should be delayed for $time_out s than its previous \n";
+ print " event ( remove device /block/sda ) \n\n";
# local variables
my $time;
@@ -566,10 +566,10 @@
kill_daemon();
# check if device exist
- check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
+ check_sysfs_device_exist("$sysfs/block/sda", "$sysfs/class/tty/tty1");
# fork udevd
- udevsend(0, "/block/hda", "add", "block");
+ udevsend(0, "/block/sda", "add", "block");
# log current system date/time
sleep 1;
@@ -577,8 +577,8 @@
system("rm -f $log_file");
# fork udevd
- udevsend(1, "/block/hda", "remove", "block");
- udevsend(1, "/block/loop1", "add", "block");
+ udevsend(1, "/block/sda", "remove", "block");
+ udevsend(1, "/class/tty/tty1", "add", "tty");
# show results
print " wait for udevd processing about $time_out s... \n\n";
@@ -592,7 +592,7 @@
print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
print " when certain event sequence number is missing.\n";
print "Test expected visible results:\n";
- print " the delay time for event(add device /block/hda) should be about $time_out s.\n\n";
+ print " the delay time for event(add device /block/sda) should be about $time_out s.\n\n";
# local variables
my $time;
@@ -601,11 +601,11 @@
kill_daemon();
# check if device exist
- check_sysfs_device_exist("$sysfs/block/hda", "$sysfs/block/loop1");
+ check_sysfs_device_exist("$sysfs/block/sda", "$sysfs/class/tty/tty1");
# fork udevd
- udevsend(0, "/block/loop1", "add", "block");
- udevsend(1, "/block/loop1", "remove", "block");
+ udevsend(0, "/class/tty/tty1", "add", "tty");
+ udevsend(1, "/class/tty/tty1", "remove", "tty");
sleep 1;
# log current system date/time
@@ -613,7 +613,7 @@
system("rm -f $log_file");
# fork udevd
- udevsend(3, "/block/hda", "add", "block");
+ udevsend(3, "/block/sda", "add", "block");
# show results
print " wait for udevd processing about $time_out s... \n\n";
[-- Attachment #3: udevd-test.pl --]
[-- Type: application/octet-stream, Size: 19686 bytes --]
#!/usr/bin/perl -w
#
# udevd-test
#
# Copyright (C) Intel Corp, 2004
#
# Author: Yin Hu <hu.yin@intel.com>
#
# Provides automated testing of the udevd binary.This test script is self-contained.
# Before you run this script please modify $sysfs to locate your sysfs filesystem,
# modify $udevd_bin to locate your udevsend binary,
# modify $udev_bin to locate dummy udev script,
# modify $udev_bin2 to locate another dummy udev script ( amplify the execution time for test),
# modify $log_file to locate where udev script have placed the log file,
# modify $time_out to decide the time out for events,
# modify $udev_exe_time to decide the execution time for dummy udev script.
#
# Detail information of each test case please refer to the header of corresponding
# test case function.
#
#
# 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 $udevd_bin = "../../udevsend";
my $udev_bin = "$ENV{PWD}/udev-log-script.pl";
my $udev_bin2 = "$ENV{PWD}/udev-log-amplify.pl";
my $log_file = "/tmp/udev_log.txt";
my $time_out = 10;
my $udev_exe_time = 5;
# global variables
my $test_case = 0;
# common functions
sub kill_daemon {
system("killall udevd");
system("rm -f $log_file");
sleep 1;
}
sub udevsend {
# This function prepares corresponding environment variables
# and then call $udevd_bin to send event.
my ($seqnum, $devpath, $action, $subsystem, $udev_bin_tmp) = @_;
$ENV{DEVPATH} = $devpath;
$ENV{ACTION} = $action;
$udev_bin_tmp = $udev_bin if ( not $udev_bin_tmp );
$ENV{UDEV_BIN} = $udev_bin_tmp;
if ( $seqnum != -1) {
$ENV{SEQNUM} = $seqnum;
} else {
delete $ENV{SEQNUM};
}
return system("$udevd_bin $subsystem");
}
sub getDate {
# Get current date function
# If we want GTM time, simply pass GMT as first argument to this function.
my $format = @_;
my $date;
if( $format =~ /GMT/i ) {
$date = gmtime() . " GMT";
} else {
$date = localtime();
}
return $date;
}
sub cmpDate {
# This function should return a difference betweent date1 and date2
my ($date1, $date2) = @_;
my @monList = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec" );
my ( $m1, $m2, $tmp );
$date1 =~ s/([\D]*)$//g;
$date2 =~ s/([\D]*)$//g;
return if( (not $date1) or (not $date2) );
my $mon = 0;
my ( @T1 ) =
( $date1 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
my ( @T2 ) =
( $date2 =~ /([\d]+)[\s]+([\d]+):([\d]+):([\d]+)[\s]+([\d]+)/g );
foreach $tmp (@monList) {
$m1 = sprintf("%2.2d",$mon) if( $date1 =~ /$tmp/i );
$m2 = sprintf("%2.2d",$mon) if( $date2 =~ /$tmp/i );
$mon++;
}
my $dt1 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T1[4], $m1, $T1[0],
$T1[1], $T1[2], $T1[3]);
my $dt2 = sprintf("%4.4d%s%2.2d%2.2d%2.2d%2.2d", $T2[4], $m2, $T2[0],
$T2[1], $T2[2], $T2[3]);
my $ret = $dt1 - $dt2;
if ( $ret > 40 ) {
$ret = abs($ret-40);
}
return $ret;
}
sub check_count_and_time {
my $event_recv_time;
my $udev_fork_time;
my $log_ln_count = 0;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
if ( $diff > $time_out ) {
print " the delay time is: $diff \n";
print " udevd doesn't act properly. \n";
exit 1;
}
$log_ln_count++;
}
close(LOGF);
return $log_ln_count;
}
sub check_sysfs_device_exist {
# check if the designated devices exist
my @dev_list = @_;
my $dev;
foreach $dev (@dev_list) {
if (! -e $dev) {
print "the designated device $dev doesn't exist. please change a device!\n";
exit 1;
}
}
}
sub show_result {
my $event_recv_time;
my $udev_fork_time;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
}
close(LOGF);
}
sub show_result_tm_out {
my $event_recv_time;
my $udev_fork_time;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
if ( $diff < $time_out ) {
print " the delay time is: $diff \n";
print " udevd doesn't act properly. \n";
exit 1;
}
}
close(LOGF);
}
sub show_result_immediate {
my $event_recv_time;
my $udev_fork_time;
my $line;
my @content;
my @line_items;
my $diff;
($event_recv_time) = @_;
print " event receiving time: $event_recv_time\n\n";
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
foreach $line ( @content ) {
@line_items = split(/,/,$line);
print " device: $line_items[0], action: $line_items[1] \n";
print " forking udev time: $line_items[-1]";
$diff = cmpDate($line_items[-1], $event_recv_time);
print " the delay time is: $diff s \n\n";
if ( $diff > $time_out ) {
print " the delay time is: $diff \n";
print " udevd doesn't act properly. \n";
exit 1;
}
}
close(LOGF);
}
sub check_exe_time {
my @exe_time;
my $i = 0;
my $line;
my @content;
my @line_items;
my $diff;
open(LOGF, $log_file) || die "Opening file $log_file: $!";
@content = <LOGF>;
close(LOGF);
foreach $line ( @content ) {
@line_items = split(/,/,$line);
$exe_time[$i] = $line_items[-1];
$i++;
}
$diff = cmpDate($exe_time[1], $exe_time[0]);
if ( $diff < $udev_exe_time ) {
print " there are more than one udev instance for a single device at the same time. \n";
exit 1;
} else {
print " there is just one udev instance for a single device at the same time. \n";
}
}
# test case functions
sub run_no_seq_test {
print "Test case name: no sequence number test\n";
print "Test case purpose: check whether udevd forks udev immediately when environment variable SEQNUM is null.\n";
print "Test expected visible results: \n";
print " the delay time between event receiving and forking udev for udevd should be negligible, \n";
print " that is, udev should be forked at once. please notice the following time...\n\n";
# local variables
my $time;
#
# add devices event test
#
kill_daemon();
# check if devices /block/sda exist
check_sysfs_device_exist("$sysfs/block/sda");
# log current system date/time
$time = getDate();
# fork udevd
udevsend(-1, "/block/sda", "add", "block");
# check if execution is successful in time
sleep 1;
show_result_immediate($time);
print " fork udev (add device) at once successfully.\n\n";
#
# remove devices event test
#
system("rm -f $log_file");
# log current system date/time
$time = getDate();
# fork udevd
udevsend(-1, "/block/sda", "remove", "block");
# check if execution is successful in time
sleep 1;
show_result_immediate($time);
print " fork udev (remove device) at once successfully.\n\n";
print "this case is ok\n\n";
}
sub run_normal_seq_test {
print "Test case name: normal sequence number stress test\n";
print "Test case purpose: check whether udevd can fork massive udev instances for \n";
print " massive sequential events successfully. \n";
print "Test expected visible results: \n";
print " Populate all the devices in directory $sysfs/class/tty, fork udved to send add/remove \n";
print " event to udev for each device. \n";
print " We can see the delay time for each device should be negligible. \n\n";
# local variables
my @file_list;
my $file;
my $seq = 0;
my $time;
my $ret_seq;
# prepare
kill_daemon();
@file_list = glob "$sysfs/class/tty/*";
# log current system date/time for device add events
$time = getDate();
#
# add devices event test
#
print "add device events test: \n";
foreach $file (@file_list) {
udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "add", "tty");
# check if execution is successful
if ($? == 0) {
$seq++;
} else {
print "add event: error\n\n";
exit 1;
}
}
# we'd better wait the udev to create all the device for a few seconds
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out;
$ret_seq = check_count_and_time($time);
if ( $ret_seq != $seq ) {
print " add event: failed. some device-adding events fail to execute.\n\n";
exit 1;
} else {
print " $seq pieces of device-adding events have executed successfully.\n\n";
}
# log current system date/time for device remove events
$time = getDate();
#
# remove devices event test
#
print "remove device events test: \n";
kill_daemon();
@file_list = glob "$sysfs/class/tty/*";
$seq = 0;
foreach $file (@file_list) {
udevsend($seq, substr($file, length($sysfs), length($file)-length($sysfs)), "remove", "tty");
# check if execution is successful
if ($? == 0) {
$seq++;
} else {
print "remove event: error\n\n";
exit 1;
}
}
# we'd better wait the udev to create all the device for a few seconds
print " waiting for udev removing devices (about $time_out s)...\n";
sleep $time_out;
# show results
$ret_seq = check_count_and_time($time);
if ( $ret_seq != $seq ) {
print " remove event: failed. some device-removing events fail to execute.\n\n";
exit 1;
} else {
print " $seq pieces of device-removing events have executed successfully.\n\n";
print "this case is ok.\n\n";
}
}
sub run_random_seq_test {
print "Test case name: random sequence number test case,\n";
print "Test case purpose: check whether udevd can order the events with random sequence number \n";
print " and fork udev correctly. \n";
print "Test expected visible results: \n";
print " We have disordered the events sent to udevd, if udevd can order them correctly, the devices' \n";
print " add/remove sequence should be tty0, tty1, tty2. \n\n";
# local variables
my $time;
# check if devices /class/tty/tty0, tty1, tty2 exist
check_sysfs_device_exist("$sysfs/class/tty/tty0", "$sysfs/class/tty/tty1", "$sysfs/class/tty/tty2");
#
# add device events test
#
print "add device events test: \n";
kill_daemon();
# log current system date/time for device remove events
$time = getDate();
# parameters: 1 sequence number, 2 device, 3 action, 4 subsystem
udevsend(3, "/class/tty/tty2", "add", "tty");
udevsend(1, "/class/tty/tty0", "add", "tty");
udevsend(2, "/class/tty/tty1", "add", "tty");
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result_tm_out($time);
#
# remove device events test
#
print "\nremove device events test: \n";
kill_daemon();
# log current system date/time for device remove events
$time = getDate();
# fork udevd
udevsend(3, "/class/tty/tty2", "remove", "tty");
udevsend(2, "/class/tty/tty1", "remove", "tty");
udevsend(1, "/class/tty/tty0", "remove", "tty");
# show results
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result_tm_out($time);
print "this case is ok.\n\n";
}
sub run_expected_seq_test {
print "Test case name: expected sequence number test \n";
print "Test case purpose: check whether udevd fork udev immediately when the incoming event\n";
print " is exactly the expected event sequence number.\n";
print "Test expected visible results:\n";
print " first, udevd disposes disorder events(sequence number is 3,1,2,5,4,6),\n";
print " thus after disposed the expected event number for udevd is 7, when incoming event is 7, udevd\n";
print " should fork udev immediately, the delay time should be negligible. \n";
print " where: event 7 is (add device /class/tty/tty2) \n\n";
# local variables
my $time;
# check if devices /class/tty0, tty1, tty2 exist
check_sysfs_device_exist("$sysfs/class/tty/tty0", "$sysfs/class/tty/tty1", "$sysfs/class/tty/tty2");
# prepare
kill_daemon();
# parameters: 1 sequence number, 2 device, 3 action, 4 subsystem
udevsend(3, "/class/tty/tty2", "add", "tty");
udevsend(1, "/class/tty/tty0", "add", "tty");
udevsend(2, "/class/tty/tty1", "add", "tty");
udevsend(5, "/class/tty/tty1", "remove", "tty");
udevsend(4, "/class/tty/tty0", "remove", "tty");
udevsend(6, "/class/tty/tty2", "remove", "tty");
print " wait for udevd timing out for disorder events (about $time_out s) \n\n";
sleep $time_out+1;
system("rm -f $log_file");
# log current system date/time for device remove events
$time = getDate();
# show results
udevsend(7, "/class/tty/tty2", "add", "tty");
sleep 1;
print " event sequence number: 7 \n";
show_result_immediate($time);
print "this case is ok.\n\n";
}
sub run_single_instance_test {
print "Test case name: single instance running for a single device test \n";
print "Test case purpose: check whether udevd only fork one udev instance for a single\n";
print " device at the same time. For each event a udev instance is \n";
print " executed in the background. All further events for the same \n";
print " device are delayed until the execution is finished. This way \n";
print " there will never be more than one instance running for a single \n";
print " device at the same time.\n";
print "Test expected visible results:\n";
print " In this test we amplify the execution time of udev (about 5 seconds), first, \n";
print " we send a add event for device /block/sda, and then we send a remove event, so the \n";
print " execution of remove event should be delayed until add is finished. \n\n";
# local variables
my $time;
# prepare
kill_daemon();
# check if device exists
check_sysfs_device_exist("$sysfs/block/sda");
# log current system date/time
$time = getDate();
# fork udved
udevsend(-1, "/block/sda", "add", "block", $udev_bin2);
udevsend(-1, "/block/sda", "remove", "block", $udev_bin2);
# show results
print " wait for udevd processing about $udev_exe_time s... \n\n";
sleep $udev_exe_time+1;
show_result_immediate($time);
check_exe_time();
print "this case is ok\n\n";
}
sub run_same_events_test {
print "Test case name: event sequence number overlap test \n";
print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
print " when encountering a event with sequence number same as the pevious event. \n";
print "Test expected visible results:\n";
print " event ( remove device /block/sda ) should be no delay, \n";
print " event ( add device /class/tty/tty1 ) should be delayed for $time_out s than its previous \n";
print " event ( remove device /block/sda ) \n\n";
# local variables
my $time;
# prepare
kill_daemon();
# check if device exist
check_sysfs_device_exist("$sysfs/block/sda", "$sysfs/class/tty/tty1");
# fork udevd
udevsend(0, "/block/sda", "add", "block");
# log current system date/time
sleep 1;
$time = getDate();
system("rm -f $log_file");
# fork udevd
udevsend(1, "/block/sda", "remove", "block");
udevsend(1, "/class/tty/tty1", "add", "tty");
# show results
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result($time);
print "this case is ok\n\n";
}
sub run_missing_seq_test {
print "Test case name: missing sequence number test \n";
print "Test case purpose: check whether udevd doesn't fork udev untill time out\n";
print " when certain event sequence number is missing.\n";
print "Test expected visible results:\n";
print " the delay time for event(add device /block/sda) should be about $time_out s.\n\n";
# local variables
my $time;
# prepare
kill_daemon();
# check if device exist
check_sysfs_device_exist("$sysfs/block/sda", "$sysfs/class/tty/tty1");
# fork udevd
udevsend(0, "/class/tty/tty1", "add", "tty");
udevsend(1, "/class/tty/tty1", "remove", "tty");
sleep 1;
# log current system date/time
$time = getDate();
system("rm -f $log_file");
# fork udevd
udevsend(3, "/block/sda", "add", "block");
# show results
print " wait for udevd processing about $time_out s... \n\n";
sleep $time_out+1;
show_result($time);
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_missing_seq_test();
run_expected_seq_test();
run_same_events_test();
run_single_instance_test();
}
# 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_missing_seq_test();
} elsif ($test_case == 5) {
run_expected_seq_test();
} elsif ($test_case == 6) {
run_single_instance_test();
} elsif ($test_case == 7) {
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: missing event sequence number\n";
print " 5: the incoming event sequence number is right the expected sequence number\n";
print " 6: single udev instance on a single device at the same time\n";
print " 7: test event sequence number overlap\n";
print " 9: all the cases\n\n";
}
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (11 preceding siblings ...)
2004-04-14 3:11 ` Yin, Hu
@ 2004-04-14 12:18 ` Kay Sievers
2004-04-14 15:24 ` Nick Yin
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-14 12:18 UTC (permalink / raw)
To: linux-hotplug
On Wed, Apr 14, 2004 at 11:11:13AM +0800, Yin, Hu wrote:
> Kay,
> I'v changed the udevd-test.pl according to your suggestion and made a
> incremental patch called 100-udevd-test.patch. I'm not sure the patch is
> feasible so I also send the updated udevd-test.pl file to you.
> The main changes lie in location of sysfs filesystem and devices we
> choosed in our test.
> Would you like to give me further suggestions?
Fine, we are self contained now and depend only on the installed
/sbin/udevd. Is it intentional to wait in testrun_random_seq_test()
for the missing 0 sequence?.
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (12 preceding siblings ...)
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
15 siblings, 0 replies; 17+ messages in thread
From: Nick Yin @ 2004-04-14 15:24 UTC (permalink / raw)
To: linux-hotplug
Kay,
Yes. There i also want to test if udevd times out when the first event is
not 0 or the expecting event sequence number. But we can change the first
event sequence number to 0 if you think it's necessary.
In addition, it seems that we have to depend on /sbin/udevd, right?
Thanks a lot!
Nick
>From: Kay Sievers <kay.sievers@vrfy.org>
>To: "Yin, Hu" <hu.yin@intel.com>
>CC: linux-hotplug-devel@lists.sourceforge.net
>Subject: Re: Test script for udevd binary, Request for Comments!
>Date: Wed, 14 Apr 2004 14:18:29 +0200
>
>On Wed, Apr 14, 2004 at 11:11:13AM +0800, Yin, Hu wrote:
> > Kay,
> > I'v changed the udevd-test.pl according to your suggestion and made a
> > incremental patch called 100-udevd-test.patch. I'm not sure the patch is
> > feasible so I also send the updated udevd-test.pl file to you.
> > The main changes lie in location of sysfs filesystem and devices we
> > choosed in our test.
> > Would you like to give me further suggestions?
>
>Fine, we are self contained now and depend only on the installed
>/sbin/udevd. Is it intentional to wait in testrun_random_seq_test()
>for the missing 0 sequence?.
>
>thanks,
>Kay
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: IBM Linux Tutorials
>Free Linux tutorial presented by Daniel Robbins, President and CEO of
>GenToo technologies. Learn everything from fundamentals to system
>administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
>_______________________________________________
>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
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?pageþatures/virus
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (13 preceding siblings ...)
2004-04-14 15:24 ` Nick Yin
@ 2004-04-14 15:33 ` Kay Sievers
2004-04-15 1:03 ` Yin, Hu
15 siblings, 0 replies; 17+ messages in thread
From: Kay Sievers @ 2004-04-14 15:33 UTC (permalink / raw)
To: linux-hotplug
On Wed, Apr 14, 2004 at 03:24:12PM +0000, Nick Yin wrote:
> Yes. There i also want to test if udevd times out when the first event is
> not 0 or the expecting event sequence number. But we can change the first
> event sequence number to 0 if you think it's necessary.
No, it's fine, if it's intended.
> In addition, it seems that we have to depend on /sbin/udevd, right?
Yes, you could start the ../../udevd in the tree instead of letting udevsend
start /sbin/udevd - but I'm fine with both versions.
You may send it as one patch with a few lines for the Changelog to Greg
for inclusion in the tree now, if you like :)
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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
^ permalink raw reply [flat|nested] 17+ messages in thread
* RE: Test script for udevd binary, Request for Comments!
2004-04-07 10:53 Test script for udevd binary, Request for Comments! Yin, Hu
` (14 preceding siblings ...)
2004-04-14 15:33 ` Kay Sievers
@ 2004-04-15 1:03 ` Yin, Hu
15 siblings, 0 replies; 17+ messages in thread
From: Yin, Hu @ 2004-04-15 1:03 UTC (permalink / raw)
To: linux-hotplug
Kay,
Thank you! I want to add you into author list of these scripts, ok?
Of course I'd like to sent it to Greg for inclusion in the tree. I will
do it after your reply.
Nick
-----Original Message-----
From: Kay Sievers [mailto:kay.sievers@vrfy.org]
Sent: Wednesday, April 14, 2004 11:34 PM
To: Nick Yin
Cc: Yin, Hu; linux-hotplug-devel@lists.sourceforge.net
Subject: Re: Test script for udevd binary, Request for Comments!
On Wed, Apr 14, 2004 at 03:24:12PM +0000, Nick Yin wrote:
> Yes. There i also want to test if udevd times out when the first event
is
> not 0 or the expecting event sequence number. But we can change the
first
> event sequence number to 0 if you think it's necessary.
No, it's fine, if it's intended.
> In addition, it seems that we have to depend on /sbin/udevd, right?
Yes, you could start the ../../udevd in the tree instead of letting
udevsend
start /sbin/udevd - but I'm fine with both versions.
You may send it as one patch with a few lines for the Changelog to Greg
for inclusion in the tree now, if you like :)
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&opÌk
_______________________________________________
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
^ 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).