~ubuntu-branches/ubuntu/lucid/curl/lucid-security

« back to all changes in this revision

Viewing changes to tests/runtests.pl

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-12 15:04:52 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20051212150452-2ymlra67b2p7kjyy
Tags: 7.15.1-1ubuntu1
Resynchronise with Debian to get URL parser overflow fix from 7.15.1
(CVE-2005-4077).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
20
# KIND, either express or implied.
21
21
#
22
 
# $Id: runtests.pl,v 1.187 2005/05/16 07:07:00 bagder Exp $
 
22
# $Id: runtests.pl,v 1.197 2005/12/06 07:44:18 bagder Exp $
23
23
###########################################################################
24
24
# These should be the only variables that might be needed to get edited:
25
25
 
26
26
use strict;
 
27
#use Time::HiRes qw( gettimeofday );
27
28
#use warnings;
28
29
 
29
30
@INC=(@INC, $ENV{'srcdir'}, ".");
45
46
my $FTP2PORT; # FTP server 2 port
46
47
my $FTPSPORT; # FTPS server port
47
48
my $FTP6PORT; # FTP IPv6 server port
 
49
my $TFTPPORT; # TFTP
 
50
my $TFTP6PORT; # TFTP
48
51
 
49
52
my $CURL="../src/curl"; # what curl executable to run on the tests
50
53
my $DBGCURL=$CURL; #"../src/.libs/curl";  # alternative for debugging
74
77
my $FTP6PIDFILE=".ftp6.pid";
75
78
my $FTP2PIDFILE=".ftp2.pid";
76
79
my $FTPSPIDFILE=".ftps.pid";
 
80
my $TFTPPIDFILE=".tftpd.pid";
 
81
my $TFTP6PIDFILE=".tftp6.pid";
77
82
 
78
83
# invoke perl like this:
79
84
my $perl="perl -I$srcdir";
89
94
 
90
95
my $stunnel = checkcmd("stunnel");
91
96
my $valgrind = checkcmd("valgrind");
 
97
my $valgrind_logfile="--logfile";
92
98
my $start;
93
99
 
94
100
my $valgrind_tool;
108
114
        $valgrind=0;
109
115
    }
110
116
    close(C);
 
117
 
 
118
    # valgrind 3 renamed the --logfile option to --log-file!!!
 
119
    my $ver=`valgrind --version`;
 
120
    # cut off all but digits and dots
 
121
    $ver =~ s/[^0-9.]//g;
 
122
 
 
123
    if($ver >= 3) {
 
124
        $valgrind_logfile="--log-file";
 
125
    }
111
126
}
112
127
 
113
128
my $gdb = checkcmd("gdb");
117
132
my $has_idn;     # set if libcurl is built with IDN support
118
133
my $http_ipv6;   # set if HTTP server has IPv6 support
119
134
my $ftp_ipv6;    # set if FTP server has IPv6 support
 
135
my $tftp_ipv6;   # set if TFTP server has IPv6 support
120
136
my $has_ipv6;    # set if libcurl is built with IPv6 support
121
137
my $has_libz;    # set if libcurl is built with libz support
122
138
my $has_getrlimit;  # set if system has getrlimit()
152
168
my $tortnum;
153
169
my $tortalloc;
154
170
 
 
171
# open and close each time to allow removal at any time
 
172
sub logmsg {
 
173
# uncomment the Time::HiRes usage for this
 
174
#    my ($seconds, $microseconds) = gettimeofday;
 
175
#    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
 
176
#        localtime($seconds);
 
177
    my $t;
 
178
    if(1) {
 
179
#        $t = sprintf ("%02d:%02d:%02d.%06d ", $hour, $min, $sec,
 
180
#                      $microseconds);
 
181
    }
 
182
    for(@_) {
 
183
        print "${t}$_";
 
184
    }
 
185
}
 
186
 
155
187
chomp($pwd = `pwd`);
156
188
 
157
189
# enable memory debugging if curl is compiled with it
160
192
 
161
193
sub catch_zap {
162
194
    my $signame = shift;
163
 
    print STDERR "runtests.pl received SIG$signame, exiting\n";
 
195
    logmsg "runtests.pl received SIG$signame, exiting\n";
164
196
    stopservers(1);
165
197
    die "Somebody sent me a SIG$signame";
166
198
}
194
226
sub startnew {
195
227
    my ($cmd, $pidfile)=@_;
196
228
 
197
 
    print "CMD: $cmd\n" if ($verbose);
 
229
    logmsg "startnew: $cmd\n" if ($verbose);
198
230
 
199
231
    my $child = fork();
200
232
    my $pid2;
257
289
    # First get URL from test server, ignore the output/result
258
290
    system($testcmd);
259
291
 
260
 
    print " CMD: $testcmd\n" if($verbose);
 
292
    logmsg " CMD: $testcmd\n" if($verbose);
261
293
 
262
294
    # memanalyze -v is our friend, get the number of allocations made
263
295
    my $count=0;
269
301
        }
270
302
    }
271
303
    if(!$count) {
272
 
        print " found no allocs to make fail\n";
 
304
        logmsg " found no allocs to make fail\n";
273
305
        return 0;
274
306
    }
275
307
 
276
 
    print " $count allocations to make fail\n";
 
308
    logmsg " $count allocations to make fail\n";
277
309
 
278
310
    for ( 1 .. $count ) {
279
311
        my $limit = $_;
284
316
            next;
285
317
        }
