catch up new lib extension when build with gcc/nlmconv.
[platform/upstream/curl.git] / tests / testcurl.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2007, 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 is suitable to be mailed to
32 # curl-autocompile@haxx.se to be dealt with automatically (make sure the
33 # subject includes the word "autobuild" as the mail gets silently discarded
34 # otherwise).  The most current build status (with a resonable backlog) will
35 # be published on the curl site, at http://curl.haxx.se/auto/
36
37 # USAGE:
38 # testcurl.pl [options] [curl-daily-name] > output
39
40 # Options:
41 #
42 # --configure=[options]    Configure options
43 # --crosscompile           This is a crosscompile
44 # --desc=[desc]            Description of your test system
45 # --email=[email]          Set email address to report as
46 # --mktarball=[command]    Command to run after completed test
47 # --name=[name]            Set name to report as
48 # --nocvsup                Don't update from CVS even though it is a CVS tree
49 # --nobuildconf            Don't run buildconf
50 # --runtestopts=[options]  Options to pass to runtests.pl
51 # --setup=[file name]      File name to read setup from (deprecated)
52 # --target=[your os]       Specify your target environment.
53 #
54 # if [curl-daily-name] is omitted, a 'curl' CVS directory is assumed.
55 #
56
57 use strict;
58
59 use Cwd;
60
61 # Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
62 #BEGIN { $^W = 1; }
63
64 use vars qw($version $fixed $infixed $CURLDIR $CVS $pwd $build $buildlog
65             $buildlogname $configurebuild $targetos $confsuffix $binext
66             $libext);
67 use vars qw($name $email $desc $confopts $runtestopts $setupfile $mktarball
68             $nocvsup $nobuildconf $crosscompile $timestamp);
69
70 # version of this script
71 $version='$Revision$';
72 $fixed=0;
73
74 # Determine if we're running from CVS or a canned copy of curl,
75 # or if we got a specific target option or setup file option.
76 $CURLDIR="curl";
77 $CVS=1;
78 $setupfile = 'setup';
79 while ($ARGV[0]) {
80   if ($ARGV[0] =~ /--target=/) {
81     $targetos = (split(/=/, shift @ARGV))[1];
82   }
83   elsif ($ARGV[0] =~ /--setup=/) {
84     $setupfile = (split(/=/, shift @ARGV))[1];
85   }
86   elsif ($ARGV[0] =~ /--mktarball=/) {
87     $mktarball = (split(/=/, shift @ARGV))[1];
88   }
89   elsif ($ARGV[0] =~ /--name=/) {
90     $name = (split(/=/, shift @ARGV))[1];
91   }
92   elsif ($ARGV[0] =~ /--email=/) {
93     $email = (split(/=/, shift @ARGV))[1];
94   }
95   elsif ($ARGV[0] =~ /--desc=/) {
96     $desc = (split(/=/, shift @ARGV))[1];
97   }
98   elsif ($ARGV[0] =~ /--configure=/) {
99     $confopts = (split(/=/, shift @ARGV))[1];
100   }
101   elsif ($ARGV[0] =~ /--nocvsup/) {
102     $nocvsup=1;
103     shift @ARGV;
104   }
105   elsif ($ARGV[0] =~ /--nobuildconf/) {
106     $nobuildconf=1;
107     shift @ARGV;
108   }
109   elsif ($ARGV[0] =~ /--crosscompile/) {
110     $crosscompile=1;
111     shift @ARGV;
112   }
113   elsif ($ARGV[0] =~ /--runtestopts=/) {
114     $runtestopts = (split(/=/, shift @ARGV, 2))[1];
115   }
116   else {
117     $CURLDIR=shift @ARGV;
118     $CVS=0;
119   }
120 }
121
122 # Do the platform-specific stuff here
123 $configurebuild = 1;
124 $confsuffix = '';
125 $binext = '';
126 $libext = '.la'; # .la since both libcurl and libcares are made with libtool
127 if ($^O eq 'MSWin32' || $targetos) {
128   if (!$targetos) {
129     # If no target defined on Win32 lets assume vc
130     $targetos = 'vc';
131   }
132   if ($targetos =~ /vc/ || $targetos =~ /borland/) {
133     $binext = '.exe';
134     $libext = '.lib';
135   }
136   elsif ($targetos =~ /mingw32/) {
137     $binext = '.exe';
138     if ($^O eq 'MSWin32') {
139       $libext = '.a';
140     }
141   }
142   elsif ($targetos =~ /netware/) {
143     $configurebuild = 0;
144     $binext = '.nlm';
145     if ($^O eq 'MSWin32') {
146       $libext = '.lib';
147     }
148     else {
149       $libext = '.a';
150     }
151   }
152 }
153
154 if (($^O eq 'MSWin32') &&
155     ($targetos =~ /vc/ || $targetos =~ /mingw32/ || $targetos =~ /borland/)) {
156
157   # Set these things only when building ON Windows and for Win32 platform.
158   # FOR Windows since we might be cross-compiling on another system. Non-
159   # Windows builds still default to configure-style builds with no confsuffix.
160
161   $configurebuild = 0;
162   $confsuffix = '-win32';
163 }
164
165
166 $ENV{LANG}="C";
167
168 sub rmtree($) {
169     my $target = $_[0];
170     if ($^O eq 'MSWin32') {
171       foreach (glob($target)) {
172         s:/:\\:g;
173         system("rd /s /q $_");
174       }
175     } else {
176       system("rm -rf $target");
177     }
178 }
179
180 sub grepfile($$) {
181     my ($target, $fn) = @_;
182     open(F, $fn) or die;
183     while (<F>) {
184       if (/$target/) {
185         close(F);
186         return 1;
187       }
188     }
189     close(F);
190     return 0;
191 }
192
193 sub logit($) {
194     my $text=$_[0];
195     if ($text) {
196       print "testcurl: $text\n";
197     }
198 }
199
200 sub mydie($){
201     my $text=$_[0];
202     logit "$text";
203     chdir $pwd; # cd back to the original root dir
204
205     if ($pwd && $build) {
206       # we have a build directory name, remove the dir
207       logit "removing the $build dir";
208       rmtree "$pwd/$build";
209     }
210     if (-r $buildlog) {
211       # we have a build log output file left, remove it
212       logit "removing the $buildlogname file";
213       unlink "$buildlog";
214     }
215     logit "ENDING HERE"; # last line logged!
216     exit 1;
217 }
218
219 if (open(F, "$setupfile")) {
220   while (<F>) {
221     if (/(\w+)=(.*)/) {
222       eval "\$$1=$2;";
223     }
224   }
225   close(F);
226   $infixed=$fixed;
227 } else {
228   $infixed=0;    # so that "additional args to configure" works properly first time...
229 }
230
231 if (!$name) {
232   print "please enter your name\n";
233   $name = <>;
234   chomp $name;
235   $fixed=1;
236 }
237
238 if (!$email) {
239   print "please enter your contact email address\n";
240   $email = <>;
241   chomp $email;
242   $fixed=2;
243 }
244
245 if (!$desc) {
246   print "please enter a one line system description\n";
247   $desc = <>;
248   chomp $desc;
249   $fixed=3;
250 }
251
252 if (!$confopts) {
253   if ($infixed < 4) {
254     print "please enter your additional arguments to configure\n";
255     print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
256     $confopts = <>;
257     chomp $confopts;
258   }
259 }
260
261
262 if ($fixed < 4) {
263     $fixed=4;
264     open(F, ">$setupfile") or die;
265     print F "name='$name'\n";
266     print F "email='$email'\n";
267     print F "desc='$desc'\n";
268     print F "confopts='$confopts'\n";
269     print F "fixed='$fixed'\n";
270     close(F);
271 }
272
273 my $str1066os = 'o' x 1066;
274
275 # Set timestamp to the UTC this script is running. Its value might
276 # be changed later in the script to the value present in curlver.h
277 $timestamp = scalar(gmtime)." UTC";
278
279 logit "STARTING HERE"; # first line logged, for scripts to trigger on
280 logit 'TRANSFER CONTROL ==== 1120 CHAR LINE' . $str1066os . 'LINE_END';
281 logit "NAME = $name";
282 logit "EMAIL = $email";
283 logit "DESC = $desc";
284 logit "CONFOPTS = $confopts";
285 logit "CPPFLAGS = ".$ENV{CPPFLAGS};
286 logit "CFLAGS = ".$ENV{CFLAGS};
287 logit "LDFLAGS = ".$ENV{LDFLAGS};
288 logit "CC = ".$ENV{CC};
289 logit "target = ".$targetos;
290 logit "version = $version"; # script version
291 logit "date = $timestamp";  # When the test build starts
292
293 $str1066os = undef;
294
295 # Make $pwd to become the path without newline. We'll use that in order to cut
296 # off that path from all possible logs and error messages etc.
297 $pwd = cwd();
298
299 if (-d $CURLDIR) {
300   if ($CVS && -d "$CURLDIR/CVS") {
301     logit "$CURLDIR is verified to be a fine source dir";
302     # remove the generated sources to force them to be re-generated each
303     # time we run this test
304     unlink "$CURLDIR/src/hugehelp.c";
305   } elsif (!$CVS && -f "$CURLDIR/tests/testcurl.pl") {
306     logit "$CURLDIR is verified to be a fine daily source dir"
307   } else {
308     mydie "$CURLDIR is not a daily source dir or checked out from CVS!"
309   }
310 }
311 $build="build-$$";
312 $buildlogname="buildlog-$$";
313 $buildlog="$pwd/$buildlogname";
314
315 # remove any previous left-overs
316 rmtree "build-*";
317 rmtree "buildlog-*";
318
319 # this is to remove old build logs that ended up in the wrong dir
320 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
321
322 # create a dir to build in
323 mkdir $build, 0777;
324
325 if (-d $build) {
326   logit "build dir $build was created fine";
327 } else {
328   mydie "failed to create dir $build";
329 }
330
331 # get in the curl source tree root
332 chdir $CURLDIR;
333
334 # Do the CVS thing, or not...
335 if ($CVS) {
336
337   # this is a temporary fix to make things work again, remove later
338   logit "remove ares/aclocal.m4";
339   unlink "ares/aclocal.m4";
340
341   logit "update from CVS";
342   my $cvsstat;
343
344   sub cvsup() {
345     # update quietly to the latest CVS
346     logit "run cvs up";
347     if($nocvsup) {
348         logit "Skipping CVS update (--nocvsup)";
349         return 1;
350     }
351     else {
352         system("cvs -Q up -dP 2>&1");
353     }
354
355     $cvsstat=$?;
356
357     # return !RETURNVALUE so that errors return 0 while goodness
358     # returns 1
359     return !$cvsstat;
360   }
361
362   my $att=0;
363   while (!cvsup()) {
364     $att++;
365     logit "failed CVS update attempt number $att.";
366     if ($att > 10) {
367       $cvsstat=111;
368       last; # get out of the loop
369     }
370     sleep 5;
371   }
372
373   if ($cvsstat != 0) {
374     mydie "failed to update from CVS ($cvsstat), exiting";
375   }
376   elsif (!$nocvsup) {
377     # Set timestamp to the UTC the CVS update took place.
378     $timestamp = scalar(gmtime)." UTC";
379   }
380
381   if($nobuildconf) {
382       logit "told to not run buildconf";
383   }
384   elsif ($configurebuild) {
385     # remove possible left-overs from the past
386     unlink "configure";
387     unlink "autom4te.cache";
388
389     # generate the build files
390     logit "invoke buildconf, but filter off the silly aclocal warnings";
391     open(F, "./buildconf 2>&1 |") or die;
392     open(LOG, ">$buildlog") or die;
393     while (<F>) {
394       next if /warning: underquoted definition of/;
395       print;
396       print LOG;
397     }
398     close(F);
399     close(LOG);
400
401     if (grepfile("^buildconf: OK", $buildlog)) {
402       logit "buildconf was successful";
403     }
404     else {
405       mydie "buildconf was NOT successful";
406     }
407   }
408   else {
409     logit "buildconf was successful (dummy message)";
410   }
411 }
412
413 # Set timestamp to the one in curlver.h if this isn't a CVS test build.
414 if ((-f "include/curl/curlver.h") &&
415     (open(F, "<include/curl/curlver.h"))) {
416   while (<F>) {
417     chomp;
418     if ($_ =~ /^\#define\s+LIBCURL_TIMESTAMP\s+\"(.+)\".*$/) {
419       my $stampstring = $1;
420       if ($stampstring !~ /CVS/) {
421           $stampstring =~ s/\s+UTC//;
422           $timestamp = $stampstring." UTC";
423       }
424       last;
425     }
426   }
427   close(F);
428 }
429
430 # Show timestamp we are using for this test build.
431 logit "timestamp = $timestamp";
432
433 if ($configurebuild) {
434   if (-f "configure") {
435     logit "configure created (at least it exists)";
436   } else {
437     mydie "no configure created/found";
438   }
439 } else {
440   logit "configure created (dummy message)"; # dummy message to feign success
441 }
442
443 sub findinpath {
444   my $c;
445   my $e;
446   my $x='';
447   $x='.exe' if ($^O eq 'MSWin32');
448   my $s=':';
449   $s=';' if ($^O eq 'MSWin32');
450   my $p=$ENV{'PATH'};
451   my @pa = split($s, $p);
452   for $c (@_) {
453     for $e (@pa) {
454       if( -x "$e/$c$x") {
455         return $c;
456       }
457     }
458   }
459 }
460
461 my $make = findinpath("gmake", "make", "nmake");
462 if(!$make) {
463     mydie "Couldn't find make in the PATH";
464 }
465 logit "going with $make as make";
466
467 # change to build dir
468 chdir "$pwd/$build";
469
470 if ($configurebuild) {
471   # run configure script
472   print `../$CURLDIR/configure $confopts 2>&1`;
473
474   if (-f "lib/Makefile") {
475     logit "configure seems to have finished fine";
476   } else {
477     mydie "configure didn't work";
478   }
479 } else {
480   if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
481     system("xcopy /s /q ..\\$CURLDIR .");
482     system("buildconf.bat");
483   }
484   elsif (($^O eq 'linux') || ($targetos =~ /netware/)) {
485     system("cp -afr ../$CURLDIR/* ."); 
486     system("cp -af ../$CURLDIR/Makefile.dist Makefile"); 
487     system("$make -i -C lib -f Makefile.$targetos prebuild");
488     system("$make -i -C src -f Makefile.$targetos prebuild");
489   }
490 }
491
492 logit "display lib/config$confsuffix.h";
493 open(F, "lib/config$confsuffix.h") or die "lib/config$confsuffix.h: $!";
494 while (<F>) {
495   print if /^ *#/;
496 }
497 close(F);
498
499 if (grepfile("define USE_ARES", "lib/config$confsuffix.h")) {
500   logit "setup to build ares";
501
502   logit "display ares/config$confsuffix.h";
503   if(open(F, "ares/config$confsuffix.h")) {
504       while (<F>) {
505           print if /^ *#/;
506       }
507       close(F);
508   }
509
510   logit "build ares";
511   chdir "ares";
512
513   if ($targetos && !$configurebuild) {
514       logit "$make -f Makefile.$targetos";
515       open(F, "$make -f Makefile.$targetos 2>&1 |") or die;
516   }
517   else {
518       logit "$make";
519       open(F, "$make 2>&1 |") or die;
520   }
521   while (<F>) {
522     s/$pwd//g;
523     print;
524   }
525   close(F);
526
527   if (-f "libcares$libext") {
528     logit "ares is now built successfully (libcares$libext)";
529   } else {
530     logit "ares build failed (libares$libext)";
531   }
532
533   # cd back to the curl build dir
534   chdir "$pwd/$build";
535 }
536
537 if ($configurebuild) {
538   logit "$make -i";
539   open(F, "$make -i 2>&1 |") or die;
540   while (<F>) {
541     s/$pwd//g;
542     print;
543   }
544   close(F);
545 }
546 else {
547   logit "$make -i $targetos";
548   if ($^O eq 'MSWin32') {
549     if ($targetos =~ /vc/) {
550       open(F, "nmake -i $targetos|") or die;
551     }
552     else {
553       open(F, "$make -i $targetos |") or die;
554     }
555   }
556   else {
557     open(F, "$make -i $targetos 2>&1 |") or die;
558   }
559   while (<F>) {
560     s/$pwd//g;
561     print;
562   }
563   close(F);
564 }
565
566 if (-f "lib/libcurl$libext") {
567   logit "libcurl was created fine (libcurl$libext)";
568 }
569 else {
570   mydie "libcurl was not created (libcurl$libext)";
571 }
572
573 if (-f "src/curl$binext") {
574   logit "curl was created fine (curl$binext)";
575 }
576 else {
577   mydie "curl was not created (curl$binext)";
578 }
579
580 if ($targetos =~ /netware/) {
581   if (-f '../../curlver') {
582     system('../../curlver');
583   }
584 }
585 elsif(!$crosscompile) {
586   logit "display curl$binext --version output";
587   open(F, "./src/curl$binext --version|");
588   while(<F>) {
589       print;
590       print LOG;
591   }
592   close(F);
593 }
594
595 if ($configurebuild && !$crosscompile) {
596   my $o;
597   if($runtestopts) {
598       $o = "TEST_F=\"$runtestopts\" ";
599   }
600   logit "$make -k ${o}test-full";
601   open(F, "$make -k ${o}test-full 2>&1 |") or die;
602   open(LOG, ">$buildlog") or die;
603   while (<F>) {
604     s/$pwd//g;
605     print;
606     print LOG;
607   }
608   close(F);
609   close(LOG);
610
611   if (grepfile("^TEST", $buildlog)) {
612     logit "tests were run";
613   } else {
614     mydie "test suite failure";
615   }
616
617   if (grepfile("^TESTFAIL:", $buildlog)) {
618     logit "the tests were not successful";
619   } else {
620     logit "the tests were successful!";
621   }
622 } else {
623   # dummy message to feign success
624   if($crosscompile) {
625     logit "cross-compiling, can't run tests";
626   }
627   print "TESTDONE: 1 tests out of 0 (dummy message)\n";
628 }
629
630 # create a tarball if we got that option.
631 if (($mktarball ne '') && (-f $mktarball)) {
632   system($mktarball);
633 }
634
635 # mydie to cleanup
636 mydie "ending nicely";