5a6ad77b146b658571d3ebb35dc00182ace6aa5c
[platform/upstream/curl.git] / tests / testcurl.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://curl.haxx.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 # $Id$
23 ###########################################################################
24
25 ###########################
26 #  What is This Script?
27 ###########################
28
29 # testcurl.pl is the master script to use for automatic testing of CVS-curl.
30 # This is written for the purpose of being run from a crontab job or similar
31 # at a regular interval. The output will be suitable to be mailed automaticly
32 # to "curl-autocompile@haxx.se" to be dealt with automatically.  The most
33 # current build status (with a resonable backlog) will be published on the
34 # curl site, at http://curl.haxx.se/auto/
35
36 # USAGE:
37 # testcurl.pl [--target=your_os] [curl-daily-name] > output
38
39 # Updated:
40 # v1.7 22-Jun-04 - added --target option for other platform targets.
41 # v1.2  8-Mar-04 - rewritten in perl
42 # v1.1  6-Nov-03 - to take an optional parameter, the name of a daily-build
43 #                  directory.  If present, build from that directory, otherwise
44 #                  perform a normal CVS build.
45
46 use strict;
47
48 use Cwd;
49
50 # Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
51 BEGIN { $^W = 1; }
52
53 use vars qw($version $fixed $infixed $CURLDIR $CVS $pwd $build $buildlog
54             $buildlogname $gnulikebuild $targetos $confsuffix $binext $libext);
55 use vars qw($name $email $desc $confopts $setupfile $mktarball);
56
57 # version of this script
58 $version='$Revision$';
59 $fixed=0;
60
61 # Determine if we're running from CVS or a canned copy of curl,
62 # or if we got a specific target option or setup file option.
63 $CURLDIR="curl";
64 $CVS=1;
65 $targetos = '';
66 $setupfile = 'setup';
67 $mktarball = '';
68 while ($ARGV[0]) {
69   if ($ARGV[0] =~ /--target=/) {
70     $targetos = (split(/=/, shift @ARGV))[1];
71   } elsif ($ARGV[0] =~ /--setup=/) {
72     $setupfile = (split(/=/, shift @ARGV))[1];
73   } elsif ($ARGV[0] =~ /--mktarball=/) {
74     $mktarball = (split(/=/, shift @ARGV))[1];
75   } else {
76     $CURLDIR=shift @ARGV;
77     $CVS=0;
78   }
79 }
80
81 # Do the platform-specific stuff here
82 $gnulikebuild = 1;
83 $confsuffix = '';
84 $binext = '';
85 $libext = '.la'; # .la since both libcurl and libcares are made with libtool
86 if ($^O eq 'MSWin32' || $targetos ne '') {
87   $gnulikebuild = 0;
88   if ($targetos eq '') {
89     # If no target defined on Win32 lets assume vc
90     $targetos = 'vc';
91   }
92   if ($targetos =~ /vc/ || $targetos =~ /mingw32/ || $targetos =~ /borland/) {
93     $confsuffix = '-win32';
94     $binext = '.exe';
95     $libext = '.lib' if ($targetos =~ /vc/ || $targetos =~ /borland/);
96     $libext = '.a' if ($targetos =~ /mingw32/);
97   } elsif ($targetos =~ /netware/) {
98     $binext = '.nlm';
99     $libext = '.lib';
100   }
101 }
102
103 $ENV{LANG}="C";
104
105 sub rmtree($) {
106     my $target = $_[0];
107     if ($^O eq 'MSWin32') {
108       foreach (glob($target)) {
109         s:/:\\:g;
110         system("rd /s /q $_");
111       }
112     } else {
113       system("rm -rf $target");
114     }
115 }
116
117 sub grepfile($$) {
118     my ($target, $fn) = @_;
119     open(F, $fn) or die;
120     while (<F>) {
121       if (/$target/) {
122         close(F);
123         return 1;
124       }
125     }
126     close(F);
127     return 0;
128 }
129
130 sub logit($) {
131     my $text=$_[0];
132     if ($text) {
133       print "testcurl: $text\n";
134     }
135 }
136
137 sub mydie($){
138     my $text=$_[0];
139     logit "$text";
140     chdir $pwd; # cd back to the original root dir
141
142     if ($pwd && $build) {
143       # we have a build directory name, remove the dir
144       logit "removing the $build dir";
145       rmtree "$pwd/$build";
146     }
147     if (-r $buildlog) {
148       # we have a build log output file left, remove it
149       logit "removing the $buildlogname file";
150       unlink "$buildlog";
151     }
152     logit "ENDING HERE"; # last line logged!
153     exit 1;
154 }
155
156 if (open(F, "$setupfile")) {
157   while (<F>) {
158     if (/(\w+)=(.*)/) {
159       eval "\$$1=$2;";
160     }
161   }
162   close(F);
163   $infixed=$fixed;
164 } else {
165   $infixed=0;    # so that "additional args to configure" works properly first time...
166 }
167
168 if (!$name) {
169   print "please enter your name\n";
170   $name = <>;
171   chomp $name;
172   $fixed=1;
173 }
174
175 if (!$email) {
176   print "please enter your contact email address\n";
177   $email = <>;
178   chomp $email;
179   $fixed=2;
180 }
181
182 if (!$desc) {
183   print "please enter a one line system description\n";
184   $desc = <>;
185   chomp $desc;
186   $fixed=3;
187 }
188
189 if (!$confopts) {
190   if ($infixed < 4) {
191     print "please enter your additional arguments to configure\n";
192     print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
193     $confopts = <>;
194     chomp $confopts;
195     $fixed=4;
196   }
197 }
198
199
200 if ($fixed > 0) {
201   open(F, ">$setupfile") or die;
202   print F "name='$name'\n";
203   print F "email='$email'\n";
204   print F "desc='$desc'\n";
205   print F "confopts='$confopts'\n";
206   print F "fixed='$fixed'\n";
207   close(F);
208 }
209
210 logit "STARTING HERE"; # first line logged
211 logit "NAME = $name";
212 logit "EMAIL = $email";
213 logit "DESC = $desc";
214 logit "CONFOPTS = $confopts";
215 logit "CFLAGS = ".($ENV{CFLAGS} ? $ENV{CFLAGS} : "");
216 logit "CC = ".($ENV{CC} ? $ENV{CC} : "");
217 logit "target = ".($targetos ? $targetos : "");
218 logit "version = $version";
219 logit "date = ".(scalar gmtime)." UTC";
220
221 # Make $pwd to become the path without newline. We'll use that in order to cut
222 # off that path from all possible logs and error messages etc.
223 $pwd = cwd();
224
225 if (-d $CURLDIR) {
226   if ($CVS && -d "$CURLDIR/CVS") {
227     logit "$CURLDIR is verified to be a fine source dir";
228     # remove the generated sources to force them to be re-generated each
229     # time we run this test
230     unlink "$CURLDIR/lib/getdate.c";
231     unlink "$CURLDIR/src/hugehelp.c";
232   } elsif (!$CVS && -f "$CURLDIR/tests/testcurl.pl") {
233     logit "$CURLDIR is verified to be a fine daily source dir"
234   } else {
235     mydie "$CURLDIR is not a daily source dir or checked out from CVS!"
236   }
237 }
238 $build="build-$$";
239 $buildlogname="buildlog-$$";
240 $buildlog="$pwd/$buildlogname";
241
242 # remove any previous left-overs
243 rmtree "build-*";
244 rmtree "buildlog-*";
245
246 # this is to remove old build logs that ended up in the wrong dir
247 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
248
249 # create a dir to build in
250 mkdir $build, 0777;
251
252 if (-d $build) {
253   logit "build dir $build was created fine";
254 } else {
255   mydie "failed to create dir $build";
256 }
257
258 # get in the curl source tree root
259 chdir $CURLDIR;
260
261 # Do the CVS thing, or not...
262 if ($CVS) {
263
264   # this is a temporary fix to make things work again, remove later
265   logit "remove ares/aclocal.m4";
266   unlink "ares/aclocal.m4";
267
268   logit "update from CVS";
269   my $cvsstat;
270
271   sub cvsup() {
272     # update quietly to the latest CVS
273     logit "run cvs up";
274     system("cvs -Q up -dP 2>&1");
275
276     $cvsstat=$?;
277
278     # return !RETURNVALUE so that errors return 0 while goodness
279     # returns 1
280     return !$cvsstat;
281   }
282
283   my $att=0;
284   while (!cvsup()) {
285     $att++;
286     logit "failed CVS update attempt number $att.";
287     if ($att > 10) {
288       $cvsstat=111;
289       last; # get out of the loop
290     }
291     sleep 5;
292   }
293
294   if ($cvsstat != 0) {
295     mydie "failed to update from CVS ($cvsstat), exiting";
296   }
297
298   # remove possible left-overs from the past
299   unlink "configure";
300   unlink "autom4te.cache";
301
302   if ($gnulikebuild) {
303     # generate the build files
304     logit "invoke buildconf, but filter off the silly aclocal warnings";
305     open(F, "./buildconf 2>&1 |") or die;
306     open(LOG, ">$buildlog") or die;
307     while (<F>) {
308       next if /warning: underquoted definition of/;
309       print;
310       print LOG;
311     }
312     close(F);
313     close(LOG);
314
315     if (grepfile("^buildconf: OK", $buildlog)) {
316       logit "buildconf was successful";
317     } else {
318       mydie "buildconf was NOT successful";
319     }
320
321     if($confopts =~ /--enable-ares/) {
322         logit "run buildconf for ares";
323         chdir "ares";
324         open(F, "./buildconf 2>&1 |") or die;
325         open(LOG, ">$buildlog") or die;
326         while (<F>) {
327             next if /warning: underquoted definition of/;
328             print;
329             print LOG;
330         }
331         close(F);
332         close(LOG);
333         chdir "..";
334     }
335
336   } else {
337       logit "buildconf was successful (dummy message)";
338   }
339 }
340
341 if ($gnulikebuild) {
342   if (-f "configure") {
343     logit "configure created";
344   } else {
345     mydie "no configure created";
346   }
347 } else {
348   logit "configure created (dummy message)"; # dummy message to feign success
349 }
350
351 # change to build dir
352 chdir "$pwd/$build";
353
354 if ($gnulikebuild) {
355   # run configure script
356   system("../$CURLDIR/configure $confopts 2>&1");
357
358   if (-f "lib/Makefile") {
359     logit "configure seems to have finished fine";
360   } else {
361     mydie "configure didn't work";
362   }
363 } else {
364   if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
365     system("xcopy /s /q ..\\$CURLDIR .");
366     system("buildconf.bat");
367   } elsif (($^O eq 'linux') || ($targetos =~ /netware/)) {
368     system("cp -afr ../$CURLDIR/* ."); 
369     system("cp -af ../$CURLDIR/Makefile.dist Makefile"); 
370     system("make -i -C lib -f Makefile.$targetos prebuild");
371     system("make -i -C src -f Makefile.$targetos prebuild");
372   }
373 }
374
375 logit "display lib/config$confsuffix.h";
376 open(F, "lib/config$confsuffix.h") or die "lib/config$confsuffix.h: $!";
377 while (<F>) {
378   print if /^ *#/;
379 }
380 close(F);
381
382 logit "display src/config$confsuffix.h";
383 open(F, "src/config$confsuffix.h") or die "src/config$confsuffix.h: $!";
384 while (<F>) {
385   print if /^ *#/;
386 }
387 close(F);
388
389 if (grepfile("define USE_ARES", "lib/config$confsuffix.h")) {
390   logit "setup to build ares";
391
392   logit "build ares";
393   chdir "ares";
394
395   if ($targetos ne '') {
396       open(F, "make -f Makefile.$targetos 2>&1 |") or die;
397   } else {
398       open(F, "make 2>&1 |") or die;
399   }
400   while (<F>) {
401     s/$pwd//g;
402     print;
403   }
404   close(F);
405
406   if (-f "libcares$libext") {
407     logit "ares is now built successfully (libcares$libext)";
408   } else {
409     logit "ares build failed (libares$libext)";
410   }
411
412   # cd back to the curl build dir
413   chdir "$pwd/$build";
414 }
415
416 logit "run make";
417 if ($gnulikebuild) {
418   open(F, "make -i 2>&1 |") or die;
419   while (<F>) {
420     s/$pwd//g;
421     print;
422   }
423   close(F);
424 } else {
425   if ($^O eq 'MSWin32') {
426     if ($targetos =~ /vc/) {
427       open(F, "nmake -i $targetos|") or die;
428     } else {
429       open(F, "make -i $targetos |") or die;
430     }
431   } else {
432     open(F, "make -i $targetos 2>&1 |") or die;
433   }
434   while (<F>) {
435     s/$pwd//g;
436     print;
437   }
438   close(F);
439 }
440
441 if (-f "lib/libcurl$libext") {
442   logit "lib/libcurl was created fine (libcurl$libext)";
443 } else {
444   logit "lib/libcurl was not created (libcurl$libext)";
445 }
446
447 if (-f "src/curl$binext") {
448   logit "src/curl was created fine (curl$binext)";
449 } else {
450   mydie "src/curl was not created (curl$binext)";
451 }
452
453 if ($targetos ne '' && $targetos =~ /netware/) {
454   if (-f '../../curlver') {
455     system('../../curlver');
456   }
457 } else {
458   logit "display curl$binext --version output";
459   system("./src/curl$binext --version");
460 }
461
462 if ($gnulikebuild) {
463   logit "run make test-full";
464   open(F, "make test-full 2>&1 |") or die;
465   open(LOG, ">$buildlog") or die;
466   while (<F>) {
467     s/$pwd//g;
468     print;
469     print LOG;
470   }
471   close(F);
472   close(LOG);
473
474   if (grepfile("^TEST", $buildlog)) {
475     logit "tests were run";
476   } else {
477     mydie "test suite failure";
478   }
479
480   if (grepfile("^TESTFAIL:", $buildlog)) {
481     logit "the tests were not successful";
482   } else {
483     logit "the tests were successful!";
484   }
485 } else {
486   print "TESTDONE: 1 tests out of 0 (dummy message)\n"; # dummy message to feign success
487 }
488
489 # create a tarball if we got that option.
490 if (($mktarball ne '') && (-f $mktarball)) {
491   system($mktarball);
492 }
493
494 # mydie to cleanup
495 mydie "ending nicely";