286
318
 
287
 
        print "Fail alloc no: $limit\r" if($verbose);
 
319
        logmsg "Fail alloc no: $limit\r" if($verbose);
288
320
 
289
321
        # make the memory allocation function number $limit return failure
290
322
        $ENV{'CURL_MEMLIMIT'} = $limit;
292
324
        # remove memdump first to be sure we get a new nice and clean one
293
325
        unlink($memdump);
294
326
 
295
 
        print "**> Alloc number $limit is now set to fail <**\n" if($gdbthis);
 
327
        logmsg "**> Alloc number $limit is now set to fail <**\n" if($gdbthis);
296
328
 
297
329
        my $ret;
298
330
        if($gdbthis) {
307
339
 
308
340
        if(-r "core") {
309
341
            # there's core file present now!
310
 
            print " core dumped!\n";
 
342
            logmsg " core dumped!\n";
311
343
            $dumped_core = 1;
312
344
            $fail = 2;
313
345
        }
315
347
        # verify that it returns a proper error code, doesn't leak memory
316
348
        # and doesn't core dump
317
349
        if($ret & 255) {
318
 
            print " system() returned $ret\n";
 
350
            logmsg " system() returned $ret\n";
319
351
            $fail=1;
320
352
        }
321
353
        else {
329
361
                }
330
362
            }
331
363
            if($leak) {
332
 
                print "** MEMORY FAILURE\n";
333
 
                print @memdata;
334
 
                print `$memanalyze -l $memdump`;
 
364
                logmsg "** MEMORY FAILURE\n";
 
365
                logmsg @memdata;
 
366
                logmsg `$memanalyze -l $memdump`;
335
367
                $fail = 1;
336
368
            }
337
369
        }
338
370
        if($fail) {
339
 
            print " Failed on alloc number $limit in test.\n",
 
371
            logmsg " Failed on alloc number $limit in test.\n",
340
372
            " invoke with -t$limit to repeat this single case.\n";
341
373
            stopservers($verbose);
342
374
            exit 1;
343
375
        }
344
376
    }
345
377
 
346
 
    print "torture OK\n";
 
378
    logmsg "torture OK\n";
347
379
    return 0;
348
380
}
349
381
 
360
392
    if($pid =~ / /) {
361
393
        # if it contains space, it might be more than one pid
362
394
        my @pids = split(" ", $pid);
363
 
        for(@pids) {
 
395
        for (@pids) {
364
396
            kill (9, $_); # die!
365
397
        }
366
398
    }
368
400
    my $res = kill (9, $pid); # die!
369
401
 
370
402
    if($verbose) {
371
 
        print "RUN: Test server pid $pid signalled to die\n";
 
403
        logmsg "RUN: Test server pid $pid signalled to die\n";
372
404
    }
373
405
}
374
406
 
384
416
    my $pid;
385
417
 
386
418
    # verify if our/any server is running on this port
387
 
    print "CMD; $cmd\n" if ($verbose);
 
419
    logmsg "CMD; $cmd\n" if ($verbose);
388
420
    my $res = system($cmd);
389
421
 
390
422
    $res >>= 8; # rotate the result
394
426
        open(ERR, "<log/verifyhttp");
395
427
        my @e = <ERR>;
396
428
        close(ERR);
397
 
        print "RUN: curl command returned $res\n";
 
429
        logmsg "RUN: curl command returned $res\n";
398
430
        for(@e) {
399
431
            if($_ !~ /^([ \t]*)$/) {
400
 
                print "RUN: $_";
 
432
                logmsg "RUN: $_";
401
433
            }
402
434
        }
403
435
    }
411
443
    }
412
444
    elsif($res == 6) {
413
445
        # curl: (6) Couldn't resolve host '::1'
414
 
        print "RUN: failed to resolve host\n";
 
446
        logmsg "RUN: failed to resolve host\n";
415
447
        return 0;
416
448
    }
417
449
    elsif($data || ($res != 7)) {
418
 
        print "RUN: Unknown server is running on port $port\n";
 
450
        logmsg "RUN: Unknown server is running on port $port\n";
419
451
        return 0;
420
452
    }
421
453
    return $pid;
434
466
    my $cmd="$CURL -m4 --silent -vg \"$proto://$ip:$port/verifiedserver\" 2>log/verifyftp";
435
467
    # check if this is our server running on this port:
436
468
    my @data=`$cmd`;
437
 
    print "RUN: $cmd\n" if($verbose);
 
469
    logmsg "RUN: $cmd\n" if($verbose);
438
470
    my $line;
439
471
 
440
472
    # if this took more than 2 secs, we assume it "hung" on a weird server
449
481
    }
450
482
    if($pid <= 0 && $data[0]) {
451
483
        # this is not a known server
452
 
        print "RUN: Unknown server on our FTP port: $port\n";
 
484
        logmsg "RUN: Unknown server on our FTP port: $port\n";
453
485
        return 0;
454
486
    }
455
487
    return $pid;
462
494
 
463
495
my %protofunc = ('http' => \&verifyhttp,
464
496
                 'https' => \&verifyhttp,
465
 
                 'ftp' => \&verifyftp);
 
497
                 'ftp' => \&verifyftp,
 
498
                 'tftp' => \&verifyftp);
466
499
 
