aboutsummaryrefslogtreecommitdiff
path: root/tests/testcurl.pl
blob: fd9e7db88f8dc13ec5cebaf599740d0eff652589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
#!/usr/bin/env perl
#***************************************************************************
#                                  _   _ ____  _
#  Project                     ___| | | |  _ \| |
#                             / __| | | | |_) | |
#                            | (__| |_| |  _ <| |___
#                             \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# $Id$
###########################################################################

###########################
#  What is This Script?
###########################

# testcurl.pl is the master script to use for automatic testing of CVS-curl.
# This is written for the purpose of being run from a crontab job or similar
# at a regular interval. The output is suitable to be mailed to
# curl-autocompile@haxx.se to be dealt with automatically (make sure the
# subject includes the word "autobuild" as the mail gets silently discarded
# otherwise).  The most current build status (with a resonable backlog) will
# be published on the curl site, at http://curl.haxx.se/auto/

# USAGE:
# testcurl.pl [options] [curl-daily-name] > output

# Options:
#
# --configure=[options]    Configure options
# --crosscompile           This is a crosscompile
# --desc=[desc]            Description of your test system
# --email=[email]          Set email address to report as
# --mktarball=[command]    Command to run after completed test
# --name=[name]            Set name to report as
# --nocvsup                Don't update from CVS even though it is a CVS tree
# --nobuildconf            Don't run buildconf
# --runtestopts=[options]  Options to pass to runtests.pl
# --setup=[file name]      File name to read setup from (deprecated)
# --target=[your os]       Specify your target environment.
#
# if [curl-daily-name] is omitted, a 'curl' CVS directory is assumed.
#

use strict;

use Cwd;

# Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
#BEGIN { $^W = 1; }

use vars qw($version $fixed $infixed $CURLDIR $CVS $pwd $build $buildlog
            $buildlogname $configurebuild $targetos $confsuffix $binext
            $libext);
use vars qw($name $email $desc $confopts $runtestopts $setupfile $mktarball
            $nocvsup $nobuildconf $crosscompile);

# version of this script
$version='$Revision$';
$fixed=0;

# Determine if we're running from CVS or a canned copy of curl,
# or if we got a specific target option or setup file option.
$CURLDIR="curl";
$CVS=1;
$setupfile = 'setup';
while ($ARGV[0]) {
  if ($ARGV[0] =~ /--target=/) {
    $targetos = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--setup=/) {
    $setupfile = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--mktarball=/) {
    $mktarball = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--name=/) {
    $name = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--email=/) {
    $email = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--desc=/) {
    $desc = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--configure=/) {
    $confopts = (split(/=/, shift @ARGV))[1];
  }
  elsif ($ARGV[0] =~ /--nocvsup/) {
    $nocvsup=1;
    shift @ARGV;
  }
  elsif ($ARGV[0] =~ /--nobuildconf/) {
    $nobuildconf=1;
    shift @ARGV;
  }
  elsif ($ARGV[0] =~ /--crosscompile/) {
    $crosscompile=1;
    shift @ARGV;
  }
  elsif ($ARGV[0] =~ /--runtestopts=/) {
    $runtestopts = (split(/=/, shift @ARGV, 2))[1];
  }
  else {
    $CURLDIR=shift @ARGV;
    $CVS=0;
  }
}

# Do the platform-specific stuff here
$configurebuild = 1;
$confsuffix = '';
$binext = '';
$libext = '.la'; # .la since both libcurl and libcares are made with libtool
if ($^O eq 'MSWin32' || $targetos) {
  if (!$targetos) {
    # If no target defined on Win32 lets assume vc
    $targetos = 'vc';
  }
  if ($targetos =~ /vc/ || $targetos =~ /borland/) {
    $binext = '.exe';
    $libext = '.lib';
  }
  elsif ($targetos =~ /mingw32/) {
    $binext = '.exe';
    if ($^O eq 'MSWin32') {
      $libext = '.a';
    }
  }
  elsif ($targetos =~ /netware/) {
    $configurebuild = 0;
    $binext = '.nlm';
    $libext = '.lib';
  }
}

