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