467
500
sub verifyserver {
468
501
    my ($proto, $ip, $port) = @_;
523
556
 
524
557
    if(!kill(0, $httppid)) {
525
558
        # it is NOT alive
526
 
        print "RUN: failed to start the HTTP server!\n";
 
559
        logmsg "RUN: failed to start the HTTP server!\n";
527
560
        stopservers($verbose);
528
561
        return (0,0);
529
562
    }
530
563
 
531
564
    # Server is up. Verify that we can speak to it.
532
565
    if(!verifyserver("http", $ip, $port)) {
533
 
        print "RUN: HTTP$nameext server failed verification\n";
 
566
        logmsg "RUN: HTTP$nameext server failed verification\n";
534
567
        # failed to talk to it properly. Kill the server and return failure
535
568
        stopserver("$httppid $pid2");
536
569
        return (0,0);
537
570
    }
538
571
 
539
572
    if($verbose) {
540
 
        print "RUN: HTTP$nameext server is now running PID $httppid\n";
 
573
        logmsg "RUN: HTTP$nameext server is now running PID $httppid\n";
541
574
    }
542
575
 
543
576
    sleep(1);
577
610
 
578
611
    if(!kill(0, $httpspid)) {
579
612
        # it is NOT alive
580
 
        print "RUN: failed to start the HTTPS server!\n";
 
613
        logmsg "RUN: failed to start the HTTPS server!\n";
581
614
        stopservers($verbose);
582
615
        return(0,0);
583
616
    }
584
617
 
585
618
    # Server is up. Verify that we can speak to it.
586
619
    if(!verifyserver("https", $ip, $HTTPSPORT)) {
587
 
        print "RUN: HTTPS server failed verification\n";
 
620
        logmsg "RUN: HTTPS server failed verification\n";
588
621
        # failed to talk to it properly. Kill the server and return failure
589
622
        stopserver("$httpspid $pid2");
590
623
        return (0,0);
591
624
    }
592
625
 
593
626
    if($verbose) {
594
 
        print "RUN: HTTPS server is now running PID $httpspid\n";
 
627
        logmsg "RUN: HTTPS server is now running PID $httpspid\n";
595
628
    }
596
629
 
597
630
    sleep(1);
625
658
    if($pid >= 0) {
626
659
        stopserver($pid);
627
660
    }
628
 
    # kill possible still-running slaves
629
 
    ftpkillslaves($verbose);
630
661
 
631
662
    # start our server:
632
663
    my $flag=$debugprotocol?"-v ":"";
639
670
    }
640
671
    $cmd="$perl $srcdir/ftpserver.pl --pidfile $pidfile $flag --port $port";
641
672
 
 
673
    unlink($pidfile);
 
674
 
642
675
    my ($ftppid, $pid2) = startnew($cmd, $pidfile);
643
676
 
644
677
    if(!$ftppid || !kill(0, $ftppid)) {
645
678
        # it is NOT alive
646
 
        print "RUN: failed to start the FTP$id$nameext server!\n";
 
679
        logmsg "RUN: failed to start the FTP$id$nameext server!\n";
647
680
        return -1;
648
681
    }
649
682
 
650
683
    # Server is up. Verify that we can speak to it.
651
684
    if(!verifyserver("ftp", $ip, $port)) {
652
 
        print "RUN: FTP$id$nameext server failed verification\n";
 
685
        logmsg "RUN: FTP$id$nameext server failed verification\n";
653
686
        # failed to talk to it properly. Kill the server and return failure
654
687
        stopserver("$ftppid $pid2");
655
688
        return (0,0);
656
689
    }
657
690
 
658
691
    if($verbose) {
659
 
        print "RUN: FTP$id$nameext server is now running PID $ftppid\n";
 
692
        logmsg "RUN: FTP$id$nameext server is now running PID $ftppid\n";
660
693
    }
661
694
 
662
695
    sleep(1);
665
698
}
666
699
 
667
700
#######################################################################
 
701
# start the tftp server
 
702
#
 
703
sub runtftpserver {
 
704
    my ($id, $verbose, $ipv6) = @_;
 
705
    my $STATUS;
 
706
    my $RUNNING;
 
707
    my $port = $TFTPPORT;
 
708
    # check for pidfile
 
709
    my $pidfile = $TFTPPIDFILE;
 
710
    my $ip=$HOSTIP;
 
711
    my $nameext;
 
712
    my $cmd;
 
713
 
 
714
    if($ipv6) {
 
715
        # if IPv6, use a different setup
 
716
        $pidfile = $TFTP6PIDFILE;
 
717
        $port = $TFTP6PORT;
 
718
        $ip = $HOST6IP;
 
719
        $nameext="-ipv6";
 
720
    }
 
721
 
 
722
    my $pid = checkserver($pidfile);
 
723
    if($pid >= 0) {
 
724
        stopserver($pid);
 
725
    }
 
726
 
 
727
    # start our server:
 
728
    my $flag=$debugprotocol?"-v ":"";
 
729
    $flag .= "-s \"$srcdir\" ";
 
730
    if($id) {
 
731
        $flag .="--id $id ";
 
732
    }
 
733
    if($ipv6) {
 
734
        $flag .="--ipv6 ";
 
735
    }
 
736
    $cmd="./server/tftpd --pidfile $pidfile $flag $port";
 
737
 
 
738
    unlink($pidfile);
 
739
 
 
740
    my ($tftppid, $pid2) = startnew($cmd, $pidfile);
 
741
 
 
742
    if(!$tftppid || !kill(0, $tftppid)) {
 
743
        # it is NOT alive
 
744
        logmsg "RUN: failed to start the FTP$id$nameext server!\n";
 
745
        return -1;
 
746
    }
 
747
 
 
748
    # Server is up. Verify that we can speak to it.
 
749
    if(!verifyserver("tftp", $ip, $port)) {
 
750
        logmsg "RUN: TFTP$id$nameext server failed verification\n";
 
751
        # failed to talk to it properly. Kill the server and return failure
 
752
        stopserver("$tftppid $pid2");
 
753
        return (0,0);
 
754
    }
 
755
 
 
756
    if($verbose) {
 
757
        logmsg "RUN: TFTP$id$nameext server is now running PID $tftppid\n";
 
758
    }
 
759
 
 
760
    sleep(1);
 
761
 
 
762
    return ($pid2, $tftppid);
 
763
}
 
