2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
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 https://curl.se/docs/copyright.html.
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.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 # SPDX-License-Identifier: curl
24 ###########################################################################
26 ###########################
27 # What is This Script?
28 ###########################
30 # testcurl.pl is the master script to use for automatic testing of curl
31 # directly off its source repository.
32 # This is written for the purpose of being run from a crontab job or similar
33 # at a regular interval. The output is suitable to be mailed to
34 # curl-autocompile@haxx.se to be dealt with automatically (make sure the
35 # subject includes the word "autobuild" as the mail gets silently discarded
36 # otherwise). The most current build status (with a reasonable backlog) will
37 # be published on the curl site, at https://curl.se/auto/
40 # testcurl.pl [options] [curl-daily-name] > output
44 # --configure=[options] Configure options
45 # --crosscompile This is a crosscompile
46 # --desc=[desc] Description of your test system
47 # --email=[email] Set email address to report as
48 # --extvercmd=[command] Command to use for displaying version with cross compiles.
49 # --mktarball=[command] Command to run after completed test
50 # --name=[name] Set name to report as
51 # --notes=[notes] More human-readable information about this configuration
52 # --nocvsup Don't pull from git even though it is a git tree
53 # --nogitpull Don't pull from git even though it is a git tree
54 # --nobuildconf Don't run buildconf
55 # --noconfigure Don't run configure
56 # --runtestopts=[options] Options to pass to runtests.pl
57 # --setup=[file name] File name to read setup from (deprecated)
58 # --target=[your os] Specify your target environment.
60 # if [curl-daily-name] is omitted, a 'curl' git directory is assumed.
68 # Turn on warnings (equivalent to -w, which can't be used with /usr/bin/env)
71 use vars qw($version $fixed $infixed $CURLDIR $git $pwd $build $buildlog
72 $buildlogname $configurebuild $targetos $confheader $binext
75 use vars qw($name $email $desc $confopts $runtestopts $setupfile $mktarball
76 $extvercmd $nogitpull $nobuildconf $crosscompile
79 # version of this script
80 $version='2023-03-28';
83 # Determine if we're running from git or a canned copy of curl,
84 # or if we got a specific target option or setup file option.
86 if (-f ".git/config") {
94 if ($ARGV[0] =~ /--target=/) {
95 $targetos = (split(/=/, shift @ARGV, 2))[1];
97 elsif ($ARGV[0] =~ /--setup=/) {
98 $setupfile = (split(/=/, shift @ARGV, 2))[1];
100 elsif ($ARGV[0] =~ /--extvercmd=/) {
101 $extvercmd = (split(/=/, shift @ARGV, 2))[1];
103 elsif ($ARGV[0] =~ /--mktarball=/) {
104 $mktarball = (split(/=/, shift @ARGV, 2))[1];
106 elsif ($ARGV[0] =~ /--name=/) {
107 $name = (split(/=/, shift @ARGV, 2))[1];
109 elsif ($ARGV[0] =~ /--email=/) {
110 $email = (split(/=/, shift @ARGV, 2))[1];
112 elsif ($ARGV[0] =~ /--desc=/) {
113 $desc = (split(/=/, shift @ARGV, 2))[1];
115 elsif ($ARGV[0] =~ /--notes=/) {
116 $notes = (split(/=/, shift @ARGV, 2))[1];
118 elsif ($ARGV[0] =~ /--configure=(.*)/) {
122 elsif (($ARGV[0] eq "--nocvsup") || ($ARGV[0] eq "--nogitpull")) {
126 elsif ($ARGV[0] =~ /--nobuildconf/) {
130 elsif ($ARGV[0] =~ /--noconfigure/) {
134 elsif ($ARGV[0] =~ /--crosscompile/) {
138 elsif ($ARGV[0] =~ /--runtestopts=/) {
139 $runtestopts = (split(/=/, shift @ARGV, 2))[1];
142 $CURLDIR=shift @ARGV;
143 $git=0; # a given dir, assume not using git
147 # Do the platform-specific stuff here
148 $confheader = 'curl_config.h';
150 $libext = '.la'; # .la since both libcurl and libcares are made with libtool
151 if ($^O eq 'MSWin32' || $targetos) {
153 # If no target defined on Win32 lets assume vc
156 if ($targetos =~ /vc/ || $targetos =~ /borland/) {
160 elsif ($targetos =~ /mingw/) {
162 if ($^O eq 'MSWin32') {
168 if (($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') &&
169 ($targetos =~ /vc/ || $targetos =~ /mingw32/ ||
170 $targetos =~ /borland/)) {
172 # Set these things only when building ON Windows and for Win32 platform.
173 # FOR Windows since we might be cross-compiling on another system. Non-
174 # Windows builds still default to configure-style builds with curl_config.h.
177 $confheader = 'config-win32.h';
180 $ENV{LC_ALL}="C" if (($ENV{LC_ALL}) && ($ENV{LC_ALL} !~ /^C$/));
181 $ENV{LC_CTYPE}="C" if (($ENV{LC_CTYPE}) && ($ENV{LC_CTYPE} !~ /^C$/));
186 if ($^O eq 'MSWin32') {
187 foreach (glob($target)) {
189 system("rd /s /q $_");
192 system("rm -rf $target");
197 my ($target, $fn) = @_;
198 open(my $fh, "<", $fn) or die;
212 print "testcurl: $text\n";
216 sub logit_spaced($) {
219 print "\ntestcurl: $text\n\n";
226 chdir $pwd; # cd back to the original root dir
228 if ($pwd && $build) {
229 # we have a build directory name, remove the dir
230 logit "removing the $build dir";
231 rmtree "$pwd/$build";
234 # we have a build log output file left, remove it
235 logit "removing the $buildlogname file";
238 logit "ENDING HERE"; # last line logged!
242 sub get_host_triplet {
244 my $configfile = "$pwd/$build/lib/curl_config.h";
246 if(-f $configfile && -s $configfile && open(my $libconfigh, "<", "$configfile")) {
247 while(<$libconfigh>) {
248 if($_ =~ /^\#define\s+OS\s+"*([^"][^"]*)"*\s*/) {
258 if($name && $email && $desc) {
259 # having these fields set are enough to continue, skip reading the setup
264 elsif (open(my $f, "<", "$setupfile")) {
274 $infixed=0; # so that "additional args to configure" works properly first time...
278 print "please enter your name\n";
285 print "please enter your contact email address\n";
292 print "please enter a one line system description\n";
300 print "please enter your additional arguments to configure\n";
301 print "examples: --with-openssl --enable-debug --enable-ipv6\n";
310 open(my $f, ">", "$setupfile") or die;
311 print $f "name='$name'\n";
312 print $f "email='$email'\n";
313 print $f "desc='$desc'\n";
314 print $f "confopts='$confopts'\n";
315 print $f "notes='$notes'\n";
316 print $f "fixed='$fixed'\n";
320 # Enable picky compiler warnings unless explicitly disabled
321 if (($confopts !~ /--enable-debug/) &&
322 ($confopts !~ /--enable-warnings/) &&
323 ($confopts !~ /--disable-warnings/)) {
324 $confopts .= " --enable-warnings";
327 my $str1066os = 'o' x 1066;
329 # Set timestamp to the UTC this script is running. Its value might
330 # be changed later in the script to the value present in curlver.h
331 $timestamp = scalar(gmtime)." UTC";
333 logit "STARTING HERE"; # first line logged, for scripts to trigger on
334 logit 'TRANSFER CONTROL ==== 1120 CHAR LINE' . $str1066os . 'LINE_END';
335 logit "NAME = $name";
336 logit "EMAIL = $email";
337 logit "DESC = $desc";
338 logit "NOTES = $notes";
339 logit "CONFOPTS = $confopts";
340 logit "RUNTESTOPTS = ".$runtestopts;
341 logit "CPPFLAGS = ".$ENV{CPPFLAGS};
342 logit "CFLAGS = ".$ENV{CFLAGS};
343 logit "LDFLAGS = ".$ENV{LDFLAGS};
344 logit "LIBS = ".$ENV{LIBS};
345 logit "CC = ".$ENV{CC};
346 logit "TMPDIR = ".$ENV{TMPDIR};
347 logit "MAKEFLAGS = ".$ENV{MAKEFLAGS};
348 logit "ACLOCAL_FLAGS = ".$ENV{ACLOCAL_FLAGS};
349 logit "PKG_CONFIG_PATH = ".$ENV{PKG_CONFIG_PATH};
350 logit "DYLD_LIBRARY_PATH = ".$ENV{DYLD_LIBRARY_PATH};
351 logit "LD_LIBRARY_PATH = ".$ENV{LD_LIBRARY_PATH};
352 logit "LIBRARY_PATH = ".$ENV{LIBRARY_PATH};
353 logit "SHLIB_PATH = ".$ENV{SHLIB_PATH};
354 logit "LIBPATH = ".$ENV{LIBPATH};
355 logit "target = ".$targetos;
356 logit "version = $version"; # script version
357 logit "date = $timestamp"; # When the test build starts
361 # Make $pwd to become the path without newline. We'll use that in order to cut
362 # off that path from all possible logs and error messages etc.
365 my $have_embedded_ares = 0;
368 if ($git && -d "$CURLDIR/.git") {
369 logit "$CURLDIR is verified to be a fine git source dir";
370 # remove the generated sources to force them to be re-generated each
371 # time we run this test
372 unlink "$CURLDIR/src/tool_hugehelp.c";
373 # find out if curl source dir has an in-tree c-ares repo
374 $have_embedded_ares = 1 if (-f "$CURLDIR/ares/GIT-INFO");
375 } elsif (!$git && -f "$CURLDIR/tests/testcurl.pl") {
376 logit "$CURLDIR is verified to be a fine daily source dir";
377 # find out if curl source dir has an in-tree c-ares extracted tarball
378 $have_embedded_ares = 1 if (-f "$CURLDIR/ares/ares_build.h");
380 mydie "$CURLDIR is not a daily source dir or checked out from git!"
384 # make the path absolute so we can use it everywhere
385 $CURLDIR = File::Spec->rel2abs("$CURLDIR");
388 $buildlogname="buildlog-$$";
389 $buildlog="$pwd/$buildlogname";
391 # remove any previous left-overs
395 # this is to remove old build logs that ended up in the wrong dir
396 foreach (glob("$CURLDIR/buildlog-*")) { unlink $_; }
398 # create a dir to build in
402 logit "build dir $build was created fine";
404 mydie "failed to create dir $build";
407 # get in the curl source tree root
410 # Do the git thing, or not...
415 # update quietly to the latest git
417 logit "skipping git pull (--nogitpull)";
419 logit "run git pull in curl";
420 system("git pull 2>&1");
422 logit "failed to update from curl git ($?), continue anyway" if ($?);
424 # Set timestamp to the UTC the git update took place.
425 $timestamp = scalar(gmtime)." UTC" if (!$gitstat);
428 # get the last 5 commits for show (even if no pull was made)
429 @commits=`git log --pretty=oneline --abbrev-commit -5`;
430 logit "The most recent curl git commits:";
436 if (-d "ares/.git") {
440 logit "skipping git pull (--nogitpull) in ares";
442 logit "run git pull in ares";
443 system("git pull 2>&1");
445 logit "failed to update from ares git ($?), continue anyway" if ($?);
447 # Set timestamp to the UTC the git update took place.
448 $timestamp = scalar(gmtime)." UTC" if (!$gitstat);
451 # get the last 5 commits for show (even if no pull was made)
452 @commits=`git log --pretty=oneline --abbrev-commit -5`;
453 logit "The most recent ares git commits:";
463 logit "told to not run buildconf";
465 elsif ($configurebuild) {
466 # remove possible left-overs from the past
468 unlink "autom4te.cache";
470 # generate the build files
471 logit "invoke autoreconf";
472 open(my $f, "-|", "autoreconf -fi 2>&1") or die;
473 open(my $log, ">", "$buildlog") or die;
482 logit "buildconf was successful";
485 logit "buildconf was successful (dummy message)";
489 # Set timestamp to the one in curlver.h if this isn't a git test build.
490 if ((-f "include/curl/curlver.h") &&
491 (open(my $f, "<", "include/curl/curlver.h"))) {
494 if ($_ =~ /^\#define\s+LIBCURL_TIMESTAMP\s+\"(.+)\".*$/) {
495 my $stampstring = $1;
496 if ($stampstring !~ /DEV/) {
497 $stampstring =~ s/\s+UTC//;
498 $timestamp = $stampstring." UTC";
506 # Show timestamp we are using for this test build.
507 logit "timestamp = $timestamp";
509 if ($configurebuild) {
510 if (-f "configure") {
511 logit "configure created (at least it exists)";
513 mydie "no configure created/found";
516 logit "configure created (dummy message)"; # dummy message to feign success
522 my $x = ($^O eq 'MSWin32') ? '.exe' : '';
523 my $s = ($^O eq 'MSWin32') ? ';' : ':';
525 my @pa = split($s, $p);
535 my $make = findinpath("gmake", "make", "nmake");
537 mydie "Couldn't find make in the PATH";
539 # force to 'nmake' for VC builds
540 $make = "nmake" if ($targetos =~ /vc/);
541 logit "going with $make as make";
543 # change to build dir
546 if ($configurebuild) {
547 # run configure script
548 print `$CURLDIR/configure $confopts 2>&1`;
550 if (-f "lib/Makefile") {
551 logit "configure seems to have finished fine";
553 mydie "configure didn't work";
556 logit "copying files to build dir ...";
557 if ($^O eq 'MSWin32') {
558 system("xcopy /s /q \"$CURLDIR\" .");
559 system("buildconf.bat");
561 elsif ($^O eq 'linux') {
562 system("cp -afr $CURLDIR/* .");
563 system("cp -af $CURLDIR/Makefile.dist Makefile");
564 system("$make -i -C lib -f Makefile.$targetos prebuild");
565 system("$make -i -C src -f Makefile.$targetos prebuild");
566 if (-d "$CURLDIR/ares") {
567 system("cp -af $CURLDIR/ares/ares_build.h.dist ./ares/ares_build.h");
568 system("$make -i -C ares -f Makefile.$targetos prebuild");
573 if(-f "./libcurl.pc") {
574 logit_spaced "display libcurl.pc";
575 if(open(my $f, "<", "libcurl.pc")) {
578 print $ll if(($ll !~ /^ *#/) && ($ll !~ /^ *$/));
584 logit_spaced "display lib/$confheader";
585 open(my $f, "<", "lib/$confheader") or die "lib/$confheader: $!";
591 if (($have_embedded_ares) &&
592 (grepfile("^#define USE_ARES", "lib/$confheader"))) {
594 logit "setup to build ares";
596 if(-f "./ares/libcares.pc") {
597 logit_spaced "display ares/libcares.pc";
598 if(open($f, "<", "ares/libcares.pc")) {
601 print $ll if(($ll !~ /^ *#/) && ($ll !~ /^ *$/));
607 if(-f "./ares/ares_build.h") {
608 logit_spaced "display ares/ares_build.h";
609 if(open($f, "<", "ares/ares_build.h")) {
612 print $ll if(($ll =~ /^ *# *define *CARES_/) && ($ll !~ /__CARES_BUILD_H/));
618 mydie "no ares_build.h created/found";
621 $confheader =~ s/curl/ares/;
622 logit_spaced "display ares/$confheader";
623 if(open($f, "<", "ares/$confheader")) {
634 if ($targetos && !$configurebuild) {
635 logit "$make -f Makefile.$targetos";
636 open($f, "-|", "$make -f Makefile.$targetos 2>&1") or die;
640 open($f, "-|", "$make 2>&1") or die;
648 if (-f "libcares$libext") {
649 logit "ares is now built successfully (libcares$libext)";
651 mydie "ares build failed (libcares$libext)";
654 # cd back to the curl build dir
658 my $mkcmd = "$make -i" . ($targetos && !$configurebuild ? " $targetos" : "");
660 open(my $f, "-|", "$mkcmd 2>&1") or die;
667 if (-f "lib/libcurl$libext") {
668 logit "libcurl was created fine (libcurl$libext)";
671 mydie "libcurl was not created (libcurl$libext)";
674 if (-f "src/curl$binext") {
675 logit "curl was created fine (curl$binext)";
678 mydie "curl was not created (curl$binext)";
681 if (!$crosscompile || (($extvercmd ne '') && (-x $extvercmd))) {
682 logit "display curl${binext} --version output";
683 my $cmd = ($extvercmd ne '' ? $extvercmd.' ' : '')."./src/curl${binext} --version|";
686 # strip CR from output on non-win32 platforms (wine on Linux)
687 s/\r// if ($^O ne 'MSWin32');
693 if ($configurebuild && !$crosscompile) {
694 my $host_triplet = get_host_triplet();
695 # build example programs for selected build targets
696 if(($host_triplet =~ /([^-]+)-([^-]+)-irix(.*)/) ||
697 ($host_triplet =~ /([^-]+)-([^-]+)-aix(.*)/) ||
698 ($host_triplet =~ /([^-]+)-([^-]+)-osf(.*)/) ||
699 ($host_triplet =~ /([^-]+)-([^-]+)-solaris2(.*)/)) {
700 chdir "$pwd/$build/docs/examples";
701 logit_spaced "build examples";
702 open($f, "-|", "$make -i 2>&1") or die;
703 open(my $log, ">", "$buildlog") or die;
713 # build and run full test suite
716 $o = "TEST_F=\"$runtestopts\" ";
718 logit "$make -k ${o}test-full";
719 open($f, "-|", "$make -k ${o}test-full 2>&1") or die;
720 open(my $log, ">", "$buildlog") or die;
729 if (grepfile("^TEST", $buildlog)) {
730 logit "tests were run";
732 mydie "test suite failure";
735 if (grepfile("^TESTFAIL:", $buildlog)) {
736 logit "the tests were not successful";
738 logit "the tests were successful!";
743 my $host_triplet = get_host_triplet();
744 # build example programs for selected cross-compiles
745 if(($host_triplet =~ /([^-]+)-([^-]+)-mingw(.*)/) ||
746 ($host_triplet =~ /([^-]+)-([^-]+)-android(.*)/)) {
747 chdir "$pwd/$build/docs/examples";
748 logit_spaced "build examples";
749 open($f, "-|", "$make -i 2>&1") or die;
750 open(my $log, ">", "$buildlog") or die;
760 # build test harness programs for selected cross-compiles
761 if($host_triplet =~ /([^-]+)-([^-]+)-mingw(.*)/) {
762 chdir "$pwd/$build/tests";
763 logit_spaced "build test harness";
764 open(my $f, "-|", "$make -i 2>&1") or die;
765 open(my $log, ">", "$buildlog") or die;
775 logit_spaced "cross-compiling, can't run tests";
777 # dummy message to feign success
778 print "TESTDONE: 1 tests out of 0 (dummy message)\n";
781 # create a tarball if we got that option.
782 if (($mktarball ne '') && (-x $mktarball)) {
787 mydie "ending nicely";