if (($^O eq 'MSWin32') &&
    ($targetos =~ /vc/ || $targetos =~ /mingw32/ || $targetos =~ /borland/)) {

  # Set these things only when building ON Windows and for Win32 platform.
  # FOR Windows since we might be cross-compiling on another system. Non-
  # Windows builds still default to configure-style builds with no confsuffix.

  $configurebuild = 0;
  $confsuffix = '-win32';
}


$ENV{LANG}="C";

sub rmtree($) {
    my $target = $_[0];
    if ($^O eq 'MSWin32') {
      foreach (glob($target)) {
        s:/:\\:g;
        system("rd /s /q $_");
      }
    } else {
      system("rm -rf $target");
    }
}

sub grepfile($$) {
    my ($target, $fn) = @_;
    open(F, $fn) or die;
    while (<F>) {
      if (/$target/) {
        close(F);
        return 1;
      }
    }
    close(F);
    return 0;
}

sub logit($) {
    my $text=$_[0];
    if ($text) {
      print "testcurl: $text\n";
    }
}

sub mydie($){
    my $text=$_[0];
    logit "$text";
    chdir $pwd; # cd back to the original root dir

    if ($pwd && $build) {
      # we have a build directory name, remove the dir
      logit "removing the $build dir";
      rmtree "$pwd/$build";
    }
    if (-r $buildlog) {
      # we have a build log output file left, remove it
      logit "removing the $buildlogname file";
      unlink "$buildlog";
    }
    logit "ENDING HERE"; # last line logged!
    exit 1;
}

if (open(F, "$setupfile")) {
  while (<F>) {
    if (/(\w+)=(.*)/) {
      eval "\$$1=$2;";
    }
  }
  close(F);
  $infixed=$fixed;
} else {
  $infixed=0;    # so that "additional args to configure" works properly first time...
}

if (!$name) {
  print "please enter your name\n";
  $name = <>;
  chomp $name;
  $fixed=1;
}

if (!$email) {
  print "please enter your contact email address\n";
  $email = <>;
  chomp $email;
  $fixed=2;
}

if (!$desc) {
  print "please enter a one line system description\n";
  $desc = <>;
  chomp $desc;
  $fixed=3;
}

if (!$confopts) {
  if ($infixed < 4) {
    print "please enter your additional arguments to configure\n";
    print "examples: --with-ssl --enable-debug --enable-ipv6 --with-krb4\n";
    $confopts = <>;
    chomp $confopts;
  }
}


if ($fixed < 4) {
    $fixed=4;
    open(F, ">$setupfile") or die;
    print F "name='$name'\n";
    print F "email='$email'\n";
    print F "desc='$desc'\n";
    print F "confopts='$confopts'\n";
    print F "fixed='$fixed'\n";
    close(F);
}

logit "STARTING HERE"; # first line logged, for scripts to trigger on
logit "NAME = $name";
logit "EMAIL = $email";
logit "DESC = $desc";
logit "CONFOPTS = $confopts";
logit "CPPFLAGS = ".$ENV{CPPFLAGS};
logit "CFLAGS = ".$ENV{CFLAGS};
logit "LDFLAGS = ".$ENV{LDFLAGS};
logit "CC = ".$ENV{CC};
logit "target = ".$targetos;
logit "version = $version"; # script version
logit "date = ".(scalar gmtime)." UTC";

# Make $pwd to become the path without newline. We'll use that in order to cut
# off that path from all possible logs and error messages etc.
$pwd = cwd();