764
 
 
765
 
 
766
#######################################################################
668
767
# Remove all files in the specified directory
669
768
#
670
769
sub cleardir {
700
799
    open(OUT, ">$ofile")
701
800
        || return 1;
702
801
 
703
 
    # print "FILTER: off $filter from $infile to $ofile\n";
 
802
    # logmsg "FILTER: off $filter from $infile to $ofile\n";
704
803
 
705
804
    while(<IN>) {
706
805
        $_ =~ s/$filter//;
724
823
 
725
824
    if($result) {
726
825
        if(!$short) {
727
 
            print "\n $subject FAILED:\n";
728
 
            print showdiff($LOGDIR, $firstref, $secondref);
 
826
            logmsg "\n $subject FAILED:\n";
 
827
            logmsg showdiff($LOGDIR, $firstref, $secondref);
729
828
        }
730
829
        else {
731
 
            print "FAILED\n";
 
830
            logmsg "FAILED\n";
732
831
        }
733
832
    }
734
833
    return $result;
744
843
    my $feat;
745
844
    my $curl;
746
845
    my $libcurl;
747
 
    my @version=`$CURL --version 2>/dev/null`;
 
846
    my $versionerr="$LOGDIR/versionerr.log";
 
847
    my $versioncmd="$CURL --version 2>$versionerr";
 
848
    my @version=`$versioncmd`;
748
849
    for(@version) {
749
850
        chomp;
750
851
 
785
886
                    }
786
887
                }
787
888
                if(!$matchlen) {
788
 
                    print "Serious error, can't find our \"real\" path!\n";
 
889
                    logmsg "Serious error, can't find our \"real\" path!\n";
789
890
                }
790
891
                else {
791
892
                    # now prepend the prefix from the mount command to build
854
955
        }
855
956
    }
856
957
    if(!$curl) {
857
 
        die "couldn't run '$CURL'"
 
958
        logmsg "unable to get curl's version! further details are:\n";
 
959
        logmsg "CURL: \n";
 
960
        logmsg "$CURL \n";
 
961
        logmsg "VERSIONCMD: \n";
 
962
        logmsg "$versioncmd \n";
 
963
        logmsg "STDOUT: \n";
 
964
        for(@version) {
 
965
            chomp;
 
966
            logmsg "$_ \n";
 
967
        }
 
968
        logmsg "STDERR: \n";
 
969
        displaylogcontent("$versionerr");
 
970
        die "couldn't get curl's version!";
858
971
    }
859
972
 
