added -nobuildconf
[platform/upstream/curl.git] / tests / testcurl.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2005, 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);
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 =~ /mingw32/ || $targetos =~ /borland/) {
133     $binext = '.exe';
134     $libext = '.lib' if ($targetos =~ /vc/ || $targetos =~ /borland/);
135     $libext = '.a' if ($targetos =~ /mingw32/);
136   }
137   elsif ($targetos =~ /netware/) {
138     $configurebuild = 0;
139     $binext = '.nlm';
140     $libext = '.lib';
141   }
142 }
143
144 if ($^O eq 'MSWin32') {
145
146   # Set these things only when building ON Windows, not when simply building
147   # FOR Windows since we might be cross-compiling on another system. Non-
148   # Windows builds still default to configure-style builds with no confsuffix.
149
150   $configurebuild = 0;
151   $confsuffix = '-win32';
152 }
153
154
155 $ENV{LANG}="C";
156
157 sub rmtree($) {
158     my $target = $_[0];
159     if ($^O eq 'MSWin32') {
160       foreach (glob($target)) {
161         s:/:\\:g;
162         system("rd /s /q $_");
163       }
164     } else {
165       system("rm -rf $target");
166     }
167 }
168
169 sub grepfile($$) {
170     my ($target, $fn) = @_;
171     open(F, $fn) or die;
172     while (<F>) {
173       if (/$target/) {
174         close(F);
175         return 1;
176       }
177     }
178     close(F);
179     return 0;
180 }
181
182 sub logit($) {
183     my $text=$_[0];
184     if ($text) {
185       print "testcurl: $text\n";
186     }
187 }
188
189 sub mydie($){
190     my $text=$_[0];
191     logit "$text";
192     chdir $pwd; # cd back to the original root dir
193
194     if ($pwd && $build) {
195       # we have a build directory name, remove the dir
196       logit "removing the $build dir";
197       rmtree "$pwd/$build";
198     }
199     if (-r $buildlog) {
200       # we have a build log output file left, remove it
201       logit "removing the $buildlogname file";
202       unlink "$buildlog";
203     }
204     logit "ENDING HERE"; # last line logged!
205     exit 1;
206 }
207
208 if (open(F, "$setupfile")) {
209   while (<F>) {
210     if (/(\w+)=(.*)/) {
211       eval "\$$1=$2;";
212     }
213   }
214   close(F);
215   $infixed=$fixed;
216 } else {
217   $infixed=0;    # so that "additional args to configure" works properly first time...
218 }
219
220 if (!$name) {
221   print "please enter your name\n";
222   $name = <>;
223   chomp $name;
224   $fixed=1;
225 }
226
227 if (!$email) {
228   print "please enter your contact email address\n";
229   $email = <>;
230   chomp $email;
231   $fixed=2;
232 }
233
234 if (!$desc) {
235   print "please enter a one line system description\n";
236   $desc = <>;
237   chomp $desc;
238   $fixed=3;
239 }
240
241 if (!$confopts) {
242   if ($infixed < 4) {
243     print "please enter your additional arguments to configure\n";
244     print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
245     $confopts = <>;
246     chomp $confopts;
247   }
248 }
249
250
251 if ($fixed < 4) {
252     $fixed=4;
253     open(F, ">$setupfile") or die;
254     print F "name='$name'\n";
255     print F "email='$email'\n";
256     print F "desc='$desc'\n";
257     print F "confopts='$confopts'\n";
258     print F "fixed='$fixed'\n";
259     close(F);
260 }
261
262 logit "STARTING HERE"; # first line logged, for scripts to trigger on
263 logit "NAME = $name";
264 logit "EMAIL = $email";
265 logit "DESC = $desc";
266 logit "CONFOPTS = $confopts";
267 logit "CFLAGS = ".$ENV{CFLAGS};
268 logit "LDFLAGS = ".$ENV{LDFLAGS};
269 logit "CC = ".$ENV{CC};
270 logit "target = ".$targetos;
271 logit "version = $version"; # script version
272 logit "date = ".(scalar gmtime)." UTC";
273
274 # Make $pwd to become the path without newline. We'll use that in order to cut
275 # off that path from all possible logs and error messages etc.
276 $pwd = cwd();
277
278 if (-d $CURLDIR) {
279   if ($CVS && -d "$CURLDIR/CVS") {
280     logit "$CURLDIR is verified to be a fine source dir";
281     # remove the generated sources to force them to be re-generated each
282     # time we run this test
283     unlink "$CURLDIR/src/hugehelp.c";
284   } elsif (!$CVS && -f "$CURLDIR/tests/testcurl.pl") {
285     logit "$CURLDIR is verified to be a fine daily source dir"
286   } else {
287     mydie "$CURLDIR is not a daily source dir or checked out from CVS!"
288   }
289 }
290 $build="build-$$";
291 $buildlogname="buildlog-$$";
292 $buildlog="$pwd/$buildlogname";
293
294 # remove any previous left-overs
295 rmtree "build-*";
296 rmtree "buildlog-*";
297
298 # this is to remove old build logs that ended up in the wrong dir
299 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
300
301 # create a dir to build in
302 mkdir $build, 0777;
303
304 if (-d $build) {
305   logit "build dir $build was created fine";
306 } else {
307   mydie "failed to create dir $build";
308 }
309
310 # get in the curl source tree root
311 chdir $CURLDIR;
312
313 # Do the CVS thing, or not...
314 if ($CVS) {
315
316   # this is a temporary fix to make things work again, remove later
317   logit "remove ares/aclocal.m4";
318   unlink "ares/aclocal.m4";
319
320   logit "update from CVS";
321   my $cvsstat;
322
323   sub cvsup() {
324     # update quietly to the latest CVS
325     logit "run cvs up";
326     if($nocvsup) {
327         logit "Skipping CVS update (--nocvsup)";
328         return 1;
329     }
330     else {
331         system("cvs -Q up -dP 2>&1");
332     }
333
334     $cvsstat=$?;
335
336     # return !RETURNVALUE so that errors return 0 while goodness
337     # returns 1
338     return !$cvsstat;
339   }
340
341   my $att=0;
342   while (!cvsup()) {
343     $att++;
344     logit "failed CVS update attempt number $att.";
345     if ($att > 10) {
346       $cvsstat=111;
347       last; # get out of the loop
348     }
349     sleep 5;
350   }
351
352   if ($cvsstat != 0) {
353     mydie "failed to update from CVS ($cvsstat), exiting";
354   }
355
356   if($nobuildconf) {
357       logit "told to not run buildconf";
358   }
359   elsif ($configurebuild) {
360     # remove possible left-overs from the past
361     unlink "configure";
362     unlink "autom4te.cache";
363
364     # generate the build files
365     logit "invoke buildconf, but filter off the silly aclocal warnings";
366     open(F, "./buildconf 2>&1 |") or die;
367     open(LOG, ">$buildlog") or die;
368     while (<F>) {
369       next if /warning: underquoted definition of/;
370       print;
371       print LOG;
372     }
373     close(F);
374     close(LOG);
375
376     if (grepfile("^buildconf: OK", $buildlog)) {
377       logit "buildconf was successful";
378     }
379     else {
380       mydie "buildconf was NOT successful";
381     }
382
383     if($confopts =~ /--enable-ares/) {
384         logit "run buildconf for ares";
385         chdir "ares";
386         open(F, "./buildconf 2>&1 |") or die;
387         open(LOG, ">$buildlog") or die;
388         while (<F>) {
389             next if /warning: underquoted definition of/;
390             print;
391             print LOG;
392         }
393         close(F);
394         close(LOG);
395         chdir "..";
396     }
397
398   }
399   else {
400     logit "buildconf was successful (dummy message)";
401   }
402 }
403
404 if ($configurebuild) {
405   if (-f "configure") {
406     logit "configure created (at least it exists)";
407   } else {
408     mydie "no configure created/found";
409   }
410 } else {
411   logit "configure created (dummy message)"; # dummy message to feign success
412 }
413
414 sub findinpath {
415     my $c;
416     my $e;
417     my $p=$ENV{'PATH'};
418     my @pa = split(":", $p);
419     for $c (@_) {
420         for $e (@pa) {
421             if( -x "$e/$c") {
422                 return $c;
423             }
424         }
425     }
426 }
427
428
429 my $make = findinpath("gmake", "make", "nmake");
430 if(!$make) {
431     mydie "Couldn't find make in the PATH";
432 }
433 logit "going with $make as make";
434
435 # change to build dir
436 chdir "$pwd/$build";
437
438 if ($configurebuild) {
439   # run configure script
440   print `../$CURLDIR/configure $confopts 2>&1`;
441
442   if (-f "lib/Makefile") {
443     logit "configure seems to have finished fine";
444   } else {
445     mydie "configure didn't work";
446   }
447 } else {
448   if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
449     system("xcopy /s /q ..\\$CURLDIR .");
450     system("buildconf.bat");
451   }
452   elsif (($^O eq 'linux') || ($targetos =~ /netware/)) {
453     system("cp -afr ../$CURLDIR/* ."); 
454     system("cp -af ../$CURLDIR/Makefile.dist Makefile"); 
455     system("$make -i -C lib -f Makefile.$targetos prebuild");
456     system("$make -i -C src -f Makefile.$targetos prebuild");
457   }
458 }
459
460 logit "display lib/config$confsuffix.h";
461 open(F, "lib/config$confsuffix.h") or die "lib/config$confsuffix.h: $!";
462 while (<F>) {
463   print if /^ *#/;
464 }
465 close(F);
466
467 if (grepfile("define USE_ARES", "lib/config$confsuffix.h")) {
468   logit "setup to build ares";
469
470   logit "display ares/config$confsuffix.h";
471   if(open(F, "ares/config$confsuffix.h")) {
472       while (<F>) {
473           print if /^ *#/;
474       }
475       close(F);
476   }
477
478   logit "build ares";
479   chdir "ares";
480
481   if ($targetos && !$configurebuild) {
482       logit "$make -f Makefile.$targetos";
483       open(F, "$make -f Makefile.$targetos 2>&1 |") or die;
484   }
485   else {
486       logit "$make";
487       open(F, "$make 2>&1 |") or die;
488   }
489   while (<F>) {
490     s/$pwd//g;
491     print;
492   }
493   close(F);
494
495   if (-f "libcares$libext") {
496     logit "ares is now built successfully (libcares$libext)";
497   } else {
498     logit "ares build failed (libares$libext)";
499   }
500
501   # cd back to the curl build dir
502   chdir "$pwd/$build";
503 }
504
505 if ($configurebuild) {
506   logit "$make -i";
507   open(F, "$make -i 2>&1 |") or die;
508   while (<F>) {
509     s/$pwd//g;
510     print;
511   }
512   close(F);
513 }
514 else {
515   logit "$make -i $targetos";
516   if ($^O eq 'MSWin32') {
517     if ($targetos =~ /vc/) {
518       open(F, "nmake -i $targetos|") or die;
519     }
520     else {
521       open(F, "$make -i $targetos |") or die;
522     }
523   }
524   else {
525     open(F, "$make -i $targetos 2>&1 |") or die;
526   }
527   while (<F>) {
528     s/$pwd//g;
529     print;
530   }
531   close(F);
532 }
533
534 if (-f "lib/libcurl$libext") {
535   logit "lib/libcurl was created fine (libcurl$libext)";
536 }
537 else {
538   logit "lib/libcurl was not created (libcurl$libext)";
539 }
540
541 if (-f "src/curl$binext") {
542   logit "src/curl was created fine (curl$binext)";
543 }
544 else {
545   mydie "src/curl was not created (curl$binext)";
546 }
547
548 if ($targetos =~ /netware/) {
549   if (-f '../../curlver') {
550     system('../../curlver');
551   }
552 }
553 elsif(!$crosscompile) {
554   logit "display curl$binext --version output";
555   open(F, "./src/curl$binext --version|");
556   while(<F>) {
557       print;
558       print LOG;
559   }
560   close(F);
561 }
562
563 if ($configurebuild && !$crosscompile) {
564   my $o;
565   if($runtestopts) {
566       $o = "TEST_F=\"$runtestopts\" ";
567   }
568   logit "$make ${o}test-full";
569   open(F, "$make ${o}test-full 2>&1 |") or die;
570   open(LOG, ">$buildlog") or die;
571   while (<F>) {
572     s/$pwd//g;
573     print;
574     print LOG;
575   }
576   close(F);
577   close(LOG);
578
579   if (grepfile("^TEST", $buildlog)) {
580     logit "tests were run";
581   } else {
582     mydie "test suite failure";
583   }
584
585   if (grepfile("^TESTFAIL:", $buildlog)) {
586     logit "the tests were not successful";
587   } else {
588     logit "the tests were successful!";
589   }
590 } else {
591   # dummy message to feign success
592   if($crosscompile) {
593     logit "cross-compiling, can't run tests";
594   }
595   print "TESTDONE: 1 tests out of 0 (dummy message)\n";
596 }
597
598 # create a tarball if we got that option.
599 if (($mktarball ne '') && (-f $mktarball)) {
600   system($mktarball);
601 }
602
603 # mydie to cleanup
604 mydie "ending nicely";