if (-d $CURLDIR) {
  if ($CVS && -d "$CURLDIR/CVS") {
    logit "$CURLDIR is verified to be a fine source dir";
    # remove the generated sources to force them to be re-generated each
    # time we run this test
    unlink "$CURLDIR/src/hugehelp.c";
  } elsif (!$CVS && -f "$CURLDIR/tests/testcurl.pl") {
    logit "$CURLDIR is verified to be a fine daily source dir"
  } else {
    mydie "$CURLDIR is not a daily source dir or checked out from CVS!"
  }
}
$build="build-$$";
$buildlogname="buildlog-$$";
$buildlog="$pwd/$buildlogname";

# remove any previous left-overs
rmtree "build-*";
rmtree "buildlog-*";

# this is to remove old build logs that ended up in the wrong dir
foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }

# create a dir to build in
mkdir $build, 0777;

if (-d $build) {
  logit "build dir $build was created fine";
} else {
  mydie "failed to create dir $build";
}

# get in the curl source tree root
chdir $CURLDIR;

# Do the CVS thing, or not...
if ($CVS) {

  # this is a temporary fix to make things work again, remove later
  logit "remove ares/aclocal.m4";
  unlink "ares/aclocal.m4";

  logit "update from CVS";
  my $cvsstat;

  sub cvsup() {
    # update quietly to the latest CVS
    logit "run cvs up";
    if($nocvsup) {
        logit "Skipping CVS update (--nocvsup)";
        return 1;
    }
    else {
        system("cvs -Q up -dP 2>&1");
    }

    $cvsstat=$?;

    # return !RETURNVALUE so that errors return 0 while goodness
    # returns 1
    return !$cvsstat;
  }

  my $att=0;
  while (!cvsup()) {
    $att++;
    logit "failed CVS update attempt number $att.";
    if ($att > 10) {
      $cvsstat=111;
      last; # get out of the loop
    }
    sleep 5;
  }

  if ($cvsstat != 0) {
    mydie "failed to update from CVS ($cvsstat), exiting";
  }

  if($nobuildconf) {
      logit "told to not run buildconf";
  }
  elsif ($configurebuild) {
    # remove possible left-overs from the past
    unlink "configure";
    unlink "autom4te.cache";

    # generate the build files
    logit "invoke buildconf, but filter off the silly aclocal warnings";
    open(F, "./buildconf 2>&1 |") or die;
    open(LOG, ">$buildlog") or die;
    while (<F>) {
      next if /warning: underquoted definition of/;
      print;
      print LOG;
    }
    close(F);
    close(LOG);

    if (grepfile("^buildconf: OK", $buildlog)) {
      logit "buildconf was successful";
    }
    else {
      mydie "buildconf was NOT successful";
    }
  }
  else {
    logit "buildconf was successful (dummy message)";
  }
}

if ($configurebuild) {
  if (-f "configure") {
    logit "configure created (at least it exists)";
  } else {
    mydie "no configure created/found";
  }
} else {
  logit "configure created (dummy message)"; # dummy message to feign success
}

sub findinpath {
  my $c;
  my $e;
  my $x='';
  $x='.exe' if ($^O eq 'MSWin32');
  my $s=':';
  $s=';' if ($^O eq 'MSWin32');
  my $p=$ENV{'PATH'};
  my @pa = split($s, $p);
  for $c (@_) {
    for $e (@pa) {
      if( -x "$e/$c$x") {
        return $c;
      }
    }
  }
}

my $make = findinpath("gmake", "make", "nmake");
if(!$make) {
    mydie "Couldn't find make in the PATH";
}
logit "going with $make as make";

# change to build dir
chdir "$pwd/$build";

if ($configurebuild) {
  # run configure script
  print `../$CURLDIR/configure $confopts 2>&1`;

  if (-f "lib/Makefile") {
    logit "configure seems to have finished fine";
  } else {
    mydie "configure didn't work";
  }
} else {
  if (($^O eq 'MSWin32') && ($targetos !~ /netware/)) {
    system("xcopy /s /q ..\\$CURLDIR .");
    system("buildconf.bat");
  }
  elsif (($^O eq 'linux') || ($targetos =~ /netware/)) {
    system("cp -afr ../$CURLDIR/* ."); 
    system("cp -af ../$CURLDIR/Makefile.dist Makefile"); 
    system("$make -i -C lib -f Makefile.$targetos prebuild");
    system("$make -i -C src -f Makefile.$targetos prebuild");
  }
}