860
973
    if(-r "../lib/config.h") {
892
1005
    my $hostname=`hostname`;
893
1006
    my $hosttype=`uname -a`;
894
1007
 
895
 
    print "********* System characteristics ******** \n",
 
1008
    logmsg ("********* System characteristics ******** \n",
896
1009
    "* $curl\n",
897
1010
    "* $libcurl\n",
898
1011
    "* Features: $feat\n",
899
1012
    "* Host: $hostname",
900
 
    "* System: $hosttype";
901
 
 
902
 
    printf("* Server SSL:     %s\n", $stunnel?"ON":"OFF");
903
 
    printf("* libcurl SSL:    %s\n", $ssl_version?"ON":"OFF");
904
 
    printf("* libcurl debug:  %s\n", $curl_debug?"ON":"OFF");
905
 
    printf("* valgrind:       %s\n", $valgrind?"ON":"OFF");
906
 
    printf("* HTTP IPv6       %s\n", $http_ipv6?"ON":"OFF");
907
 
    printf("* FTP IPv6        %s\n", $ftp_ipv6?"ON":"OFF");
908
 
 
909
 
    printf("* HTTP port:      %d\n", $HTTPPORT);
910
 
    printf("* FTP port:       %d\n", $FTPPORT);
911
 
    printf("* FTP port 2:     %d\n", $FTP2PORT);
 
1013
    "* System: $hosttype");
 
1014
 
 
1015
    logmsg sprintf("* Server SSL:     %s\n", $stunnel?"ON":"OFF");
 
1016
    logmsg sprintf("* libcurl SSL:    %s\n", $ssl_version?"ON":"OFF");
 
1017
    logmsg sprintf("* libcurl debug:  %s\n", $curl_debug?"ON":"OFF");
 
1018
    logmsg sprintf("* valgrind:       %s\n", $valgrind?"ON":"OFF");
 
1019
    logmsg sprintf("* HTTP IPv6       %s\n", $http_ipv6?"ON":"OFF");
 
1020
    logmsg sprintf("* FTP IPv6        %s\n", $ftp_ipv6?"ON":"OFF");
 
1021
 
 
1022
    logmsg sprintf("* HTTP port:      %d\n", $HTTPPORT);
 
1023
    logmsg sprintf("* FTP port:       %d\n", $FTPPORT);
 
1024
    logmsg sprintf("* FTP port 2:     %d\n", $FTP2PORT);
912
1025
    if($stunnel) {
913
 
        #printf("* FTPS port:      %d\n", $FTPSPORT);
914
 
        printf("* HTTPS port:     %d\n", $HTTPSPORT);
 
1026
        #logmsg sprintf("* FTPS port:      %d\n", $FTPSPORT);
 
1027
        logmsg sprintf("* HTTPS port:     %d\n", $HTTPSPORT);
915
1028
    }
916
1029
    if($http_ipv6) {
917
 
        printf("* HTTP IPv6 port: %d\n", $HTTP6PORT);
 
1030
        logmsg sprintf("* HTTP IPv6 port: %d\n", $HTTP6PORT);
918
1031
    }
919
1032
    if($ftp_ipv6) {
920
 
        printf("* FTP IPv6 port:  %d\n", $FTP6PORT);
 
1033
        logmsg sprintf("* FTP IPv6 port:  %d\n", $FTP6PORT);
 
1034
    }
 
1035
    logmsg sprintf("* TFTP port:      %d\n", $TFTPPORT);
 
1036
    if($tftp_ipv6) {
 
1037
        logmsg sprintf("* TFTP IPv6 port: %d\n", $TFTP6PORT);
921
1038
    }
922
1039
    
923
1040
    if($ssl_version) {
924
 
        printf("* SSL library:    %s\n",
 
1041
        logmsg sprintf("* SSL library:    %s\n",
925
1042
               $has_gnutls?"GnuTLS":($has_openssl?"OpenSSL":"<unknown>"));
926
1043
    }
927
1044
 
928
1045
    $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
929
1046
 
930
 
    print "***************************************** \n";
 
1047
    logmsg "***************************************** \n";
931
1048
}
932
1049
 
933
1050
#######################################################################
947
1064
  $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
948
1065
  $$thing =~ s/%SRCDIR/$srcdir/g;
949
1066
  $$thing =~ s/%PWD/$pwd/g;
 
1067
  $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
 
1068
  $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
950
1069
}
951
1070
 
952
1071
sub fixarray {
974
1093
    if(loadtest("${TESTDIR}/test${testnum}")) {
975
1094
        if($verbose) {
976
1095
            # this is not a test
977
 
            print "RUN: $testnum doesn't look like a test case!\n";
 
1096
            logmsg "RUN: $testnum doesn't look like a test case!\n";
978
1097
        }
979
1098
        $why = "no test";
980
1099
    }
1057
1176
                $why = $o[0];
1058
1177
                chomp $why;
1059
1178
            }
 
1179
            logmsg "prechecked $cmd\n" if($verbose);
1060
1180
        }
1061
1181
    }
1062
1182
 
1072
1192
 
1073
1193
        return -1;
1074
1194
    }
1075
 
    printf("test %03d...", $testnum);
1076
 
 
 
1195
    logmsg sprintf("test %03d...", $testnum);
1077
1196
 
1078
1197
    # extract the reply data
1079
1198
    my @reply = getpart("reply", "data");
1119
1238
    if(!$short) {
1120
1239
        my $name = $testname[0];
1121
1240
        $name =~ s/\n//g;
1122
 
        print "[$name]\n";
 
1241
        logmsg "[$name]\n";
1123
1242
    }
1124
1243
 
1125
1244
    if($listonly) {
1182
1301
        my $filename=$fileattr{'name'};
1183
1302
 
1184
1303
        if(!$filename) {
1185
 
            print "ERROR: section client=>file has no name attribute!\n";
 
1304
            logmsg "ERROR: section client=>file has no name attribute!\n";
1186
1305
            return -1;
1187
1306
        }
1188
1307
        my $fileContent = join('', @inputfile);
1189
1308
        subVariables \$fileContent;
1190
 
#        print "DEBUG: writing file " . $filename . "\n";
 
1309
#        logmsg "DEBUG: writing file " . $filename . "\n";
1191
1310
        open OUTFILE, ">$filename";
1192
1311
        binmode OUTFILE; # for crapage systems, use binary
1193
1312
        print OUTFILE $fileContent;
1234
1353
    }
1235
1354
 
1236
1355
    if($valgrind) {
1237
 
        $CMDLINE = "valgrind ".$valgrind_tool."--leak-check=yes --num-callers=16 --logfile=log/valgrind$testnum $CMDLINE";
 
1356
        $CMDLINE = "valgrind ".$valgrind_tool."--leak-check=yes --num-callers=16 ${valgrind_logfile}=log/valgrind$testnum $CMDLINE";
1238
1357
    }
1239
1358
 
1240
1359
    $CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
1241
1360
 
1242
1361
    if($verbose) {
1243
 
        print "$CMDLINE\n";
 
1362
        logmsg "$CMDLINE\n";
1244
1363
    }
1245
1364
 
1246
1365
    print CMDLOG "$CMDLINE\n";
1256
1375
        my $code = join("", @precommand);
1257
1376
        eval $code;
1258
1377
        if($@) {
1259
 
            print "perl: $code\n";
1260
 
            print "precommand: $@";
 
1378
            logmsg "perl: $code\n";
 
1379
            logmsg "precommand: $@";
1261
1380
            stopservers($verbose);
1262
1381
            return -1;
1263
1382
        }
1298
1417
    }
