~drizzle-trunk/drizzle/development

0.67.305 by Bernt M. Johnsen
Copyright headres and license added
1
# Copyright (C) 2008-2010 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
7
#
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16
# USA
17
0.67.1 by Philip Stoev
initial import from internal tree
18
package GenTest;
19
use base 'Exporter';
0.99.22 by Bernt M. Johnsen
ISO-8601 timestamps, both for logging and XML(using UTC)
20
0.108.2 by John H. Embretsen
DBServer: Add basic support for Mac OS X by having utility functions to check for darwin, and looking for libmysqlclient.dylib instead of .so.
21
@EXPORT = ('say', 'sayFile', 'tmpdir', 'safe_exit', 
22
           'osWindows', 'osLinux', 'osSolaris', 'osMac',
23
           'isoTimestamp', 'isoUTCTimestamp', 'rqg_debug', 'unix2winPath');
0.67.1 by Philip Stoev
initial import from internal tree
24
25
use strict;
26
27
use Cwd;
28
use POSIX;
0.82.7 by Bernt M. Johnsen
Merger + fixes
29
use Carp;
0.67.1 by Philip Stoev
initial import from internal tree
30
31
my $tmpdir;
32
33
1;
34
35
sub BEGIN {
36
	foreach my $tmp ($ENV{TMP}, $ENV{TEMP}, $ENV{TMPDIR}, '/tmp', '/var/tmp', cwd()."/tmp" ) {
37
		if (
38
			(defined $tmp) &&
39
			(-e $tmp)
40
		) {
41
			$tmpdir = $tmp;
42
			last;
43
		}
44
	}
45
0.67.399 by John H. Embretsen
Fix for tmpdir bug in GenTest.pm:
46
	if (defined $tmpdir) {
47
		if (
48
			($^O eq 'MSWin32') ||
49
			($^O eq 'MSWin64')
50
		) {
51
			$tmpdir = $tmpdir.'\\';
52
		} else {
53
			$tmpdir = $tmpdir.'/';
54
		}
0.67.1 by Philip Stoev
initial import from internal tree
55
	}
56
0.82.7 by Bernt M. Johnsen
Merger + fixes
57
	croak("Unable to locate suitable temporary directory.") if not defined $tmpdir;
0.67.1 by Philip Stoev
initial import from internal tree
58
	
59
	return 1;
60
}
61
62
sub new {
63
	my $class = shift;
64
	my $args = shift;
65
66
	my $obj = bless ([], $class);
67
68
        my $max_arg = (scalar(@_) / 2) - 1;
69
70
        foreach my $i (0..$max_arg) {
71
                if (exists $args->{$_[$i * 2]}) {
0.67.250 by Philip Stoev
protection against duplicate arguments and against constuctor constants with the same value
72
			if (defined $obj->[$args->{$_[$i * 2]}]) {
73
				carp("Argument '$_[$i * 2]' passed twice to ".$class.'->new()');
74
			} else {
75
	                        $obj->[$args->{$_[$i * 2]}] = $_[$i * 2 + 1];
76
			}
0.67.1 by Philip Stoev
initial import from internal tree
77
                } else {
0.82.7 by Bernt M. Johnsen
Merger + fixes
78
                        carp("Unkown argument '$_[$i * 2]' to ".$class.'->new()');
0.67.1 by Philip Stoev
initial import from internal tree
79
                }
80
        }
81
82
        return $obj;
83
}
84
85
sub say {
86
	my $text = shift;
87
88
	if ($text =~ m{[\r\n]}sio) {
89
	        foreach my $line (split (m{[\r\n]}, $text)) {
0.99.22 by Bernt M. Johnsen
ISO-8601 timestamps, both for logging and XML(using UTC)
90
			print "# ".isoTimestamp()." $line\n";
0.67.1 by Philip Stoev
initial import from internal tree
91
		}
92
	} else {
0.99.22 by Bernt M. Johnsen
ISO-8601 timestamps, both for logging and XML(using UTC)
93
		print "# ".isoTimestamp()." $text\n";
0.67.1 by Philip Stoev
initial import from internal tree
94
	}
95
}
96
0.67.331 by Bernt M. Johnsen
sayFile + quote for spaces
97
sub sayFile {
98
    my ($file) = @_;
99
0.67.342 by Bernt M. Johnsen
Enable runall-new test. Start replication properly and test that replication is working
100
    say("--------- Contents of $file -------------");
0.67.331 by Bernt M. Johnsen
sayFile + quote for spaces
101
    open FILE,$file;
102
    while (<FILE>) {
0.67.342 by Bernt M. Johnsen
Enable runall-new test. Start replication properly and test that replication is working
103
	say("| ".$_);
0.67.331 by Bernt M. Johnsen
sayFile + quote for spaces
104
    }
105
    close FILE;
0.67.342 by Bernt M. Johnsen
Enable runall-new test. Start replication properly and test that replication is working
106
    say("----------------------------------");
0.67.331 by Bernt M. Johnsen
sayFile + quote for spaces
107
}
108
0.67.1 by Philip Stoev
initial import from internal tree
109
sub tmpdir {
110
	return $tmpdir;
111
}
112
113
sub safe_exit {
114
	my $exit_status = shift;
115
	POSIX::_exit($exit_status);
116
}
117
0.67.381 by Bernt M. Johnsen
Adjustments after merge
118
sub osWindows {
0.67.1 by Philip Stoev
initial import from internal tree
119
	if (
120
		($^O eq 'MSWin32') ||
121
	        ($^O eq 'MSWin64')
122
	) {
123
		return 1;
124
	} else {
125
		return 0;
126
	}	
127
}
128
0.67.381 by Bernt M. Johnsen
Adjustments after merge
129
sub osLinux {
0.101.23 by John H. Embretsen
Introduce sub for check for linux OS in GenTest. Use this and solaris() in XML/Report.pm.
130
	if ($^O eq 'linux') {
131
		return 1;
132
	} else {
133
		return 0;
134
	}
135
}
136
0.67.381 by Bernt M. Johnsen
Adjustments after merge
137
sub osSolaris {
0.67.296 by Bernt M. Johnsen
dbx-based stack dump Solaris with pstack/c++filt as alternative
138
	if ($^O eq 'solaris') {
139
		return 1;
140
	} else {
141
		return 0;
142
	}	
143
}
144
0.108.2 by John H. Embretsen
DBServer: Add basic support for Mac OS X by having utility functions to check for darwin, and looking for libmysqlclient.dylib instead of .so.
145
sub osMac {
146
    if ($^O eq 'darwin') {
147
        return 1;
148
    } else {
149
        return 0;
150
    }
151
}
152
0.99.22 by Bernt M. Johnsen
ISO-8601 timestamps, both for logging and XML(using UTC)
153
sub isoTimestamp {
0.67.1 by Philip Stoev
initial import from internal tree
154
	my $datetime = shift;
155
156
	my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = defined $datetime ? localtime($datetime) : localtime();
0.99.22 by Bernt M. Johnsen
ISO-8601 timestamps, both for logging and XML(using UTC)
157
	return sprintf("%04d-%02d-%02dT%02d:%02d:%02d", $year+1900, $mon+1 ,$mday ,$hour, $min, $sec);
0.101.22 by John H. Embretsen
Merge from lp:randgen, revno 376.
158
0.99.22 by Bernt M. Johnsen
ISO-8601 timestamps, both for logging and XML(using UTC)
159
}
160
161
sub isoUTCTimestamp {
162
	my $datetime = shift;
163
164
	my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = defined $datetime ? gmtime($datetime) : gmtime();
165
	return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year+1900, $mon+1 ,$mday ,$hour, $min, $sec);
0.67.1 by Philip Stoev
initial import from internal tree
166
	
167
}
168
0.107.11 by John H. Embretsen
runall-new.pl: Convert paths fed to system utils on windows to win-style to avoid errors (there are probably more paths to be converted, but this is a start). Add utility function unix2winPath() to GenTest.pm.
169
# unix2winPath:
170
#   Converts the given file path from unix style to windows native style
171
#   by replacing all forward slashes to backslashes.
172
sub unix2winPath {
173
    my $path = shift;
174
    $path =~ s/\//\\/g; # replace "/" with "\"
175
    return $path;
176
}
177
0.67.9 by Philip Stoev
merge from internal tree
178
sub rqg_debug {
179
	if ($ENV{RQG_DEBUG}) {
180
		return 1;
181
	} else {
182
		return 0;
183
	}
184
}
185
0.67.1 by Philip Stoev
initial import from internal tree
186
1;