logit "display lib/config$confsuffix.h";
open(F, "lib/config$confsuffix.h") or die "lib/config$confsuffix.h: $!";
while (<F>) {
  print if /^ *#/;
}
close(F);

if (grepfile("define USE_ARES", "lib/config$confsuffix.h")) {
  logit "setup to build ares";

  logit "display ares/config$confsuffix.h";
  if(open(F, "ares/config$confsuffix.h")) {
      while (<F>) {
          print if /^ *#/;
      }
      close(F);
  }

  logit "build ares";
  chdir "ares";

  if ($targetos && !$configurebuild) {
      logit "$make -f Makefile.$targetos";
      open(F, "$make -f Makefile.$targetos 2>&1 |") or die;
  }
  else {
      logit "$make";
      open(F, "$make 2>&1 |") or die;
  }
  while (<F>) {
    s/$pwd//g;
    print;
  }
  close(F);

  if (-f "libcares$libext") {
    logit "ares is now built successfully (libcares$libext)";
  } else {
    logit "ares build failed (libares$libext)";
  }

  # cd back to the curl build dir
  chdir "$pwd/$build";
}

if ($configurebuild) {
  logit "$make -i";
  open(F, "$make -i 2>&1 |") or die;
  while (<F>) {
    s/$pwd//g;
    print;
  }
  close(F);
}
else {
  logit "$make -i $targetos";
  if ($^O eq 'MSWin32') {
    if ($targetos =~ /vc/) {
      open(F, "nmake -i $targetos|") or die;
    }
    else {
      open(F, "$make -i $targetos |") or die;
    }
  }
  else {
    open(F, "$make -i $targetos 2>&1 |") or die;
  }
  while (<F>) {
    s/$pwd//g;
    print;
  }
  close(F);
}

if (-f "lib/libcurl$libext") {
  logit "libcurl was created fine (libcurl$libext)";
}
else {
  mydie "libcurl was not created (libcurl$libext)";
}

if (-f "src/curl$binext") {
  logit "curl was created fine (curl$binext)";
}
else {
  mydie "curl was not created (curl$binext)";
}

if ($targetos =~ /netware/) {
  if (-f '../../curlver') {
    system('../../curlver');
  }
}
elsif(!$crosscompile) {
  logit "display curl$binext --version output";
  open(F, "./src/curl$binext --version|");
  while(<F>) {
      print;
      print LOG;
  }
  close(F);
}

if ($configurebuild && !$crosscompile) {
  my $o;
  if($runtestopts) {
      $o = "TEST_F=\"$runtestopts\" ";
  }
  logit "$make -k ${o}test-full";
  open(F, "$make -k ${o}test-full 2>&1 |") or die;
  open(LOG, ">$buildlog") or die;
  while (<F>) {
    s/$pwd//g;
    print;
    print LOG;
  }
  close(F);
  close(LOG);

  if (grepfile("^TEST", $buildlog)) {
    logit "tests were run";
  } else {
    mydie "test suite failure";
  }

  if (grepfile("^TESTFAIL:", $buildlog)) {
    logit "the tests were not successful";
  } else {
    logit "the tests were successful!";
  }
} else {
  # dummy message to feign success
  if($crosscompile) {
    logit "cross-compiling, can't run tests";
  }
  print "TESTDONE: 1 tests out of 0 (dummy message)\n";
}

# create a tarball if we got that option.
if (($mktarball ne '') && (-f $mktarball)) {
  system($mktarball);
}

# mydie to cleanup
mydie "ending nicely";