1299
1418
 
1300
1419
    if($dumped_core) {
1301
 
        print "core dumped!\n";
 
1420
        logmsg "core dumped!\n";
1302
1421
        if(0 && $gdb) {
1303
 
            print "running gdb for post-mortem analysis:\n";
 
1422
            logmsg "running gdb for post-mortem analysis:\n";
1304
1423
            open(GDBCMD, ">log/gdbcmd2");
1305
1424
            print GDBCMD "bt\n";
1306
1425
            close(GDBCMD);
1325
1444
        # verify redirected stdout
1326
1445
        my @actual = loadarray($STDOUT);
1327
1446
 
 
1447
        # get all attributes
 
1448
        my %hash = getpartattr("verify", "stdout");
 
1449
 
 
1450
        # get the mode attribute
 
1451
        my $filemode=$hash{'mode'};
 
1452
        if(($filemode eq "text") && $has_textaware) {
 
1453
            # text mode when running on windows: fix line endings
 
1454
            map s/\r\n/\n/g, @actual;
 
1455
        }
 
1456
 
1328
1457
        $res = compare("stdout", \@actual, \@validstdout);
1329
1458
        if($res) {
1330
1459
            return 1;
1339
1468
    if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
1340
1469
        # verify the received data
1341
1470
        my @out = loadarray($CURLOUT);
 
1471
        my %hash = getpartattr("reply", "data");
 
1472
        # get the mode attribute
 
1473
        my $filemode=$hash{'mode'};
 
1474
        if(($filemode eq "text") && $has_textaware) {
 
1475
            # text mode when running on windows: fix line endings
 
1476
            map s/\r\n/\n/g, @out;
 
1477
        }
 
1478
 
1342
1479
        $res = compare("data", \@out, \@reply);
1343
1480
        if ($res) {
1344
1481
            return 1;
1430
1567
 
1431
1568
        my $filename=$hash{'name'};
1432
1569
        if(!$filename) {
1433
 
            print "ERROR: section verify=>file has no name attribute!\n";
 
1570
            logmsg "ERROR: section verify=>file has no name attribute!\n";
1434
1571
            stopservers($verbose);
1435
1572
            return -1;
1436
1573
        }
1437
 
        my $filemode=$hash{'mode'};
1438
 
        
1439
1574
        my @generated=loadarray($filename);
1440
1575
 
1441
1576
        # what parts to cut off from the file
1442
1577
        my @stripfile = getpart("verify", "stripfile");
1443
1578
        
 
1579
        my $filemode=$hash{'mode'};
1444
1580
        if(($filemode eq "text") && $has_textaware) {
1445
1581
            # text mode when running on windows means adding an extra
1446
1582
            # strip expression
1484
1620
        if(!$short) {
1485
1621
            printf "\ncurl returned $cmdres, %s was expected\n", $errorcode;
1486
1622
        }
1487
 
        print " exit FAILED\n";
 
1623
        logmsg " exit FAILED\n";
1488
1624
        return 1;
1489
1625
    }
1490
1626
 
1492
1628
    for(@what) {
1493
1629
        my $serv = $_;
1494
1630
        chomp $serv;
 
1631
        if($serv =~ /^ftp(\d*)(-ipv6|)/) {
 
1632
            my ($id, $ext) = ($1, $2);
 
1633
            print STDERR "SERV $serv $id $ext\n";
 
1634
            ftpkillslave($id, $ext, 1);
 
1635
        }
1495
1636
        if($run{$serv}) {
1496
1637
            stopserver($run{$serv}); # the pid file is in the hash table
1497
1638
            $run{$serv}=0; # clear pid
1498
1639
        }
1499
1640
        else {
1500
 
            print STDERR "RUN: The $serv server is not running\n";
 
1641
            logmsg "RUN: The $serv server is not running\n";
1501
1642
        }
1502
1643
    }
1503
1644
 
1504
1645
    if($curl_debug) {
1505
1646
        if(! -f $memdump) {
1506
 
            print "\n** ALERT! memory debuggin without any output file?\n";
 
1647
            logmsg "\n** ALERT! memory debuggin without any output file?\n";
1507
1648
        }
1508
1649
        else {
1509
1650
            my @memdata=`$memanalyze $memdump`;
1516
1657
                }
1517
1658
            }
1518
1659
            if($leak) {
1519
 
                print "\n** MEMORY FAILURE\n";
1520
 
                print @memdata;
 
1660
                logmsg "\n** MEMORY FAILURE\n";
 
1661
                logmsg @memdata;
1521
1662
                return 1;
1522
1663
            }
1523
1664
            else {
1553
1694
            }
1554
1695
            my @e = valgrindparse($src, $feature{'SSL'}, "log/$l");
1555
1696
            if($e[0]) {
1556
 
                print " valgrind ERROR ";
1557
 
                print @e;
 
1697
                logmsg " valgrind ERROR ";
 
1698
                logmsg @e;
1558
1699
                return 1;
1559
1700
            }
1560
1701
            $ok .= "v";
1561
1702
        }
1562
1703
        else {
1563
1704
            if(!$short) {
1564
 
                print " valgrind SKIPPED";
 
1705
                logmsg " valgrind SKIPPED";
1565
1706
            }
1566
1707
            $ok .= "-"; # skipped
1567
1708
        }
1570
1711
        $ok .= "-"; # valgrind not checked
1571
1712
    }
1572
1713
 
1573
 
    print "$ok " if(!$short);
 
1714
    logmsg "$ok " if(!$short);
1574
1715
 
1575
1716
    my $sofar= time()-$start;
1576
1717
    my $esttotal = $sofar/$count * $total;
1577
1718
    my $estleft = $esttotal - $sofar;
1578
 
    my $left=sprintf("remaining: %dm%ds",
 
1719
    my $left=sprintf("remaining: %02d:%02d",
1579
1720
                     $estleft/60,
1580
1721
                     $estleft%60);
1581
 
    printf "OK ($count out of $total, %s)\n", $left;
 
1722
    printf "OK (%-3d out of %-3d, %s)\n", $count, $total, $left;
1582
1723
 
1583
1724
    # the test succeeded, remove all log files
1584
1725
    if(!$keepoutfiles) {
1598
1739
        my $server = $_;
1599
1740
        my $pids=$run{$server};
1600
1741
        my $pid;
 
1742
        my $prev;
1601
1743
 
1602
1744
        foreach $pid (split(" ", $pids)) {
1603
 
            printf("* kill pid for %-5s => %-5d\n",
1604
 
                   $server, $pid) if($verbose);
1605
 
            stopserver($pid);
 
1745
            if($pid != $prev) {
 
1746
                # no need to kill same pid twice!
 
1747
                logmsg sprintf("* kill pid for %s => %d\n",
 
1748
                               $server, $pid) if($verbose);
 
1749
                stopserver($pid);
 
1750
            }
 
1751
            $prev = $pid;
1606
1752
        }
1607
1753
    }
1608
1754
    ftpkillslaves($verbose);
1625
1771
                if($pid <= 0) {
1626
1772
                    return "failed starting FTP server";
1627
1773
                }
1628
 
                printf ("* pid ftp => %-5d %-5d\n", $pid, $pid2) if($verbose);
 
1774
                printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
1629
1775
                $run{'ftp'}="$pid $pid2";
1630
1776
            }
1631
1777
        }
1635
1781
                if($pid <= 0) {
1636
1782
                    return "failed starting FTP2 server";
1637
1783
                }
1638
 
                printf ("* pid ftp2 => %-5d %-5d\n", $pid, $pid2) if($verbose);
 
1784
                printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
1639
1785
                $run{'ftp2'}="$pid $pid2";
1640
1786
            }
