summaryrefslogtreecommitdiff
path: root/test/udevd-test/udev-log-amplify.pl
blob: c2d472397414ddd4c5a248bd65d39b0a7f57b329 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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;
}