Skip to content
This repository
Newer
Older
100644 332 lines (262 sloc) 6.472 kb
71b3497c » jonjensen
2008-05-06 Remove extra/ copied CPAN modules.
1 # $Id: test.pl,v 2.6 2008-05-06 17:12:18 jon Exp $
43d511c9 » pajamian
2007-08-09 * Updated copyright headers to 2007 (closes bug #102)
2 #
3 # Copyright (C) 2002-2007 Interchange Development Group
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public
16 # License along with this program; if not, write to the Free
17 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 # MA 02110-1301 USA.
19
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
20 use Cwd;
21 use Config;
26665366 » perusionmike
2001-02-18 Changed test.pl to use Errno.pm to derive socket test error messages.
22 use Errno;
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
23
24 $cur_dir = cwd();
25 $failed = 0;
26
b31a690c » jonjensen
2001-07-18 Move DEV_4_7_0 development branch to repository trunk.
27 if($^O =~ /cygwin|win32/) {
28 print "no tests supported on Windows platform.\n";
29 exit;
30 }
31
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
32 die "Must be in build directory\n" unless -d 'blib';
33 die "No tests defined for Windows\n" if $^O =~ /win32/i;
34
35 $ENV{MINIVEND_ROOT} = "$cur_dir/blib";
36 $ENV{MINIVEND_PORT} = 8786 unless defined $ENV{MINIVEND_PORT};
37
d8cf3398 » perusionmike
2005-02-27 * Allow Interchange to install and run on a threaded system without
38 my $extra_cfg = '';
39
40 if(-f '_allow_threads') {
41 open(THR, ">$ENV{MINIVEND_ROOT}/_allow_threads")
42 or die "Can't write allow threads file: $!\n";
43 print THR "I agree not to hold anyone but myself responsible for the results of running an experimental system.\n";
44 close THR;
45 $^O =~ /linux/i and $extra_cfg = 'Variable MV_GETPPID_BROKEN 1';
46 }
47
d4330ccf » perusionmike
2000-09-23 Change minivend.cfg to interchange.cfg, etc.
48 open(CONFIG, ">$ENV{MINIVEND_ROOT}/interchange.cfg")
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
49 or die "open: $!\n";
50
51 print CONFIG <<EOF;
52 Catalog test $ENV{MINIVEND_ROOT} /test
53 TcpMap $ENV{MINIVEND_PORT} -
3c052942 » perusionmike
2002-02-04 * Keep test from giving warning about not being able to stat
54 TagDir 0
55 TagDir etc
d8cf3398 » perusionmike
2005-02-27 * Allow Interchange to install and run on a threaded system without
56 $extra_cfg
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
57 EOF
58
59 open(CONFIG, ">$ENV{MINIVEND_ROOT}/catalog.cfg")
60 or die "open: $!\n";
61
a5878f09 » jonjensen
2002-11-26 Update some old URLs and Red Hat references.
62 print CONFIG <<'EOF';
63 MailOrderTo info@icdevgroup.org
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
64 VendURL http:/test
65 SecureURL http:/test
66 Database products products.asc DEFAULT
67 EOF
68
69 mkdir ("$ENV{MINIVEND_ROOT}/etc", 0777);
70 mkdir ("$ENV{MINIVEND_ROOT}/pages", 0777);
71 mkdir ("$ENV{MINIVEND_ROOT}/products", 0777);
72 mkdir ("$ENV{MINIVEND_ROOT}/session", 0777);
71b3497c » jonjensen
2008-05-06 Remove extra/ copied CPAN modules.
73 my $lib = "$cur_dir/blib/lib";
74 if ($ENV{PERL5LIB}) {
75 $ENV{PERL5LIB} .= ":$lib";
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
76 }
77 else {
71b3497c » jonjensen
2008-05-06 Remove extra/ copied CPAN modules.
78 $ENV{PERL5LIB} = $lib;
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
79 }
80
81 my $testnum = 1;
82
83 open(CONFIG, ">$ENV{MINIVEND_ROOT}/products/products.asc")
84 or die "open: $!\n";
85
86 print CONFIG <<EOF;
87 sku description price
88 test test product 1
89 EOF
90
91 open(CONFIG, ">$ENV{MINIVEND_ROOT}/pages/catalog.html")
92 or die "open: $!\n";
93
94 for(1 .. 100) {
95 print CONFIG <<EOF;
96 test succeeded test succeeded
97 EOF
98 }
99
100 close CONFIG;
101
102 $| = 1;
103
104 print "server/unixmode.......";
ca460c8a » Eric Zarko
2000-09-20 s:blib/script/minivend:blib/script/interchange:
105 if ( system qq{$Config{'perlpath'} blib/script/interchange -q -r -u} ) {
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
106 print "not ok $testnum\n";
107 $failed++;
108 }
109 else {
110 print "ok $testnum\n";
111 }
112 $testnum++;
113
114 print "server/startup........";
115 for(1 .. 5) {
d4330ccf » perusionmike
2000-09-23 Change minivend.cfg to interchange.cfg, etc.
116 open(PID, "$ENV{MINIVEND_ROOT}/etc/interchange.pid") or sleep $_, next;
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
117 $pid = <PID>;
118 $pid =~ s/\D+//g;
119 last;
120 }
121
122 for(1 .. 5) {
123 unless (-e "$ENV{MINIVEND_ROOT}/etc/socket") {
124 system "ls -l $ENV{MINIVEND_ROOT}/*";
125 sleep $_;
126 next;
127 }
128 $LINK_FILE = "$ENV{MINIVEND_ROOT}/etc/socket";
129 last;
130 }
131
132 if(! $pid or ! $LINK_FILE) {
133 print "not ok $testnum\n";
134 $failed++;
135 }
136 else {
137 print "ok $testnum\n";
138 }
139 $testnum++;
140
141 use Socket;
8ef654ad » jonjensen
2003-08-01 Use 127.0.0.1 instead of localhost for default INET host values to avoid
142 my $LINK_HOST = '127.0.0.1';
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
143 my $LINK_PORT = $ENV{MINIVEND_PORT};
144 my $LINK_TIMEOUT = 15;
145 my $ERROR_ACTION = "-none";
146
147 $ENV{SCRIPT_NAME} = "/test";
148 $ENV{PATH_INFO} = "/catalog";
149 $ENV{REMOTE_ADDR} = "TEST";
150 $ENV{REQUEST_METHOD} = "GET";
151
152 sub send_arguments {
153
154 my $count = @ARGV;
155 my $val = "arg $count\n";
156 for(@ARGV) {
157 $val .= length($_);
158 $val .= " $_\n";
159 }
160 return $val;
161 }
162
163 sub send_environment () {
164 my (@tmp) = keys %ENV;
165 my $count = @tmp;
166 my ($str);
167 my $val = "env $count\n";
168 for(@tmp) {
169 $str = "$_=$ENV{$_}";
170 $val .= length($str);
171 $val .= " $str\n";
172 }
173 return $val;
174 }
175
176 $SIG{PIPE} = sub { die("signal"); };
177 $SIG{ALRM} = sub { die("not communicating with server\n"); exit 1; };
178
179
180
181 print "link/unixmode.........";
182 eval {
183 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!\n";
184
185 my $ok;
186 do {
187 $ok = connect(SOCK, sockaddr_un($LINK_FILE));
26665366 » perusionmike
2001-02-18 Changed test.pl to use Errno.pm to derive socket test error messages.
188 } while ( ! defined $ok and $!{EINTR} || $!{ENOENT});
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
189
190 my $undef = ! defined $ok;
191 die "ok=$ok def: $undef connect: $!\n" if ! $ok;
192
193 select SOCK;
194 $| = 1;
195 select STDOUT;
196
197 print SOCK send_arguments();
198 print SOCK send_environment();
199 print SOCK "end\n";
200
201
202 while(<SOCK>) {
203 $result .= $_;
204 }
205
206 close (SOCK) or die "close: $!\n";
207
208 };
209
210 if(length($result) > 500 and $result =~ /test succeeded/i) {
211 print "ok $testnum\n";
212 }
213 else {
214 print "not ok $testnum";
215 print " ($@)" if $@;
216 print "\n";
217 print <<EOF;
218
219 # When the above test fails, it may be due to your ISP or some other
220 # mechanism blocking port 8786.
221
222 EOF
223 $failed++;
224 }
225 $testnum++;
226
227 print "server/inetmode.......";
ca460c8a » Eric Zarko
2000-09-20 s:blib/script/minivend:blib/script/interchange:
228 if ( system qq{$Config{'perlpath'} blib/script/interchange -q -r -i} ) {
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
229 print "not ok $testnum\n";
230 $failed++;
231 }
232 else {
233 print "ok $testnum\n";
234 }
235 $testnum++;
236
237 alarm 0;
238 alarm $LINK_TIMEOUT;
239
240 $result = '';
241
242 print "link/inetmode.........";
243 eval {
244 $remote = $LINK_HOST;
245 $port = $LINK_PORT;
246
247 if ($port =~ /\D/) { $port = getservbyname($port, 'tcp'); }
248
249 die("no port") unless $port;
250
251 $iaddr = inet_aton($remote);
252 $paddr = sockaddr_in($port,$iaddr);
253
254 $proto = getprotobyname('tcp');
255
256 socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n";
257
258 my $ok;
259
260 do {
261 $ok = connect(SOCK, $paddr);
26665366 » perusionmike
2001-02-18 Changed test.pl to use Errno.pm to derive socket test error messages.
262 } while ( ! defined $ok and $!{EINTR});
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
263
264 my $undef = ! defined $ok;
265 die "ok=$ok def: $undef connect: $!\n" if ! $ok;
266
267 select SOCK;
268 $| = 1;
269 select STDOUT;
270
271 print SOCK send_arguments();
272 print SOCK send_environment();
273 print SOCK "end\n";
274
275
276 while(<SOCK>) {
277 $result .= $_;
278 }
279
280 close (SOCK) or die "close: $!\n";
281
282 };
283
284 alarm 0;
285
286 if(length($result) > 500 and $result =~ /test succeeded/i) {
287 print "ok $testnum\n";
288 }
289 else {
290 print "not ok $testnum\n";
291 $failed++;
292 }
293 $testnum++;
294
295 print "server/control........";
ca460c8a » Eric Zarko
2000-09-20 s:blib/script/minivend:blib/script/interchange:
296 if ( system qq{$Config{'perlpath'} blib/script/interchange -q -stop} ) {
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
297 print "not ok $testnum\n";
298 $failed++;
299 }
300
301 my $pid_there;
302
303 for(1 .. 5) {
d4330ccf » perusionmike
2000-09-23 Change minivend.cfg to interchange.cfg, etc.
304 $pid_there = -f 'blib/etc/interchange.pid';
5550c3ad » perusionmike
2000-05-26 Initial import of changed Challenger with UI instead of Minimate.
305 last unless $pid_there;
306 sleep 1;
307 }
308
309 if ($pid_there) {
310 print "not ok $testnum\n";
311 $failed++;
312 }
313 else {
314 print "ok $testnum\n";
315 }
316 $testnum++;
317
318
319 $testnum--;
320 print "$testnum tests run";
321 if($failed) {
322 print " -- $failed/$testnum failed.\n";
323 exit 1;
324 }
325 else {
326 print ", all tests successful.\n";
327 exit 0;
328 }
329
330 END {
331 kill 'KILL', $pid if $pid;
332 }
Something went wrong with that request. Please try again.