1641
1787
        }
1645
1791
                if($pid <= 0) {
1646
1792
                    return "failed starting FTP-ipv6 server";
1647
1793
                }
1648
 
                printf("* pid ftp-ipv6 => %-5d %-5d\n", $pid,
 
1794
                logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
1649
1795
                       $pid2) if($verbose);
1650
1796
                $run{'ftp-ipv6'}="$pid $pid2";
1651
1797
            }
1656
1802
                if($pid <= 0) {
1657
1803
                    return "failed starting HTTP server";
1658
1804
                }
1659
 
                printf ("* pid http => %-5d %-5d\n", $pid, $pid2) if($verbose);
 
1805
                printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
1660
1806
                $run{'http'}="$pid $pid2";
1661
1807
            }
1662
1808
        }
1666
1812
                if($pid <= 0) {
1667
1813
                    return "failed starting IPv6 HTTP server";
1668
1814
                }
1669
 
                printf("* pid http-ipv6 => %-5d %-5d\n", $pid, $pid2)
 
1815
                logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
1670
1816
                    if($verbose);
1671
1817
                $run{'http-ipv6'}="$pid $pid2";
1672
1818
            }
1693
1839
                if($pid <= 0) {
1694
1840
                    return "failed starting HTTP server";
1695
1841
                }
1696
 
                printf ("* pid http => %-5d %-5d\n", $pid, $pid2) if($verbose);
 
1842
                printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
1697
1843
                $run{'http'}="$pid $pid2";
1698
1844
            }
1699
1845
            if(!$run{'https'}) {
1701
1847
                if($pid <= 0) {
1702
1848
                    return "failed starting HTTPS server (stunnel)";
1703
1849
                }
1704
 
                printf("* pid https => %-5d %-5d\n", $pid, $pid2)
 
1850
                logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
1705
1851
                    if($verbose);
1706
1852
                $run{'https'}="$pid $pid2";
1707
1853
            }
1708
1854
        }
 
1855
        elsif($what eq "tftp") {
 
1856
            if(!$run{'tftp'}) {
 
1857
                ($pid, $pid2) = runtftpserver("", $verbose);
 
1858
                if($pid <= 0) {
 
1859
                    return "failed starting TFTP server";
 
1860
                }
 
1861
                printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
 
1862
                $run{'tftp'}="$pid $pid2";
 
1863
            }
 
1864
        }
 
1865
        elsif($what eq "tftp-ipv6") {
 
1866
            if(!$run{'tftp-ipv6'}) {
 
1867
                ($pid, $pid2) = runtftpserver("", $verbose, "IPv6");
 
1868
                if($pid <= 0) {
 
1869
                    return "failed starting TFTP-IPv6 server";
 
1870
                }
 
1871
                printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
 
1872
                $run{'tftp-ipv6'}="$pid $pid2";
 
1873
            }
 
1874
        }
1709
1875
        elsif($what eq "none") {
1710
 
            print "* starts no server\n" if ($verbose);
 
1876
            logmsg "* starts no server\n" if ($verbose);
1711
1877
        }
1712
1878
        else {
1713
1879
            warn "we don't support a server for $what";
1731
1897
    if(loadtest("${TESTDIR}/test${testnum}")) {
1732
1898
        if($verbose) {
1733
1899
            # this is not a test
1734
 
            print "$testnum doesn't look like a test case!\n";
 
1900
            logmsg "$testnum doesn't look like a test case!\n";
1735
1901
        }
1736
1902
        return "no test";
1737
1903
    }
1853
2019
    my $code = system("valgrind >/dev/null 2>&1");
1854
2020
 
1855
2021
    if(($code>>8) != 1) {
1856
 
        #print "Valgrind failure, disable it\n";
 
2022
        #logmsg "Valgrind failure, disable it\n";
1857
2023
        undef $valgrind;
1858
2024
    }
1859
2025
}
1866
2032
                        # but we follow the same port scheme anyway)
1867
2033
$FTP2PORT =  $base + 5; # FTP server 2 port
1868
2034
$FTP6PORT =  $base + 6; # FTP IPv6 port
 
2035
$TFTPPORT =  $base + 7; # TFTP (UDP) port
 
2036
$TFTP6PORT =  $base + 8; # TFTP IPv6 (UDP) port
 
2037
 
 
2038
#######################################################################
 
2039
# clear and create logging directory:
 
2040
#
 
2041
 
 
2042
cleardir($LOGDIR);
 
2043
mkdir($LOGDIR, 0777);
1869
2044
 
1870
2045
#######################################################################
1871
2046
# Output curl version and host info being tested
1876
2051
}
1877
2052
 
1878
2053
#######################################################################
1879
 
# clear and create logging directory:
1880
 
#
1881
 
cleardir($LOGDIR);
1882
 
mkdir($LOGDIR, 0777);
1883
 
 
1884
 
#######################################################################
1885
2054
# If 'all' tests are requested, find out all test numbers
1886
2055
#
1887
2056
 
1907
2076
# Start the command line log
1908
2077
#
1909
2078
open(CMDLOG, ">$CURLLOG") ||
1910
 
    print "can't log command lines to $CURLLOG\n";
 
2079
    logmsg "can't log command lines to $CURLLOG\n";
1911
2080
 
1912
2081
#######################################################################
1913
2082
 
1915
2084
    my ($file)=@_;
1916
2085
    open(SINGLE, "<$file");
1917
2086
    while(<SINGLE>) {
1918
 
        print " $_";
 
2087
        logmsg " $_";
1919
2088
    }
1920
2089
    close(SINGLE);
1921
2090
}
1928
2097
    closedir DIR;
1929
2098
    my $log;
1930
2099
 
1931
 
    print "== Contents of files in the log/ dir after test $testnum\n";
 
2100
    logmsg "== Contents of files in the log/ dir after test $testnum\n";
1932
2101
    foreach $log (sort @logs) {
1933
2102
        # the log file is not "." or ".." and contains more than zero bytes
1934
2103
        if(($log !~ /\.(\.|)$/) &&
1937
2106
            if($log =~ /^\.nfs/) {
1938
2107
                next;
1939
2108
            }
1940
 
            print "== Start of file $log\n";
 
2109
            logmsg "== Start of file $log\n";
1941
2110
            displaylogcontent("$LOGDIR/$log");
1942
 
            print "== End of file $log\n";
 
2111
            logmsg "== End of file $log\n";
1943
2112
        }
1944
2113
    }
1945
2114
}
1979
2148
        }
1980
2149
        if(!$anyway) {
1981
2150
            # a test failed, abort
1982
 
            print "\n - abort tests\n";
 
2151
            logmsg "\n - abort tests\n";
1983
2152
            last;
1984
2153
        }
1985
2154
    }
2001
2170
my $all = $total + $skipped;
2002
2171
 
2003
2172
if($total) {
2004
 
    printf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
2005
 
           $ok/$total*100);
 
2173
    logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
 
2174
                   $ok/$total*100);
2006
2175
 
2007
2176
    if($ok != $total) {
2008
 
        print "TESTFAIL: These test cases failed: $failed\n";
 
2177
        logmsg "TESTFAIL: These test cases failed: $failed\n";
2009
2178
    }
2010
2179
}
2011
2180
else {
2012
 
    print "TESTFAIL: No tests were performed!\n";
 
2181
    logmsg "TESTFAIL: No tests were performed!\n";
2013
2182
}
2014
2183
 
2015
2184
if($all) {
2016
2185
    my $sofar = time()-$start;
2017
 
    print "TESTDONE: $all tests were considered during $sofar seconds.\n";
 
2186
    logmsg "TESTDONE: $all tests were considered during $sofar seconds.\n";
2018
2187
}
2019
2188
 
2020
2189
if($skipped) {
2021
2190
    my $s=0;
2022
 
    print "TESTINFO: $skipped tests were skipped due to these restraints:\n";
 
2191
    logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
2023
2192
 
2024
2193
    for(keys %skipped) {
2025
2194
        my $r = $_;
2031
2200
        for(0 .. $lasttest) {
2032
2201
            my $t = $_;
2033
2202
            if($teststat[$_] eq $r) {
2034
 
                print ", " if($c);
2035
 
                print $_;
 
2203
                logmsg ", " if($c);
 
2204
                logmsg $_;
2036
2205
                $c++;
2037
2206
            }
2038
2207
        }
2039
 
        print ")\n";
 
2208
        logmsg ")\n";
2040
2209
    }
2041
2210
}
2042
2211
if($total && ($ok != $total)) {